uscc-utils
Version:
Utils about unified social credit code | 统一社会信用代码工具方法
74 lines (69 loc) • 1.67 kB
text/typescript
/**
* Result of {@link parseUSCC}
*/
interface ParseResult {
/**
* category of the USCC
*/
category: string;
/**
* whether the USCC is valid
*/
isValid: boolean;
/**
* type of the USCC
*/
type: string;
}
/**
* Options of {@link parseUSCC}
*/
interface ParseOptions {
/**
* placeholder for unknown category
*/
unknownCategory?: string;
/**
* placeholder for unknown type
*/
unknownType?: string;
}
/**
* parse uscc
* @param code - code to parse
* @param options - parse options
* @returns parsed result `ParseResult`
*
* @example
* ```
* import { parseUSCC } from 'uscc-utils'
* parseUSCC('91110108551385082Q') // { isValid: true, category: '工商', type: '企业' }
* ```
*/
declare function parseUSCC(code: string, options?: ParseOptions): ParseResult;
/**
* 校验统一社会信用代码
* @param code - 统一社会信用代码
* @returns 是否有效
*
* @example
* ```
* import { validateUSCC } from 'uscc-utils'
* validateUSCC('91110108551385082Q') // true
* ```
*/
declare function validateUSCC(code: string): boolean;
/**
* 正则 统一社会信用代码
* @see {@link https://www.wikidata.org/wiki/Property:P6795}
* @see {@link https://regexper.com/#%2F%5B1-9ANY%5D%5B1-59%5D%5Cd%7B6%7D%5B%5CdA-Z%5D%7B8%7D%5B%5CdX%5D%5B%5CdA-HJ-NP-RTUW-Y%5D%2F}
*/
declare const USCC_PATTERN: RegExp;
/**
* 登记管理部门代码
*/
declare const USCC_CATEGORY_MAP: Record<string, {
category: string;
map: Record<string, string>;
}>;
export { type ParseOptions, type ParseResult, USCC_CATEGORY_MAP, USCC_PATTERN, parseUSCC, validateUSCC };