Utils about unified social credit code(统一社会信用代码工具方法).
npm i uscc-utilsyarn add uscc-utilspnpm add uscc-utilsimport { parseUSCC, validateUSCC } from 'uscc-utils'
const code = '91110108551385082Q' // 小米科技有限责任公司
validateUSCC(code) // true
parseUSCC(code) // { isValid: true, category: '工商', type: '企业' }Check if the given code match the uscc pattern.
Type definition:
interface ValidateOptions {
normalize?: boolean
}
function validateUSCC(code: string, options?: ValidateOptions): booleanReturn detailed validation result.
Type definition:
type USCCValidationErrorCode =
| 'INVALID_LENGTH'
| 'INVALID_PATTERN'
| 'INVALID_CHECKSUM'
interface ValidateUSCCResult {
normalizedCode: string
isValid: boolean
errorCode?: USCCValidationErrorCode
}
function explainUSCC(
code: string,
options?: ValidateOptions,
): ValidateUSCCResultSplit valid uscc to structural parts.
Type definition:
interface USCCParts {
registrationAuthorityCode: string
entityTypeCode: string
regionCode: string
organizationCode: string
checkChar: string
}
function splitUSCC(code: string, options?: ValidateOptions): USCCParts | nullParse the given uscc.
Type definition:
interface ParseOptions {
unknownCategory?: string
unknownType?: string
normalize?: boolean
}
interface ParseResult {
isValid: boolean
category: string
type: string
}
function parseUSCC(code: string, options?: ParseOptions): ParseResult