GithubHelp home page GithubHelp logo

numerum-tech / custom-id Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fazlulkarimweb/custom-id

0.0 0.0 0.0 677 KB

A tiny, unique but customizable, 🀠 human-friendly but secure, encrypted but beautiful,πŸ±β€πŸ‰ string ID generator for JavaScript πŸŽ‰πŸŽ‰πŸŽ‰

License: MIT License

JavaScript 100.00%

custom-id's Introduction

Custom ID

Forked from github.com/fazlulkarimweb/custom-id

A tiny, unique but customizable,🀠 human-friendly but secure, encrypted but beautiful,πŸ±β€πŸ‰intuitive string ID generator for JavaScript πŸŽ‰πŸŽ‰

Inspiration

It is built for both human and machine. We use familiar letters (from given name & email) in our randomly generated ID. People can easily recognize those familiar letters as they use it every time, everyday, every moment. You can randomly generate IDs with uuid or nanoid, but these are not generated for human. These are for machine. But this library is for both of them.

Wy this fork?

Resolve deprecation warning; update dependancy packages to remove npm vulnerability warning; and added a few generation options.

customId({
  name: "Jhon Doe", // Optional
  email: "[email protected]", // Optional
  randomLength: 2, // Optional
  lowerCase: true // Optional
  //New options are :
  prefix:'PRFX',// Optional - prefix the id
  sufix:'SFX',// Optional - sufix the id
  alphaFirst:true // Optional - start with aphabetic chars
});

Wy new package name ?

Unfortunately pull requests to original custom-id are pending... In the meantime at Numerum we will be using this package name for installation : (n-custom-id). Feel free to do like us.

npm installation

npm i n-custom-id

yarn installation

yarn add n-custom-id

Original version Installation

You can still download they original package from here - custom-id npm

npm i n-custom-id

Yarn installation

yarn add n-custom-id

Use Case

As it's human-friendly you can use it as an OTP(one-time password), transaction ID, activation code, SMS code, Invitation key, React component key, Database random ID etc. Your imagination is your limitation. πŸŽ‰πŸŽ‰

Usage

You can generate an ID instantly by giving an empty object as the argument. πŸ‘€πŸ‘€πŸ‘€

var customId = require("n-custom-id");

customId({}); // Voila... A random 8 character string will be generated automatically

The custom ID will be generated in this format -

✌✌** 2 Number + 2 Letter + 2 Number + 2 Letter = 8 characters ** ✌✌

All those number and letter will be generated randomly. We use cryptography to generate ids (if available).

Customizable

The most beautiful & unique advantage of this library is its customizability.

customId({
  name: "Jhon Doe", // Optional
  email: "[email protected]", // Optional
  randomLength: 2, // Optional
  lowerCase: true // Optional
  //New options
  prefix:'PRFX',// Optional - prefix the with whatever string you want
  sufix:'SFX',// Optional - sufix the id with whatever string you want
  alphaFirst:true // Optional - start with aphabetic chars
});

API

customId.name (string || optional)

You can provide a name for randomization. We sanitize the string by removing space, full stop or any special characters. Then we randomize those characters and select required number of characters(by default 2 characters) from those characters.

If no name is provided, we just select two random alphabet.

customId({
  name: "Jhon Doe" // Optional
});

customId.email (string || optional)

You can provide an email too. We sanitize the email and convert it to a string by removing space or any special characters. Then we randomize those characters and select required number of characters(by default 2 characters) from those words.

If no email is provided, we just select two random alphabet.

customId({
  email: "[email protected]" // Optional
});

customId.randomLength (number || optional)

Okay... you need flexibility too. Our by default structure is -

✌✌ 2 Number + 2 Letter + 2 Number + 2 Letter = 8 character random Id✌✌ (For example: 89KL43ZY)

We can alter this pattern too. if we pass customId.randomLength the value of 4, the result will be -

customId({
  randomLength: 4 // Optional // By default it's 2
});

✌✌ ** 4 Number + 4 String + 4 Number + 4 String = 16 character **✌✌ (For example: 9831MKLS7621GHYX)

Power is in your hand. You can make it super strong or super easy. It's your call. Use long key combination for really important random number. And use small key combination like 4K8L for OTP or inivitaion code.

customId.lowerCase (bool || optional)

We sanitize your string by toUpperCase() method. It's for easy readibility. So every ID created is always in uppercase format. But you may want it in lowercase format. You have the freedom. 😎😎

customId({
  lowerCase: true // Optional
});

customId.uniqueId ( number || Optional )

It's all about control & security. If you want to manipulate your randomly generated string, you can give an unique ID. Our encryption based algorithm will use this number to make a totally unpredictable combination of IDs. We just multiply the given number with the randomly generated number and cherrypick required characters from that multiplied number randomly. It's completely optional. You can give a static number or node js environment variable to increase unpredictabilty while generating IDs. This is how we can use both server & client machine to generate random ID. (nightmare for hackers & sniffersπŸ˜‚)

customId({
  uniqueId: 4563 // Optional // You can provide any number
});

React Use Case

react client-id

Example Custom ID

customId({
  name: "Jhon Doe",
  email: "[email protected]"
});

Rendered ID will be like below - 19UI91RR 69KI16LU 64IA13AG 34LA94KC 58ZU48MA

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate. πŸƒβ€πŸƒβ€

License

MIT

custom-id's People

Contributors

fazlulkarimweb avatar ndimorle avatar numerum-tech avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.