@scalar/helpers 0.1.0 → 0.1.2
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 +16 -0
- package/dist/general/debounce.d.ts +33 -0
- package/dist/general/debounce.d.ts.map +1 -0
- package/dist/general/debounce.js +55 -0
- package/dist/general/debounce.js.map +7 -0
- package/dist/regex/find-variables.d.ts +8 -1
- package/dist/regex/find-variables.d.ts.map +1 -1
- package/dist/regex/find-variables.js +3 -1
- package/dist/regex/find-variables.js.map +2 -2
- package/dist/regex/regex-helpers.d.ts +7 -0
- package/dist/regex/regex-helpers.d.ts.map +1 -1
- package/dist/regex/regex-helpers.js +3 -0
- package/dist/regex/regex-helpers.js.map +2 -2
- package/dist/string/create-hash.d.ts +1 -1
- package/dist/string/create-hash.js.map +1 -1
- package/dist/string/generate-hash.d.ts +15 -0
- package/dist/string/generate-hash.d.ts.map +1 -0
- package/dist/string/generate-hash.js +130 -0
- package/dist/string/generate-hash.js.map +7 -0
- package/dist/string/truncate.d.ts +13 -0
- package/dist/string/truncate.d.ts.map +1 -0
- package/dist/string/truncate.js +10 -0
- package/dist/string/truncate.js.map +7 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @scalar/helpers
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#7392](https://github.com/scalar/scalar/pull/7392) [`d86f1d6`](https://github.com/scalar/scalar/commit/d86f1d6911ecbca70b011a2a0efb6d6e0eca59bb) Thanks [@amritk](https://github.com/amritk)! - fix: move away from wasm hashing algo
|
|
8
|
+
|
|
9
|
+
- [#7348](https://github.com/scalar/scalar/pull/7348) [`cded2d6`](https://github.com/scalar/scalar/commit/cded2d6c087418c3c44731d344d0827a87b78b74) Thanks [@hwkr](https://github.com/hwkr)! - feat(components): add ScalarWrappingText component
|
|
10
|
+
|
|
11
|
+
## 0.1.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#7289](https://github.com/scalar/scalar/pull/7289) [`9c9dbba`](https://github.com/scalar/scalar/commit/9c9dbbaa940667303f0ace59469fd78c2a741937) Thanks [@amritk](https://github.com/amritk)! - feat: move debounce to helpers and add max wait
|
|
16
|
+
|
|
17
|
+
- [#7252](https://github.com/scalar/scalar/pull/7252) [`4bec1ba`](https://github.com/scalar/scalar/commit/4bec1ba332e919c4ee32dcfbfb07bd8ee42c4d74) Thanks [@hwkr](https://github.com/hwkr)! - fix(api-reference): improve wrapping of long strings
|
|
18
|
+
|
|
3
19
|
## 0.1.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring the debounce behavior.
|
|
3
|
+
*/
|
|
4
|
+
export type DebounceOptions = {
|
|
5
|
+
/** The delay in milliseconds before executing the function. Defaults to 100ms. */
|
|
6
|
+
delay?: number;
|
|
7
|
+
/** Maximum time in milliseconds to wait before forcing execution, even with continuous calls. */
|
|
8
|
+
maxWait?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a debounced function executor that delays execution until after a specified time.
|
|
12
|
+
* Multiple calls with the same key will cancel previous pending executions.
|
|
13
|
+
*
|
|
14
|
+
* This is useful for batching rapid updates (like auto-save or API calls) to avoid
|
|
15
|
+
* unnecessary processing or network requests.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Configuration options for delay, maxWait, and key separator
|
|
18
|
+
* @returns A function that accepts a key array and callback to execute
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const debouncedSave = debounce({ delay: 328 })
|
|
22
|
+
* debouncedSave.execute(['user', '123'], () => saveUser(user))
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // With maxWait to guarantee execution even with continuous calls
|
|
26
|
+
* const debouncedSave = debounce({ delay: 328, maxWait: 2000 })
|
|
27
|
+
* debouncedSave.execute(['user', '123'], () => saveUser(user))
|
|
28
|
+
*/
|
|
29
|
+
export declare const debounce: (options?: DebounceOptions) => {
|
|
30
|
+
execute: (key: string, fn: () => unknown | Promise<unknown>) => void;
|
|
31
|
+
cleanup: () => void;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=debounce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/general/debounce.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iGAAiG;IACjG,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,GAAI,UAAS,eAAoB;mBA6C9B,MAAM,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAG,IAAI;mBAvCrD,IAAI;CAiEzB,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const debounce = (options = {}) => {
|
|
2
|
+
const { delay = 328, maxWait } = options;
|
|
3
|
+
const timeouts = /* @__PURE__ */ new Map();
|
|
4
|
+
const maxWaitTimeouts = /* @__PURE__ */ new Map();
|
|
5
|
+
const latestFunctions = /* @__PURE__ */ new Map();
|
|
6
|
+
const cleanup = () => {
|
|
7
|
+
timeouts.forEach(clearTimeout);
|
|
8
|
+
maxWaitTimeouts.forEach(clearTimeout);
|
|
9
|
+
timeouts.clear();
|
|
10
|
+
maxWaitTimeouts.clear();
|
|
11
|
+
latestFunctions.clear();
|
|
12
|
+
};
|
|
13
|
+
const executeAndCleanup = (key) => {
|
|
14
|
+
const fn = latestFunctions.get(key);
|
|
15
|
+
const timeout = timeouts.get(key);
|
|
16
|
+
if (timeout !== void 0) {
|
|
17
|
+
clearTimeout(timeout);
|
|
18
|
+
timeouts.delete(key);
|
|
19
|
+
}
|
|
20
|
+
const maxWaitTimeout = maxWaitTimeouts.get(key);
|
|
21
|
+
if (maxWaitTimeout !== void 0) {
|
|
22
|
+
clearTimeout(maxWaitTimeout);
|
|
23
|
+
maxWaitTimeouts.delete(key);
|
|
24
|
+
}
|
|
25
|
+
latestFunctions.delete(key);
|
|
26
|
+
if (fn !== void 0) {
|
|
27
|
+
try {
|
|
28
|
+
fn();
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const execute = (key, fn) => {
|
|
34
|
+
latestFunctions.set(key, fn);
|
|
35
|
+
const existingTimeout = timeouts.get(key);
|
|
36
|
+
if (existingTimeout !== void 0) {
|
|
37
|
+
clearTimeout(existingTimeout);
|
|
38
|
+
}
|
|
39
|
+
timeouts.set(
|
|
40
|
+
key,
|
|
41
|
+
setTimeout(() => executeAndCleanup(key), delay)
|
|
42
|
+
);
|
|
43
|
+
if (maxWait !== void 0 && !maxWaitTimeouts.has(key)) {
|
|
44
|
+
maxWaitTimeouts.set(
|
|
45
|
+
key,
|
|
46
|
+
setTimeout(() => executeAndCleanup(key), maxWait)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return { execute, cleanup };
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
debounce
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=debounce.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/general/debounce.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Options for configuring the debounce behavior.\n */\nexport type DebounceOptions = {\n /** The delay in milliseconds before executing the function. Defaults to 100ms. */\n delay?: number\n /** Maximum time in milliseconds to wait before forcing execution, even with continuous calls. */\n maxWait?: number\n}\n\n/**\n * Creates a debounced function executor that delays execution until after a specified time.\n * Multiple calls with the same key will cancel previous pending executions.\n *\n * This is useful for batching rapid updates (like auto-save or API calls) to avoid\n * unnecessary processing or network requests.\n *\n * @param options - Configuration options for delay, maxWait, and key separator\n * @returns A function that accepts a key array and callback to execute\n *\n * @example\n * const debouncedSave = debounce({ delay: 328 })\n * debouncedSave.execute(['user', '123'], () => saveUser(user))\n *\n * @example\n * // With maxWait to guarantee execution even with continuous calls\n * const debouncedSave = debounce({ delay: 328, maxWait: 2000 })\n * debouncedSave.execute(['user', '123'], () => saveUser(user))\n */\nexport const debounce = (options: DebounceOptions = {}) => {\n const { delay = 328, maxWait } = options\n const timeouts = new Map<string, ReturnType<typeof setTimeout>>()\n const maxWaitTimeouts = new Map<string, ReturnType<typeof setTimeout>>()\n const latestFunctions = new Map<string, () => unknown | Promise<unknown>>()\n\n const cleanup = (): void => {\n timeouts.forEach(clearTimeout)\n maxWaitTimeouts.forEach(clearTimeout)\n timeouts.clear()\n maxWaitTimeouts.clear()\n latestFunctions.clear()\n }\n\n /** Executes the function and cleans up all associated timeouts */\n const executeAndCleanup = (key: string): void => {\n // Get the latest function for this key\n const fn = latestFunctions.get(key)\n\n // Clear both timeout types\n const timeout = timeouts.get(key)\n if (timeout !== undefined) {\n clearTimeout(timeout)\n timeouts.delete(key)\n }\n\n const maxWaitTimeout = maxWaitTimeouts.get(key)\n if (maxWaitTimeout !== undefined) {\n clearTimeout(maxWaitTimeout)\n maxWaitTimeouts.delete(key)\n }\n\n // Clear the latest function reference\n latestFunctions.delete(key)\n\n // Execute the function if it exists\n if (fn !== undefined) {\n try {\n fn()\n } catch {\n // Errors are silently caught to prevent the debounce mechanism from breaking\n }\n }\n }\n\n const execute = (key: string, fn: () => unknown | Promise<unknown>): void => {\n // Store the latest function for this key\n latestFunctions.set(key, fn)\n\n // Clear existing debounce timeout\n const existingTimeout = timeouts.get(key)\n if (existingTimeout !== undefined) {\n clearTimeout(existingTimeout)\n }\n\n // Set debounce timeout\n timeouts.set(\n key,\n setTimeout(() => executeAndCleanup(key), delay),\n )\n\n // Set maxWait timeout only if configured and this is a new sequence\n if (maxWait !== undefined && !maxWaitTimeouts.has(key)) {\n maxWaitTimeouts.set(\n key,\n setTimeout(() => executeAndCleanup(key), maxWait),\n )\n }\n }\n\n return { execute, cleanup }\n}\n"],
|
|
5
|
+
"mappings": "AA6BO,MAAM,WAAW,CAAC,UAA2B,CAAC,MAAM;AACzD,QAAM,EAAE,QAAQ,KAAK,QAAQ,IAAI;AACjC,QAAM,WAAW,oBAAI,IAA2C;AAChE,QAAM,kBAAkB,oBAAI,IAA2C;AACvE,QAAM,kBAAkB,oBAAI,IAA8C;AAE1E,QAAM,UAAU,MAAY;AAC1B,aAAS,QAAQ,YAAY;AAC7B,oBAAgB,QAAQ,YAAY;AACpC,aAAS,MAAM;AACf,oBAAgB,MAAM;AACtB,oBAAgB,MAAM;AAAA,EACxB;AAGA,QAAM,oBAAoB,CAAC,QAAsB;AAE/C,UAAM,KAAK,gBAAgB,IAAI,GAAG;AAGlC,UAAM,UAAU,SAAS,IAAI,GAAG;AAChC,QAAI,YAAY,QAAW;AACzB,mBAAa,OAAO;AACpB,eAAS,OAAO,GAAG;AAAA,IACrB;AAEA,UAAM,iBAAiB,gBAAgB,IAAI,GAAG;AAC9C,QAAI,mBAAmB,QAAW;AAChC,mBAAa,cAAc;AAC3B,sBAAgB,OAAO,GAAG;AAAA,IAC5B;AAGA,oBAAgB,OAAO,GAAG;AAG1B,QAAI,OAAO,QAAW;AACpB,UAAI;AACF,WAAG;AAAA,MACL,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,CAAC,KAAa,OAA+C;AAE3E,oBAAgB,IAAI,KAAK,EAAE;AAG3B,UAAM,kBAAkB,SAAS,IAAI,GAAG;AACxC,QAAI,oBAAoB,QAAW;AACjC,mBAAa,eAAe;AAAA,IAC9B;AAGA,aAAS;AAAA,MACP;AAAA,MACA,WAAW,MAAM,kBAAkB,GAAG,GAAG,KAAK;AAAA,IAChD;AAGA,QAAI,YAAY,UAAa,CAAC,gBAAgB,IAAI,GAAG,GAAG;AACtD,sBAAgB;AAAA,QACd;AAAA,QACA,WAAW,MAAM,kBAAkB,GAAG,GAAG,OAAO;AAAA,MAClD;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,QAAQ;AAC5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Find all strings wrapped in {} or {{}} in value.
|
|
3
|
+
*
|
|
4
|
+
* @param value - The string to find variables in
|
|
5
|
+
* @param includePath - Whether to include path variables {single}
|
|
6
|
+
* @param includeEnv - Whether to include environment variables {{double}}
|
|
3
7
|
*/
|
|
4
|
-
export declare const findVariables: (value: string
|
|
8
|
+
export declare const findVariables: (value: string, { includePath, includeEnv }?: {
|
|
9
|
+
includePath?: boolean;
|
|
10
|
+
includeEnv?: boolean;
|
|
11
|
+
}) => string[];
|
|
5
12
|
//# sourceMappingURL=find-variables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-variables.d.ts","sourceRoot":"","sources":["../../src/regex/find-variables.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"find-variables.d.ts","sourceRoot":"","sources":["../../src/regex/find-variables.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,MAAM,EACb,8BAA2C;IAAE,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,KAC9F,MAAM,EAON,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { REGEX } from "./regex-helpers.js";
|
|
2
|
-
const findVariables = (value) => [
|
|
2
|
+
const findVariables = (value, { includePath = true, includeEnv = true } = {}) => [includePath && REGEX.PATH, includeEnv && REGEX.VARIABLES].flatMap(
|
|
3
|
+
(regex) => regex ? [...value.matchAll(regex)].map((match) => match[1]?.trim()).filter((variable) => variable !== void 0) : []
|
|
4
|
+
);
|
|
3
5
|
export {
|
|
4
6
|
findVariables
|
|
5
7
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/regex/find-variables.ts"],
|
|
4
|
-
"sourcesContent": ["import { REGEX } from './regex-helpers'\n\n/**\n * Find all strings wrapped in {} or {{}} in value.\n */\nexport const findVariables = (value: string) =>\n [
|
|
5
|
-
"mappings": "AAAA,SAAS,aAAa;
|
|
4
|
+
"sourcesContent": ["import { REGEX } from './regex-helpers'\n\n/**\n * Find all strings wrapped in {} or {{}} in value.\n *\n * @param value - The string to find variables in\n * @param includePath - Whether to include path variables {single}\n * @param includeEnv - Whether to include environment variables {{double}}\n */\nexport const findVariables = (\n value: string,\n { includePath = true, includeEnv = true }: { includePath?: boolean; includeEnv?: boolean } = {},\n): string[] =>\n [includePath && REGEX.PATH, includeEnv && REGEX.VARIABLES].flatMap((regex) =>\n regex\n ? [...value.matchAll(regex)]\n .map((match) => match[1]?.trim())\n .filter((variable): variable is string => variable !== undefined)\n : [],\n )\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AASf,MAAM,gBAAgB,CAC3B,OACA,EAAE,cAAc,MAAM,aAAa,KAAK,IAAqD,CAAC,MAE9F,CAAC,eAAe,MAAM,MAAM,cAAc,MAAM,SAAS,EAAE;AAAA,EAAQ,CAAC,UAClE,QACI,CAAC,GAAG,MAAM,SAAS,KAAK,CAAC,EACtB,IAAI,CAAC,UAAU,MAAM,CAAC,GAAG,KAAK,CAAC,EAC/B,OAAO,CAAC,aAAiC,aAAa,MAAS,IAClE,CAAC;AACP;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection of regular expressions used throughout the application.
|
|
3
|
+
* These patterns handle URL parsing, variable detection, and reference path extraction.
|
|
4
|
+
*/
|
|
1
5
|
export declare const REGEX: {
|
|
2
6
|
/** Checks for a valid scheme */
|
|
3
7
|
readonly PROTOCOL: RegExp;
|
|
4
8
|
/** Finds multiple slashes after the scheme to replace with a single slash */
|
|
5
9
|
readonly MULTIPLE_SLASHES: RegExp;
|
|
10
|
+
/** Finds all variables wrapped in {{double}} */
|
|
6
11
|
readonly VARIABLES: RegExp;
|
|
12
|
+
/** Finds all variables wrapped in {single} */
|
|
7
13
|
readonly PATH: RegExp;
|
|
8
14
|
/** Finds the name of the schema from the ref path */
|
|
9
15
|
readonly REF_NAME: RegExp;
|
|
16
|
+
/** Finds template variables in multiple formats: {{var}}, {var}, or :var */
|
|
10
17
|
readonly TEMPLATE_VARIABLE: RegExp;
|
|
11
18
|
};
|
|
12
19
|
//# sourceMappingURL=regex-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex-helpers.d.ts","sourceRoot":"","sources":["../../src/regex/regex-helpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;IAChB,gCAAgC;;IAEhC,6EAA6E
|
|
1
|
+
{"version":3,"file":"regex-helpers.d.ts","sourceRoot":"","sources":["../../src/regex/regex-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,KAAK;IAChB,gCAAgC;;IAEhC,6EAA6E;;IAE7E,gDAAgD;;IAEhD,8CAA8C;;IAE9C,qDAAqD;;IAErD,4EAA4E;;CAEpE,CAAA"}
|
|
@@ -3,10 +3,13 @@ const REGEX = {
|
|
|
3
3
|
PROTOCOL: /^(?:https?|ftp|file|mailto|tel|data|wss?)*:\/\//,
|
|
4
4
|
/** Finds multiple slashes after the scheme to replace with a single slash */
|
|
5
5
|
MULTIPLE_SLASHES: /(?<!:)\/{2,}/g,
|
|
6
|
+
/** Finds all variables wrapped in {{double}} */
|
|
6
7
|
VARIABLES: /{{((?:[^{}]|{[^{}]*})*)}}/g,
|
|
8
|
+
/** Finds all variables wrapped in {single} */
|
|
7
9
|
PATH: /(?:{)([^{}]+)}(?!})/g,
|
|
8
10
|
/** Finds the name of the schema from the ref path */
|
|
9
11
|
REF_NAME: /\/([^\/]+)$/,
|
|
12
|
+
/** Finds template variables in multiple formats: {{var}}, {var}, or :var */
|
|
10
13
|
TEMPLATE_VARIABLE: /{{\s*([^}\s]+?)\s*}}|{\s*([^}\s]+?)\s*}|:\b[\w.]+\b/g
|
|
11
14
|
};
|
|
12
15
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/regex/regex-helpers.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Collection of regular expressions used throughout the application.\n * These patterns handle URL parsing, variable detection, and reference path extraction.\n */\nexport const REGEX = {\n /** Checks for a valid scheme */\n PROTOCOL: /^(?:https?|ftp|file|mailto|tel|data|wss?)*:\\/\\//,\n /** Finds multiple slashes after the scheme to replace with a single slash */\n MULTIPLE_SLASHES: /(?<!:)\\/{2,}/g,\n /** Finds all variables wrapped in {{double}} */\n VARIABLES: /{{((?:[^{}]|{[^{}]*})*)}}/g,\n /** Finds all variables wrapped in {single} */\n PATH: /(?:{)([^{}]+)}(?!})/g,\n /** Finds the name of the schema from the ref path */\n REF_NAME: /\\/([^\\/]+)$/,\n /** Finds template variables in multiple formats: {{var}}, {var}, or :var */\n TEMPLATE_VARIABLE: /{{\\s*([^}\\s]+?)\\s*}}|{\\s*([^}\\s]+?)\\s*}|:\\b[\\w.]+\\b/g,\n} as const\n"],
|
|
5
|
+
"mappings": "AAIO,MAAM,QAAQ;AAAA;AAAA,EAEnB,UAAU;AAAA;AAAA,EAEV,kBAAkB;AAAA;AAAA,EAElB,WAAW;AAAA;AAAA,EAEX,MAAM;AAAA;AAAA,EAEN,UAAU;AAAA;AAAA,EAEV,mBAAmB;AACrB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Simple 32 bit non-secure hash from a string input
|
|
3
3
|
*
|
|
4
|
-
* @deprecated
|
|
4
|
+
* @deprecated Please use generateHash from ./generate-hash.ts instead
|
|
5
5
|
*
|
|
6
6
|
* @see https://stackoverflow.com/a/7616484/1624255
|
|
7
7
|
*/
|
|
@@ -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 * @deprecated
|
|
4
|
+
"sourcesContent": ["/**\n * Simple 32 bit non-secure hash from a string input\n *\n * @deprecated Please use generateHash from ./generate-hash.ts 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
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
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MurmurHash3 64-bit (x64_128) implementation
|
|
3
|
+
*
|
|
4
|
+
* Generate a hash from a string using the MurmurHash3 algorithm
|
|
5
|
+
* Provides 128-bit hash output with excellent speed and distribution
|
|
6
|
+
*
|
|
7
|
+
* We had to move away from xxhash-wasm since it was causing issues with content security policy (CSP) violations.
|
|
8
|
+
*
|
|
9
|
+
* We cannot use crypto.subtle because it is only available in secure contexts (HTTPS) or on localhost.
|
|
10
|
+
*
|
|
11
|
+
* @param input - The string to hash
|
|
12
|
+
* @returns The hash of the input string
|
|
13
|
+
*/
|
|
14
|
+
export declare const generateHash: (input: string) => string;
|
|
15
|
+
//# sourceMappingURL=generate-hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-hash.d.ts","sourceRoot":"","sources":["../../src/string/generate-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,MA4K5C,CAAA"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const generateHash = (input) => {
|
|
2
|
+
const seed = 0;
|
|
3
|
+
let h1 = seed;
|
|
4
|
+
let h2 = seed;
|
|
5
|
+
const len = input.length;
|
|
6
|
+
const remainder = len & 15;
|
|
7
|
+
const bytes = len - remainder;
|
|
8
|
+
const c1 = 2277735313;
|
|
9
|
+
const c2 = 1291169091;
|
|
10
|
+
const c3 = 1390208809;
|
|
11
|
+
const c4 = 944331445;
|
|
12
|
+
for (let i = 0; i < bytes; i += 16) {
|
|
13
|
+
let k1 = input.charCodeAt(i) & 255 | (input.charCodeAt(i + 1) & 255) << 8 | (input.charCodeAt(i + 2) & 255) << 16 | (input.charCodeAt(i + 3) & 255) << 24;
|
|
14
|
+
let k2 = input.charCodeAt(i + 4) & 255 | (input.charCodeAt(i + 5) & 255) << 8 | (input.charCodeAt(i + 6) & 255) << 16 | (input.charCodeAt(i + 7) & 255) << 24;
|
|
15
|
+
let k3 = input.charCodeAt(i + 8) & 255 | (input.charCodeAt(i + 9) & 255) << 8 | (input.charCodeAt(i + 10) & 255) << 16 | (input.charCodeAt(i + 11) & 255) << 24;
|
|
16
|
+
let k4 = input.charCodeAt(i + 12) & 255 | (input.charCodeAt(i + 13) & 255) << 8 | (input.charCodeAt(i + 14) & 255) << 16 | (input.charCodeAt(i + 15) & 255) << 24;
|
|
17
|
+
k1 = Math.imul(k1, c1);
|
|
18
|
+
k1 = k1 << 15 | k1 >>> 17;
|
|
19
|
+
k1 = Math.imul(k1, c2);
|
|
20
|
+
h1 ^= k1;
|
|
21
|
+
h1 = h1 << 13 | h1 >>> 19;
|
|
22
|
+
h1 = Math.imul(h1, 5) + 3864292196;
|
|
23
|
+
k2 = Math.imul(k2, c2);
|
|
24
|
+
k2 = k2 << 16 | k2 >>> 16;
|
|
25
|
+
k2 = Math.imul(k2, c3);
|
|
26
|
+
h2 ^= k2;
|
|
27
|
+
h2 = h2 << 17 | h2 >>> 15;
|
|
28
|
+
h2 = Math.imul(h2, 5) + 461845907;
|
|
29
|
+
k3 = Math.imul(k3, c3);
|
|
30
|
+
k3 = k3 << 17 | k3 >>> 15;
|
|
31
|
+
k3 = Math.imul(k3, c4);
|
|
32
|
+
h1 ^= k3;
|
|
33
|
+
h1 = h1 << 15 | h1 >>> 17;
|
|
34
|
+
h1 = Math.imul(h1, 5) + 1390208809;
|
|
35
|
+
k4 = Math.imul(k4, c4);
|
|
36
|
+
k4 = k4 << 18 | k4 >>> 14;
|
|
37
|
+
k4 = Math.imul(k4, c1);
|
|
38
|
+
h2 ^= k4;
|
|
39
|
+
h2 = h2 << 13 | h2 >>> 19;
|
|
40
|
+
h2 = Math.imul(h2, 5) + 944331445;
|
|
41
|
+
}
|
|
42
|
+
if (remainder > 0) {
|
|
43
|
+
let k1 = 0;
|
|
44
|
+
let k2 = 0;
|
|
45
|
+
let k3 = 0;
|
|
46
|
+
let k4 = 0;
|
|
47
|
+
if (remainder >= 15) {
|
|
48
|
+
k4 ^= (input.charCodeAt(bytes + 14) & 255) << 16;
|
|
49
|
+
}
|
|
50
|
+
if (remainder >= 14) {
|
|
51
|
+
k4 ^= (input.charCodeAt(bytes + 13) & 255) << 8;
|
|
52
|
+
}
|
|
53
|
+
if (remainder >= 13) {
|
|
54
|
+
k4 ^= input.charCodeAt(bytes + 12) & 255;
|
|
55
|
+
k4 = Math.imul(k4, c4);
|
|
56
|
+
k4 = k4 << 18 | k4 >>> 14;
|
|
57
|
+
k4 = Math.imul(k4, c1);
|
|
58
|
+
h2 ^= k4;
|
|
59
|
+
}
|
|
60
|
+
if (remainder >= 12) {
|
|
61
|
+
k3 ^= (input.charCodeAt(bytes + 11) & 255) << 24;
|
|
62
|
+
}
|
|
63
|
+
if (remainder >= 11) {
|
|
64
|
+
k3 ^= (input.charCodeAt(bytes + 10) & 255) << 16;
|
|
65
|
+
}
|
|
66
|
+
if (remainder >= 10) {
|
|
67
|
+
k3 ^= (input.charCodeAt(bytes + 9) & 255) << 8;
|
|
68
|
+
}
|
|
69
|
+
if (remainder >= 9) {
|
|
70
|
+
k3 ^= input.charCodeAt(bytes + 8) & 255;
|
|
71
|
+
k3 = Math.imul(k3, c3);
|
|
72
|
+
k3 = k3 << 17 | k3 >>> 15;
|
|
73
|
+
k3 = Math.imul(k3, c4);
|
|
74
|
+
h1 ^= k3;
|
|
75
|
+
}
|
|
76
|
+
if (remainder >= 8) {
|
|
77
|
+
k2 ^= (input.charCodeAt(bytes + 7) & 255) << 24;
|
|
78
|
+
}
|
|
79
|
+
if (remainder >= 7) {
|
|
80
|
+
k2 ^= (input.charCodeAt(bytes + 6) & 255) << 16;
|
|
81
|
+
}
|
|
82
|
+
if (remainder >= 6) {
|
|
83
|
+
k2 ^= (input.charCodeAt(bytes + 5) & 255) << 8;
|
|
84
|
+
}
|
|
85
|
+
if (remainder >= 5) {
|
|
86
|
+
k2 ^= input.charCodeAt(bytes + 4) & 255;
|
|
87
|
+
k2 = Math.imul(k2, c2);
|
|
88
|
+
k2 = k2 << 16 | k2 >>> 16;
|
|
89
|
+
k2 = Math.imul(k2, c3);
|
|
90
|
+
h2 ^= k2;
|
|
91
|
+
}
|
|
92
|
+
if (remainder >= 4) {
|
|
93
|
+
k1 ^= (input.charCodeAt(bytes + 3) & 255) << 24;
|
|
94
|
+
}
|
|
95
|
+
if (remainder >= 3) {
|
|
96
|
+
k1 ^= (input.charCodeAt(bytes + 2) & 255) << 16;
|
|
97
|
+
}
|
|
98
|
+
if (remainder >= 2) {
|
|
99
|
+
k1 ^= (input.charCodeAt(bytes + 1) & 255) << 8;
|
|
100
|
+
}
|
|
101
|
+
if (remainder >= 1) {
|
|
102
|
+
k1 ^= input.charCodeAt(bytes) & 255;
|
|
103
|
+
k1 = Math.imul(k1, c1);
|
|
104
|
+
k1 = k1 << 15 | k1 >>> 17;
|
|
105
|
+
k1 = Math.imul(k1, c2);
|
|
106
|
+
h1 ^= k1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
h1 ^= len;
|
|
110
|
+
h2 ^= len;
|
|
111
|
+
h1 += h2;
|
|
112
|
+
h2 += h1;
|
|
113
|
+
h1 ^= h1 >>> 16;
|
|
114
|
+
h1 = Math.imul(h1, 2246822507);
|
|
115
|
+
h1 ^= h1 >>> 13;
|
|
116
|
+
h1 = Math.imul(h1, 3266489909);
|
|
117
|
+
h1 ^= h1 >>> 16;
|
|
118
|
+
h2 ^= h2 >>> 16;
|
|
119
|
+
h2 = Math.imul(h2, 2246822507);
|
|
120
|
+
h2 ^= h2 >>> 13;
|
|
121
|
+
h2 = Math.imul(h2, 3266489909);
|
|
122
|
+
h2 ^= h2 >>> 16;
|
|
123
|
+
h1 += h2;
|
|
124
|
+
h2 += h1;
|
|
125
|
+
return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
|
126
|
+
};
|
|
127
|
+
export {
|
|
128
|
+
generateHash
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=generate-hash.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/string/generate-hash.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * MurmurHash3 64-bit (x64_128) implementation\n *\n * Generate a hash from a string using the MurmurHash3 algorithm\n * Provides 128-bit hash output with excellent speed and distribution\n *\n * We had to move away from xxhash-wasm since it was causing issues with content security policy (CSP) violations.\n *\n * We cannot use crypto.subtle because it is only available in secure contexts (HTTPS) or on localhost.\n *\n * @param input - The string to hash\n * @returns The hash of the input string\n */\nexport const generateHash = (input: string): string => {\n const seed = 0\n\n // Working with 64-bit values using pairs of 32-bit integers\n let h1 = seed\n let h2 = seed\n\n const len = input.length\n const remainder = len & 15 // len % 16\n const bytes = len - remainder\n\n const c1 = 0x87c37b91\n const c2 = 0x4cf5ad43\n const c3 = 0x52dce729\n const c4 = 0x38495ab5\n\n // Process 16-byte chunks\n for (let i = 0; i < bytes; i += 16) {\n let k1 =\n (input.charCodeAt(i) & 0xff) |\n ((input.charCodeAt(i + 1) & 0xff) << 8) |\n ((input.charCodeAt(i + 2) & 0xff) << 16) |\n ((input.charCodeAt(i + 3) & 0xff) << 24)\n\n let k2 =\n (input.charCodeAt(i + 4) & 0xff) |\n ((input.charCodeAt(i + 5) & 0xff) << 8) |\n ((input.charCodeAt(i + 6) & 0xff) << 16) |\n ((input.charCodeAt(i + 7) & 0xff) << 24)\n\n let k3 =\n (input.charCodeAt(i + 8) & 0xff) |\n ((input.charCodeAt(i + 9) & 0xff) << 8) |\n ((input.charCodeAt(i + 10) & 0xff) << 16) |\n ((input.charCodeAt(i + 11) & 0xff) << 24)\n\n let k4 =\n (input.charCodeAt(i + 12) & 0xff) |\n ((input.charCodeAt(i + 13) & 0xff) << 8) |\n ((input.charCodeAt(i + 14) & 0xff) << 16) |\n ((input.charCodeAt(i + 15) & 0xff) << 24)\n\n k1 = Math.imul(k1, c1)\n k1 = (k1 << 15) | (k1 >>> 17)\n k1 = Math.imul(k1, c2)\n h1 ^= k1\n\n h1 = (h1 << 13) | (h1 >>> 19)\n h1 = Math.imul(h1, 5) + 0xe6546b64\n\n k2 = Math.imul(k2, c2)\n k2 = (k2 << 16) | (k2 >>> 16)\n k2 = Math.imul(k2, c3)\n h2 ^= k2\n\n h2 = (h2 << 17) | (h2 >>> 15)\n h2 = Math.imul(h2, 5) + 0x1b873593\n\n k3 = Math.imul(k3, c3)\n k3 = (k3 << 17) | (k3 >>> 15)\n k3 = Math.imul(k3, c4)\n h1 ^= k3\n\n h1 = (h1 << 15) | (h1 >>> 17)\n h1 = Math.imul(h1, 5) + 0x52dce729\n\n k4 = Math.imul(k4, c4)\n k4 = (k4 << 18) | (k4 >>> 14)\n k4 = Math.imul(k4, c1)\n h2 ^= k4\n\n h2 = (h2 << 13) | (h2 >>> 19)\n h2 = Math.imul(h2, 5) + 0x38495ab5\n }\n\n // Process remaining bytes\n if (remainder > 0) {\n let k1 = 0\n let k2 = 0\n let k3 = 0\n let k4 = 0\n\n if (remainder >= 15) {\n k4 ^= (input.charCodeAt(bytes + 14) & 0xff) << 16\n }\n if (remainder >= 14) {\n k4 ^= (input.charCodeAt(bytes + 13) & 0xff) << 8\n }\n if (remainder >= 13) {\n k4 ^= input.charCodeAt(bytes + 12) & 0xff\n k4 = Math.imul(k4, c4)\n k4 = (k4 << 18) | (k4 >>> 14)\n k4 = Math.imul(k4, c1)\n h2 ^= k4\n }\n\n if (remainder >= 12) {\n k3 ^= (input.charCodeAt(bytes + 11) & 0xff) << 24\n }\n if (remainder >= 11) {\n k3 ^= (input.charCodeAt(bytes + 10) & 0xff) << 16\n }\n if (remainder >= 10) {\n k3 ^= (input.charCodeAt(bytes + 9) & 0xff) << 8\n }\n if (remainder >= 9) {\n k3 ^= input.charCodeAt(bytes + 8) & 0xff\n k3 = Math.imul(k3, c3)\n k3 = (k3 << 17) | (k3 >>> 15)\n k3 = Math.imul(k3, c4)\n h1 ^= k3\n }\n\n if (remainder >= 8) {\n k2 ^= (input.charCodeAt(bytes + 7) & 0xff) << 24\n }\n if (remainder >= 7) {\n k2 ^= (input.charCodeAt(bytes + 6) & 0xff) << 16\n }\n if (remainder >= 6) {\n k2 ^= (input.charCodeAt(bytes + 5) & 0xff) << 8\n }\n if (remainder >= 5) {\n k2 ^= input.charCodeAt(bytes + 4) & 0xff\n k2 = Math.imul(k2, c2)\n k2 = (k2 << 16) | (k2 >>> 16)\n k2 = Math.imul(k2, c3)\n h2 ^= k2\n }\n\n if (remainder >= 4) {\n k1 ^= (input.charCodeAt(bytes + 3) & 0xff) << 24\n }\n if (remainder >= 3) {\n k1 ^= (input.charCodeAt(bytes + 2) & 0xff) << 16\n }\n if (remainder >= 2) {\n k1 ^= (input.charCodeAt(bytes + 1) & 0xff) << 8\n }\n if (remainder >= 1) {\n k1 ^= input.charCodeAt(bytes) & 0xff\n k1 = Math.imul(k1, c1)\n k1 = (k1 << 15) | (k1 >>> 17)\n k1 = Math.imul(k1, c2)\n h1 ^= k1\n }\n }\n\n // Finalization\n h1 ^= len\n h2 ^= len\n\n h1 += h2\n h2 += h1\n\n h1 ^= h1 >>> 16\n h1 = Math.imul(h1, 0x85ebca6b)\n h1 ^= h1 >>> 13\n h1 = Math.imul(h1, 0xc2b2ae35)\n h1 ^= h1 >>> 16\n\n h2 ^= h2 >>> 16\n h2 = Math.imul(h2, 0x85ebca6b)\n h2 ^= h2 >>> 13\n h2 = Math.imul(h2, 0xc2b2ae35)\n h2 ^= h2 >>> 16\n\n h1 += h2\n h2 += h1\n\n // Return 128-bit hash as hex string\n return (h1 >>> 0).toString(16).padStart(8, '0') + (h2 >>> 0).toString(16).padStart(8, '0')\n}\n"],
|
|
5
|
+
"mappings": "AAaO,MAAM,eAAe,CAAC,UAA0B;AACrD,QAAM,OAAO;AAGb,MAAI,KAAK;AACT,MAAI,KAAK;AAET,QAAM,MAAM,MAAM;AAClB,QAAM,YAAY,MAAM;AACxB,QAAM,QAAQ,MAAM;AAEpB,QAAM,KAAK;AACX,QAAM,KAAK;AACX,QAAM,KAAK;AACX,QAAM,KAAK;AAGX,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK,IAAI;AAClC,QAAI,KACD,MAA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": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncates a string to a specified length and adds an ellipsis if it's longer in JS
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to truncate
|
|
5
|
+
* @param maxLength - The maximum length before truncation (default: 18)
|
|
6
|
+
* @returns The truncated string with ellipsis if needed
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* truncate('Very long name that needs truncation') // 'Very long name th…'
|
|
10
|
+
* truncate('Short') // 'Short'
|
|
11
|
+
*/
|
|
12
|
+
export declare const truncate: (str: string, maxLength?: number) => string;
|
|
13
|
+
//# sourceMappingURL=truncate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate.d.ts","sourceRoot":"","sources":["../../src/string/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,kBAAc,KAAG,MAKtD,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/string/truncate.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Truncates a string to a specified length and adds an ellipsis if it's longer in JS\n *\n * @param str - The string to truncate\n * @param maxLength - The maximum length before truncation (default: 18)\n * @returns The truncated string with ellipsis if needed\n *\n * @example\n * truncate('Very long name that needs truncation') // 'Very long name th\u2026'\n * truncate('Short') // 'Short'\n */\nexport const truncate = (str: string, maxLength = 18): string => {\n if (str.length <= maxLength) {\n return str\n }\n return str.slice(0, maxLength) + '\u2026'\n}\n"],
|
|
5
|
+
"mappings": "AAWO,MAAM,WAAW,CAAC,KAAa,YAAY,OAAe;AAC/D,MAAI,IAAI,UAAU,WAAW;AAC3B,WAAO;AAAA,EACT;AACA,SAAO,IAAI,MAAM,GAAG,SAAS,IAAI;AACnC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
"helpers",
|
|
15
15
|
"js"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.1.
|
|
17
|
+
"version": "0.1.2",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=20"
|
|
20
20
|
},
|
|
21
21
|
"type": "module",
|
|
22
22
|
"main": "dist/index.js",
|
|
23
|
+
"module": "dist/index.js",
|
|
23
24
|
"exports": {
|
|
24
25
|
"./array/*": {
|
|
25
26
|
"import": "./dist/array/*.js",
|
|
@@ -86,18 +87,17 @@
|
|
|
86
87
|
"dist",
|
|
87
88
|
"CHANGELOG.md"
|
|
88
89
|
],
|
|
89
|
-
"module": "dist/index.js",
|
|
90
90
|
"devDependencies": {
|
|
91
|
+
"jsdom": "26.1.0",
|
|
91
92
|
"vite": "7.1.11",
|
|
92
93
|
"vitest": "3.2.4",
|
|
93
|
-
"@scalar/build-tooling": "0.
|
|
94
|
+
"@scalar/build-tooling": "0.3.0"
|
|
94
95
|
},
|
|
95
96
|
"scripts": {
|
|
96
97
|
"build": "scalar-build-esbuild",
|
|
97
98
|
"lint:check": "biome lint --diagnostic-level=error",
|
|
98
99
|
"lint:fix": "biome lint --write",
|
|
99
100
|
"test": "vitest",
|
|
100
|
-
"test:coverage": "vitest run --coverage",
|
|
101
101
|
"types:build": "scalar-types-build",
|
|
102
102
|
"types:check": "scalar-types-check"
|
|
103
103
|
}
|