@gram-data/gram-identity
Advanced tools
Comparing version 0.3.9-alpha.2 to 0.3.9
@@ -77,32 +77,20 @@ (function (global, factory) { | ||
// All bundlers will remove this block in the production bundle. | ||
if ( | ||
typeof navigator !== 'undefined' && | ||
navigator.product === 'ReactNative' && | ||
typeof crypto === 'undefined' | ||
) { | ||
throw new Error( | ||
'React Native does not have a built-in secure random generator. ' + | ||
'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' + | ||
'For secure IDs, import `react-native-get-random-values` ' + | ||
'before Nano ID. If you use Expo, install `expo-random` ' + | ||
'and use `nanoid/async`.' | ||
) | ||
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative' && typeof crypto === 'undefined') { | ||
throw new Error('React Native does not have a built-in secure random generator. ' + 'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' + 'For secure IDs, import `react-native-get-random-values` ' + 'before Nano ID. If you use Expo, install `expo-random` ' + 'and use `nanoid/async`.'); | ||
} | ||
if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') { | ||
throw new Error( | ||
'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' + | ||
' before importing Nano ID to fix IE 11 support' | ||
) | ||
throw new Error('Import file with `if (!window.crypto) window.crypto = window.msCrypto`' + ' before importing Nano ID to fix IE 11 support'); | ||
} | ||
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.' | ||
) | ||
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)); | ||
var random = function random(bytes) { | ||
return crypto.getRandomValues(new Uint8Array(bytes)); | ||
}; | ||
let customRandom = (alphabet, size, getRandom) => { | ||
var customRandom = function customRandom(alphabet, size, getRandom) { | ||
// First, a bitmask is necessary to generate the ID. The bitmask makes bytes | ||
@@ -113,11 +101,8 @@ // values closer to the alphabet size. The bitmask calculates the closest | ||
// `Math.clz32` is not used, because it is not available in browsers. | ||
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1; | ||
// Though, the bitmask solution is not perfect since the bytes exceeding | ||
var mask = (2 << Math.log(alphabet.length - 1) / Math.LN2) - 1; // Though, the bitmask solution is not perfect since the bytes exceeding | ||
// the alphabet size are refused. Therefore, to reliably generate the ID, | ||
// the random bytes redundancy has to be satisfied. | ||
// Note: every hardware random generator call is performance expensive, | ||
// because the system call for entropy collection takes a lot of time. | ||
// So, to avoid additional system calls, extra bytes are requested in advance. | ||
// Next, a step determines how many random bytes to generate. | ||
@@ -127,23 +112,26 @@ // The number of random bytes gets decided upon the ID size, mask, | ||
// according to benchmarks). | ||
// `-~f => Math.ceil(f)` if f is a float | ||
// `-~i => i + 1` if i is an integer | ||
let step = -~((1.6 * mask * size) / alphabet.length); | ||
return () => { | ||
let id = ''; | ||
var step = -~(1.6 * mask * size / alphabet.length); | ||
return function () { | ||
var id = ''; | ||
while (true) { | ||
let bytes = getRandom(step); | ||
// A compact alternative for `for (var i = 0; i < step; i++)`. | ||
let j = step; | ||
var bytes = getRandom(step); // A compact alternative for `for (var i = 0; i < step; i++)`. | ||
var j = step; | ||
while (j--) { | ||
// Adding `|| ''` refuses a random byte that exceeds the alphabet size. | ||
id += alphabet[bytes[j] & mask] || ''; | ||
if (id.length === size) return id | ||
if (id.length === size) return id; | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random); | ||
var customAlphabet = function customAlphabet(alphabet, size) { | ||
return customRandom(alphabet, size, random); | ||
}; | ||
@@ -150,0 +138,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e=e||self).gram=e.gram||{},e.gram.identity={}))}(this,(function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e}).apply(this,arguments)}var r={base2:"01",dieBase6:"⚀⚁⚂⚃⚄⚅",base8:"01234567",base10:"0123456789",astrologyBase12:"♈︎♉︎♊︎♋︎♌︎♍︎♎︎♏︎♐︎♑︎♒︎♓︎",base11:"0123456789a",chessBase12:"♚♛♜♝♞♟♔♕♖♗♘♙",base16:"0123456789abcdef",dominoBase28:"🁣🁤🁫🁥🁬🁳🁦🁭🁴🁻🁧🁮🁵🁼🂃🁨🁯🁶🁽🂊🂋🁩🁰🁷🁾🂅🂌🂓",base32:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",zBase32:"ybndrfg8ejkmcpqxot1uwisza345h769",crock32:"0123456789ABCDEFGHJKMNPQRSTVWXYZ",base32Hex:"0123456789ABCDEFGHIJKLMNOPQRSTUV",base36:"0123456789abcdefghijklmnopqrstuvwxyz",mahjongBase43:"🀑🀒🀓🀔🀕🀖🀗🀘🀙🀚🀛🀜🀝🀞🀟🀠🀡🀇🀈🀉🀊🀋🀌🀍🀎🀏🀀🀁🀂🀃🀄︎🀅🀆🀐🀢🀣🀤🀥🀦🀧🀨🀩🀪",cards56:"🂡🂢🂣🂤🂥🂦🂧🂨🂩🂪🂫🂬🂭🂮🂱🂲🂳🂴🂵🂶🂷🂸🂹🂺🂻🂼🂽🂾🃁🃂🃃🃄🃅🃆🃇🃈🃉🃊🃋🃌🃍🃎🃑🃒🃓🃔🃕🃖🃗🃘🃙🃝🃞",base58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",flickrBase58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",base62:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",base64:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@",cookieBase90:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+-./:<=>?@[]^_`{|}~"},a=function(e){var t=0;return{generate:function(){return""+(e||"")+t++}}};let n=e=>crypto.getRandomValues(new Uint8Array(e));var o=function(e,t,a){void 0===e&&(e=r.base64),void 0===t&&(t=21);var o=((e,t)=>((e,t,r)=>{let a=(2<<Math.log(e.length-1)/Math.LN2)-1,n=-~(1.6*a*t/e.length);return()=>{let o="";for(;;){let i=r(n),s=n;for(;s--;)if(o+=e[i[s]&a]||"",o.length===t)return o}}})(e,t,n))(e,t);return{generate:function(){return a?a+o():o()}}},i=require("unist-util-visit"),s={generator:"counter",alphabet:r.base58,prefix:void 0};e.alphabets=r,e.counterIDGenerator=a,e.gramIdentityPlugin=function(e){var r=t({},s,e);return function(e){var t;switch(r.generator){case"nanoid":t=o(r.alphabet,21,r.prefix);break;case"counter":default:t=a(r.prefix)}i(e,(function(e){var r;(r=e).type&&"path"===r.type&&(e.id=e.id||t.generate())}))}},e.nanoidGenerator=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e=e||self).gram=e.gram||{},e.gram.identity={}))}(this,(function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n={base2:"01",dieBase6:"⚀⚁⚂⚃⚄⚅",base8:"01234567",base10:"0123456789",astrologyBase12:"♈︎♉︎♊︎♋︎♌︎♍︎♎︎♏︎♐︎♑︎♒︎♓︎",base11:"0123456789a",chessBase12:"♚♛♜♝♞♟♔♕♖♗♘♙",base16:"0123456789abcdef",dominoBase28:"🁣🁤🁫🁥🁬🁳🁦🁭🁴🁻🁧🁮🁵🁼🂃🁨🁯🁶🁽🂊🂋🁩🁰🁷🁾🂅🂌🂓",base32:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",zBase32:"ybndrfg8ejkmcpqxot1uwisza345h769",crock32:"0123456789ABCDEFGHJKMNPQRSTVWXYZ",base32Hex:"0123456789ABCDEFGHIJKLMNOPQRSTUV",base36:"0123456789abcdefghijklmnopqrstuvwxyz",mahjongBase43:"🀑🀒🀓🀔🀕🀖🀗🀘🀙🀚🀛🀜🀝🀞🀟🀠🀡🀇🀈🀉🀊🀋🀌🀍🀎🀏🀀🀁🀂🀃🀄︎🀅🀆🀐🀢🀣🀤🀥🀦🀧🀨🀩🀪",cards56:"🂡🂢🂣🂤🂥🂦🂧🂨🂩🂪🂫🂬🂭🂮🂱🂲🂳🂴🂵🂶🂷🂸🂹🂺🂻🂼🂽🂾🃁🃂🃃🃄🃅🃆🃇🃈🃉🃊🃋🃌🃍🃎🃑🃒🃓🃔🃕🃖🃗🃘🃙🃝🃞",base58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",flickrBase58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",base62:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",base64:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@",cookieBase90:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+-./:<=>?@[]^_`{|}~"},r=function(e){var t=0;return{generate:function(){return""+(e||"")+t++}}},a=function(e){return crypto.getRandomValues(new Uint8Array(e))},o=function(e,t,r){void 0===e&&(e=n.base64),void 0===t&&(t=21);var o=function(e,t){return function(e,t,n){var r=(2<<Math.log(e.length-1)/Math.LN2)-1,a=-~(1.6*r*t/e.length);return function(){for(var o="";;)for(var i=n(a),s=a;s--;)if((o+=e[i[s]&r]||"").length===t)return o}}(e,t,a)}(e,t);return{generate:function(){return r?r+o():o()}}},i=require("unist-util-visit"),s={generator:"counter",alphabet:n.base58,prefix:void 0};e.alphabets=n,e.counterIDGenerator=r,e.gramIdentityPlugin=function(e){var n=t({},s,e);return function(e){var t;switch(n.generator){case"nanoid":t=o(n.alphabet,21,n.prefix);break;case"counter":default:t=r(n.prefix)}i(e,(function(e){var n;(n=e).type&&"path"===n.type&&(e.id=e.id||t.generate())}))}},e.nanoidGenerator=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=gram-identity.umd.production.min.js.map |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.3.9-alpha.2", | ||
"version": "0.3.9", | ||
"license": "MIT", | ||
@@ -55,3 +55,3 @@ "repository": { | ||
"devDependencies": { | ||
"@gram-data/gram-parse": "^0.3.9-alpha.2", | ||
"@gram-data/gram-parse": "^0.3.9", | ||
"@types/jest": "^26.0.19", | ||
@@ -73,3 +73,3 @@ "@types/shortid": "^0.0.29", | ||
"dependencies": { | ||
"@gram-data/gram-ast": "^0.3.9-alpha.2", | ||
"@gram-data/gram-ast": "^0.3.9", | ||
"nanoid": "^3.1.20", | ||
@@ -83,3 +83,3 @@ "unified": "^9.2.0", | ||
}, | ||
"gitHead": "32528b415789ea165d93b2432a50322c977642eb" | ||
"gitHead": "f77b8ca02cfafdf66e58eb67632ba8ad9857d3f2" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69370
550
Updated@gram-data/gram-ast@^0.3.9