Socket
Socket
Sign inDemoInstall

hashids

Package Overview
Dependencies
0
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-prerelease.3 to 2.0.0-prerelease.4

esm/index.d.ts

2

dist/hashids.min.js

@@ -1,2 +0,2 @@

!function(t,e){if("function"==typeof define&&define.amd)define("Hashids",["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={};e(n),t.Hashids=n}}(this,function(t){"use strict";function l(t){return function(t){if(Array.isArray(t))return t}(t)||e(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function f(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||e(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function e(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function c(t){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}Object.defineProperty(t,"__esModule",{value:!0}),t.unicodeSubstr=t.onlyChars=t.withoutChars=t.keepUniqueChars=t.default=void 0;var n=function(){function h(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:"cfhistuCFHISTU";if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,h),this.salt=t,"number"!=typeof(this.minLength=e))throw new Error("Hashids: Provided 'minLength' has to be a number (is ".concat(c(e),")"));if("string"!=typeof t)throw new Error("Hashids: Provided 'salt' has to be a string (is ".concat(c(t),")"));if("string"!=typeof n)throw new Error("Hashids: Provided alphabet has to be a string (is ".concat(c(n),")"));var i=b(n);if(i.length<g)throw new Error("Hashids: alphabet must contain at least ".concat(g," unique characters, provided: ").concat(i));this.alphabet=v(i,r);var o,a,s=y(r,i);this.seps=w(s,t),(0===f(this.seps).length||f(this.alphabet).length/f(this.seps).length>d)&&(o=Math.ceil(f(this.alphabet).length/d))>f(this.seps).length&&(a=o-f(this.seps).length,this.seps+=m(this.alphabet,0,a),this.alphabet=m(this.alphabet,a)),this.alphabet=w(this.alphabet,t);var u=Math.ceil(f(this.alphabet).length/p);f(this.alphabet).length<3?(this.guards=m(this.seps,0,u),this.seps=m(this.seps,u)):(this.guards=m(this.alphabet,0,u),this.alphabet=m(this.alphabet,u))}return function(t,e,n){e&&r(t.prototype,e),n&&r(t,n)}(h,[{key:"encode",value:function(t){for(var e=arguments.length,n=new Array(1<e?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return(n=Array.isArray(t)?t:[].concat(f(null!=t?[t]:[]),f(n))).length?(n.every(i)||(n=n.map(function(t){return"bigint"==typeof t||"number"==typeof t?t:s(String(t))})),n.every(o)?this._encode(n):""):""}},{key:"decode",value:function(t){return t&&"string"==typeof t&&0!==t.length?this._decode(t,this.alphabet):[]}},{key:"encodeHex",value:function(t){switch(c(t)){case"bigint":t=t.toString(16);break;case"string":if(!/^[0-9a-fA-F]+$/.test(t))return"";break;default:throw new Error("Hashids: The provided value is neither a string, nor a BigInt (got: ".concat(c(t),")"))}var e=u(t,12,function(t){return parseInt("1".concat(t),16)});return this.encode(e)}},{key:"decodeHex",value:function(t){return this.decode(t).map(function(t){return t.toString(16).slice(1)}).join("")}},{key:"_encode",value:function(a){var s,u=this,h=this.alphabet,t=a.reduce(function(t,e,n){return t+("bigint"==typeof e?Number(e%BigInt(n+100)):e%(n+100))},0),l=s=f(h)[t%f(h).length],c=f(this.seps),e=f(this.guards);if(a.forEach(function(t,e){var n=l+u.salt+h;h=w(h,m(n,0));var r=A(t,h);if(s+=r,e+1<a.length){var i=r.codePointAt(0)+e,o="bigint"==typeof t?Number(t%BigInt(i)):t%i;s+=c[o%c.length]}}),f(s).length<this.minLength){var n=(t+f(s)[0].codePointAt(0))%e.length;if(f(s=e[n]+s).length<this.minLength){var r=(t+f(s)[2].codePointAt(0))%e.length;s+=e[r]}}for(var i=Math.floor(f(h).length/2);f(s).length<this.minLength;){h=w(h,h);var o=f(s=m(h,i)+s+m(h,0,i)).length-this.minLength;0<o&&(s=m(s,o/2,this.minLength))}return s}},{key:"_decode",value:function(t,e){var a=this,n=S(t,function(t){return a.guards.includes(t)}),r=f(n[3===n.length||2===n.length?1:0]);if(0===r.length)return[];var i=l(r),s=i[0],o=i.slice(1).join(""),u=S(o,function(t){return a.seps.includes(t)}).reduce(function(t,e){var n=t.result,r=t.lastAlphabet,i=s+a.salt+r,o=w(r,m(i,0,f(r).length));return{result:[].concat(f(n),[I(e,o)]),lastAlphabet:o}},{result:[],lastAlphabet:e}).result;return this._encode(u)!==t?[]:u}}]),h}();t.default=n;var g=16,d=3.5,p=12,b=function(t){return Array.from(new Set(t)).join("")};t.keepUniqueChars=b;var v=function(t,e){var n=l(t).slice(0),r=l(e).slice(0);return n.filter(function(t){return!r.includes(t)}).join("")};t.withoutChars=v;var y=function(t,e){var n=l(t).slice(0),r=l(e).slice(0);return n.filter(function(t){return r.includes(t)}).join("")};t.onlyChars=y;var m=function(t,e,n){return l(t).slice(0).slice(e,void 0===n?void 0:e+n).join("")};t.unicodeSubstr=m;var i=function(t){return"bigint"==typeof t||!Number.isNaN(Number(t))&&Math.floor(Number(t))===t},o=function(t){return"bigint"==typeof t||0<=t&&Number.isSafeInteger(t)};function w(t,e){var n,r=l(e).slice(0);if(!r.length)return t;for(var i=f(t),o=i.length-1,a=0,s=0;0<o;o--,a++){s+=n=r[a%=r.length].codePointAt(0);var u=(n+a+s)%o,h=[i[o],i[u]];i[u]=h[0],i[o]=h[1]}return i.join("")}var A=function(t,e){var n=l(e).slice(0),r="";if("bigint"==typeof t)for(var i=BigInt(n.length);r=n[Number(t%i)]+r,t/=i;);else for(;r=n[t%n.length]+r,t=Math.floor(t/n.length););return r},I=function(t,e){var n=l(t).slice(0),r=l(e).slice(0);return n.map(function(t){return r.indexOf(t)}).reduce(function(t,e){if("bigint"==typeof t)return t*BigInt(r.length)+BigInt(e);var n=t*r.length+e;if(Number.isSafeInteger(n))return n;if("function"==typeof BigInt)return BigInt(t)*BigInt(r.length)+BigInt(e);throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment")},0)},S=function(t,n){return l(t).slice(0).reduce(function(t,e){return n(e)?[].concat(f(t),[""]):[].concat(f(t.slice(0,-1)),[t[t.length-1]+e])},[""])},a=/^\+?[0-9]+$/,s=function(t){return a.test(t)?parseInt(t,10):NaN},u=function(n,r,i){return Array.from({length:Math.ceil(n.length/r)},function(t,e){return i(n.slice(e*r,(e+1)*r))})}});
!function(t,e){if("function"==typeof define&&define.amd)define("Hashids",["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={exports:{}};e(n.exports),t.Hashids=n.exports}}(this,function(t){"use strict";function e(t){return function(t){if(Array.isArray(t))return t}(t)||r(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function n(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||r(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function r(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}Object.defineProperty(t,"__esModule",{value:!0}),t.unicodeSubstr=t.onlyChars=t.withoutChars=t.keepUniqueChars=t.default=void 0;var a=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"cfhistuCFHISTU";if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.salt=e,this.minLength=r,"number"!=typeof r)throw new Error("Hashids: Provided 'minLength' has to be a number (is ".concat(i(r),")"));if("string"!=typeof e)throw new Error("Hashids: Provided 'salt' has to be a string (is ".concat(i(e),")"));if("string"!=typeof o)throw new Error("Hashids: Provided alphabet has to be a string (is ".concat(i(o),")"));var p=l(o);if(p.length<s)throw new Error("Hashids: alphabet must contain at least ".concat(s," unique characters, provided: ").concat(p));this.alphabet=c(p,a);var d,v,y=f(a,p);this.seps=b(y,e),(0===n(this.seps).length||n(this.alphabet).length/n(this.seps).length>u)&&(d=Math.ceil(n(this.alphabet).length/u))>n(this.seps).length&&(v=d-n(this.seps).length,this.seps+=g(this.alphabet,0,v),this.alphabet=g(this.alphabet,v)),this.alphabet=b(this.alphabet,e);var m=Math.ceil(n(this.alphabet).length/h);n(this.alphabet).length<3?(this.guards=g(this.seps,0,m),this.seps=g(this.seps,m)):(this.guards=g(this.alphabet,0,m),this.alphabet=g(this.alphabet,m))}var r,a,w;return r=t,(a=[{key:"encode",value:function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];var o="";return(r=Array.isArray(t)?t:[].concat(n(null!=t?[t]:[]),n(r))).length?(r.every(p)||(r=r.map(function(t){return"bigint"==typeof t||"number"==typeof t?t:A(String(t))})),r.every(d)?this._encode(r):o):o}},{key:"decode",value:function(t){return t&&"string"==typeof t&&0!==t.length?this._decode(t,this.alphabet):[]}},{key:"encodeHex",value:function(t){switch(i(t)){case"bigint":t=t.toString(16);break;case"string":if(!/^[0-9a-fA-F]+$/.test(t))return"";break;default:throw new Error("Hashids: The provided value is neither a string, nor a BigInt (got: ".concat(i(t),")"))}var e=I(t,12,function(t){return parseInt("1".concat(t),16)});return this.encode(e)}},{key:"decodeHex",value:function(t){return this.decode(t).map(function(t){return t.toString(16).slice(1)}).join("")}},{key:"_encode",value:function(t){var e,r=this,i=this.alphabet,o=t.reduce(function(t,e,n){return t+("bigint"==typeof e?Number(e%BigInt(n+100)):e%(n+100))},0),a=e=n(i)[o%n(i).length],s=n(this.seps),u=n(this.guards);if(t.forEach(function(n,o){var u=a+r.salt+i;i=b(i,g(u,0));var h=v(n,i);if(e+=h,o+1<t.length){var l=h.codePointAt(0)+o,c="bigint"==typeof n?Number(n%BigInt(l)):n%l;e+=s[c%s.length]}}),n(e).length<this.minLength){var h=(o+n(e)[0].codePointAt(0))%u.length;if(n(e=u[h]+e).length<this.minLength){var l=(o+n(e)[2].codePointAt(0))%u.length;e+=u[l]}}for(var c=Math.floor(n(i).length/2);n(e).length<this.minLength;){i=b(i,i);var f=n(e=g(i,c)+e+g(i,0,c)).length-this.minLength;f>0&&(e=g(e,f/2,this.minLength))}return e}},{key:"_decode",value:function(t,r){var i=this,o=m(t,function(t){return i.guards.includes(t)}),a=n(o[3===o.length||2===o.length?1:0]);if(0===a.length)return[];var s=e(a),u=s[0],h=s.slice(1).join(""),l=m(h,function(t){return i.seps.includes(t)}).reduce(function(t,e){var r=t.result,o=t.lastAlphabet,a=u+i.salt+o,s=b(o,g(a,0,n(o).length));return{result:[].concat(n(r),[y(e,s)]),lastAlphabet:s}},{result:[],lastAlphabet:r}).result;return this._encode(l)!==t?[]:l}}])&&o(r.prototype,a),w&&o(r,w),t}();t.default=a;var s=16,u=3.5,h=12,l=function(t){return Array.from(new Set(t)).join("")};t.keepUniqueChars=l;var c=function(t,n){var r=e(t).slice(0),i=e(n).slice(0);return r.filter(function(t){return!i.includes(t)}).join("")};t.withoutChars=c;var f=function(t,n){var r=e(t).slice(0),i=e(n).slice(0);return r.filter(function(t){return i.includes(t)}).join("")};t.onlyChars=f;var g=function(t,n,r){return e(t).slice(0).slice(n,void 0===r?void 0:n+r).join("")};t.unicodeSubstr=g;var p=function(t){return"bigint"==typeof t||!Number.isNaN(Number(t))&&Math.floor(Number(t))===t},d=function(t){return"bigint"==typeof t||t>=0&&Number.isSafeInteger(t)};function b(t,r){var i,o=e(r).slice(0);if(!o.length)return t;for(var a=n(t),s=a.length-1,u=0,h=0;s>0;s--,u++){h+=i=o[u%=o.length].codePointAt(0);var l=(i+u+h)%s,c=[a[s],a[l]];a[l]=c[0],a[s]=c[1]}return a.join("")}var v=function(t,n){var r=e(n).slice(0),i="";if("bigint"==typeof t){var o=BigInt(r.length);do{i=r[Number(t%o)]+i,t/=o}while(t)}else do{i=r[t%r.length]+i,t=Math.floor(t/r.length)}while(t);return i},y=function(t,n){var r=e(t).slice(0),i=e(n).slice(0);return r.map(function(t){return i.indexOf(t)}).reduce(function(t,e){if("bigint"==typeof t)return t*BigInt(i.length)+BigInt(e);var n=t*i.length+e;if(Number.isSafeInteger(n))return n;if("function"==typeof BigInt)return BigInt(t)*BigInt(i.length)+BigInt(e);throw new Error("Unable to decode the provided string, due to lack of support for BigInt numbers in the current environment")},0)},m=function(t,r){return e(t).slice(0).reduce(function(t,e){return r(e)?[].concat(n(t),[""]):[].concat(n(t.slice(0,-1)),[t[t.length-1]+e])},[""])},w=/^\+?[0-9]+$/,A=function(t){return w.test(t)?parseInt(t,10):NaN},I=function(t,e,n){return Array.from({length:Math.ceil(t.length/e)},function(r,i){return n(t.slice(i*e,(i+1)*e))})}});
//# sourceMappingURL=hashids.min.js.map

@@ -17,3 +17,3 @@ {

],
"version": "2.0.0-prerelease.3",
"version": "2.0.0-prerelease.4",
"homepage": "http://hashids.org/javascript",

@@ -27,4 +27,4 @@ "repository": {

},
"main": "dist/hashids.mjs",
"module": "dist/hashids.mjs",
"main": "esm/index.js",
"module": "esm/index.js",
"browser": "dist/hashids.min",

@@ -38,5 +38,5 @@ "scripts": {

"build:umd": "babel lib/hashids.ts --source-maps -o dist/hashids.js",
"build:modules": "BABEL_MODULES=1 babel lib/hashids.ts --source-maps -o dist/hashids.mjs",
"minify": "cd dist && uglifyjs hashids.js -o hashids.min.js --source-map \"url=hashids.min.js.map\" --compress --mangle",
"build": "yarn run build:umd && yarn run build:modules && yarn run minify",
"build:esm": "BABEL_MODULES=1 babel lib/hashids.ts --source-maps -o esm/index.js",
"minify": "cd dist && terser hashids.js -o hashids.min.js --source-map \"url=hashids.min.js.map\" --compress --mangle",
"build": "yarn run build:umd && yarn run build:esm && yarn run minify",
"clean": "rm -rf coverage yarn-debug.log",

@@ -66,3 +66,3 @@ "all": "yarn run lint && yarn run coverage && yarn run build && yarn run clean",

"@types/jest": "^24.0.17",
"@types/node": "^12.7.1",
"@types/node": "^12.7.2",
"@typescript-eslint/eslint-plugin": "^2.0.0",

@@ -77,9 +77,8 @@ "@typescript-eslint/parser": "^2.0.0",

"eslint-plugin-jest": "^22.15.1",
"expect": "^24.8.0",
"husky": "^3.0.3",
"jest": "^24.8.0",
"husky": "^3.0.4",
"jest": "^24.9.0",
"prettier": "^1.18.2",
"semantic-release": "^16.0.0-beta.22",
"typescript": "^3.5.3",
"uglify-js": "^3.4.8"
"terser": "^4.1.4",
"typescript": "^3.5.3"
},

@@ -86,0 +85,0 @@ "license": "MIT",

@@ -1,2 +0,2 @@

// this will only parse and run if you're using node >= 10 with the --experimental-modules flag
// this will only parse and run if you're using node >= 12 with the --experimental-modules flag
// alternatively, if you use something like webpack

@@ -7,3 +7,7 @@ // that's why it is in a separate file

describe('importing', () => {
const supportsEsm = /^v\d[2-9]/.test(process.version)
const describeIfEsm = supportsEsm ? describe : describe.skip
// only run on node >= v12:
describeIfEsm('importing', () => {
test('loads via .mjs', async () => {

@@ -10,0 +14,0 @@ expect.assertions(1)

@@ -13,3 +13,3 @@ {

},
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules"]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc