@stryke/hash 0.8.4 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,7 +22,7 @@ This package is part of Storm Software's **đŸŒŠī¸ Stryke** monorepo. Stryke pac
22
22
 
23
23
  <h3 align="center">đŸ’ģ Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
24
24
 
25
- [![Version](https://img.shields.io/badge/version-0.8.3-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
+ [![Version](https://img.shields.io/badge/version-0.9.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
26
26
 
27
27
  > [!IMPORTANT] This repository, and the apps, libraries, and tools contained
28
28
  > within, is still in it's initial development phase. As a result, bugs and
package/dist/hash.cjs CHANGED
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.hash = hash;
7
- var _isString = require("@stryke/type-checks/is-string");
8
- var _hashObject = require("./hash-object.cjs");
9
- var _sha = require("./sha-256.cjs");
10
- function hash(t, e) {
11
- const s = (0, _sha.sha256base64)((0, _isString.isString)(t) ? t : (0, _hashObject.hashObject)(t, e)),
7
+ var _ohash = require("ohash");
8
+ function hash(s, e) {
9
+ const t = (0, _ohash.hash)(s),
12
10
  n = e?.maxLength ?? 32;
13
- return s.length > n ? s.slice(0, n) : s;
11
+ return t.length > n ? t.slice(0, n) : t;
14
12
  }
package/dist/hash.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { HashObjectOptions } from "./hash-object";
2
- export interface HashOptions extends HashObjectOptions {
1
+ export interface HashOptions {
3
2
  /**
4
3
  * The maximum length of the hash
5
4
  *
package/dist/hash.mjs CHANGED
@@ -1 +1 @@
1
- import{isString as r}from"@stryke/type-checks/is-string";import{hashObject as h}from"./hash-object";import{sha256base64 as a}from"./sha-256";export function hash(t,e){const s=a(r(t)?t:h(t,e)),n=e?.maxLength??32;return s.length>n?s.slice(0,n):s}
1
+ import{hash as h}from"ohash";export function hash(s,e){const t=h(s),n=e?.maxLength??32;return t.length>n?t.slice(0,n):t}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/hash",
3
- "version": "0.8.4",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "description": "A package containing utility functions that hash data using various algorithms.",
6
6
  "repository": {
@@ -11,8 +11,8 @@
11
11
  "private": false,
12
12
  "dependencies": {
13
13
  "js-xxhash": "^4.0.0",
14
- "@stryke/fs": ">=0.10.5",
15
- "@stryke/type-checks": ">=0.1.4"
14
+ "ohash": "^2.0.11",
15
+ "@stryke/fs": "^0.11.2"
16
16
  },
17
17
  "publishConfig": { "access": "public" },
18
18
  "devDependencies": {},
@@ -114,20 +114,6 @@
114
114
  "require": { "types": "./dist/hash.d.ts", "default": "./dist/hash.cjs" },
115
115
  "default": { "types": "./dist/hash.d.ts", "default": "./dist/hash.mjs" }
116
116
  },
117
- "./hash-object": {
118
- "import": {
119
- "types": "./dist/hash-object.d.ts",
120
- "default": "./dist/hash-object.mjs"
121
- },
122
- "require": {
123
- "types": "./dist/hash-object.d.ts",
124
- "default": "./dist/hash-object.cjs"
125
- },
126
- "default": {
127
- "types": "./dist/hash-object.d.ts",
128
- "default": "./dist/hash-object.mjs"
129
- }
130
- },
131
117
  "./hash-files": {
132
118
  "import": {
133
119
  "types": "./dist/hash-files.d.ts",
@@ -1,230 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hashObject = hashObject;
7
- const f = Object.freeze({
8
- ignoreUnknown: !1,
9
- respectType: !1,
10
- respectFunctionNames: !1,
11
- respectFunctionProperties: !1,
12
- unorderedObjects: !0,
13
- unorderedArrays: !1,
14
- unorderedSets: !1,
15
- excludeKeys: void 0,
16
- excludeValues: void 0,
17
- replacer: void 0
18
- });
19
- function hashObject(t, o) {
20
- o ? o = {
21
- ...f,
22
- ...o
23
- } : o = f;
24
- const u = p(o);
25
- return u.dispatch(t), u.toString();
26
- }
27
- const b = Object.freeze(["prototype", "__proto__", "constructor"]);
28
- function p(t) {
29
- let o = "",
30
- u = new Map();
31
- const r = e => {
32
- o += e;
33
- };
34
- return {
35
- toString() {
36
- return o;
37
- },
38
- getContext() {
39
- return u;
40
- },
41
- dispatch(e) {
42
- return t.replacer && (e = t.replacer(e)), this[e === null ? "null" : typeof e](e);
43
- },
44
- object(e) {
45
- if (e && typeof e.toJSON == "function") return this.object(e.toJSON());
46
- const n = Object.prototype.toString.call(e);
47
- let a = "";
48
- const y = n.length;
49
- y < 10 ? a = `unknown:[${n}]` : a = n.slice(8, y - 1), a = a.toLowerCase();
50
- let l = null;
51
- if ((l = u.get(e)) === void 0) u.set(e, u.size);else return this.dispatch(`[CIRCULAR:${l}]`);
52
- if (typeof Buffer < "u" && Buffer.isBuffer && Buffer.isBuffer(e)) return r("buffer:"), r(e.toString("utf8"));
53
- if (a !== "object" && a !== "function" && a !== "asyncfunction") this[a] ? this[a](e) : t.ignoreUnknown || this.unknown(e, a);else {
54
- let i = Object.keys(e);
55
- t.unorderedObjects && (i = i.sort());
56
- let c = [];
57
- t.respectType !== !1 && !g(e) && (c = b), t.excludeKeys && (i = i.filter(s => !t.excludeKeys(s)), c = c.filter(s => !t.excludeKeys(s))), r(`object:${i.length + c.length}:`);
58
- const d = s => {
59
- this.dispatch(s), r(":"), t.excludeValues || this.dispatch(e[s]), r(",");
60
- };
61
- for (const s of i) d(s);
62
- for (const s of c) d(s);
63
- }
64
- },
65
- array(e, n) {
66
- if (n = n === void 0 ? t.unorderedArrays !== !1 : n, r(`array:${e.length}:`), !n || e.length <= 1) {
67
- for (const l of e) this.dispatch(l);
68
- return;
69
- }
70
- const a = new Map(),
71
- y = e.map(l => {
72
- const i = p(t);
73
- i.dispatch(l);
74
- for (const [c, d] of i.getContext()) a.set(c, d);
75
- return i.toString();
76
- });
77
- return u = a, y.sort(), this.array(y, !1);
78
- },
79
- date(e) {
80
- return r(`date:${e.toJSON()}`);
81
- },
82
- symbol(e) {
83
- return r(`symbol:${e.toString()}`);
84
- },
85
- unknown(e, n) {
86
- if (r(n), !!e && (r(":"), e && typeof e.entries == "function")) return this.array(Array.from(e.entries()), !0);
87
- },
88
- error(e) {
89
- return r(`error:${e.toString()}`);
90
- },
91
- boolean(e) {
92
- return r(`bool:${e}`);
93
- },
94
- string(e) {
95
- r(`string:${e.length}:`), r(e);
96
- },
97
- function(e) {
98
- r("fn:"), g(e) ? this.dispatch("[native]") : this.dispatch(e.toString()), t.respectFunctionNames !== !1 && this.dispatch(`function-name:${String(e.name)}`), t.respectFunctionProperties && this.object(e);
99
- },
100
- number(e) {
101
- return r(`number:${e}`);
102
- },
103
- xml(e) {
104
- return r(`xml:${e.toString()}`);
105
- },
106
- null() {
107
- return r("Null");
108
- },
109
- undefined() {
110
- return r("Undefined");
111
- },
112
- regexp(e) {
113
- return r(`regex:${e.toString()}`);
114
- },
115
- uint8array(e) {
116
- return r("uint8array:"), this.dispatch(Array.prototype.slice.call(e));
117
- },
118
- uint8clampedarray(e) {
119
- return r("uint8clampedarray:"), this.dispatch(Array.prototype.slice.call(e));
120
- },
121
- int8array(e) {
122
- return r("int8array:"), this.dispatch(Array.prototype.slice.call(e));
123
- },
124
- uint16array(e) {
125
- return r("uint16array:"), this.dispatch(Array.prototype.slice.call(e));
126
- },
127
- int16array(e) {
128
- return r("int16array:"), this.dispatch(Array.prototype.slice.call(e));
129
- },
130
- uint32array(e) {
131
- return r("uint32array:"), this.dispatch(Array.prototype.slice.call(e));
132
- },
133
- int32array(e) {
134
- return r("int32array:"), this.dispatch(Array.prototype.slice.call(e));
135
- },
136
- float32array(e) {
137
- return r("float32array:"), this.dispatch(Array.prototype.slice.call(e));
138
- },
139
- float64array(e) {
140
- return r("float64array:"), this.dispatch(Array.prototype.slice.call(e));
141
- },
142
- arraybuffer(e) {
143
- return r("arraybuffer:"), this.dispatch(new Uint8Array(e));
144
- },
145
- url(e) {
146
- return r(`url:${e.toString()}`);
147
- },
148
- map(e) {
149
- r("map:");
150
- const n = [...e];
151
- return this.array(n, t.unorderedSets !== !1);
152
- },
153
- set(e) {
154
- r("set:");
155
- const n = [...e];
156
- return this.array(n, t.unorderedSets !== !1);
157
- },
158
- file(e) {
159
- return r("file:"), this.dispatch([e.name, e.size, e.type, e.lastModfied]);
160
- },
161
- blob() {
162
- if (t.ignoreUnknown) return r("[blob]");
163
- throw new Error(`Hashing Blob objects is currently not supported
164
- Use "options.replacer" or "options.ignoreUnknown"
165
- `);
166
- },
167
- domwindow() {
168
- return r("domwindow");
169
- },
170
- bigint(e) {
171
- return r(`bigint:${e.toString()}`);
172
- },
173
- process() {
174
- return r("process");
175
- },
176
- timer() {
177
- return r("timer");
178
- },
179
- pipe() {
180
- return r("pipe");
181
- },
182
- tcp() {
183
- return r("tcp");
184
- },
185
- udp() {
186
- return r("udp");
187
- },
188
- tty() {
189
- return r("tty");
190
- },
191
- statwatcher() {
192
- return r("statwatcher");
193
- },
194
- securecontext() {
195
- return r("securecontext");
196
- },
197
- connection() {
198
- return r("connection");
199
- },
200
- zlib() {
201
- return r("zlib");
202
- },
203
- context() {
204
- return r("context");
205
- },
206
- nodescript() {
207
- return r("nodescript");
208
- },
209
- httpparser() {
210
- return r("httpparser");
211
- },
212
- dataview() {
213
- return r("dataview");
214
- },
215
- signal() {
216
- return r("signal");
217
- },
218
- fsevent() {
219
- return r("fsevent");
220
- },
221
- tlswrap() {
222
- return r("tlswrap");
223
- }
224
- };
225
- }
226
- const h = "[native code] }",
227
- w = h.length;
228
- function g(t) {
229
- return typeof t != "function" ? !1 : Function.prototype.toString.call(t).slice(-w) === h;
230
- }
@@ -1,71 +0,0 @@
1
- export interface HashObjectOptions {
2
- /**
3
- * Function to determine if a key should be excluded from hashing.
4
- * @optional
5
- * @param key - The key to check for exclusion.
6
- * @returns {boolean} - Returns true to exclude the key from hashing.
7
- */
8
- excludeKeys?: ((key: string) => boolean) | undefined;
9
- /**
10
- * Specifies whether to exclude values from hashing, so that only the object keys are hashed.
11
- * @optional
12
- */
13
- excludeValues?: boolean | undefined;
14
- /**
15
- * Specifies whether to ignore objects of unknown type (not directly serialisable) when hashing.
16
- * @optional
17
- * @default false
18
- */
19
- ignoreUnknown?: boolean | undefined;
20
- /**
21
- * A function that replaces values before they are hashed, which can be used to customise the hashing process.
22
- * @optional
23
- * @param value - The current value to be hashed.
24
- * @returns {any} - The value to use for hashing instead.
25
- */
26
- replacer?: ((value: any) => any) | undefined;
27
- /**
28
- * Specifies whether the 'name' property of functions should be taken into account when hashing.
29
- * @optional
30
- * @default false
31
- */
32
- respectFunctionNames?: boolean | undefined;
33
- /**
34
- * Specifies whether properties of functions should be taken into account when hashing.
35
- * @optional
36
- * @default false
37
- */
38
- respectFunctionProperties?: boolean | undefined;
39
- /**
40
- * Specifies whether to include type-specific properties such as prototype or constructor in the hash to distinguish between types.
41
- * @optional
42
- * @default false
43
- */
44
- respectType?: boolean | undefined;
45
- /**
46
- * Specifies whether arrays should be sorted before hashing to ensure consistent order.
47
- * @optional
48
- * @default false
49
- */
50
- unorderedArrays?: boolean | undefined;
51
- /**
52
- * Specifies whether Set and Map instances should be sorted by key before hashing to ensure consistent order.
53
- * @optional
54
- * @default true
55
- */
56
- unorderedObjects?: boolean | undefined;
57
- /**
58
- * Specifies whether the elements of `Set' and keys of `Map' should be sorted before hashing to ensure consistent order.
59
- * @optional
60
- * @default false
61
- */
62
- unorderedSets?: boolean | undefined;
63
- }
64
- /**
65
- * Serialize any JS value into a stable, hashable string
66
- * @param {object} object value to hash
67
- * @param {HashObjectOptions} options hashing options. See {@link HashObjectOptions}.
68
- * @return {string} serialized value
69
- * @api public
70
- */
71
- export declare function hashObject(object: any, options?: HashObjectOptions): string;
@@ -1,3 +0,0 @@
1
- const f=Object.freeze({ignoreUnknown:!1,respectType:!1,respectFunctionNames:!1,respectFunctionProperties:!1,unorderedObjects:!0,unorderedArrays:!1,unorderedSets:!1,excludeKeys:void 0,excludeValues:void 0,replacer:void 0});export function hashObject(t,o){o?o={...f,...o}:o=f;const u=p(o);return u.dispatch(t),u.toString()}const b=Object.freeze(["prototype","__proto__","constructor"]);function p(t){let o="",u=new Map;const r=e=>{o+=e};return{toString(){return o},getContext(){return u},dispatch(e){return t.replacer&&(e=t.replacer(e)),this[e===null?"null":typeof e](e)},object(e){if(e&&typeof e.toJSON=="function")return this.object(e.toJSON());const n=Object.prototype.toString.call(e);let a="";const y=n.length;y<10?a=`unknown:[${n}]`:a=n.slice(8,y-1),a=a.toLowerCase();let l=null;if((l=u.get(e))===void 0)u.set(e,u.size);else return this.dispatch(`[CIRCULAR:${l}]`);if(typeof Buffer<"u"&&Buffer.isBuffer&&Buffer.isBuffer(e))return r("buffer:"),r(e.toString("utf8"));if(a!=="object"&&a!=="function"&&a!=="asyncfunction")this[a]?this[a](e):t.ignoreUnknown||this.unknown(e,a);else{let i=Object.keys(e);t.unorderedObjects&&(i=i.sort());let c=[];t.respectType!==!1&&!g(e)&&(c=b),t.excludeKeys&&(i=i.filter(s=>!t.excludeKeys(s)),c=c.filter(s=>!t.excludeKeys(s))),r(`object:${i.length+c.length}:`);const d=s=>{this.dispatch(s),r(":"),t.excludeValues||this.dispatch(e[s]),r(",")};for(const s of i)d(s);for(const s of c)d(s)}},array(e,n){if(n=n===void 0?t.unorderedArrays!==!1:n,r(`array:${e.length}:`),!n||e.length<=1){for(const l of e)this.dispatch(l);return}const a=new Map,y=e.map(l=>{const i=p(t);i.dispatch(l);for(const[c,d]of i.getContext())a.set(c,d);return i.toString()});return u=a,y.sort(),this.array(y,!1)},date(e){return r(`date:${e.toJSON()}`)},symbol(e){return r(`symbol:${e.toString()}`)},unknown(e,n){if(r(n),!!e&&(r(":"),e&&typeof e.entries=="function"))return this.array(Array.from(e.entries()),!0)},error(e){return r(`error:${e.toString()}`)},boolean(e){return r(`bool:${e}`)},string(e){r(`string:${e.length}:`),r(e)},function(e){r("fn:"),g(e)?this.dispatch("[native]"):this.dispatch(e.toString()),t.respectFunctionNames!==!1&&this.dispatch(`function-name:${String(e.name)}`),t.respectFunctionProperties&&this.object(e)},number(e){return r(`number:${e}`)},xml(e){return r(`xml:${e.toString()}`)},null(){return r("Null")},undefined(){return r("Undefined")},regexp(e){return r(`regex:${e.toString()}`)},uint8array(e){return r("uint8array:"),this.dispatch(Array.prototype.slice.call(e))},uint8clampedarray(e){return r("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(e))},int8array(e){return r("int8array:"),this.dispatch(Array.prototype.slice.call(e))},uint16array(e){return r("uint16array:"),this.dispatch(Array.prototype.slice.call(e))},int16array(e){return r("int16array:"),this.dispatch(Array.prototype.slice.call(e))},uint32array(e){return r("uint32array:"),this.dispatch(Array.prototype.slice.call(e))},int32array(e){return r("int32array:"),this.dispatch(Array.prototype.slice.call(e))},float32array(e){return r("float32array:"),this.dispatch(Array.prototype.slice.call(e))},float64array(e){return r("float64array:"),this.dispatch(Array.prototype.slice.call(e))},arraybuffer(e){return r("arraybuffer:"),this.dispatch(new Uint8Array(e))},url(e){return r(`url:${e.toString()}`)},map(e){r("map:");const n=[...e];return this.array(n,t.unorderedSets!==!1)},set(e){r("set:");const n=[...e];return this.array(n,t.unorderedSets!==!1)},file(e){return r("file:"),this.dispatch([e.name,e.size,e.type,e.lastModfied])},blob(){if(t.ignoreUnknown)return r("[blob]");throw new Error(`Hashing Blob objects is currently not supported
2
- Use "options.replacer" or "options.ignoreUnknown"
3
- `)},domwindow(){return r("domwindow")},bigint(e){return r(`bigint:${e.toString()}`)},process(){return r("process")},timer(){return r("timer")},pipe(){return r("pipe")},tcp(){return r("tcp")},udp(){return r("udp")},tty(){return r("tty")},statwatcher(){return r("statwatcher")},securecontext(){return r("securecontext")},connection(){return r("connection")},zlib(){return r("zlib")},context(){return r("context")},nodescript(){return r("nodescript")},httpparser(){return r("httpparser")},dataview(){return r("dataview")},signal(){return r("signal")},fsevent(){return r("fsevent")},tlswrap(){return r("tlswrap")}}}const h="[native code] }",w=h.length;function g(t){return typeof t!="function"?!1:Function.prototype.toString.call(t).slice(-w)===h}