-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v1.x' of github.com:ct-js/ct-js into v1.x
- Loading branch information
Showing
8 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Nano ID for ct.js | ||
|
||
This catmod is a bit modified and minified `nanoid` [npm module](https://github.com/ai/nanoid). The original module is made by Andrey Sitnik and dozens of contributors, and is distributed under the MIT license. | ||
|
||
Nano ID is an URL-friendly, secure ID generator that is shorter but more collision-resilient than GUID. | ||
|
||
# Usage | ||
|
||
```js | ||
// Regular ID | ||
var id = ct.nanoid.generate() //=> "V1StGXR8_Z5jdHi6B-myT" | ||
// An ID of a specific size | ||
var shortId = ct.nanoid.generate(10) //=> "IRFa-VaY2b" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Nano ID (https://github.com/ai/nanoid) | ||
The MIT License (MIT) | ||
Copyright 2017 Andrey Sitnik <[email protected]> | ||
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. | ||
*/ | ||
|
||
(function(exports){'use strict';let urlAlphabet='ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW';if(typeof crypto==='undefined'){throw new Error('Your browser does not have secure random generator. If you don’t need unpredictable IDs, you can use nanoid/non-secure.')}let random=bytes=>crypto.getRandomValues(new Uint8Array(bytes));let customRandom=(alphabet,size,getRandom)=>{let mask=(2<<(Math.log(alphabet.length-1)/Math.LN2))-1;let step= - ~((1.6*mask*size)/alphabet.length);return()=>{let id='';while(true){let bytes=getRandom(step);let j=step;while(j--){id+=alphabet[bytes[j]&mask]||'';if(id.length===size){return id}}}}};let customAlphabet=(alphabet,size)=>customRandom(alphabet,size,random);let nanoid=(size=21)=>{let id='';let bytes=crypto.getRandomValues(new Uint8Array(size));while(size--){let byte=bytes[size]&63;if(byte<36){id+=byte.toString(36)}else if(byte<62){id+=(byte-26).toString(36).toUpperCase()}else if(byte<63){id+='_'}else{id+='-'}}return id};exports.customAlphabet=customAlphabet;exports.customRandom=customRandom;exports.generate=nanoid;exports.random=random;exports.urlAlphabet=urlAlphabet;return exports}(ct.nanoid={})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"main": { | ||
"name": "Nano ID", | ||
"tagline": "A tiny, secure, URL-friendly, unique string ID generator for JavaScript, bundled for ct.js.", | ||
"version": "3.1.20", | ||
"packageName": "nanoid", | ||
"authors": [{ | ||
"name": "Andrey Sitnik and contributors" | ||
}], | ||
"categories": [ | ||
"utilities" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters