Small, zero-dependency library for quick generation of some kind of keys.
Our team creates fully open-source tools and solutions for developers, designers, and those who teach these subjects. You can help us: share this tool, contribute to it, or donate to us to support future work.
Just add the NPM package to your program:
npm i keycrafter
Import necessary functions to your module. Supports CommonJS "require" & ESM "import" For example:
const { generateKey } = require("keycrafter")
or
import { generateKey } from "keycrafter"
Then call the function:
const key = generateKey()
Receive no arguments or option object with several parameters
Now library can generate two types of codes: digit (default) and string.
Only positive integers are supported. The max value for the digit is 16, for the string – 32.
Function cat receives no arguments. In this way, the key will be generated with the parameters:
- type: "digit" (only digit symbols will be presented)
- length: 4. For example, 0000
If any of the options parameters won't be presented in options, the default one will be passed.
The function returns a string (regardless of type) with the new key.
The module provides an error, when something goes wrong. You can catch this error in handling the pattern you choose in the project.