@scalar/helpers 0.0.13 → 0.1.0
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/CHANGELOG.md +10 -0
- package/dist/node/path.d.ts +23 -0
- package/dist/node/path.d.ts.map +1 -0
- package/dist/node/path.js +157 -0
- package/dist/node/path.js.map +7 -0
- package/dist/string/create-hash.d.ts +2 -0
- package/dist/string/create-hash.d.ts.map +1 -1
- package/dist/string/create-hash.js.map +2 -2
- package/package.json +6 -1
- package/dist/crypto/generate-hash.d.ts +0 -15
- package/dist/crypto/generate-hash.d.ts.map +0 -1
- package/dist/crypto/generate-hash.js +0 -10
- package/dist/crypto/generate-hash.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @scalar/helpers
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#7235](https://github.com/scalar/scalar/pull/7235) [`c1ecd0c`](https://github.com/scalar/scalar/commit/c1ecd0c6096f3fbe2e3d8ad3794ea718bb6bce66) Thanks [@marcalexiei](https://github.com/marcalexiei)! - feat(helpers): add `node:path` polyfill
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#7266](https://github.com/scalar/scalar/pull/7266) [`fddf294`](https://github.com/scalar/scalar/commit/fddf294b00dd8c9eb5c713c338f2ec6e3f62523d) Thanks [@amritk](https://github.com/amritk)! - fix: remove useage of crypto.subtle in all contexts
|
|
12
|
+
|
|
3
13
|
## 0.0.13
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare function resolve(...parameters: Array<string>): string;
|
|
2
|
+
export declare function normalize(inputPath: string): string;
|
|
3
|
+
export declare function isAbsolute(path: string): boolean;
|
|
4
|
+
export declare function join(...paths: string[]): string;
|
|
5
|
+
export declare function relative(from: string, to: string): string;
|
|
6
|
+
export declare const sep = "/";
|
|
7
|
+
export declare const delimiter = ":";
|
|
8
|
+
export declare function dirname(path: string): string;
|
|
9
|
+
export declare function basename(path: string, ext?: string): string;
|
|
10
|
+
export declare function extname(path: string): string;
|
|
11
|
+
export declare const path: {
|
|
12
|
+
extname: typeof extname;
|
|
13
|
+
basename: typeof basename;
|
|
14
|
+
dirname: typeof dirname;
|
|
15
|
+
sep: string;
|
|
16
|
+
delimiter: string;
|
|
17
|
+
relative: typeof relative;
|
|
18
|
+
join: typeof join;
|
|
19
|
+
isAbsolute: typeof isAbsolute;
|
|
20
|
+
normalize: typeof normalize;
|
|
21
|
+
resolve: typeof resolve;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/node/path.ts"],"names":[],"mappings":"AAgEA,wBAAgB,OAAO,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,UA6BnD;AAID,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAkBnD;AAGD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAGD,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,UAWtC;AAID,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UA6ChD;AAED,eAAO,MAAM,GAAG,MAAM,CAAA;AACtB,eAAO,MAAM,SAAS,MAAM,CAAA;AAE5B,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB5C;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,eAAO,MAAM,IAAI;;;;;;;;;;;CAWhB,CAAA"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
function normalizeArray(parts, allowAboveRoot) {
|
|
2
|
+
let up = 0;
|
|
3
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
4
|
+
const last = parts[i];
|
|
5
|
+
if (last === ".") {
|
|
6
|
+
parts.splice(i, 1);
|
|
7
|
+
} else if (last === "..") {
|
|
8
|
+
parts.splice(i, 1);
|
|
9
|
+
up++;
|
|
10
|
+
} else if (up) {
|
|
11
|
+
parts.splice(i, 1);
|
|
12
|
+
up--;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (allowAboveRoot) {
|
|
16
|
+
for (; up--; up) {
|
|
17
|
+
parts.unshift("..");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return parts;
|
|
21
|
+
}
|
|
22
|
+
const splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/;
|
|
23
|
+
const splitPath = (filename) => splitPathRe.exec(filename).slice(1);
|
|
24
|
+
function resolve(...parameters) {
|
|
25
|
+
let resolvedPath = "", resolvedAbsolute = false;
|
|
26
|
+
for (let i = parameters.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
27
|
+
const path2 = i >= 0 ? parameters[i] : "/";
|
|
28
|
+
if (typeof path2 !== "string") {
|
|
29
|
+
throw new TypeError("Arguments to path.resolve must be strings");
|
|
30
|
+
}
|
|
31
|
+
if (!path2) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
resolvedPath = path2 + "/" + resolvedPath;
|
|
35
|
+
resolvedAbsolute = path2.charAt(0) === "/";
|
|
36
|
+
}
|
|
37
|
+
resolvedPath = normalizeArray(
|
|
38
|
+
resolvedPath.split("/").filter((p) => !!p),
|
|
39
|
+
!resolvedAbsolute
|
|
40
|
+
).join("/");
|
|
41
|
+
return (resolvedAbsolute ? "/" : "") + resolvedPath || ".";
|
|
42
|
+
}
|
|
43
|
+
function normalize(inputPath) {
|
|
44
|
+
const isPathAbsolute = isAbsolute(inputPath), trailingSlash = inputPath.slice(-1) === "/";
|
|
45
|
+
let path2 = normalizeArray(
|
|
46
|
+
inputPath.split("/").filter((p) => !!p),
|
|
47
|
+
!isPathAbsolute
|
|
48
|
+
).join("/");
|
|
49
|
+
if (!path2 && !isPathAbsolute) {
|
|
50
|
+
path2 = ".";
|
|
51
|
+
}
|
|
52
|
+
if (path2 && trailingSlash) {
|
|
53
|
+
path2 += "/";
|
|
54
|
+
}
|
|
55
|
+
return (isPathAbsolute ? "/" : "") + path2;
|
|
56
|
+
}
|
|
57
|
+
function isAbsolute(path2) {
|
|
58
|
+
return path2.charAt(0) === "/";
|
|
59
|
+
}
|
|
60
|
+
function join(...paths) {
|
|
61
|
+
return normalize(
|
|
62
|
+
paths.filter((p) => {
|
|
63
|
+
if (typeof p !== "string") {
|
|
64
|
+
throw new TypeError("Arguments to path.join must be strings");
|
|
65
|
+
}
|
|
66
|
+
return p;
|
|
67
|
+
}).join("/")
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function relative(from, to) {
|
|
71
|
+
const fromResolved = resolve(from).substring(1);
|
|
72
|
+
const toResolved = resolve(to).substring(1);
|
|
73
|
+
function trim(arr) {
|
|
74
|
+
let start = 0;
|
|
75
|
+
for (; start < arr.length; start++) {
|
|
76
|
+
if (arr[start] !== "") {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let end = arr.length - 1;
|
|
81
|
+
for (; end >= 0; end--) {
|
|
82
|
+
if (arr[end] !== "") {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (start > end) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
return arr.slice(start, end - start + 1);
|
|
90
|
+
}
|
|
91
|
+
const fromParts = trim(fromResolved.split("/"));
|
|
92
|
+
const toParts = trim(toResolved.split("/"));
|
|
93
|
+
const length = Math.min(fromParts.length, toParts.length);
|
|
94
|
+
let samePartsLength = length;
|
|
95
|
+
for (let i = 0; i < length; i++) {
|
|
96
|
+
if (fromParts[i] !== toParts[i]) {
|
|
97
|
+
samePartsLength = i;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let outputParts = [];
|
|
102
|
+
for (let i = samePartsLength; i < fromParts.length; i++) {
|
|
103
|
+
outputParts.push("..");
|
|
104
|
+
}
|
|
105
|
+
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
|
106
|
+
return outputParts.join("/");
|
|
107
|
+
}
|
|
108
|
+
const sep = "/";
|
|
109
|
+
const delimiter = ":";
|
|
110
|
+
function dirname(path2) {
|
|
111
|
+
const result = splitPath(path2);
|
|
112
|
+
const root = result[0];
|
|
113
|
+
let dir = result[1];
|
|
114
|
+
if (!root && !dir) {
|
|
115
|
+
return ".";
|
|
116
|
+
}
|
|
117
|
+
if (dir) {
|
|
118
|
+
dir = dir.slice(0, -1);
|
|
119
|
+
}
|
|
120
|
+
return root + dir;
|
|
121
|
+
}
|
|
122
|
+
function basename(path2, ext) {
|
|
123
|
+
let f = splitPath(path2)[2];
|
|
124
|
+
if (ext && f.slice(-ext.length) === ext) {
|
|
125
|
+
f = f.slice(0, -ext.length);
|
|
126
|
+
}
|
|
127
|
+
return f;
|
|
128
|
+
}
|
|
129
|
+
function extname(path2) {
|
|
130
|
+
return splitPath(path2)[3];
|
|
131
|
+
}
|
|
132
|
+
const path = {
|
|
133
|
+
extname,
|
|
134
|
+
basename,
|
|
135
|
+
dirname,
|
|
136
|
+
sep,
|
|
137
|
+
delimiter,
|
|
138
|
+
relative,
|
|
139
|
+
join,
|
|
140
|
+
isAbsolute,
|
|
141
|
+
normalize,
|
|
142
|
+
resolve
|
|
143
|
+
};
|
|
144
|
+
export {
|
|
145
|
+
basename,
|
|
146
|
+
delimiter,
|
|
147
|
+
dirname,
|
|
148
|
+
extname,
|
|
149
|
+
isAbsolute,
|
|
150
|
+
join,
|
|
151
|
+
normalize,
|
|
152
|
+
path,
|
|
153
|
+
relative,
|
|
154
|
+
resolve,
|
|
155
|
+
sep
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/node/path.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n// resolves . and .. elements in a path array with directory names there\n// must be no slashes, empty elements, or device names (c:\\) in the array\n// (so also no leading and trailing slashes - it does not distinguish\n// relative and absolute paths)\n\n// !! WARNING !!\n// The original implementation included ponyfills for `filters` and `substr`.\n// These have been removed in favor of native implementations supported by the current platforms.\n// See: https://github.com/scalar/scalar/pull/7235#discussion_r2484230212\n\nfunction normalizeArray(parts: Array<string>, allowAboveRoot: boolean): Array<string> {\n // if the path tries to go above the root, `up` ends up > 0\n let up = 0\n for (let i = parts.length - 1; i >= 0; i--) {\n const last = parts[i]\n if (last === '.') {\n parts.splice(i, 1)\n } else if (last === '..') {\n parts.splice(i, 1)\n up++\n } else if (up) {\n parts.splice(i, 1)\n up--\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (allowAboveRoot) {\n for (; up--; up) {\n parts.unshift('..')\n }\n }\n\n return parts\n}\n\n// Split a filename into [root, dir, basename, ext], unix version\n// 'root' is just a slash, or nothing.\nconst splitPathRe = /^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^/]+?|)(\\.[^./]*|))(?:[/]*)$/\nconst splitPath = (filename: string): Array<string> | undefined => splitPathRe.exec(filename)!.slice(1)\n\n// path.resolve([from ...], to)\n// posix version\nexport function resolve(...parameters: Array<string>) {\n let resolvedPath = '',\n resolvedAbsolute = false\n\n for (let i = parameters.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n const path = i >= 0 ? parameters[i] : '/'\n\n // Skip empty and invalid entries\n if (typeof path !== 'string') {\n throw new TypeError('Arguments to path.resolve must be strings')\n }\n if (!path) {\n continue\n }\n\n resolvedPath = path + '/' + resolvedPath\n resolvedAbsolute = path.charAt(0) === '/'\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeArray(\n resolvedPath.split('/').filter((p) => !!p),\n !resolvedAbsolute,\n ).join('/')\n\n return (resolvedAbsolute ? '/' : '') + resolvedPath || '.'\n}\n\n// path.normalize(path)\n// posix version\nexport function normalize(inputPath: string): string {\n const isPathAbsolute = isAbsolute(inputPath),\n trailingSlash = inputPath.slice(-1) === '/'\n\n // Normalize the path\n let path = normalizeArray(\n inputPath.split('/').filter((p) => !!p),\n !isPathAbsolute,\n ).join('/')\n\n if (!path && !isPathAbsolute) {\n path = '.'\n }\n if (path && trailingSlash) {\n path += '/'\n }\n\n return (isPathAbsolute ? '/' : '') + path\n}\n\n// posix version\nexport function isAbsolute(path: string): boolean {\n return path.charAt(0) === '/'\n}\n\n// posix version\nexport function join(...paths: string[]) {\n return normalize(\n paths\n .filter((p) => {\n if (typeof p !== 'string') {\n throw new TypeError('Arguments to path.join must be strings')\n }\n return p\n })\n .join('/'),\n )\n}\n\n// path.relative(from, to)\n// posix version\nexport function relative(from: string, to: string) {\n const fromResolved = resolve(from).substring(1)\n const toResolved = resolve(to).substring(1)\n\n function trim(arr: Array<string>): Array<string> {\n let start = 0\n for (; start < arr.length; start++) {\n if (arr[start] !== '') {\n break\n }\n }\n\n let end = arr.length - 1\n for (; end >= 0; end--) {\n if (arr[end] !== '') {\n break\n }\n }\n\n if (start > end) {\n return []\n }\n return arr.slice(start, end - start + 1)\n }\n\n const fromParts = trim(fromResolved.split('/'))\n const toParts = trim(toResolved.split('/'))\n\n const length = Math.min(fromParts.length, toParts.length)\n let samePartsLength = length\n for (let i = 0; i < length; i++) {\n if (fromParts[i] !== toParts[i]) {\n samePartsLength = i\n break\n }\n }\n\n let outputParts = []\n for (let i = samePartsLength; i < fromParts.length; i++) {\n outputParts.push('..')\n }\n\n outputParts = outputParts.concat(toParts.slice(samePartsLength))\n\n return outputParts.join('/')\n}\n\nexport const sep = '/'\nexport const delimiter = ':'\n\nexport function dirname(path: string): string {\n const result = splitPath(path) as Array<string>\n const root = result[0]\n let dir = result[1]\n\n if (!root && !dir) {\n // No dirname whatsoever\n return '.'\n }\n\n if (dir) {\n // It has a dirname, strip trailing slash\n dir = dir.slice(0, -1)\n }\n\n return (root as string) + dir\n}\n\nexport function basename(path: string, ext?: string): string {\n let f = splitPath(path)![2] as string\n // TODO: make this comparison case-insensitive on windows?\n if (ext && f.slice(-ext.length) === ext) {\n f = f.slice(0, -ext.length)\n }\n return f\n}\n\nexport function extname(path: string): string {\n return splitPath(path)![3] as string\n}\n\nexport const path = {\n extname,\n basename,\n dirname,\n sep,\n delimiter,\n relative,\n join,\n isAbsolute,\n normalize,\n resolve,\n}\n"],
|
|
5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ateHash from @scalar/json-magic/helpers/generate-hash instead
|
|
5
|
+
*
|
|
4
6
|
* @see https://stackoverflow.com/a/7616484/1624255
|
|
5
7
|
*/
|
|
6
8
|
export declare const createHash: (input?: string) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-hash.d.ts","sourceRoot":"","sources":["../../src/string/create-hash.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"create-hash.d.ts","sourceRoot":"","sources":["../../src/string/create-hash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,KAAG,MAe3C,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/string/create-hash.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Simple 32 bit non-secure hash from a string input\n *\n * @see https://stackoverflow.com/a/7616484/1624255\n */\nexport const createHash = (input?: string): number => {\n let chr = 0\n let hash = 0\n let i = 0\n\n if (!input?.length) {\n return hash\n }\n\n for (i = 0; i < input.length; i++) {\n chr = input.charCodeAt(i)\n hash = (hash << 5) - hash + chr\n hash |= 0 // Convert to 32bit integer\n }\n return hash\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Simple 32 bit non-secure hash from a string input\n *\n * @deprecated Use generateHash from @scalar/json-magic/helpers/generate-hash instead\n *\n * @see https://stackoverflow.com/a/7616484/1624255\n */\nexport const createHash = (input?: string): number => {\n let chr = 0\n let hash = 0\n let i = 0\n\n if (!input?.length) {\n return hash\n }\n\n for (i = 0; i < input.length; i++) {\n chr = input.charCodeAt(i)\n hash = (hash << 5) - hash + chr\n hash |= 0 // Convert to 32bit integer\n }\n return hash\n}\n"],
|
|
5
|
+
"mappings": "AAOO,MAAM,aAAa,CAAC,UAA2B;AACpD,MAAI,MAAM;AACV,MAAI,OAAO;AACX,MAAI,IAAI;AAER,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AAEA,OAAK,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACjC,UAAM,MAAM,WAAW,CAAC;AACxB,YAAQ,QAAQ,KAAK,OAAO;AAC5B,YAAQ;AAAA,EACV;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"helpers",
|
|
15
15
|
"js"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.0
|
|
17
|
+
"version": "0.1.0",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=20"
|
|
20
20
|
},
|
|
@@ -46,6 +46,11 @@
|
|
|
46
46
|
"types": "./dist/http/*.d.ts",
|
|
47
47
|
"default": "./dist/http/*.js"
|
|
48
48
|
},
|
|
49
|
+
"./node/*": {
|
|
50
|
+
"import": "./dist/node/*.js",
|
|
51
|
+
"types": "./dist/node/*.d.ts",
|
|
52
|
+
"default": "./dist/node/*.js"
|
|
53
|
+
},
|
|
49
54
|
"./object/*": {
|
|
50
55
|
"import": "./dist/object/*.js",
|
|
51
56
|
"types": "./dist/object/*.d.ts",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a SHA-256 hexadecimal hash for the provided string input.
|
|
3
|
-
*
|
|
4
|
-
* This function uses the Web Crypto API, returning a lowercase hex string.
|
|
5
|
-
* The resulting hash is deterministic for the same input.
|
|
6
|
-
*
|
|
7
|
-
* @param input - The input string to hash.
|
|
8
|
-
* @returns A Promise that resolves to a hexadecimal string representing the SHA-256 hash.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const hash = await generateHash('hello world')
|
|
12
|
-
* console.log(hash) // => 'b94d27b9934d3e08a52e52d7da7dabfadeb...'
|
|
13
|
-
*/
|
|
14
|
-
export declare const generateHash: (input: string) => Promise<string>;
|
|
15
|
-
//# sourceMappingURL=generate-hash.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-hash.d.ts","sourceRoot":"","sources":["../../src/crypto/generate-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAU,OAAO,MAAM,KAAG,OAAO,CAAC,MAAM,CAUhE,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const generateHash = async (input) => {
|
|
2
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(input));
|
|
3
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
4
|
-
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
5
|
-
return hashHex;
|
|
6
|
-
};
|
|
7
|
-
export {
|
|
8
|
-
generateHash
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=generate-hash.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/crypto/generate-hash.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Generates a SHA-256 hexadecimal hash for the provided string input.\n *\n * This function uses the Web Crypto API, returning a lowercase hex string.\n * The resulting hash is deterministic for the same input.\n *\n * @param input - The input string to hash.\n * @returns A Promise that resolves to a hexadecimal string representing the SHA-256 hash.\n *\n * @example\n * const hash = await generateHash('hello world')\n * console.log(hash) // => 'b94d27b9934d3e08a52e52d7da7dabfadeb...'\n */\nexport const generateHash = async (input: string): Promise<string> => {\n const hashBuffer = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(input))\n\n // Convert the ArrayBuffer to a Uint8Array\n const hashArray = Array.from(new Uint8Array(hashBuffer))\n\n // Convert each byte to its hexadecimal representation and join them\n const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')\n\n return hashHex\n}\n"],
|
|
5
|
-
"mappings": "AAaO,MAAM,eAAe,OAAO,UAAmC;AACpE,QAAM,aAAa,MAAM,OAAO,OAAO,OAAO,WAAW,IAAI,YAAY,EAAE,OAAO,KAAK,CAAC;AAGxF,QAAM,YAAY,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;AAGvD,QAAM,UAAU,UAAU,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAE7E,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|