1.2.1 • Published 2 years ago

hkid v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

hkid

Generate and Validate HKID

npm version Node.js CI codecov Known Vulnerabilities FOSSA Status

Installation

yarn add hkid

Usage

import * as hkid from "hkid";

random()

generate valid HKID randomly

console.log(hkid.random()); // H3497811

validate(candidate: string, option?: { checkPrefix?: boolean})

validate HKID

  • checkPrefix: check candidate against the known prefix list. If the prefix of candidate is not in the list, consider it as validation failure. (default: false)

    Note: the known prefix list may be incomplete, so false negative may be returned if checkPrefix is set to true.

console.log(hkid.validate("H3497811")); // true
console.log(hkid.validate("h3497811")); // true
console.log(hkid.validate("H349781(1)")); // true

console.log(hkid.validate("H3497810")); // false

console.log(hkid.validate("YK1597716")); // true
console.log(hkid.validate("YK1597716", { checkPrefix: false})); // true
console.log(hkid.validate("YK1597716", { checkPrefix: true})); // false

CodeSandbox

References

License

FOSSA Status

1.2.1

2 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago