New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

object-code

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-code - npm Package Compare versions

Comparing version
1.3.3
to
1.3.4
+21
LICENSE
MIT License
Copyright (c) 2022 - present Arthur Fiorette
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1
-1

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

{"version":3,"file":"index.js","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","error","assign","charCodeAt"],"mappings":"SAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,cCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAMb,IAFA,IAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAE1Bc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,IAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFS,GAAJC,EAAUH,EAAKC,EAAIgB,YAAaf,EAGvC,CAEA,IAAIgB,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}
{"version":3,"file":"index.js","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (_error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","_error","assign","charCodeAt"],"mappings":"SAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,cCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAMb,IAFA,IAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAE1Bc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,IAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFS,GAAJC,EAAUH,EAAKC,EAAIgB,YAAaf,EAGvC,CAEA,IAAIgB,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}

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

{"version":3,"file":"index.mjs","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","error","assign","charCodeAt"],"mappings":"SAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,CCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAMb,IAFA,IAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAE1Bc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,IAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFS,GAAJC,EAAUH,EAAKC,EAAIgB,YAAaf,EAGvC,CAEA,IAAIgB,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}
{"version":3,"file":"index.mjs","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (_error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","_error","assign","charCodeAt"],"mappings":"SAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,CCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAMb,IAFA,IAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAE1Bc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,IAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFS,GAAJC,EAAUH,EAAKC,EAAIgB,YAAaf,EAGvC,CAEA,IAAIgB,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}

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

{"version":3,"file":"index.modern.mjs","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","error","assign","charCodeAt"],"mappings":"SAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,CCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAIb,MAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAEnC,IAAK,IAAIc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,MAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFAC,EAAS,GAAJA,EAAUH,EAAKC,EAAIgB,YAAaf,GAE9BC,CACT,CAEA,IAAIe,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}
{"version":3,"file":"index.modern.mjs","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (_error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","_error","assign","charCodeAt"],"mappings":"SAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,CCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAIb,MAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAEnC,IAAK,IAAIc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,MAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFAC,EAAS,GAAJA,EAAUH,EAAKC,EAAIgB,YAAaf,GAE9BC,CACT,CAEA,IAAIe,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}

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

{"version":3,"file":"index.umd.js","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","error","assign","charCodeAt"],"mappings":"6OAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,QCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAMb,IAFA,IAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAE1Bc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,IAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFS,GAAJC,EAAUH,EAAKC,EAAIgB,YAAaf,EAGvC,CAEA,IAAIgB,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}
{"version":3,"file":"index.umd.js","sources":["../src/util.ts","../src/hash.ts"],"sourcesContent":["export function sortNumbers(a: string, b: string) {\n return a > b ? 1 : -1;\n}\n","import { sortNumbers } from './util';\n\n/**\n * Hashes a given value into a unique number.\n *\n * This function accepts **ANY** kind of value, like `functions`, `classes`, `objects` and\n * so on.\n *\n * **Note**: Symbols uniqueness are not guaranteed, as they are transformed to strings.\n *\n * @example\n *\n * ```ts\n * class B {}\n *\n * const bHash = hash(B);\n * const bInstanceHash = hash(new B());\n * const bArrayHash = hash([B, new B(), new B(), { b: new B() }]);\n * const bBuilderHash = hash(() => B);\n * const bFactoryHash = hash(() => new B());\n * ```\n *\n * @param val The value to be hashed\n * @returns The signed integer result from the provided value\n * @see https://tinylibs.js.org/packages/object-code/\n */\nexport function hash(val: unknown, seen?: WeakSet<object>): number {\n let h = 5381;\n\n // Objects should be recursively hashed\n if (\n typeof val === 'object' &&\n val !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (!seen) {\n seen = new WeakSet();\n }\n\n // Sort keys to keep the hash consistent\n const keys = Object.keys(val).sort(sortNumbers);\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = val[key as keyof typeof val] as object;\n\n h = (h * 33) ^ hash(key, seen);\n\n // Uses an internal WeakMap to keep track of previous seen values\n // and avoid circular references serializations which would cause\n // an infinite loop.\n if (\n typeof value === 'object' &&\n value !== null &&\n (val.toString === Object.prototype.toString ||\n val.toString === Array.prototype.toString)\n ) {\n if (seen.has(value)) {\n continue;\n }\n\n seen.add(value);\n }\n\n // Hashes the value\n h = (h * 33) ^ hash(value, seen);\n }\n\n // Also hashes the constructor\n h = (h * 33) ^ hash(val.constructor, seen);\n\n return h;\n }\n\n let toHash = typeof val;\n\n try {\n if (val instanceof Date) {\n toHash += val.getTime();\n } else {\n toHash += String(val);\n }\n } catch (_error) {\n toHash += String(Object.assign({}, val));\n }\n\n for (let i = 0; i < toHash.length; i++) {\n h = (h * 33) ^ toHash.charCodeAt(i);\n }\n\n return h;\n}\n"],"names":["sortNumbers","a","b","hash","val","seen","h","toString","Object","prototype","Array","WeakSet","keys","sort","i","length","key","value","has","add","constructor","toHash","Date","getTime","String","_error","assign","charCodeAt"],"mappings":"6OAAgBA,EAAYC,EAAWC,GACrC,OAAOD,EAAIC,EAAI,GAAK,CACtB,QCwBgB,SAAAC,EAAKC,EAAcC,GACjC,IAAIC,EAAI,KAGR,GACiB,iBAARF,GACC,OAARA,IACCA,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACKF,IACHA,EAAO,IAAIM,SAMb,IAFA,IAAMC,EAAOJ,OAAOI,KAAKR,GAAKS,KAAKb,GAE1Bc,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,IAAK,CACpC,IAAME,EAAMJ,EAAKE,GACXG,EAAQb,EAAIY,GAOlB,GALAV,EAAS,GAAJA,EAAUH,EAAKa,EAAKX,GAMN,iBAAVY,GACG,OAAVA,IACCb,EAAIG,WAAaC,OAAOC,UAAUF,UACjCH,EAAIG,WAAaG,MAAMD,UAAUF,UACnC,CACA,GAAIF,EAAKa,IAAID,GACX,SAGFZ,EAAKc,IAAIF,EACX,CAGAX,EAAS,GAAJA,EAAUH,EAAKc,EAAOZ,EAC7B,CAKA,OAFS,GAAJC,EAAUH,EAAKC,EAAIgB,YAAaf,EAGvC,CAEA,IAAIgB,SAAgBjB,EAEpB,IACMA,aAAekB,KACjBD,GAAUjB,EAAImB,UAEdF,GAAUG,OAAOpB,EAErB,CAAE,MAAOqB,GACPJ,GAAUG,OAAOhB,OAAOkB,OAAO,GAAItB,GACrC,CAEA,IAAK,IAAIU,EAAI,EAAGA,EAAIO,EAAON,OAAQD,IACjCR,EAAS,GAAJA,EAAUe,EAAOM,WAAWb,GAGnC,OAAOR,CACT"}
{
"name": "object-code",
"version": "1.3.3",
"version": "1.3.4",
"description": "A blazing fast hash code generator that supports every possible javascript value.",

@@ -27,2 +27,8 @@ "homepage": "https://tinylibs.js.org/packages/object-code",

],
"devDependencies": {
"@types/object-hash": "^3.0.6",
"benny": "^3.7.1",
"microbundle": "^0.15.1",
"object-hash": "^3.0.0"
},
"scripts": {

@@ -32,9 +38,3 @@ "benchmark": "pnpm build && node benchmark/benchmark.js",

"test": "jest --coverage"
},
"devDependencies": {
"@types/object-hash": "3.0.6",
"benny": "3.7.1",
"microbundle": "0.15.1",
"object-hash": "3.0.0"
}
}
}

@@ -84,3 +84,3 @@ import { sortNumbers } from './util';

}
} catch (error) {
} catch (_error) {
toHash += String(Object.assign({}, val));

@@ -87,0 +87,0 @@ }