Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@grandom/fnv1a

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grandom/fnv1a - npm Package Compare versions

Comparing version
1.0.2
to
1.0.3
+2
-2
index.js
/*!
* @grandom/fnv1a v1.0.2
* @grandom/fnv1a v1.0.3
* https://github.com/grandom-library/fnv1a#readme

@@ -9,3 +9,3 @@ *

*
* Date: 2023-08-24T15:41:09.671Z
* Date: 2023-08-28T07:39:33.259Z
*/

@@ -12,0 +12,0 @@ 'use strict';

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

{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["const _32_BIT_OFFSET = 2166136261\n\nconst PRIMES = {\n 32: BigInt(2 ** 24 + 2 ** 8 + 0x93),\n 64: BigInt(2 ** 40 + 2 ** 8 + 0xb3),\n 128: BigInt(2) ** BigInt(88) + BigInt(2 ** 8 + 0x3b),\n 256: BigInt(2) ** BigInt(168) + BigInt(2 ** 8 + 0x63),\n 512: BigInt(2) ** BigInt(344) + BigInt(2 ** 8 + 0x57),\n 1024: BigInt(2) ** BigInt(680) + BigInt(2 ** 8 + 0x8d)\n} as const\n\nconst OFFSETS: Record<keyof typeof PRIMES, bigint> = {\n 32: BigInt(_32_BIT_OFFSET),\n 64: 14695981039346656037n,\n 128: 144066263297769815596495629667062367629n,\n 256: 100029257958052580907070968620625704837092796014241193945225284501741471925557n,\n 512: 9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,\n 1024: 14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n\n} as const\n\n/**\n * Returns a 32-bit FNV-1a hash.\n *\n * @param string The string to hash.\n */\nfunction fnv1a (string: string): number\n\n/**\n * Returns an n-bit FNV-1a hash.\n *\n * @param string The string to hash.\n * @param hashSize The size of the hash.\n */\nfunction fnv1a (string: string, hashSize: number): bigint\n\nfunction fnv1a (arg1: any, arg2?: any): any {\n if (typeof arg1 !== 'string') {\n throw new TypeError(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `The 'string' argument must be a string, got: ${arg1} (typeof === '${typeof arg1}').`\n )\n }\n\n const length = arg1.length\n\n // 32 bit hash as number -------------------------------------------------------------------------\n if (typeof arg2 === 'undefined') {\n let hash = _32_BIT_OFFSET\n\n for (let i = 0; i < length; i++) {\n hash ^= arg1.charCodeAt(i)\n hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24)\n }\n\n return hash >>> 0\n }\n\n if (typeof arg2 !== 'number') {\n throw new TypeError(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `The 'hashSize' argument must be a number, got: ${arg2} (typeof === '${typeof arg2}').`\n )\n }\n\n if (!(arg2 in PRIMES)) {\n throw new RangeError(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `The 'hashSize' argument must be one of 32, 64, 128, 256, 512, 1024, got: ${arg2}.`\n )\n }\n\n // n-bit hash as BigInt --------------------------------------------------------------------------\n const size = arg2 as keyof typeof PRIMES\n const prime = PRIMES[size]\n\n let hash = OFFSETS[size]\n\n for (let i = 0; i < length; i++) {\n hash ^= BigInt(arg1.charCodeAt(i))\n hash = BigInt.asUintN(size, hash * prime)\n }\n\n return hash\n}\n\nexport default fnv1a\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,cAAc,GAAG,UAAU,CAAA;AAEjC,MAAM,MAAM,GAAG;AACb,IAAA,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACnC,IAAA,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,C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T_OFFSET = 2166136261;\nconst PRIMES = {\n 32: BigInt(2 ** 24 + 2 ** 8 + 0x93),\n 64: BigInt(2 ** 40 + 2 ** 8 + 0xb3),\n 128: BigInt(2) ** BigInt(88) + BigInt(2 ** 8 + 0x3b),\n 256: BigInt(2) ** BigInt(168) + BigInt(2 ** 8 + 0x63),\n 512: BigInt(2) ** BigInt(344) + BigInt(2 ** 8 + 0x57),\n 1024: BigInt(2) ** BigInt(680) + BigInt(2 ** 8 + 0x8d)\n};\nconst OFFSETS = {\n 32: BigInt(_32_BIT_OFFSET),\n 64: 14695981039346656037n,\n 128: 144066263297769815596495629667062367629n,\n 256: 100029257958052580907070968620625704837092796014241193945225284501741471925557n,\n 512: 9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,\n 1024: 14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n\n};\nfunction fnv1a(arg1, arg2) {\n if (typeof arg1 !== 'string') {\n throw new TypeError(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `The 'string' argument must be a string, got: ${arg1} (typeof === '${typeof arg1}').`);\n }\n const length = arg1.length;\n // 32 bit hash as number -------------------------------------------------------------------------\n if (typeof arg2 === 'undefined') {\n let hash = _32_BIT_OFFSET;\n for (let i = 0; i < length; i++) {\n hash ^= arg1.charCodeAt(i);\n hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);\n }\n return hash >>> 0;\n }\n if (typeof arg2 !== 'number') {\n throw new TypeError(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `The 'hashSize' argument must be a number, got: ${arg2} (typeof === '${typeof arg2}').`);\n }\n if (!(arg2 in PRIMES)) {\n throw new RangeError(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `The 'hashSize' argument must be one of 32, 64, 128, 256, 512, 1024, got: ${arg2}.`);\n }\n // n-bit hash as BigInt --------------------------------------------------------------------------\n const size = arg2;\n const prime = PRIMES[size];\n let hash = OFFSETS[size];\n for (let i = 0; i < length; i++) {\n hash ^= BigInt(arg1.charCodeAt(i));\n hash = BigInt.asUintN(size, hash * prime);\n }\n return hash;\n}\nexport default fnv1a;\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,cAAc,GAAG,UAAU,CAAC;AAClC,MAAM,MAAM,GAAG;AACf,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACvC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACvC,IAAI,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACxD,IAAI,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACzD,IAAI,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACzD,IAAI,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC1D,CAAC,CAAC;AACF,MAAM,OAAO,GAAG;AAChB,IAAI,EAAE,EAAE,MAAM,CAAC,cAAc,CAAC;AAC9B,IAAI,EAAE,EAAE,qBAAqB;AAC7B,IAAI,GAAG,EAAE,wCAAwC;AACjD,IAAI,GAAG,EAAE,+EAA+E;AACxF,IA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AAC7F,KAAK;AACL;AACA,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC;AACtB,IAAI,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/B,IAAI,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC7B,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;AACrC,QAAQ,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,QAAQ,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC,CAAC;AAClD,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB;;;;"}
{
"name": "@grandom/fnv1a",
"version": "1.0.2",
"version": "1.0.3",
"description": "FNV-1a non-cryptographic hash function implementation written in TypeScript.",

@@ -64,3 +64,3 @@ "author": "Richard King <richrdkng@gmail.com> (www.richrdkng.com)",

"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.2",
"@rollup/plugin-typescript": "^11.1.3",
"@semantic-release/changelog": "^6.0.3",

@@ -67,0 +67,0 @@ "@semantic-release/exec": "^6.0.3",