From 21caa7ce63d54be392ac62e4fc7cbc61d6d6ec71 Mon Sep 17 00:00:00 2001 From: Cosmo Myzrail Gorynych Date: Sat, 20 Feb 2021 21:42:45 +1200 Subject: [PATCH] :sparkles: Nano ID catmod of the same-named tiny library by Andrei Sitnik --- app/data/ct.libs/nanoid/README.md | 14 ++++++++++++++ app/data/ct.libs/nanoid/index.js | 26 ++++++++++++++++++++++++++ app/data/ct.libs/nanoid/module.json | 14 ++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 app/data/ct.libs/nanoid/README.md create mode 100644 app/data/ct.libs/nanoid/index.js create mode 100644 app/data/ct.libs/nanoid/module.json diff --git a/app/data/ct.libs/nanoid/README.md b/app/data/ct.libs/nanoid/README.md new file mode 100644 index 000000000..21d3b6124 --- /dev/null +++ b/app/data/ct.libs/nanoid/README.md @@ -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" +``` diff --git a/app/data/ct.libs/nanoid/index.js b/app/data/ct.libs/nanoid/index.js new file mode 100644 index 000000000..bc9eb3159 --- /dev/null +++ b/app/data/ct.libs/nanoid/index.js @@ -0,0 +1,26 @@ +/* +Nano ID (https://github.com/ai/nanoid) + +The MIT License (MIT) + +Copyright 2017 Andrey Sitnik + +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={})); diff --git a/app/data/ct.libs/nanoid/module.json b/app/data/ct.libs/nanoid/module.json new file mode 100644 index 000000000..d60e3bb8c --- /dev/null +++ b/app/data/ct.libs/nanoid/module.json @@ -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" + ] + } +}