Skip to content

v3.0.0

Latest
Compare
Choose a tag to compare
@Edditoria Edditoria released this 30 Sep 18:37
· 1 commit to main since this release

The entire codebase is re-written to:

  • Catch up the ecosystem of Javascript and NodeJS.
  • Provide better experience of LSP and auto-completion.
  • More functions and variables for UI.
  • Support existing functions in v2, although they will deprecate eventually.

Radical Changes:

  • Decaffeinate: Coffeescript → ECMAScript
    • JSDoc for your code-editing experience.
    • Suppose Typescript LSP should work, too.
  • Returns boolean → Returns an object
    • Before: validid.hkid('X') // returns false.
    • Now: validateHkid('X') // returns { ok: false, status: ... }.
    • The validation functions returns reason of failure, or simply valid.
    • Type definition in 📁 validid/esm/response.mjs.
  • One giant object validid → Node's package system
    • Before: import validid from 'validid'.
    • Now: import { validateHkid } from 'validid/hkid'.
    • Code are grouped using modules, including utils, response and ones for each card type.
    • Adapt "conditional exports" of NodeJS's package system.
    • For overview, please read "exports" object in 📁 package.json.
  • Default export → Named export
    • The default exports in v2 are now named export with keyword "validate", e.g. validateHkid.
    • To experience, type the keyword "validate" for auto-completion in common text editors.
    • There are some variables and functions in each module. Please search and see the export keyword in the code.
    • For example, the module "hkid" exports validateHkid as the core feature of HKID. It also exports HKID_PATTERN, HkidStatus, validateHkidLength and getHkidDigit for your usage.

Feature changes:

  • The "twid" module
    • The Taiwan government launched new numbering format of Resident Certificate to create a friendly environment for foreign nationals living in Taiwan. I believe that the code should reflect this. I am happily support equality in Taiwan.
    • Therefore, validateTwid() now validate Taiwan NIC and RC together.
    • You can use identifyTwidType() and identifyTwrcVersion() after the validation.
  • The "krid" module
    • The validateKrid() does not validate any checksum anymore.
  • The "utils" functions are updated as well. Please read the code in 📁 esm/utils.mjs.

The old functions are deprecated, but they are still available in the codebase in v3.

However, you still need to update your code because those old things will be removed eventually.

In short, you may want to update the code like this:

import { validateHkid } from 'validid/hkid';
const answer = validateHkid(inputId);
const isValid = answer.ok;

For CommonJS, all exports are flattened in a single bundled file:

const { validateHkid } = require('validid'); // Required the bundled UMD file.
const answer = validateHkid(inputId);
const isValid = answer.ok;

Currently there is no plan to build CJS modules, tho.

Thanks for your reading.

May the smoothness be with you!