1.0.5 ā¢ Published 10 months ago
@alg-mapper/string-tools v1.0.5
@alg-mapper/string-tools
@alg-mapper/string-tools
is a package that provides easy-to-use string tools, such as generating unique IDs and random strings.
Installation
To install the package, run the following command:
npm install @alg-mapper/string-tools
Usage
Here's an example of how to use it..
const { string } = require('@alg-mapper/string-tools');
const tools = string();
// generate a unique string with numbers.
console.log(tools.generateUniqueString(10)); // { value: 'dP9HD4Wg7V' }
// generate a random id with options
let options = {
numbers: true,
special: false
};
console.log(tools.generateRandomID(10, options)); // { value: 'U1mm3PgK30' }
// generate a random string
console.log(tools.generateRandomString(10, { from:"zxcvbnmasdfghjklqwertyuui" })); // { value: 'rzcuseewmi' }
Options and functions
Function | Option | Type | Default | Description |
---|---|---|---|---|
generateUniqueString() | caps | boolean | true | If true , the generated ID may contain capital letters. |
generateUniqueString() | ignoreLengthError | boolean | false | If true , it will ignore the length error. |
generateRandomID() | numbers | boolean | false | If true , the generated ID will include numbers. |
generateRandomID() | special | boolean | true | If true , the generated ID will include special characters like !@#$%. |
generateRandomID() | strong | boolean | false | If true , the generated ID will be made stronger with some random numbers from timestamp. |
generateRandomID() | caps | boolean | true | If true , the generated ID may contain capital letters. |
generateRandomString() | from | string | "abcdefghijklmnopqrstuvwxyz" | generate random string from the given value |
generateRandomString() | ignoreLengthError | boolean | false | If true , it will ignore the length error. |
š More helpful functions are on the way!
š This package was originally created for personal use, but I decided to share it with the world.
š Stay tuned for more awesome new functions!