UNPKG

harsh

Version:

A number-hash ready to go for Talk Like A Pirate Day

2 lines (1 loc) 2.87 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.harsh=e.harsh||{})}(this,function(e){"use strict";function r(e,r){for(var n=[],o=0;o<e;o++)n.push(Math.floor(Math.random()*Math.pow(10,6)).toString(r));return n}function n(e,r,n){var o=e.toString(n),t=[].concat(s(r),[o]),h="";do{var a=Math.floor(Math.random()*t.length);h+=t[a],t.splice(a,1)}while(t.length);return h}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[Math.floor(100*Math.random())],o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:36;if(!e.splice)throw new TypeError("The ids argument should be an array of numbers");if("number"!=typeof o||o<0)throw new TypeError("The number of salts should be a positive integer");if("number"!=typeof t||t<16||t>36)throw new TypeError("The base should be a number between 16 and 36");var h=r(o,t);return{ids:e,hashes:e.map(function(e){if("number"!=typeof e)throw new TypeError("The ids you're hashing should only be numbers");return n(e,h,t)}),salts:h,base:t}}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.floor(100*Math.random()),o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:36;return n(e,r(o,t),t)}function h(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:36;if("number"!=typeof e)throw new TypeError("The num should be a number");if("number"!=typeof o||o<0)throw new TypeError("The number of salts should be a positive integer");if("number"!=typeof t||t<16||t>36)throw new TypeError("The base should be a number between 16 and 36");for(var h=[],a=0;a<e;a++)h.push(Math.floor(Math.random()*Math.pow(10,e.toString(10).length+2)));var s=r(o,t);return{ids:h,hashes:h.map(function(e){return n(e,s,t)}),salts:s,base:t}}function a(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:36;if(!e.splice)throw new TypeError("The hashes argument should be an array of hashes provided by the hash method");if(!r.splice)throw new TypeError("The salts argument should be an array of salt strings provided by the hash method");if("number"!=typeof n||n<16||n>36)throw new TypeError("The base should be a number between 16 and 36");var o=new RegExp(r.join("|"),"g");return e.map(function(e){if("string"!=typeof e)throw new TypeError("The hashes you're reversing should only be strings");var r=e.replace(o,"");return parseInt(r,n)})}var s=function(e){if(Array.isArray(e)){for(var r=0,n=Array(e.length);r<e.length;r++)n[r]=e[r];return n}return Array.from(e)};e.hash=o,e.hashish=t,e.bunch=h,e.reverse=a,Object.defineProperty(e,"__esModule",{value:!0})});