@scalar/helpers 0.0.10 → 0.0.12

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scalar/helpers
2
2
 
3
+ ## 0.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 3f6d0b9: fix(helpers): `scrollToId` is not an async function
8
+
9
+ ## 0.0.11
10
+
11
+ ### Patch Changes
12
+
13
+ - bff46e5: feat: don’t use proxy for reserved tlds
14
+
3
15
  ## 0.0.10
4
16
 
5
17
  ### Patch Changes
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * Also focuses the element if the focus flag is true
5
5
  */
6
- export declare const scrollToId: (id: string, focus?: boolean) => Promise<void>;
6
+ export declare const scrollToId: (id: string, focus?: boolean) => void;
7
7
  //# sourceMappingURL=scroll-to-id.d.ts.map
@@ -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,GAAU,IAAI,MAAM,EAAE,QAAQ,OAAO,kBAkC3D,CAAA"}
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"}
@@ -1,4 +1,4 @@
1
- const scrollToId = async (id, focus) => {
1
+ const scrollToId = (id, focus) => {
2
2
  const scrollToElement = (element2) => {
3
3
  element2.scrollIntoView();
4
4
  if (focus) {
@@ -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 = async (id: string, focus?: boolean) => {\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 = () => {\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,OAAO,IAAY,UAAoB;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,MAAM;AACtB,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;",
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
  }
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDqB,CAAA;AAEjD;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASnD,CAAA"}
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"}
@@ -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 connect: {\n short: 'CONN',\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,SAAS;AAAA,IACP,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;",
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 plus connect */
2
- export declare const HTTP_METHODS: readonly ["connect", "delete", "get", "head", "options", "patch", "post", "put", "trace"];
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<"connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace">>;
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,4CAA4C;AAC5C,eAAO,MAAM,YAAY,2FAA4F,CAAA;AAErH,kCAAkC;AAClC,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtD,yCAAyC;AACzC,eAAO,MAAM,WAAW,uGAAuC,CAAA"}
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 = ["connect", "delete", "get", "head", "options", "patch", "post", "put", "trace"];
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 plus connect */\nexport const HTTP_METHODS = ['connect', '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,WAAW,UAAU,OAAO,QAAQ,WAAW,SAAS,QAAQ,OAAO,OAAO;AAMpG,MAAM,cAAc,OAAO,OAAO,IAAI,IAAI,YAAY,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: <T>(name: string, fn: () => T) => T;
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,EAAE,MAAM,MAAM,EAAE,IAAI,MAAM,CAAC,KAAG,CAW1D,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
+ {"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 = <T>(name: string, fn: () => T): T => {\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\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,CAAI,MAAc,OAAmB;AAC9D,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;",
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=measure.test-d.d.ts.map
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Detect requests to localhost
2
+ * Detect requests to localhost or reserved TLDs
3
3
  */
4
4
  export declare function isLocalUrl(url: string): boolean;
5
5
  //# sourceMappingURL=is-local-url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-local-url.d.ts","sourceRoot":"","sources":["../../src/url/is-local-url.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,WAUrC"}
1
+ {"version":3,"file":"is-local-url.d.ts","sourceRoot":"","sources":["../../src/url/is-local-url.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,WAqBrC"}
@@ -1,8 +1,16 @@
1
1
  const LOCAL_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]", "0.0.0.0"];
2
+ const RESERVED_TLDS = ["test", "example", "invalid", "localhost"];
2
3
  function isLocalUrl(url) {
3
4
  try {
4
5
  const { hostname } = new URL(url);
5
- return LOCAL_HOSTNAMES.includes(hostname);
6
+ if (LOCAL_HOSTNAMES.includes(hostname)) {
7
+ return true;
8
+ }
9
+ const tld = hostname.split(".").pop();
10
+ if (tld && RESERVED_TLDS.includes(tld)) {
11
+ return true;
12
+ }
13
+ return false;
6
14
  } catch {
7
15
  return true;
8
16
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/url/is-local-url.ts"],
4
- "sourcesContent": ["/** Obviously local hostnames */\nconst LOCAL_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]', '0.0.0.0']\n\n/**\n * Detect requests to localhost\n */\nexport function isLocalUrl(url: string) {\n try {\n const { hostname } = new URL(url)\n\n return LOCAL_HOSTNAMES.includes(hostname)\n } catch {\n // If it's not a valid URL, we can't use the proxy anyway,\n // but it also covers cases like relative URLs (e.g. `openapi.json`).\n return true\n }\n}\n"],
5
- "mappings": "AACA,MAAM,kBAAkB,CAAC,aAAa,aAAa,SAAS,SAAS;AAK9D,SAAS,WAAW,KAAa;AACtC,MAAI;AACF,UAAM,EAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAEhC,WAAO,gBAAgB,SAAS,QAAQ;AAAA,EAC1C,QAAQ;AAGN,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["/** Obviously local hostnames */\nconst LOCAL_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]', '0.0.0.0']\n\n/** Reserved TLDs that are guaranteed to never be assigned */\nconst RESERVED_TLDS = ['test', 'example', 'invalid', 'localhost']\n\n/**\n * Detect requests to localhost or reserved TLDs\n */\nexport function isLocalUrl(url: string) {\n try {\n const { hostname } = new URL(url)\n\n // Check if hostname is in the local hostnames list\n if (LOCAL_HOSTNAMES.includes(hostname)) {\n return true\n }\n\n // Check if hostname ends with a reserved TLD\n const tld = hostname.split('.').pop()\n if (tld && RESERVED_TLDS.includes(tld)) {\n return true\n }\n\n return false\n } catch {\n // If it's not a valid URL, we can't use the proxy anyway,\n // but it also covers cases like relative URLs (e.g. `openapi.json`).\n return true\n }\n}\n"],
5
+ "mappings": "AACA,MAAM,kBAAkB,CAAC,aAAa,aAAa,SAAS,SAAS;AAGrE,MAAM,gBAAgB,CAAC,QAAQ,WAAW,WAAW,WAAW;AAKzD,SAAS,WAAW,KAAa;AACtC,MAAI;AACF,UAAM,EAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAGhC,QAAI,gBAAgB,SAAS,QAAQ,GAAG;AACtC,aAAO;AAAA,IACT;AAGA,UAAM,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI;AACpC,QAAI,OAAO,cAAc,SAAS,GAAG,GAAG;AACtC,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,QAAQ;AAGN,WAAO;AAAA,EACT;AACF;",
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.10",
17
+ "version": "0.0.12",
18
18
  "engines": {
19
19
  "node": ">=20"
20
20
  },
@@ -78,8 +78,8 @@
78
78
  ],
79
79
  "module": "dist/index.js",
80
80
  "devDependencies": {
81
- "vite": "6.1.6",
82
- "vitest": "^3.2.4",
81
+ "vite": "7.1.5",
82
+ "vitest": "3.2.4",
83
83
  "@scalar/build-tooling": "0.2.7"
84
84
  },
85
85
  "scripts": {