@scalar/helpers 0.0.11 → 0.0.13
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 +12 -0
- package/dist/crypto/generate-hash.d.ts +15 -0
- package/dist/crypto/generate-hash.d.ts.map +1 -0
- package/dist/crypto/generate-hash.js +10 -0
- package/dist/crypto/generate-hash.js.map +7 -0
- package/dist/dom/scroll-to-id.d.ts +1 -1
- package/dist/dom/scroll-to-id.d.ts.map +1 -1
- package/dist/dom/scroll-to-id.js +1 -1
- package/dist/dom/scroll-to-id.js.map +2 -2
- package/dist/http/http-info.d.ts +0 -11
- package/dist/http/http-info.d.ts.map +1 -1
- package/dist/http/http-info.js +0 -6
- package/dist/http/http-info.js.map +2 -2
- package/dist/http/http-methods.d.ts +3 -3
- package/dist/http/http-methods.d.ts.map +1 -1
- package/dist/http/http-methods.js +1 -1
- package/dist/http/http-methods.js.map +2 -2
- package/dist/testing/measure.d.ts +1 -1
- package/dist/testing/measure.d.ts.map +1 -1
- package/dist/testing/measure.js.map +2 -2
- package/dist/testing/measure.test-d.d.ts +2 -0
- package/dist/testing/measure.test-d.d.ts.map +1 -0
- package/dist/testing/measure.test-d.js +12 -0
- package/dist/testing/measure.test-d.js.map +7 -0
- package/package.json +8 -3
- package/dist/dom/freeze-at-top.d.ts +0 -6
- package/dist/dom/freeze-at-top.d.ts.map +0 -1
- package/dist/dom/freeze-at-top.js +0 -34
- package/dist/dom/freeze-at-top.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @scalar/helpers
|
|
2
2
|
|
|
3
|
+
## 0.0.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#7129](https://github.com/scalar/scalar/pull/7129) [`6ec8c29`](https://github.com/scalar/scalar/commit/6ec8c299d912111b029e8058979d00968b70691a) Thanks [@geoffgscott](https://github.com/geoffgscott)! - Simplify ApiReferences state management and migrate to new shared sidebar component. Eliminates the useSidebar and useNav hooks in favour of event bubbling and centralized state management in ApiReference.vue
|
|
8
|
+
|
|
9
|
+
## 0.0.12
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3f6d0b9: fix(helpers): `scrollToId` is not an async function
|
|
14
|
+
|
|
3
15
|
## 0.0.11
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-to-id.d.ts","sourceRoot":"","sources":["../../src/dom/scroll-to-id.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"scroll-to-id.d.ts","sourceRoot":"","sources":["../../src/dom/scroll-to-id.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,MAAM,EAAE,QAAQ,OAAO,KAAG,IAkCxD,CAAA"}
|
package/dist/dom/scroll-to-id.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/scroll-to-id.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Tiny wrapper around the scrollIntoView API\n *\n * Also focuses the element if the focus flag is true\n */\nexport const scrollToId =
|
|
5
|
-
"mappings": "AAKO,MAAM,aAAa,
|
|
4
|
+
"sourcesContent": ["/**\n * Tiny wrapper around the scrollIntoView API\n *\n * Also focuses the element if the focus flag is true\n */\nexport const scrollToId = (id: string, focus?: boolean): void => {\n const scrollToElement = (element: HTMLElement) => {\n element.scrollIntoView()\n if (focus) {\n element.focus()\n }\n }\n\n // Try to find the element immediately\n const element = document.getElementById(id)\n if (element) {\n scrollToElement(element)\n return\n }\n\n /** Try to find the element for up to 1 second\n * allowing it to render for instance in markdown heading usage\n */\n const stopTime = Date.now() + 1000\n\n const tryScroll = (): void => {\n const element = document.getElementById(id)\n if (element) {\n scrollToElement(element)\n return\n }\n\n if (Date.now() < stopTime) {\n requestAnimationFrame(tryScroll)\n }\n }\n\n // Start the retry process if the element doesn't exist yet\n requestAnimationFrame(tryScroll)\n}\n"],
|
|
5
|
+
"mappings": "AAKO,MAAM,aAAa,CAAC,IAAY,UAA0B;AAC/D,QAAM,kBAAkB,CAACA,aAAyB;AAChD,IAAAA,SAAQ,eAAe;AACvB,QAAI,OAAO;AACT,MAAAA,SAAQ,MAAM;AAAA,IAChB;AAAA,EACF;AAGA,QAAM,UAAU,SAAS,eAAe,EAAE;AAC1C,MAAI,SAAS;AACX,oBAAgB,OAAO;AACvB;AAAA,EACF;AAKA,QAAM,WAAW,KAAK,IAAI,IAAI;AAE9B,QAAM,YAAY,MAAY;AAC5B,UAAMA,WAAU,SAAS,eAAe,EAAE;AAC1C,QAAIA,UAAS;AACX,sBAAgBA,QAAO;AACvB;AAAA,IACF;AAEA,QAAI,KAAK,IAAI,IAAI,UAAU;AACzB,4BAAsB,SAAS;AAAA,IACjC;AAAA,EACF;AAGA,wBAAsB,SAAS;AACjC;",
|
|
6
6
|
"names": ["element"]
|
|
7
7
|
}
|
package/dist/http/http-info.d.ts
CHANGED
|
@@ -51,12 +51,6 @@ export declare const REQUEST_METHODS: {
|
|
|
51
51
|
readonly colorVar: "var(--scalar-color-2)";
|
|
52
52
|
readonly backgroundColor: "bg-c-2/10";
|
|
53
53
|
};
|
|
54
|
-
readonly connect: {
|
|
55
|
-
readonly short: "CONN";
|
|
56
|
-
readonly colorClass: "text-c-2";
|
|
57
|
-
readonly colorVar: "var(--scalar-color-2)";
|
|
58
|
-
readonly backgroundColor: "bg-c-2/10";
|
|
59
|
-
};
|
|
60
54
|
readonly trace: {
|
|
61
55
|
readonly short: "TRACE";
|
|
62
56
|
readonly colorClass: "text-c-2";
|
|
@@ -102,11 +96,6 @@ export declare const getHttpMethodInfo: (methodName: string) => {
|
|
|
102
96
|
readonly colorClass: "text-c-2";
|
|
103
97
|
readonly colorVar: "var(--scalar-color-2)";
|
|
104
98
|
readonly backgroundColor: "bg-c-2/10";
|
|
105
|
-
} | {
|
|
106
|
-
readonly short: "CONN";
|
|
107
|
-
readonly colorClass: "text-c-2";
|
|
108
|
-
readonly colorVar: "var(--scalar-color-2)";
|
|
109
|
-
readonly backgroundColor: "bg-c-2/10";
|
|
110
99
|
} | {
|
|
111
100
|
readonly short: "TRACE";
|
|
112
101
|
readonly colorClass: "text-c-2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-info.d.ts","sourceRoot":"","sources":["../../src/http/http-info.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,QAAQ,MAAM,EAAE,CAAA;IAC5B,QAAQ,EAAE,sBAAsB,MAAM,GAAG,CAAA;IACzC,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"http-info.d.ts","sourceRoot":"","sources":["../../src/http/http-info.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,QAAQ,MAAM,EAAE,CAAA;IAC5B,QAAQ,EAAE,sBAAsB,MAAM,GAAG,CAAA;IACzC,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDqB,CAAA;AAEjD;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASnD,CAAA"}
|
package/dist/http/http-info.js
CHANGED
|
@@ -41,12 +41,6 @@ const REQUEST_METHODS = {
|
|
|
41
41
|
colorVar: "var(--scalar-color-2)",
|
|
42
42
|
backgroundColor: "bg-c-2/10"
|
|
43
43
|
},
|
|
44
|
-
connect: {
|
|
45
|
-
short: "CONN",
|
|
46
|
-
colorClass: "text-c-2",
|
|
47
|
-
colorVar: "var(--scalar-color-2)",
|
|
48
|
-
backgroundColor: "bg-c-2/10"
|
|
49
|
-
},
|
|
50
44
|
trace: {
|
|
51
45
|
short: "TRACE",
|
|
52
46
|
colorClass: "text-c-2",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/http/http-info.ts"],
|
|
4
|
-
"sourcesContent": ["import type { HttpMethod } from './http-methods'\n\nexport type HttpInfo = {\n short: string\n colorClass: `text-${string}`\n colorVar: `var(--scalar-color-${string})`\n backgroundColor: string\n}\n\n/**\n * HTTP methods in a specific order\n * Do not change the order\n */\nexport const REQUEST_METHODS = {\n get: {\n short: 'GET',\n colorClass: 'text-blue',\n colorVar: 'var(--scalar-color-blue)',\n backgroundColor: 'bg-blue/10',\n },\n post: {\n short: 'POST',\n colorClass: 'text-green',\n colorVar: 'var(--scalar-color-green)',\n backgroundColor: 'bg-green/10',\n },\n put: {\n short: 'PUT',\n colorClass: 'text-orange',\n colorVar: 'var(--scalar-color-orange)',\n backgroundColor: 'bg-orange/10',\n },\n patch: {\n short: 'PATCH',\n colorClass: 'text-yellow',\n colorVar: 'var(--scalar-color-yellow)',\n backgroundColor: 'bg-yellow/10',\n },\n delete: {\n short: 'DEL',\n colorClass: 'text-red',\n colorVar: 'var(--scalar-color-red)',\n backgroundColor: 'bg-red/10',\n },\n options: {\n short: 'OPTS',\n colorClass: 'text-purple',\n colorVar: 'var(--scalar-color-purple)',\n backgroundColor: 'bg-purple/10',\n },\n head: {\n short: 'HEAD',\n colorClass: 'text-c-2',\n colorVar: 'var(--scalar-color-2)',\n backgroundColor: 'bg-c-2/10',\n },\n
|
|
5
|
-
"mappings": "AAaO,MAAM,kBAAkB;AAAA,EAC7B,KAAK;AAAA,IACH,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,KAAK;AAAA,IACH,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,SAAS;AAAA,IACP,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,
|
|
4
|
+
"sourcesContent": ["import type { HttpMethod } from './http-methods'\n\nexport type HttpInfo = {\n short: string\n colorClass: `text-${string}`\n colorVar: `var(--scalar-color-${string})`\n backgroundColor: string\n}\n\n/**\n * HTTP methods in a specific order\n * Do not change the order\n */\nexport const REQUEST_METHODS = {\n get: {\n short: 'GET',\n colorClass: 'text-blue',\n colorVar: 'var(--scalar-color-blue)',\n backgroundColor: 'bg-blue/10',\n },\n post: {\n short: 'POST',\n colorClass: 'text-green',\n colorVar: 'var(--scalar-color-green)',\n backgroundColor: 'bg-green/10',\n },\n put: {\n short: 'PUT',\n colorClass: 'text-orange',\n colorVar: 'var(--scalar-color-orange)',\n backgroundColor: 'bg-orange/10',\n },\n patch: {\n short: 'PATCH',\n colorClass: 'text-yellow',\n colorVar: 'var(--scalar-color-yellow)',\n backgroundColor: 'bg-yellow/10',\n },\n delete: {\n short: 'DEL',\n colorClass: 'text-red',\n colorVar: 'var(--scalar-color-red)',\n backgroundColor: 'bg-red/10',\n },\n options: {\n short: 'OPTS',\n colorClass: 'text-purple',\n colorVar: 'var(--scalar-color-purple)',\n backgroundColor: 'bg-purple/10',\n },\n head: {\n short: 'HEAD',\n colorClass: 'text-c-2',\n colorVar: 'var(--scalar-color-2)',\n backgroundColor: 'bg-c-2/10',\n },\n trace: {\n short: 'TRACE',\n colorClass: 'text-c-2',\n colorVar: 'var(--scalar-color-2)',\n backgroundColor: 'bg-c-2/10',\n },\n} as const satisfies Record<HttpMethod, HttpInfo>\n\n/**\n * Accepts an HTTP Method name and returns some properties for the tag\n */\nexport const getHttpMethodInfo = (methodName: string) => {\n const normalizedMethod = methodName.trim().toLowerCase() as HttpMethod\n return (\n REQUEST_METHODS[normalizedMethod] ?? {\n short: normalizedMethod,\n color: 'text-c-2',\n backgroundColor: 'bg-c-2',\n }\n )\n}\n"],
|
|
5
|
+
"mappings": "AAaO,MAAM,kBAAkB;AAAA,EAC7B,KAAK;AAAA,IACH,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,KAAK;AAAA,IACH,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,SAAS;AAAA,IACP,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,iBAAiB;AAAA,EACnB;AACF;AAKO,MAAM,oBAAoB,CAAC,eAAuB;AACvD,QAAM,mBAAmB,WAAW,KAAK,EAAE,YAAY;AACvD,SACE,gBAAgB,gBAAgB,KAAK;AAAA,IACnC,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/** All OpenAPI HTTP methods
|
|
2
|
-
export declare const HTTP_METHODS: readonly ["
|
|
1
|
+
/** All OpenAPI HTTP methods */
|
|
2
|
+
export declare const HTTP_METHODS: readonly ["delete", "get", "head", "options", "patch", "post", "put", "trace"];
|
|
3
3
|
/** All http methods we support */
|
|
4
4
|
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
5
5
|
/** Set of all http methods we support */
|
|
6
|
-
export declare const httpMethods: Readonly<Set<"
|
|
6
|
+
export declare const httpMethods: Readonly<Set<"delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace">>;
|
|
7
7
|
//# sourceMappingURL=http-methods.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-methods.d.ts","sourceRoot":"","sources":["../../src/http/http-methods.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"http-methods.d.ts","sourceRoot":"","sources":["../../src/http/http-methods.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,eAAO,MAAM,YAAY,gFAAiF,CAAA;AAE1G,kCAAkC;AAClC,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtD,yCAAyC;AACzC,eAAO,MAAM,WAAW,2FAAuC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const HTTP_METHODS = ["
|
|
1
|
+
const HTTP_METHODS = ["delete", "get", "head", "options", "patch", "post", "put", "trace"];
|
|
2
2
|
const httpMethods = Object.freeze(new Set(HTTP_METHODS));
|
|
3
3
|
export {
|
|
4
4
|
HTTP_METHODS,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/http/http-methods.ts"],
|
|
4
|
-
"sourcesContent": ["/** All OpenAPI HTTP methods
|
|
5
|
-
"mappings": "AACO,MAAM,eAAe,CAAC,
|
|
4
|
+
"sourcesContent": ["/** All OpenAPI HTTP methods */\nexport const HTTP_METHODS = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'trace'] as const\n\n/** All http methods we support */\nexport type HttpMethod = (typeof HTTP_METHODS)[number]\n\n/** Set of all http methods we support */\nexport const httpMethods = Object.freeze(new Set(HTTP_METHODS))\n"],
|
|
5
|
+
"mappings": "AACO,MAAM,eAAe,CAAC,UAAU,OAAO,QAAQ,WAAW,SAAS,QAAQ,OAAO,OAAO;AAMzF,MAAM,cAAc,OAAO,OAAO,IAAI,IAAI,YAAY,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* })
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
export declare const measureSync: <
|
|
15
|
+
export declare const measureSync: <F extends () => unknown>(name: string, fn: ReturnType<F> extends Promise<unknown> ? never : F) => ReturnType<F>;
|
|
16
16
|
/**
|
|
17
17
|
* Measures the execution time of an async function and logs it.
|
|
18
18
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../src/testing/measure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../src/testing/measure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,OAAO,EACjD,MAAM,MAAM,EACZ,IAAI,UAAU,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,KACrD,UAAU,CAAC,CAAC,CAWd,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,EAAE,MAAM,MAAM,EAAE,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAWnF,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/testing/measure.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Measures the execution time of a function and logs it.\n *\n * Works only with sync functions and returns the result of the measured function.\n *\n * @example\n *\n * ```ts\n * // Sync function\n * const result = measureSync('computation', () => {\n * return heavyComputation()\n * })\n * ```\n */\nexport const measureSync = <
|
|
5
|
-
"mappings": "AAcO,MAAM,cAAc,
|
|
4
|
+
"sourcesContent": ["/**\n * Measures the execution time of a function and logs it.\n *\n * Works only with sync functions and returns the result of the measured function.\n *\n * @example\n *\n * ```ts\n * // Sync function\n * const result = measureSync('computation', () => {\n * return heavyComputation()\n * })\n * ```\n */\nexport const measureSync = <F extends () => unknown>(\n name: string,\n fn: ReturnType<F> extends Promise<unknown> ? never : F,\n): ReturnType<F> => {\n const start = performance.now()\n\n const result = fn()\n\n const end = performance.now()\n const duration = Math.round(end - start)\n\n console.info(`${name}: ${duration} ms`)\n\n return result as ReturnType<F>\n}\n\n/**\n * Measures the execution time of an async function and logs it.\n *\n * Works only with async functions and returns the result of the measured function.\n *\n * @example\n *\n * ```ts\n * // Async function\n * const result = await measure('api-call', async () => {\n * return await fetchData()\n * })\n * ````\n */\nexport const measureAsync = async <T>(name: string, fn: () => Promise<T>): Promise<T> => {\n const start = performance.now()\n\n const result = await fn()\n\n const end = performance.now()\n const duration = Math.round(end - start)\n\n console.info(`${name}: ${duration} ms`)\n\n return result\n}\n"],
|
|
5
|
+
"mappings": "AAcO,MAAM,cAAc,CACzB,MACA,OACkB;AAClB,QAAM,QAAQ,YAAY,IAAI;AAE9B,QAAM,SAAS,GAAG;AAElB,QAAM,MAAM,YAAY,IAAI;AAC5B,QAAM,WAAW,KAAK,MAAM,MAAM,KAAK;AAEvC,UAAQ,KAAK,GAAG,IAAI,KAAK,QAAQ,KAAK;AAEtC,SAAO;AACT;AAgBO,MAAM,eAAe,OAAU,MAAc,OAAqC;AACvF,QAAM,QAAQ,YAAY,IAAI;AAE9B,QAAM,SAAS,MAAM,GAAG;AAExB,QAAM,MAAM,YAAY,IAAI;AAC5B,QAAM,WAAW,KAAK,MAAM,MAAM,KAAK;AAEvC,UAAQ,KAAK,GAAG,IAAI,KAAK,QAAQ,KAAK;AAEtC,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure.test-d.d.ts","sourceRoot":"","sources":["../../src/testing/measure.test-d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, vi } from "vitest";
|
|
2
|
+
import { measureAsync, measureSync } from "./measure.js";
|
|
3
|
+
const asyncFunction = vi.fn();
|
|
4
|
+
describe("measureAsync types", async () => {
|
|
5
|
+
await measureAsync("test", asyncFunction);
|
|
6
|
+
await measureAsync("test", () => 1);
|
|
7
|
+
});
|
|
8
|
+
describe("measureSync types", () => {
|
|
9
|
+
measureSync("test", () => 1);
|
|
10
|
+
measureSync("test", asyncFunction);
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=measure.test-d.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/testing/measure.test-d.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, vi } from 'vitest'\n\nimport { measureAsync, measureSync } from './measure'\n\nconst asyncFunction = vi.fn<() => Promise<number>>()\n\ndescribe('measureAsync types', async () => {\n // works with async methods\n await measureAsync('test', asyncFunction)\n\n // @ts-expect-error should error because `fn` doesn't return a Promise\n await measureAsync('test', () => 1)\n})\n\ndescribe('measureSync types', () => {\n // works with sync methods\n measureSync('test', () => 1)\n\n // @ts-expect-error should error because `fn` doesn't return a Promise\n measureSync('test', asyncFunction)\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,UAAU;AAE7B,SAAS,cAAc,mBAAmB;AAE1C,MAAM,gBAAgB,GAAG,GAA0B;AAEnD,SAAS,sBAAsB,YAAY;AAEzC,QAAM,aAAa,QAAQ,aAAa;AAGxC,QAAM,aAAa,QAAQ,MAAM,CAAC;AACpC,CAAC;AAED,SAAS,qBAAqB,MAAM;AAElC,cAAY,QAAQ,MAAM,CAAC;AAG3B,cAAY,QAAQ,aAAa;AACnC,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"helpers",
|
|
15
15
|
"js"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.0.
|
|
17
|
+
"version": "0.0.13",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=20"
|
|
20
20
|
},
|
|
@@ -70,6 +70,11 @@
|
|
|
70
70
|
"import": "./dist/url/*.js",
|
|
71
71
|
"types": "./dist/url/*.d.ts",
|
|
72
72
|
"default": "./dist/url/*.js"
|
|
73
|
+
},
|
|
74
|
+
"./crypto/*": {
|
|
75
|
+
"import": "./dist/crypto/*.js",
|
|
76
|
+
"types": "./dist/crypto/*.d.ts",
|
|
77
|
+
"default": "./dist/crypto/*.js"
|
|
73
78
|
}
|
|
74
79
|
},
|
|
75
80
|
"files": [
|
|
@@ -78,9 +83,9 @@
|
|
|
78
83
|
],
|
|
79
84
|
"module": "dist/index.js",
|
|
80
85
|
"devDependencies": {
|
|
81
|
-
"vite": "7.1.
|
|
86
|
+
"vite": "7.1.11",
|
|
82
87
|
"vitest": "3.2.4",
|
|
83
|
-
"@scalar/build-tooling": "0.2.
|
|
88
|
+
"@scalar/build-tooling": "0.2.8"
|
|
84
89
|
},
|
|
85
90
|
"scripts": {
|
|
86
91
|
"build": "scalar-build-esbuild",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Freezes an element at the top of the viewport using a mutation observer to check if the element has entered the dom
|
|
3
|
-
* Differs from freezeElement as the element doesn't need to exist yet
|
|
4
|
-
*/
|
|
5
|
-
export declare const freezeAtTop: (id: string) => () => void;
|
|
6
|
-
//# sourceMappingURL=freeze-at-top.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"freeze-at-top.d.ts","sourceRoot":"","sources":["../../src/dom/freeze-at-top.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,IAAI,MAAM,eAyCrC,CAAA"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const freezeAtTop = (id) => {
|
|
2
|
-
if (!id) {
|
|
3
|
-
return () => null;
|
|
4
|
-
}
|
|
5
|
-
let rafId = null;
|
|
6
|
-
let element = document.getElementById(id);
|
|
7
|
-
const observer = new MutationObserver(() => {
|
|
8
|
-
element ||= document.getElementById(id);
|
|
9
|
-
if (!element) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (rafId !== null) {
|
|
13
|
-
cancelAnimationFrame(rafId);
|
|
14
|
-
}
|
|
15
|
-
rafId = requestAnimationFrame(() => {
|
|
16
|
-
element?.scrollIntoView();
|
|
17
|
-
rafId = null;
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
observer.observe(document.body, {
|
|
21
|
-
childList: true,
|
|
22
|
-
subtree: true
|
|
23
|
-
});
|
|
24
|
-
return () => {
|
|
25
|
-
if (rafId !== null) {
|
|
26
|
-
cancelAnimationFrame(rafId);
|
|
27
|
-
}
|
|
28
|
-
observer.disconnect();
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
freezeAtTop
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=freeze-at-top.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/dom/freeze-at-top.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Freezes an element at the top of the viewport using a mutation observer to check if the element has entered the dom\n * Differs from freezeElement as the element doesn't need to exist yet\n */\nexport const freezeAtTop = (id: string) => {\n if (!id) {\n return () => null\n }\n\n let rafId: number | null = null\n let element = document.getElementById(id)\n\n // Create mutation observer to watch for DOM changes\n const observer = new MutationObserver(() => {\n element ||= document.getElementById(id)\n\n if (!element) {\n return\n }\n\n // Cancel any pending animation frame\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n }\n\n // Schedule the scroll adjustment for the next frame\n rafId = requestAnimationFrame(() => {\n element?.scrollIntoView()\n rafId = null\n })\n })\n\n // Start observing with more specific configuration\n observer.observe(document.body, {\n childList: true,\n subtree: true,\n })\n\n // Return function to stop maintaining position\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n }\n observer.disconnect()\n }\n}\n"],
|
|
5
|
-
"mappings": "AAIO,MAAM,cAAc,CAAC,OAAe;AACzC,MAAI,CAAC,IAAI;AACP,WAAO,MAAM;AAAA,EACf;AAEA,MAAI,QAAuB;AAC3B,MAAI,UAAU,SAAS,eAAe,EAAE;AAGxC,QAAM,WAAW,IAAI,iBAAiB,MAAM;AAC1C,gBAAY,SAAS,eAAe,EAAE;AAEtC,QAAI,CAAC,SAAS;AACZ;AAAA,IACF;AAGA,QAAI,UAAU,MAAM;AAClB,2BAAqB,KAAK;AAAA,IAC5B;AAGA,YAAQ,sBAAsB,MAAM;AAClC,eAAS,eAAe;AACxB,cAAQ;AAAA,IACV,CAAC;AAAA,EACH,CAAC;AAGD,WAAS,QAAQ,SAAS,MAAM;AAAA,IAC9B,WAAW;AAAA,IACX,SAAS;AAAA,EACX,CAAC;AAGD,SAAO,MAAM;AACX,QAAI,UAAU,MAAM;AAClB,2BAAqB,KAAK;AAAA,IAC5B;AACA,aAAS,WAAW;AAAA,EACtB;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|