mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-mockapi.git
synced 2026-09-01 19:04:25 +00:00
added necessary npm packages
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
# Change Log
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## 1.1.1
|
||||
* Improve performance and reduce size of non-secure ID generator.
|
||||
|
||||
## 1.1
|
||||
* Add non-secure ID generator.
|
||||
* Suggest to use non-secure ID generator for React Native developers.
|
||||
* Reduce size.
|
||||
|
||||
## 1.0.7
|
||||
* Fix documentation.
|
||||
|
||||
## 1.0.6
|
||||
* Fix documentation.
|
||||
|
||||
## 1.0.5
|
||||
* Reduce `nanoid/index` size (by Anton Khlynovskiy).
|
||||
|
||||
## 1.0.4
|
||||
* Reduce npm package size.
|
||||
|
||||
## 1.0.3
|
||||
* Reduce npm package size.
|
||||
|
||||
## 1.0.2
|
||||
* Fix Web Workers support (by Zachary Golba).
|
||||
|
||||
## 1.0.1
|
||||
* Reduce `nanoid/index` size (by Anton Khlynovskiy).
|
||||
|
||||
## 1.0
|
||||
* Use 21 symbols by default (by David Klebanoff).
|
||||
|
||||
## 0.2.2
|
||||
* Reduce `nanoid/generate` size (by Anton Khlynovskiy).
|
||||
* Speed up Node.js random generator.
|
||||
|
||||
## 0.2.1
|
||||
* Fix documentation (by Piper Chester).
|
||||
|
||||
## 0.2
|
||||
* Add `size` argument to `nanoid()`.
|
||||
* Improve performance by 50%.
|
||||
* Reduce library size by 26% (by Vsevolod Rodionov and Oleg Mokhov).
|
||||
|
||||
## 0.1.1
|
||||
* Reduce library size by 5%.
|
||||
|
||||
## 0.1
|
||||
* Initial release.
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
|
||||
|
||||
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.
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
# Nano ID
|
||||
|
||||
<img src="https://ai.github.io/nanoid/logo.svg" align="right"
|
||||
alt="Nano ID logo by Anton Lovchikov" width="180" height="94">
|
||||
|
||||
A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
|
||||
|
||||
**Safe.** It uses cryptographically strong random APIs
|
||||
and tests distribution of symbols.
|
||||
|
||||
**Small.** 143 bytes (minified and gzipped). No dependencies.
|
||||
It uses [Size Limit] to control size.
|
||||
|
||||
**Compact.** It uses a larger alphabet than UUID (`A-Za-z0-9_~`).
|
||||
As result it could reduce ID size from 36 to 21 symbols.
|
||||
|
||||
```js
|
||||
var nanoid = require('nanoid')
|
||||
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B~myT"
|
||||
```
|
||||
|
||||
The generator supports Node.js, React Native, and [all browsers].
|
||||
|
||||
[all browsers]: http://caniuse.com/#feat=getrandomvalues
|
||||
[Size Limit]: https://github.com/ai/size-limit
|
||||
|
||||
<a href="https://evilmartians.com/?utm_source=nanoid">
|
||||
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
|
||||
alt="Sponsored by Evil Martians" width="236" height="54">
|
||||
</a>
|
||||
|
||||
|
||||
## Security
|
||||
|
||||
*See a good article about random generators theory:
|
||||
[Secure random values (in Node.js)]*
|
||||
|
||||
|
||||
### Unpredictability
|
||||
|
||||
Instead of using the unsafe `Math.random()`, Nano ID uses the `crypto` module
|
||||
in Node.js and the Web Crypto API in browsers. This modules use unpredictable
|
||||
hardware random generator.
|
||||
|
||||
|
||||
### Uniformity
|
||||
|
||||
`random % alphabet` is a popular mistake to make when coding an ID generator.
|
||||
The spread will not be even; there will be a lower chance for some symbols
|
||||
to appear compared to others—so it will reduce the number of tries
|
||||
when brute-forcing.
|
||||
|
||||
Nano ID uses a [better algorithm] and is tested for uniformity.
|
||||
|
||||
<img src="img/distribution.png" alt="Nano ID uniformity"
|
||||
width="340" height="135">
|
||||
|
||||
[Secure random values (in Node.js)]: https://gist.github.com/joepie91/7105003c3b26e65efcea63f3db82dfba
|
||||
[better algorithm]: https://github.com/ai/nanoid/blob/master/format.js
|
||||
|
||||
|
||||
## Comparison with UUID
|
||||
|
||||
Nano ID is quite comparable to UUID v4 (random-based).
|
||||
It has a similar number of random bits in the ID
|
||||
(126 in Nano ID and 122 in UUID), so it has a similar collision probability:
|
||||
|
||||
> For there to be a one in a billion chance of duplication,
|
||||
> 103 trillion version 4 IDs must be generated.
|
||||
|
||||
There are two main differences between Nano ID and UUID v4:
|
||||
|
||||
1. Nano ID uses a bigger alphabet, so a similar number of random bits
|
||||
are packed in just 21 symbols instead of 36.
|
||||
2. Nano ID code is 3 times less than `uuid/v4` package:
|
||||
143 bytes instead of 435.
|
||||
|
||||
|
||||
## Benchmark
|
||||
|
||||
```
|
||||
$ ./test/benchmark
|
||||
nanoid 363,539 ops/sec
|
||||
nanoid/generate 352,418 ops/sec
|
||||
uid.sync 332,502 ops/sec
|
||||
uuid/v4 345,867 ops/sec
|
||||
shortid 34,193 ops/sec
|
||||
rndm 2,557,778 ops/sec
|
||||
nanoid/non-secure 2,578,934 ops/sec
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Normal
|
||||
|
||||
The main module uses URL-friendly symbols (`A-Za-z0-9_~`) and returns an ID
|
||||
with 21 characters (to have a collision probability similar to UUID v4).
|
||||
|
||||
```js
|
||||
var nanoid = require('nanoid')
|
||||
model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqLJ"
|
||||
```
|
||||
|
||||
Symbols `-,.()` are not encoded in the URL. If used at the end of a link
|
||||
they could be identified as a punctuation symbol.
|
||||
|
||||
If you want to reduce ID length (and increase collisions probability),
|
||||
you can pass the length as an argument.
|
||||
|
||||
```js
|
||||
nanoid(10) //=> "IRFa~VaY2b"
|
||||
```
|
||||
|
||||
Don’t forget to check safety of your ID length
|
||||
in our [ID collision probability] calculator.
|
||||
|
||||
[ID collision probability]: https://alex7kom.github.io/nano-nanoid-cc/
|
||||
|
||||
|
||||
### React Native and Web Workers
|
||||
|
||||
React Native and Web Worker don’t have access to secure random generator.
|
||||
|
||||
Security is important in ID, when ID should be unpredictable. For instance,
|
||||
in “access by URL” link generation.
|
||||
|
||||
If you don’t need unpredictable IDs, but you need React Native
|
||||
or Web Workers support, you can use non‑secure ID generator.
|
||||
|
||||
```js
|
||||
var nanoid = require('nanoid/non-secure')
|
||||
model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqLJ"
|
||||
```
|
||||
|
||||
|
||||
### Custom Alphabet or Length
|
||||
|
||||
If you want to change the ID's alphabet or length
|
||||
you can use the low-level `generate` module.
|
||||
|
||||
```js
|
||||
var generate = require('nanoid/generate')
|
||||
model.id = generate('1234567890abcdef', 10) //=> "4f90d13a42"
|
||||
```
|
||||
|
||||
Check safety of your custom alphabet and ID length
|
||||
in our [ID collision probability] calculator.
|
||||
You can find popular alphabets in [`nanoid-dictionary`].
|
||||
|
||||
Alphabet must contain 256 symbols or less.
|
||||
Otherwise, the generator will not be secure.
|
||||
|
||||
[ID collision probability]: https://alex7kom.github.io/nano-nanoid-cc/
|
||||
[`nanoid-dictionary`]: https://github.com/CyberAP/nanoid-dictionary
|
||||
|
||||
|
||||
### Custom Random Bytes Generator
|
||||
|
||||
You can replace the default safe random generator using the `format` module.
|
||||
For instance, to use a seed-based generator.
|
||||
|
||||
```js
|
||||
var format = require('nanoid/format')
|
||||
|
||||
function random (size) {
|
||||
var result = []
|
||||
for (var i = 0; i < size; i++) result.push(randomByte())
|
||||
return result
|
||||
}
|
||||
|
||||
format(random, "abcdef", 10) //=> "fbaefaadeb"
|
||||
```
|
||||
|
||||
`random` callback must accept the array size and return an array
|
||||
with random numbers.
|
||||
|
||||
If you want to use the same URL-friendly symbols with `format`,
|
||||
you can get the default alphabet from the `url` file.
|
||||
|
||||
```js
|
||||
var url = require('nanoid/url')
|
||||
format(random, url, 10) //=> "93ce_Ltuub"
|
||||
```
|
||||
|
||||
|
||||
## Tools
|
||||
|
||||
* [ID size calculator] to choice smaller ID size depends on your case.
|
||||
* [`nanoid-dictionary`] with popular alphabets to use with `nanoid/generate`.
|
||||
* [`nanoid-cli`] to generate ID from CLI.
|
||||
* [`nanoid-good`] to be sure that your ID doesn't contain any obscene words.
|
||||
|
||||
[`nanoid-dictionary`]: https://github.com/CyberAP/nanoid-dictionary
|
||||
[ID size calculator]: https://alex7kom.github.io/nano-nanoid-cc/
|
||||
[`nanoid-cli`]: https://github.com/twhitbeck/nanoid-cli
|
||||
[`nanoid-good`]: https://github.com/y-gagar1n/nanoid-good
|
||||
|
||||
|
||||
## Other Programming Languages
|
||||
|
||||
* [C#](https://github.com/codeyu/nanoid-net)
|
||||
* [Clojure and ClojureScript](https://github.com/zelark/nano-id)
|
||||
* [Crystal](https://github.com/mamantoha/nanoid.cr)
|
||||
* [Dart](https://github.com/pd4d10/nanoid)
|
||||
* [Go](https://github.com/matoous/go-nanoid)
|
||||
* [Elixir](https://github.com/railsmechanic/nanoid)
|
||||
* [Haskell](https://github.com/4e6/nanoid-hs)
|
||||
* [Java](https://github.com/aventrix/jnanoid)
|
||||
* [PHP](https://github.com/hidehalo/nanoid-php)
|
||||
* [Python](https://github.com/puyuan/py-nanoid)
|
||||
* [Ruby](https://github.com/radeno/nanoid.rb)
|
||||
* [Rust](https://github.com/nikolay-govorov/nanoid)
|
||||
* [Swift](https://github.com/antiflasher/NanoID)
|
||||
|
||||
Also, [CLI tool] is available to generate IDs from command line.
|
||||
|
||||
[CLI tool]: https://github.com/twhitbeck/nanoid-cli
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Secure random string generator with custom alphabet.
|
||||
*
|
||||
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||
* will not be secure.
|
||||
*
|
||||
* @param {generator} random The random bytes generator.
|
||||
* @param {string} alphabet Symbols to be used in new random string.
|
||||
* @param {size} size The number of symbols in new random string.
|
||||
*
|
||||
* @return {string} Random string.
|
||||
*
|
||||
* @example
|
||||
* var format = require('nanoid/format')
|
||||
*
|
||||
* function random (size) {
|
||||
* var result = []
|
||||
* for (var i = 0; i < size; i++) result.push(randomByte())
|
||||
* return result
|
||||
* }
|
||||
*
|
||||
* format(random, "abcdef", 5) //=> "fbaef"
|
||||
*
|
||||
* @name format
|
||||
* @function
|
||||
*/
|
||||
module.exports = function (random, alphabet, size) {
|
||||
var mask = (2 << Math.log(alphabet.length - 1) / Math.LN2) - 1
|
||||
var step = Math.ceil(1.6 * mask * size / alphabet.length)
|
||||
|
||||
var id = ''
|
||||
while (true) {
|
||||
var bytes = random(step)
|
||||
for (var i = 0; i < step; i++) {
|
||||
var byte = bytes[i] & mask
|
||||
if (alphabet[byte]) {
|
||||
id += alphabet[byte]
|
||||
if (id.length === size) return id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @callback generator
|
||||
* @param {number} bytes The number of bytes to generate.
|
||||
* @return {number[]} Random bytes.
|
||||
*/
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
var random = require('./random')
|
||||
var format = require('./format')
|
||||
|
||||
/**
|
||||
* Low-level function to change alphabet and ID size.
|
||||
*
|
||||
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||
* will not be secure.
|
||||
*
|
||||
* @param {string} alphabet Symbols to be used in ID.
|
||||
* @param {number} size The number of symbols in ID.
|
||||
*
|
||||
* @return {string} Unique ID.
|
||||
*
|
||||
* @example
|
||||
* var generate = require('nanoid/generate')
|
||||
* model.id = generate('0123456789абвгдеё', 5) //=> "8ё56а"
|
||||
*
|
||||
* @name generate
|
||||
* @function
|
||||
*/
|
||||
module.exports = function (alphabet, size) {
|
||||
return format(random, alphabet, size)
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (typeof self === 'undefined' || (!self.crypto && !self.msCrypto)) {
|
||||
throw new Error(
|
||||
'Your browser does not have secure random generator. ' +
|
||||
'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
var crypto = self.crypto || self.msCrypto
|
||||
|
||||
var url = '_~getRandomVcryp0123456789bfhijklqsuvwxzABCDEFGHIJKLMNOPQSTUWXYZ'
|
||||
|
||||
module.exports = function (size) {
|
||||
size = size || 21
|
||||
var id = ''
|
||||
var bytes = crypto.getRandomValues(new Uint8Array(size))
|
||||
while (0 < size--) {
|
||||
id += url[bytes[size] & 63]
|
||||
}
|
||||
return id
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
var random = require('./random')
|
||||
var url = require('./url')
|
||||
|
||||
/**
|
||||
* Generate secure URL-friendly unique ID.
|
||||
*
|
||||
* By default, ID will have 21 symbols to have a collision probability similar
|
||||
* to UUID v4.
|
||||
*
|
||||
* @param {number} [size=21] The number of symbols in ID.
|
||||
*
|
||||
* @return {string} Random string.
|
||||
*
|
||||
* @example
|
||||
* var nanoid = require('nanoid')
|
||||
* model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqL"
|
||||
*
|
||||
* @name nanoid
|
||||
* @function
|
||||
*/
|
||||
module.exports = function (size) {
|
||||
size = size || 21
|
||||
var id = ''
|
||||
var bytes = random(size)
|
||||
while (0 < size--) {
|
||||
id += url[bytes[size] & 63]
|
||||
}
|
||||
return id
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
var url = '_~getRandomVcryp0123456789bfhijklqsuvwxzABCDEFGHIJKLMNOPQSTUWXYZ'
|
||||
|
||||
module.exports = function (size) {
|
||||
size = size || 21
|
||||
var id = ''
|
||||
while (0 < size--) {
|
||||
id += url[Math.floor(Math.random() * 63)]
|
||||
}
|
||||
return id
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"_from": "nanoid@^1.0.2",
|
||||
"_id": "nanoid@1.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-tIMrzc7X0rCP4WK5+FB5jtZXWWazqQkvA1wxg4ZYo5OWDADR0QPFm+ITN2tv2RWnhXXsryinICcO2qQSG3SGGw==",
|
||||
"_location": "/nanoid",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "nanoid@^1.0.2",
|
||||
"name": "nanoid",
|
||||
"escapedName": "nanoid",
|
||||
"rawSpec": "^1.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/json-server"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.1.1.tgz",
|
||||
"_shasum": "6159cc3c985acb7ebd70fb231b0b01f2947ed7a3",
|
||||
"_spec": "nanoid@^1.0.2",
|
||||
"_where": "D:\\izyim-mockapi\\node_modules\\json-server",
|
||||
"author": {
|
||||
"name": "Andrey Sitnik",
|
||||
"email": "andrey@sitnik.ru"
|
||||
},
|
||||
"browser": {
|
||||
"./random.js": "./random.browser.js",
|
||||
"./index.js": "./index.browser.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ai/nanoid/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A tiny (145 bytes), secure URL-friendly unique string ID generator",
|
||||
"homepage": "https://github.com/ai/nanoid#readme",
|
||||
"keywords": [
|
||||
"uuid",
|
||||
"random",
|
||||
"id",
|
||||
"url"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "nanoid",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ai/nanoid.git"
|
||||
},
|
||||
"version": "1.1.1"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
var crypto = self.crypto || self.msCrypto
|
||||
|
||||
module.exports = function (bytes) {
|
||||
return crypto.getRandomValues(new Uint8Array(bytes))
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('crypto').randomBytes
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* URL safe symbols.
|
||||
*
|
||||
* @name url
|
||||
* @type {string}
|
||||
*
|
||||
* @example
|
||||
* var url = require('nanoid/url')
|
||||
* generate(url, 10) //=> "Uakgb_J5m9"
|
||||
*/
|
||||
module.exports =
|
||||
'_~0123456789' +
|
||||
'abcdefghijklmnopqrstuvwxyz' +
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
Reference in New Issue
Block a user