@scalar/snippetz 0.2.20 → 0.3.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.
Files changed (80) hide show
  1. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts.map +1 -1
  2. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js +37 -8
  3. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js.map +2 -2
  4. package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts.map +1 -1
  5. package/dist/httpsnippet-lite/esm/targets/go/native/client.js +76 -30
  6. package/dist/httpsnippet-lite/esm/targets/go/native/client.js.map +2 -2
  7. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts.map +1 -1
  8. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js +25 -9
  9. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js.map +2 -2
  10. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts.map +1 -1
  11. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js +25 -9
  12. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js.map +2 -2
  13. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts.map +1 -1
  14. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js +11 -0
  15. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js.map +2 -2
  16. package/dist/plugins/c/libcurl/libcurl.test.js +19 -11
  17. package/dist/plugins/c/libcurl/libcurl.test.js.map +2 -2
  18. package/dist/plugins/go/native/native.test.js +35 -36
  19. package/dist/plugins/go/native/native.test.js.map +2 -2
  20. package/dist/plugins/java/okhttp/okhttp.test.js +164 -0
  21. package/dist/plugins/java/okhttp/okhttp.test.js.map +7 -0
  22. package/dist/plugins/js/axios/index.d.ts +1 -1
  23. package/dist/plugins/js/axios/index.d.ts.map +1 -1
  24. package/dist/plugins/js/axios/index.js +4 -1
  25. package/dist/plugins/js/axios/index.js.map +2 -2
  26. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
  27. package/dist/plugins/js/fetch/fetch.js +30 -9
  28. package/dist/plugins/js/fetch/fetch.js.map +2 -2
  29. package/dist/plugins/js/fetch/fetch.test.js +103 -0
  30. package/dist/plugins/js/fetch/fetch.test.js.map +2 -2
  31. package/dist/plugins/js/fetch/index.d.ts +1 -1
  32. package/dist/plugins/js/fetch/index.d.ts.map +1 -1
  33. package/dist/plugins/js/fetch/index.js +4 -1
  34. package/dist/plugins/js/fetch/index.js.map +2 -2
  35. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
  36. package/dist/plugins/js/ofetch/ofetch.js +1 -10
  37. package/dist/plugins/js/ofetch/ofetch.js.map +2 -2
  38. package/dist/plugins/js/ofetch/ofetch.test.js +7 -4
  39. package/dist/plugins/js/ofetch/ofetch.test.js.map +2 -2
  40. package/dist/plugins/kotlin/okhttp/okhttp.test.js +164 -0
  41. package/dist/plugins/kotlin/okhttp/okhttp.test.js.map +7 -0
  42. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
  43. package/dist/plugins/node/fetch/fetch.js +37 -9
  44. package/dist/plugins/node/fetch/fetch.js.map +2 -2
  45. package/dist/plugins/node/fetch/fetch.test.js +89 -0
  46. package/dist/plugins/node/fetch/fetch.test.js.map +2 -2
  47. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
  48. package/dist/plugins/node/ofetch/ofetch.js +1 -10
  49. package/dist/plugins/node/ofetch/ofetch.js.map +2 -2
  50. package/dist/plugins/node/ofetch/ofetch.test.js +7 -4
  51. package/dist/plugins/node/ofetch/ofetch.test.js.map +2 -2
  52. package/dist/plugins/node/undici/undici.d.ts.map +1 -1
  53. package/dist/plugins/node/undici/undici.js +4 -6
  54. package/dist/plugins/node/undici/undici.js.map +2 -2
  55. package/dist/plugins/python/requests/requests.d.ts.map +1 -1
  56. package/dist/plugins/python/requests/requests.js +4 -3
  57. package/dist/plugins/python/requests/requests.js.map +3 -3
  58. package/dist/plugins/python/requests/requests.test.js +31 -2
  59. package/dist/plugins/python/requests/requests.test.js.map +2 -2
  60. package/dist/plugins/shell/httpie/httpie.test.js +3 -3
  61. package/dist/plugins/shell/httpie/httpie.test.js.map +2 -2
  62. package/dist/utils/create-search-params.d.ts +4 -0
  63. package/dist/utils/create-search-params.d.ts.map +1 -0
  64. package/dist/utils/create-search-params.js +11 -0
  65. package/dist/utils/create-search-params.js.map +7 -0
  66. package/dist/utils/create-search-params.test.js +49 -0
  67. package/dist/utils/create-search-params.test.js.map +7 -0
  68. package/dist/utils/index.d.ts +0 -1
  69. package/dist/utils/index.d.ts.map +1 -1
  70. package/dist/utils/index.js +0 -1
  71. package/dist/utils/index.js.map +2 -2
  72. package/dist/utils/objectToString.d.ts +8 -0
  73. package/dist/utils/objectToString.d.ts.map +1 -1
  74. package/dist/utils/objectToString.js +20 -15
  75. package/dist/utils/objectToString.js.map +2 -2
  76. package/package.json +5 -5
  77. package/dist/utils/arrayToObject.d.ts +0 -8
  78. package/dist/utils/arrayToObject.d.ts.map +0 -1
  79. package/dist/utils/arrayToObject.js +0 -10
  80. package/dist/utils/arrayToObject.js.map +0 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-search-params.d.ts","sourceRoot":"","sources":["../../src/utils/create-search-params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD,2FAA2F;AAC3F,eAAO,MAAM,kBAAkB,WAAW,UAAU,CAAC,aAAa,CAAC,oBAMlE,CAAA"}
