UNPKG

inthash

Version:

Efficient integer hashing library using Knuth's multiplicative method for Javascript and Typescript, perfect for obfuscating sequential numbers.

72 lines (69 loc) 2.72 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); // deno-lint-ignore-file no-explicit-any const dntShim = __importStar(require("./_dnt.shims.js")); const hasher_js_1 = require("./hasher.js"); const isDeno = typeof dntShim.dntGlobalThis.Deno !== "undefined"; const cmd = isDeno ? "deno run jsr:@denostack/inthash/cli" : "npx inthash"; const rawArgs = isDeno ? dntShim.dntGlobalThis.Deno.args : dntShim.dntGlobalThis.process.argv.slice(2); const cmdSuffix = rawArgs.join(" "); const args = parse(rawArgs); const bit = args.b ?? args.bit ?? args.bits ?? 53; const options = hasher_js_1.Hasher.generate(bit); const hasher = new hasher_js_1.Hasher(options); console.log(JSON.stringify(options, null, " ")); console.error(` $ ${cmd}${cmdSuffix ? " " + cmdSuffix : ""} | pbcopy Now go ahead and paste it into your code! Good luck. :-) Note: The supported range of integers is from min: 0 to max: ${hasher._max}. Please make sure your inputs fall within this range.`); function parse(args) { const argv = {}; for (let i = 0; i < args.length; i++) { const arg = args[i]; let match; if ((match = arg.match(/^--(b|bit|bits)=(\d+)/))) { const [, key, value] = match; argv[key] = +value; } else if ((match = arg.match(/^--(b|bit|bits)$/))) { const [, key] = match; const next = args[i + 1]; if (next && /\d+/.test(next)) { argv[key] = +next; i++; } } else if ((match = arg.match(/^-b(\d+)/))) { argv.b = +match[1]; } } return argv; }