├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── english.js ├── index.js ├── lowercase.js ├── nolookalikes.js ├── numbers.js ├── package-lock.json ├── package.json └── uppercase.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | ## 1.1.0 4 | 5 | - Added alphanumeric set thanks to @crazycto (#1)[https://github.com/CyberAP/nanoid-generate/pull/1] 6 | 7 | ## 1.0.0 8 | 9 | - First release 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Stanislav Lashmanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nanoid-generate 2 | 3 | Custom [nanoid generate](https://github.com/ai/nanoid#custom-alphabet-or-length) functions with predefined character sets. Uses [nanoid-dictionary](https://github.com/CyberAP/nanoid-dictionary) as a dictionary. 4 | 5 | ## Usage 6 | 7 | Install nanoid-generate 8 | 9 | `npm i nanoid-generate -S` 10 | 11 | Then pick a desired generator and set its' output string length 12 | 13 | ```javascript 14 | const generate = require('nanoid-generate'); 15 | 16 | const englishRandomString = generate.english(10); 17 | ``` 18 | 19 | Or instead require a specific generator 20 | 21 | ```javascript 22 | const nolookalikes = require('nanoid-generate/nolookalikes'); 23 | 24 | const nolookalikesRndString = nolookalikes(10); 25 | ``` 26 | 27 | ## Generators 28 | 29 | ### `numbers` 30 | 31 | Numbers from 0 to 9 32 | 33 | ```javascript 34 | const numbers = require('nanoid-generator/numbers'); 35 | ``` 36 | 37 | ### `lowercase` 38 | 39 | Lowercase English letters. 40 | 41 | ```javascript 42 | const englishLowercase = require('nanoid-generator/lowercase'); 43 | ``` 44 | 45 | ### `uppercase` 46 | 47 | Uppercase English letters. 48 | 49 | ```javascript 50 | const englishUppercase = require('nanoid-generator/uppercase'); 51 | ``` 52 | 53 | ### `alphanumeric` 54 | 55 | Uppercase and lowercase English letters with numbers. 56 | 57 | ```javascript 58 | const alphanumeric = require('nanoid-generator/alphanumeric'); 59 | ``` 60 | 61 | ### `english` 62 | 63 | English alphabet. 64 | 65 | ```javascript 66 | const englishUppercase = require('nanoid-generator/english'); 67 | ``` 68 | 69 | ### `nolookalikes` 70 | 71 | Numbers and english alphabet without lookalikes: `1`, `l`, `I`, `0`, `O`, `o`, `u`, `v` 72 | 73 | ```javascript 74 | const nolookalikes = require('nanoid-generator/nolookalikes'); 75 | ``` 76 | -------------------------------------------------------------------------------- /english.js: -------------------------------------------------------------------------------- 1 | const generate = require('nanoid/generate'); 2 | const lowercase = require('nanoid-dictionary/lowercase'); 3 | const uppercase = require('nanoid-dictionary/uppercase'); 4 | const english = lowercase + uppercase; 5 | 6 | module.exports = generate.bind(null, english); -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const generate = require('nanoid/generate'); 2 | const dictionary = require('nanoid-dictionary'); 3 | const lowercase = dictionary.lowercase; 4 | const uppercase = dictionary.uppercase; 5 | const english = lowercase + uppercase; 6 | const alphanumeric = uppercase + lowercase + dictionary.numbers; 7 | 8 | module.exports = { 9 | lowercase: generate.bind(null, lowercase), 10 | uppercase: generate.bind(null, uppercase), 11 | english: generate.bind(null, english), 12 | numbers: generate.bind(null, dictionary.numbers), 13 | nolookalikes: generate.bind(null, dictionary.nolookalikes), 14 | alphanumeric: generate.bind(null, alphanumeric), 15 | } 16 | -------------------------------------------------------------------------------- /lowercase.js: -------------------------------------------------------------------------------- 1 | const generate = require('nanoid/generate'); 2 | const lowercase = require('nanoid-dictionary/lowercase'); 3 | 4 | module.exports = generate.bind(null, lowercase); -------------------------------------------------------------------------------- /nolookalikes.js: -------------------------------------------------------------------------------- 1 | const generate = require('nanoid/generate'); 2 | const nolookalikes = require('nanoid-dictionary/nolookalikes'); 3 | 4 | module.exports = generate.bind(null, nolookalikes); -------------------------------------------------------------------------------- /numbers.js: -------------------------------------------------------------------------------- 1 | const generate = require('nanoid/generate'); 2 | const numbers = require('nanoid-dictionary/numbers'); 3 | 4 | module.exports = generate.bind(null, numbers); -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nanoid-generate", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "nanoid": { 8 | "version": "2.0.0", 9 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.0.0.tgz", 10 | "integrity": "sha512-SG2qscLE3iM4C0CNzGrsAojJHSVHMS1J8NnvJ31P1lH8P0hGHOiafmniNJz6w6q7vuoDlV7RdySlJgtqkFEVtQ==" 11 | }, 12 | "nanoid-dictionary": { 13 | "version": "2.0.0", 14 | "resolved": "https://registry.npmjs.org/nanoid-dictionary/-/nanoid-dictionary-2.0.0.tgz", 15 | "integrity": "sha512-mjMNB0yg2lH6stvxeZs2sBFhwhMwoYdbevPT5DYMxk8iDTI3vAZ6YAvHm+uBFT4VvGITpPpBX1U0sWVRTlPzOA==" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nanoid-generate", 3 | "version": "1.1.0", 4 | "description": "Nanoid generate with custom dictionaries", 5 | "main": "index.js", 6 | "author": "Stanislav Lashmanov ", 7 | "license": "MIT", 8 | "repository": "github:CyberAP/nanoid-generate", 9 | "dependencies": { 10 | "nanoid": "^2.0.0", 11 | "nanoid-dictionary": "^2.0.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /uppercase.js: -------------------------------------------------------------------------------- 1 | const generate = require('nanoid/generate'); 2 | const uppercase = require('nanoid-dictionary/uppercase'); 3 | 4 | module.exports = generate.bind(null, uppercase); --------------------------------------------------------------------------------