@@ -0,0 +1,11 @@
1
+ const createSearchParams = (query = []) => {
2
+ const searchParams = new URLSearchParams();
3
+ query.forEach((q) => {
4
+ searchParams.append(q.name, q.value);
5
+ });
6
+ return searchParams;
7
+ };
8
+ export {
9
+ createSearchParams
10
+ };
11
+ //# sourceMappingURL=create-search-params.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/create-search-params.ts"],
4
+ "sourcesContent": ["import type { HarRequest } from '@scalar/types/snippetz'\n\n/** Creates a new URL search params object and sets query params so we can handle arrays */\nexport const createSearchParams = (query: HarRequest['queryString'] = []) => {\n const searchParams = new URLSearchParams()\n query.forEach((q) => {\n searchParams.append(q.name, q.value)\n })\n return searchParams\n}\n"],
5
+ "mappings": "AAGO,MAAM,qBAAqB,CAAC,QAAmC,CAAC,MAAM;AAC3E,QAAM,eAAe,IAAI,gBAAgB;AACzC,QAAM,QAAQ,CAAC,MAAM;AACnB,iBAAa,OAAO,EAAE,MAAM,EAAE,KAAK;AAAA,EACrC,CAAC;AACD,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { createSearchParams } from "./create-search-params.js";
3
+ describe("createSearchParams", () => {
4
+ it("creates search params from empty query array", () => {
5
+ const query = [];
6
+ const result = createSearchParams(query);
7
+ expect(result.toString()).toBe("");
8
+ });
9
+ it("creates search params from single query parameter", () => {
10
+ const query = [{ name: "foo", value: "bar" }];
11
+ const result = createSearchParams(query);
12
+ expect(result.toString()).toBe("foo=bar");
13
+ });
14
+ it("creates search params from multiple query parameters", () => {
15
+ const query = [
16
+ { name: "foo", value: "bar" },
17
+ { name: "baz", value: "qux" }
18
+ ];
19
+ const result = createSearchParams(query);
20
+ expect(result.toString()).toBe("foo=bar&baz=qux");
21
+ });
22
+ it("handles multiple parameters with the same name", () => {
23
+ const query = [
24
+ { name: "foo", value: "bar" },
25
+ { name: "foo", value: "baz" }
26
+ ];
27
+ const result = createSearchParams(query);
28
+ expect(result.toString()).toBe("foo=bar&foo=baz");
29
+ });
30
+ it("handles special characters in parameter names and values", () => {
31
+ const query = [
32
+ { name: "special!@#", value: "value!@#" },
33
+ { name: "space name", value: "space value" }
34
+ ];
35
+ const result = createSearchParams(query);
36
+ expect(result.toString()).toBe("special%21%40%23=value%21%40%23&space+name=space+value");
37
+ });
38
+ it("handles empty parameter values", () => {
39
+ const query = [{ name: "empty", value: "" }];
40
+ const result = createSearchParams(query);
41
+ expect(result.toString()).toBe("empty=");
42
+ });
43
+ it("handles URL-encoded values", () => {
44
+ const query = [{ name: "encoded", value: "hello%20world" }];
45
+ const result = createSearchParams(query);
46
+ expect(result.toString()).toBe("encoded=hello%2520world");
47
+ });
48
+ });
49
+ //# sourceMappingURL=create-search-params.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/create-search-params.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from 'vitest'\nimport { createSearchParams } from './create-search-params'\nimport type { HarRequest } from '@scalar/types/snippetz'\n\ndescribe('createSearchParams', () => {\n it('creates search params from empty query array', () => {\n const query: HarRequest['queryString'] = []\n const result = createSearchParams(query)\n expect(result.toString()).toBe('')\n })\n\n it('creates search params from single query parameter', () => {\n const query: HarRequest['queryString'] = [{ name: 'foo', value: 'bar' }]\n const result = createSearchParams(query)\n expect(result.toString()).toBe('foo=bar')\n })\n\n it('creates search params from multiple query parameters', () => {\n const query: HarRequest['queryString'] = [\n { name: 'foo', value: 'bar' },\n { name: 'baz', value: 'qux' },\n ]\n const result = createSearchParams(query)\n expect(result.toString()).toBe('foo=bar&baz=qux')\n })\n\n it('handles multiple parameters with the same name', () => {\n const query: HarRequest['queryString'] = [\n { name: 'foo', value: 'bar' },\n { name: 'foo', value: 'baz' },\n ]\n const result = createSearchParams(query)\n expect(result.toString()).toBe('foo=bar&foo=baz')\n })\n\n it('handles special characters in parameter names and values', () => {\n const query: HarRequest['queryString'] = [\n { name: 'special!@#', value: 'value!@#' },\n { name: 'space name', value: 'space value' },\n ]\n const result = createSearchParams(query)\n expect(result.toString()).toBe('special%21%40%23=value%21%40%23&space+name=space+value')\n })\n\n it('handles empty parameter values', () => {\n const query: HarRequest['queryString'] = [{ name: 'empty', value: '' }]\n const result = createSearchParams(query)\n expect(result.toString()).toBe('empty=')\n })\n\n it('handles URL-encoded values', () => {\n const query: HarRequest['queryString'] = [{ name: 'encoded', value: 'hello%20world' }]\n const result = createSearchParams(query)\n expect(result.toString()).toBe('encoded=hello%2520world')\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAS,0BAA0B;AAGnC,SAAS,sBAAsB,MAAM;AACnC,KAAG,gDAAgD,MAAM;AACvD,UAAM,QAAmC,CAAC;AAC1C,UAAM,SAAS,mBAAmB,KAAK;AACvC,WAAO,OAAO,SAAS,CAAC,EAAE,KAAK,EAAE;AAAA,EACnC,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,UAAM,QAAmC,CAAC,EAAE,MAAM,OAAO,OAAO,MAAM,CAAC;AACvE,UAAM,SAAS,mBAAmB,KAAK;AACvC,WAAO,OAAO,SAAS,CAAC,EAAE,KAAK,SAAS;AAAA,EAC1C,CAAC;AAED,KAAG,wDAAwD,MAAM;AAC/D,UAAM,QAAmC;AAAA,MACvC,EAAE,MAAM,OAAO,OAAO,MAAM;AAAA,MAC5B,EAAE,MAAM,OAAO,OAAO,MAAM;AAAA,IAC9B;AACA,UAAM,SAAS,mBAAmB,KAAK;AACvC,WAAO,OAAO,SAAS,CAAC,EAAE,KAAK,iBAAiB;AAAA,EAClD,CAAC;AAED,KAAG,kDAAkD,MAAM;AACzD,UAAM,QAAmC;AAAA,MACvC,EAAE,MAAM,OAAO,OAAO,MAAM;AAAA,MAC5B,EAAE,MAAM,OAAO,OAAO,MAAM;AAAA,IAC9B;AACA,UAAM,SAAS,mBAAmB,KAAK;AACvC,WAAO,OAAO,SAAS,CAAC,EAAE,KAAK,iBAAiB;AAAA,EAClD,CAAC;AAED,KAAG,4DAA4D,MAAM;AACnE,UAAM,QAAmC;AAAA,MACvC,EAAE,MAAM,cAAc,OAAO,WAAW;AAAA,MACxC,EAAE,MAAM,cAAc,OAAO,cAAc;AAAA,IAC7C;AACA,UAAM,SAAS,mBAAmB,KAAK;AACvC,WAAO,OAAO,SAAS,CAAC,EAAE,KAAK,wDAAwD;AAAA,EACzF,CAAC;AAED,KAAG,kCAAkC,MAAM;AACzC,UAAM,QAAmC,CAAC,EAAE,MAAM,SAAS,OAAO,GAAG,CAAC;AACtE,UAAM,SAAS,mBAAmB,KAAK;AACvC,WAAO,OAAO,SAAS,CAAC,EAAE,KAAK,QAAQ;AAAA,EACzC,CAAC;AAED,KAAG,8BAA8B,MAAM;AACrC,UAAM,QAAmC,CAAC,EAAE,MAAM,WAAW,OAAO,gBAAgB,CAAC;AACrF,UAAM,SAAS,mBAAmB,KAAK;AACvC,WAAO,OAAO,SAAS,CAAC,EAAE,KAAK,yBAAyB;AAAA,EAC1D,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -1,4 +1,3 @@
1
- export * from './arrayToObject.js';
2
1
  export * from './convertWithHttpSnippetLite.js';
