kinoid
v2.0.0
Published
Unique ID generator
Downloads
122
Maintainers
Readme
kinoid
A JavaScript library for generating unique IDs.
Overview
kinoid generates unique IDs as strings made up of numbers and the 26 lowercase characters of the English alphabet; every string generated by kinoid can be considered as a base-36 number.
The generated IDs are unique because, no matter how many IDs are generated, no ID will ever be the same as one generated previously, nor as any ID that will be generated subsequently, nor as any ID generated simultaneously in any other process running on the same machine.
Features
Each ID is composed of a timestamp (representing milliseconds since the UNIX epoch), a number that identifies the process in which the program runs, and a final number which can be said a serialization value or a singularity factor that guarantees the uniqueness of the ID.
IDs are sortable by time, because they are based on the time they were created. Additionally, the
time an ID was created can be calculated from the ID itself thanks to the decodeId()
function
which returns an object containing, among other things, the date on which that ID was generated.
Warning
IDs are not passwords. Kinoid ensures that each generated id is unique, not unpredictable. No ID has ever been created the same and will never happen in the future. Kinoid is not intended to create cryptographically secure strings.
If you are interested in a library for creating cryptographically secure passwords, try crypto-pwd-generator
Installation
# with npm
npm install kinoid
# with yarn
yarn add kinoid
How to use
import
import kinoid from "kinoid";
const { newId, decodeId } = kinoid();
const id = newId();
console.log(id);
// 26cgyty8lts9s831q
console.log(`The id '${id}' was generated on ${decodeId(id).date.toDateString()}`);
// The id '26cgyty8lts9s831q' was generated on Tue Nov 19 2024
console.log(decodeId(id));
// {
// id: '26cgyty8lts9s831q',
// date: 2024-11-19T16:52:19.962Z,
// singularity: 1134,
// pid: 13934
// }
require
const { newId } = require("kinoid")();
const newBook = {
title: "Love at the time of the inquisition",
author: "John White",
publisher: "Hypercubes",
id: newId(),
};
db.add(newBook);
Contributing
Contributions to this project are welcomed!
Whether you have
- questions, concerns, or suggestions for improving this library
- want to report a bug
- submit a fix
- propose new features
please don't hesitate to reach out to me on GitHub and open an issue.
Disclaimer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.