3
2
  export * from './needsQuotes.js';
4
3
  export * from './objectToString.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
@@ -1,4 +1,3 @@
1
- export * from "./arrayToObject.js";
2
1
  export * from "./convertWithHttpSnippetLite.js";
3
2
  export * from "./needsQuotes.js";
4
3
  export * from "./objectToString.js";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/index.ts"],
4
- "sourcesContent": ["export * from './arrayToObject'\nexport * from './convertWithHttpSnippetLite'\nexport * from './needsQuotes'\nexport * from './objectToString'\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from './convertWithHttpSnippetLite'\nexport * from './needsQuotes'\nexport * from './objectToString'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Represents a raw code that should not be quoted, e.g. `JSON.stringify(...)`.
3
+ * If consists of multiple lines, they will be indented properly.
4
+ */
5
+ export declare class Unquoted {
6
+ value: string;
7
+ constructor(value: string);
8
+ }
1
9
  /**
2
10
  * Converts an object into a string representation with proper formatting and indentation
3
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../src/utils/objectToString.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAoD3E"}
1
+ {"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../src/utils/objectToString.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,QAAQ;IACA,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;CACjC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAkD3E"}
@@ -1,11 +1,28 @@
1
1
  import { needsQuotes } from "./needsQuotes.js";
2
+ class Unquoted {
3
+ constructor(value) {
4
+ this.value = value;
5
+ }
6
+ }
2
7
  function objectToString(obj, indent = 0) {
3
8
  const parts = [];
4
9
  const indentation = " ".repeat(indent);
5
10
  const innerIndentation = " ".repeat(indent + 2);
6
11
  for (const [key, value] of Object.entries(obj)) {
7
12
  const formattedKey = needsQuotes(key) ? `'${key}'` : key;
8
- if (Array.isArray(value)) {
13
+ if (value instanceof Unquoted) {
14
+ const lines = value.value.split("\n");
15
+ let formattedValue = `${value.value}`;
16
+ if (lines.length > 1) {
17
+ formattedValue = lines.map((line, index) => {
18
+ if (index === 0) {
19
+ return line;
20
+ }
21
+ return `${innerIndentation}${line}`;
22
+ }).join("\n");
23
+ }
24
+ parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`);
25
+ } else if (Array.isArray(value)) {
9
26
  const arrayString = value.map((item) => {
10
27
  if (typeof item === "string") {
11
28
  return `'${item}'`;
@@ -19,20 +36,7 @@ function objectToString(obj, indent = 0) {
19
36
  } else if (value && typeof value === "object") {
20
37
  parts.push(`${innerIndentation}${formattedKey}: ${objectToString(value, indent + 2)}`);
21
38
  } else if (typeof value === "string") {
22
- let formattedValue = `${value}`;
23
- if (value.startsWith("JSON.stringify")) {
24
- const lines = value.split("\n");
25
- if (lines.length > 1) {
26
- formattedValue = lines.map((line, index) => {
27
- if (index === 0) {
28
- return line;
29
- }
30
- return `${innerIndentation}${line}`;
31
- }).join("\n");
32
- }
33
- } else {
34
- formattedValue = `'${value}'`;
35
- }
39
+ const formattedValue = `'${value}'`;
36
40
  parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`);
37
41
  } else {
38
42
  parts.push(`${innerIndentation}${formattedKey}: ${value}`);
@@ -43,6 +47,7 @@ ${parts.join(",\n")}
43
47
  ${indentation}}`;
44
48
  }
45
49
  export {
50
+ Unquoted,
46
51
  objectToString
47
52
  };
48
53
  //# sourceMappingURL=objectToString.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/objectToString.ts"],
4
- "sourcesContent": ["import { needsQuotes } from './needsQuotes'\n\n/**\n * Converts an object into a string representation with proper formatting and indentation\n *\n * Handles nested objects, arrays, and special string values\n */\nexport function objectToString(obj: Record<string, any>, indent = 0): string {\n const parts = []\n const indentation = ' '.repeat(indent)\n const innerIndentation = ' '.repeat(indent + 2)\n\n for (const [key, value] of Object.entries(obj)) {\n const formattedKey = needsQuotes(key) ? `'${key}'` : key\n\n if (Array.isArray(value)) {\n const arrayString = value\n .map((item) => {\n if (typeof item === 'string') {\n return `'${item}'`\n }\n if (item && typeof item === 'object') {\n return objectToString(item, indent + 2)\n }\n return item\n })\n .join(`, ${innerIndentation}`)\n parts.push(`${innerIndentation}${formattedKey}: [${arrayString}]`)\n } else if (value && typeof value === 'object') {\n parts.push(`${innerIndentation}${formattedKey}: ${objectToString(value, indent + 2)}`)\n } else if (typeof value === 'string') {\n let formattedValue = `${value}`\n\n if (value.startsWith('JSON.stringify')) {\n // If it has more than one line, add indentation to the other lines\n const lines = value.split('\\n')\n\n if (lines.length > 1) {\n formattedValue = lines\n .map((line, index) => {\n if (index === 0) {\n return line\n }\n\n return `${innerIndentation}${line}`\n })\n .join('\\n')\n }\n } else {\n formattedValue = `'${value}'`\n }\n\n parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`)\n } else {\n parts.push(`${innerIndentation}${formattedKey}: ${value}`)\n }\n }\n\n return `{\\n${parts.join(',\\n')}\\n${indentation}}`\n}\n"],
5
- "mappings": "AAAA,SAAS,mBAAmB;AAOrB,SAAS,eAAe,KAA0B,SAAS,GAAW;AAC3E,QAAM,QAAQ,CAAC;AACf,QAAM,cAAc,IAAI,OAAO,MAAM;AACrC,QAAM,mBAAmB,IAAI,OAAO,SAAS,CAAC;AAE9C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,UAAM,eAAe,YAAY,GAAG,IAAI,IAAI,GAAG,MAAM;AAErD,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,YAAM,cAAc,MACjB,IAAI,CAAC,SAAS;AACb,YAAI,OAAO,SAAS,UAAU;AAC5B,iBAAO,IAAI,IAAI;AAAA,QACjB;AACA,YAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,iBAAO,eAAe,MAAM,SAAS,CAAC;AAAA,QACxC;AACA,eAAO;AAAA,MACT,CAAC,EACA,KAAK,KAAK,gBAAgB,EAAE;AAC/B,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,MAAM,WAAW,GAAG;AAAA,IACnE,WAAW,SAAS,OAAO,UAAU,UAAU;AAC7C,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,eAAe,OAAO,SAAS,CAAC,CAAC,EAAE;AAAA,IACvF,WAAW,OAAO,UAAU,UAAU;AACpC,UAAI,iBAAiB,GAAG,KAAK;AAE7B,UAAI,MAAM,WAAW,gBAAgB,GAAG;AAEtC,cAAM,QAAQ,MAAM,MAAM,IAAI;AAE9B,YAAI,MAAM,SAAS,GAAG;AACpB,2BAAiB,MACd,IAAI,CAAC,MAAM,UAAU;AACpB,gBAAI,UAAU,GAAG;AACf,qBAAO;AAAA,YACT;AAEA,mBAAO,GAAG,gBAAgB,GAAG,IAAI;AAAA,UACnC,CAAC,EACA,KAAK,IAAI;AAAA,QACd;AAAA,MACF,OAAO;AACL,yBAAiB,IAAI,KAAK;AAAA,MAC5B;AAEA,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,cAAc,EAAE;AAAA,IACpE,OAAO;AACL,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,KAAK,EAAE;AAAA,IAC3D;AAAA,EACF;AAEA,SAAO;AAAA,EAAM,MAAM,KAAK,KAAK,CAAC;AAAA,EAAK,WAAW;AAChD;",
4
+ "sourcesContent": ["import { needsQuotes } from './needsQuotes'\n\n/**\n * Represents a raw code that should not be quoted, e.g. `JSON.stringify(...)`.\n * If consists of multiple lines, they will be indented properly.\n */\nexport class Unquoted {\n constructor(public value: string) {}\n}\n\n/**\n * Converts an object into a string representation with proper formatting and indentation\n *\n * Handles nested objects, arrays, and special string values\n */\nexport function objectToString(obj: Record<string, any>, indent = 0): string {\n const parts = []\n const indentation = ' '.repeat(indent)\n const innerIndentation = ' '.repeat(indent + 2)\n\n for (const [key, value] of Object.entries(obj)) {\n const formattedKey = needsQuotes(key) ? `'${key}'` : key\n\n if (value instanceof Unquoted) {\n const lines = value.value.split('\\n')\n let formattedValue = `${value.value}`\n\n if (lines.length > 1) {\n formattedValue = lines\n .map((line, index) => {\n if (index === 0) {\n return line\n }\n\n return `${innerIndentation}${line}`\n })\n .join('\\n')\n }\n\n parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`)\n } else if (Array.isArray(value)) {\n const arrayString = value\n .map((item) => {\n if (typeof item === 'string') {\n return `'${item}'`\n }\n if (item && typeof item === 'object') {\n return objectToString(item, indent + 2)\n }\n return item\n })\n .join(`, ${innerIndentation}`)\n parts.push(`${innerIndentation}${formattedKey}: [${arrayString}]`)\n } else if (value && typeof value === 'object') {\n parts.push(`${innerIndentation}${formattedKey}: ${objectToString(value, indent + 2)}`)\n } else if (typeof value === 'string') {\n const formattedValue = `'${value}'`\n\n parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`)\n } else {\n parts.push(`${innerIndentation}${formattedKey}: ${value}`)\n }\n }\n\n return `{\\n${parts.join(',\\n')}\\n${indentation}}`\n}\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAMrB,MAAM,SAAS;AAAA,EACpB,YAAmB,OAAe;AAAf;AAAA,EAAgB;AACrC;AAOO,SAAS,eAAe,KAA0B,SAAS,GAAW;AAC3E,QAAM,QAAQ,CAAC;AACf,QAAM,cAAc,IAAI,OAAO,MAAM;AACrC,QAAM,mBAAmB,IAAI,OAAO,SAAS,CAAC;AAE9C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,UAAM,eAAe,YAAY,GAAG,IAAI,IAAI,GAAG,MAAM;AAErD,QAAI,iBAAiB,UAAU;AAC7B,YAAM,QAAQ,MAAM,MAAM,MAAM,IAAI;AACpC,UAAI,iBAAiB,GAAG,MAAM,KAAK;AAEnC,UAAI,MAAM,SAAS,GAAG;AACpB,yBAAiB,MACd,IAAI,CAAC,MAAM,UAAU;AACpB,cAAI,UAAU,GAAG;AACf,mBAAO;AAAA,UACT;AAEA,iBAAO,GAAG,gBAAgB,GAAG,IAAI;AAAA,QACnC,CAAC,EACA,KAAK,IAAI;AAAA,MACd;AAEA,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,cAAc,EAAE;AAAA,IACpE,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,YAAM,cAAc,MACjB,IAAI,CAAC,SAAS;AACb,YAAI,OAAO,SAAS,UAAU;AAC5B,iBAAO,IAAI,IAAI;AAAA,QACjB;AACA,YAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,iBAAO,eAAe,MAAM,SAAS,CAAC;AAAA,QACxC;AACA,eAAO;AAAA,MACT,CAAC,EACA,KAAK,KAAK,gBAAgB,EAAE;AAC/B,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,MAAM,WAAW,GAAG;AAAA,IACnE,WAAW,SAAS,OAAO,UAAU,UAAU;AAC7C,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,eAAe,OAAO,SAAS,CAAC,CAAC,EAAE;AAAA,IACvF,WAAW,OAAO,UAAU,UAAU;AACpC,YAAM,iBAAiB,IAAI,KAAK;AAEhC,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,cAAc,EAAE;AAAA,IACpE,OAAO;AACL,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,KAAK,EAAE;AAAA,IAC3D;AAAA,EACF;AAEA,SAAO;AAAA,EAAM,MAAM,KAAK,KAAK,CAAC;AAAA,EAAK,WAAW;AAChD;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -9,9 +9,9 @@
9
9
  "url": "git+https://github.com/scalar/scalar.git",
10
10
  "directory": "packages/snippetz"
11
11
  },
12
- "version": "0.2.20",
12
+ "version": "0.3.0",
13
13
  "engines": {
14
- "node": ">=18"
14
+ "node": ">=20"
15
15
  },
16
16
  "type": "module",
17
17
  "types": "./dist/index.d.ts",
@@ -211,9 +211,9 @@
211
211
  "stringify-object": "^5.0.0"
212
212
  },
213
213
  "devDependencies": {
214
- "vite": "^5.4.10",
215
- "@scalar/build-tooling": "0.1.19",
216
- "@scalar/types": "0.1.14"
214
+ "vite": "5.4.19",
215
+ "@scalar/build-tooling": "0.2.0",
216
+ "@scalar/types": "0.2.1"
217
217
  },
218
218
  "scripts": {
219
219
  "build": "scalar-build-esbuild",
@@ -1,8 +0,0 @@
1
- /**
2
- * Converts an array of name/value pairs into an object with those mappings
3
- *
4
- * @example
5
- * arrayToObject([{ name: 'foo', value: 'bar' }]) // => { foo: 'bar' }
6
- */
7
- export declare function arrayToObject(items: any): any;
8
- //# sourceMappingURL=arrayToObject.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arrayToObject.d.ts","sourceRoot":"","sources":["../../src/utils/arrayToObject.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,OAKvC"}
@@ -1,10 +0,0 @@
1
- function arrayToObject(items) {
2
- return items.reduce((acc, item) => {
3
- acc[item.name] = item.value;
4
- return acc;
5
- }, {});
6
- }
7
- export {
8
- arrayToObject
9
- };
10
- //# sourceMappingURL=arrayToObject.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/arrayToObject.ts"],
4
- "sourcesContent": ["/**\n * Converts an array of name/value pairs into an object with those mappings\n *\n * @example\n * arrayToObject([{ name: 'foo', value: 'bar' }]) // => { foo: 'bar' }\n */\nexport function arrayToObject(items: any) {\n return items.reduce((acc: any, item: any) => {\n acc[item.name] = item.value\n return acc\n }, {})\n}\n"],
5
- "mappings": "AAMO,SAAS,cAAc,OAAY;AACxC,SAAO,MAAM,OAAO,CAAC,KAAU,SAAc;AAC3C,QAAI,KAAK,IAAI,IAAI,KAAK;AACtB,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;",
6
- "names": []
7
- }