@scalar/snippetz 0.1.5 → 0.2.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 (52) hide show
  1. package/dist/core/index.d.ts +5 -0
  2. package/dist/core/index.d.ts.map +1 -0
  3. package/dist/core/index.js +3 -0
  4. package/dist/core/types.d.ts +12 -0
  5. package/dist/core/types.d.ts.map +1 -0
  6. package/dist/core/utils/arrayToObject.d.ts +3 -0
  7. package/dist/core/utils/arrayToObject.d.ts.map +1 -0
  8. package/dist/core/utils/arrayToObject.js +9 -0
  9. package/dist/core/utils/isKeyNeedsQuotes.d.ts +2 -0
  10. package/dist/core/utils/isKeyNeedsQuotes.d.ts.map +1 -0
  11. package/dist/core/utils/isKeyNeedsQuotes.js +5 -0
  12. package/dist/core/utils/objectToString.d.ts +2 -0
  13. package/dist/core/utils/objectToString.d.ts.map +1 -0
  14. package/dist/core/utils/objectToString.js +56 -0
  15. package/dist/index.d.ts +2 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -163
  18. package/dist/plugins/js/fetch/fetch.d.ts +3 -0
  19. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -0
  20. package/dist/plugins/js/fetch/fetch.js +65 -0
  21. package/dist/plugins/js/fetch/index.d.ts +2 -0
  22. package/dist/plugins/js/fetch/index.d.ts.map +1 -0
  23. package/dist/plugins/js/fetch/index.js +1 -0
  24. package/dist/plugins/js/ofetch/index.d.ts +2 -0
  25. package/dist/plugins/js/ofetch/index.d.ts.map +1 -0
  26. package/dist/plugins/js/ofetch/index.js +1 -0
  27. package/dist/plugins/js/ofetch/ofetch.d.ts +3 -0
  28. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -0
  29. package/dist/plugins/js/ofetch/ofetch.js +70 -0
  30. package/dist/plugins/node/fetch/fetch.d.ts +3 -0
  31. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -0
  32. package/dist/plugins/node/fetch/fetch.js +65 -0
  33. package/dist/plugins/node/fetch/index.d.ts +2 -0
  34. package/dist/plugins/node/fetch/index.d.ts.map +1 -0
  35. package/dist/plugins/node/fetch/index.js +1 -0
  36. package/dist/plugins/node/ofetch/index.d.ts +2 -0
  37. package/dist/plugins/node/ofetch/index.d.ts.map +1 -0
  38. package/dist/plugins/node/ofetch/index.js +1 -0
  39. package/dist/plugins/node/ofetch/ofetch.d.ts +3 -0
  40. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -0
  41. package/dist/plugins/node/ofetch/ofetch.js +70 -0
  42. package/dist/plugins/node/undici/index.d.ts +2 -0
  43. package/dist/plugins/node/undici/index.d.ts.map +1 -0
  44. package/dist/plugins/node/undici/index.js +1 -0
  45. package/dist/plugins/node/undici/undici.d.ts +3 -0
  46. package/dist/plugins/node/undici/undici.d.ts.map +1 -0
  47. package/dist/plugins/node/undici/undici.js +67 -0
  48. package/dist/snippetz.d.ts +4 -4
  49. package/dist/snippetz.d.ts.map +1 -1
  50. package/dist/snippetz.js +50 -0
  51. package/package.json +42 -19
  52. package/dist/index.umd.cjs +0 -8
@@ -0,0 +1,5 @@
1
+ export * from './utils/arrayToObject.js';
2
+ export * from './utils/isKeyNeedsQuotes.js';
3
+ export * from './utils/objectToString.js';
4
+ export * from './types';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AAEtC,cAAc,SAAS,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { arrayToObject } from './utils/arrayToObject.js';
2
+ export { isKeyNeedsQuotes } from './utils/isKeyNeedsQuotes.js';
3
+ export { objectToString } from './utils/objectToString.js';
@@ -0,0 +1,12 @@
1
+ export type { Request } from 'har-format';
2
+ export type Source = {
3
+ /** The language or environment. */
4
+ target: TargetId;
5
+ /** The identifier of the client. */
6
+ client: ClientId;
7
+ /** The actual source code. */
8
+ code: string;
9
+ };
10
+ export type TargetId = 'node' | 'js';
11
+ export type ClientId = 'undici' | 'fetch' | 'ofetch';
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,MAAM,MAAM,GAAG;IACnB,mCAAmC;IACnC,MAAM,EAAE,QAAQ,CAAA;IAChB,oCAAoC;IACpC,MAAM,EAAE,QAAQ,CAAA;IAChB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAA"}
@@ -0,0 +1,3 @@
1
+ /** Helper function to map { name: 'foo', value: 'bar' } to { foo: 'bar' } */
2
+ export declare function arrayToObject(items: any): any;
3
+ //# sourceMappingURL=arrayToObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrayToObject.d.ts","sourceRoot":"","sources":["../../../src/core/utils/arrayToObject.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,OAKvC"}
@@ -0,0 +1,9 @@
1
+ /** Helper function to map { name: 'foo', value: 'bar' } to { foo: 'bar' } */
2
+ function arrayToObject(items) {
3
+ return items.reduce((acc, item) => {
4
+ acc[item.name] = item.value;
5
+ return acc;
6
+ }, {});
7
+ }
8
+
9
+ export { arrayToObject };
@@ -0,0 +1,2 @@
1
+ export declare function isKeyNeedsQuotes(key: string): boolean;
2
+ //# sourceMappingURL=isKeyNeedsQuotes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isKeyNeedsQuotes.d.ts","sourceRoot":"","sources":["../../../src/core/utils/isKeyNeedsQuotes.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,WAE3C"}
@@ -0,0 +1,5 @@
1
+ function isKeyNeedsQuotes(key) {
2
+ return /\s|-/.test(key);
3
+ }
4
+
5
+ export { isKeyNeedsQuotes };
@@ -0,0 +1,2 @@
1
+ export declare function objectToString(obj: Record<string, any>, indent?: number): string;
2
+ //# sourceMappingURL=objectToString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../../src/core/utils/objectToString.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAyD3E"}
@@ -0,0 +1,56 @@
1
+ import { isKeyNeedsQuotes } from './isKeyNeedsQuotes.js';
2
+
3
+ function objectToString(obj, indent = 0) {
4
+ let parts = [];
5
+ let indentation = ' '.repeat(indent);
6
+ let innerIndentation = ' '.repeat(indent + 2);
7
+ for (const [key, value] of Object.entries(obj)) {
8
+ let formattedKey = isKeyNeedsQuotes(key) ? `'${key}'` : key;
9
+ if (Array.isArray(value)) {
10
+ const arrayString = value
11
+ .map((item) => {
12
+ if (typeof item === 'string') {
13
+ return `'${item}'`;
14
+ }
15
+ else if (item && typeof item === 'object') {
16
+ return objectToString(item, indent + 2);
17
+ }
18
+ else {
19
+ return item;
20
+ }
21
+ })
22
+ .join(`, ${innerIndentation}`);
23
+ parts.push(`${innerIndentation}${formattedKey}: [${arrayString}]`);
24
+ }
25
+ else if (value && typeof value === 'object') {
26
+ parts.push(`${innerIndentation}${formattedKey}: ${objectToString(value, indent + 2)}`);
27
+ }
28
+ else if (typeof value === 'string') {
29
+ let formattedValue = `${value}`;
30
+ if (value.startsWith('JSON.stringify')) {
31
+ // If it has more than one line, add indentation to the other lines
32
+ const lines = value.split('\n');
33
+ if (lines.length > 1) {
34
+ formattedValue = lines
35
+ .map((line, index) => {
36
+ if (index === 0) {
37
+ return line;
38
+ }
39
+ return `${innerIndentation}${line}`;
40
+ })
41
+ .join('\n');
42
+ }
43
+ }
44
+ else {
45
+ formattedValue = `'${value}'`;
46
+ }
47
+ parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`);
48
+ }
49
+ else {
50
+ parts.push(`${innerIndentation}${formattedKey}: ${value}`);
51
+ }
52
+ }
53
+ return `{\n${parts.join(',\n')}\n${indentation}}`;
54
+ }
55
+
56
+ export { objectToString };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './snippetz';
1
+ export * from './snippetz.js';
2
+ export * from './core/types';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,163 +1 @@
1
- function u(s) {
2
- return s.reduce((t, e) => (t[e.name] = e.value, t), {});
3
- }
4
- function p(s) {
5
- return /\s|-/.test(s);
6
- }
7
- function h(s, t = 0) {
8
- let e = [], n = " ".repeat(t), o = " ".repeat(t + 2);
9
- for (const [c, a] of Object.entries(s)) {
10
- let d = p(c) ? `'${c}'` : c;
11
- if (Array.isArray(a)) {
12
- const i = a.map((r) => typeof r == "string" ? `'${r}'` : r && typeof r == "object" ? h(r, t + 2) : r).join(`, ${o}`);
13
- e.push(`${o}${d}: [${i}]`);
14
- } else if (a && typeof a == "object")
15
- e.push(
16
- `${o}${d}: ${h(
17
- a,
18
- t + 2
19
- )}`
20
- );
21
- else if (typeof a == "string") {
22
- let i = `${a}`;
23
- if (a.startsWith("JSON.stringify")) {
24
- const r = a.split(`
25
- `);
26
- r.length > 1 && (i = r.map((f, l) => l === 0 ? f : `${o}${f}`).join(`
27
- `));
28
- } else
29
- i = `'${a}'`;
30
- e.push(`${o}${d}: ${i}`);
31
- } else
32
- e.push(`${o}${d}: ${a}`);
33
- }
34
- return `{
35
- ${e.join(`,
36
- `)}
37
- ${n}}`;
38
- }
39
- function $(s) {
40
- var d, i;
41
- const t = {
42
- method: "GET",
43
- ...s
44
- };
45
- t.method = t.method.toUpperCase();
46
- const e = {
47
- method: t.method === "GET" ? void 0 : t.method
48
- }, n = new URLSearchParams(
49
- t.queryString ? u(t.queryString) : void 0
50
- ), o = n.size ? `?${n.toString()}` : "";
51
- (d = t.headers) != null && d.length && (e.headers = {}, t.headers.forEach((r) => {
52
- e.headers[r.name] = r.value;
53
- })), (i = t.cookies) != null && i.length && (e.headers = e.headers || {}, t.cookies.forEach((r) => {
54
- e.headers["Set-Cookie"] = e.headers["Set-Cookie"] ? `${e.headers["Set-Cookie"]}; ${r.name}=${r.value}` : `${r.name}=${r.value}`;
55
- })), Object.keys(e).forEach((r) => {
56
- e[r] === void 0 && delete e[r];
57
- }), t.postData && (e.body = t.postData.text, t.postData.mimeType === "application/json" && (e.body = `JSON.stringify(${h(JSON.parse(e.body))})`));
58
- const c = Object.keys(e).length ? `, ${h(e)}` : "";
59
- return {
60
- target: "node",
61
- client: "undici",
62
- code: `import { request } from 'undici'
63
-
64
- const { statusCode, body } = await request('${t.url}${o}'${c})`
65
- };
66
- }
67
- function g(s) {
68
- var d, i;
69
- const t = {
70
- method: "GET",
71
- ...s
72
- };
73
- t.method = t.method.toUpperCase();
74
- const e = {
75
- method: t.method === "GET" ? void 0 : t.method
76
- }, n = new URLSearchParams(
77
- t.queryString ? u(t.queryString) : void 0
78
- ), o = n.size ? `?${n.toString()}` : "";
79
- (d = t.headers) != null && d.length && (e.headers = {}, t.headers.forEach((r) => {
80
- e.headers[r.name] = r.value;
81
- })), (i = t.cookies) != null && i.length && (e.headers = e.headers || {}, t.cookies.forEach((r) => {
82
- e.headers["Set-Cookie"] = e.headers["Set-Cookie"] ? `${e.headers["Set-Cookie"]}; ${r.name}=${r.value}` : `${r.name}=${r.value}`;
83
- })), Object.keys(e).forEach((r) => {
84
- e[r] === void 0 && delete e[r];
85
- }), t.postData && (e.body = t.postData.text, t.postData.mimeType === "application/json" && (e.body = `JSON.stringify(${h(
86
- JSON.parse(e.body)
87
- )})`));
88
- const c = Object.keys(e).length ? `, ${h(e)}` : "";
89
- return {
90
- target: "node",
91
- client: "fetch",
92
- code: `fetch('${t.url}${o}'${c})`
93
- };
94
- }
95
- function m(s) {
96
- var d, i;
97
- const t = {
98
- method: "GET",
99
- ...s
100
- };
101
- t.method = t.method.toUpperCase();
102
- const e = {
103
- method: t.method === "GET" ? void 0 : t.method
104
- }, n = new URLSearchParams(
105
- t.queryString ? u(t.queryString) : void 0
106
- ), o = n.size ? `?${n.toString()}` : "";
107
- (d = t.headers) != null && d.length && (e.headers = {}, t.headers.forEach((r) => {
108
- e.headers[r.name] = r.value;
109
- })), (i = t.cookies) != null && i.length && (e.headers = e.headers || {}, t.cookies.forEach((r) => {
110
- e.headers["Set-Cookie"] = e.headers["Set-Cookie"] ? `${e.headers["Set-Cookie"]}; ${r.name}=${r.value}` : `${r.name}=${r.value}`;
111
- })), Object.keys(e).forEach((r) => {
112
- e[r] === void 0 && delete e[r];
113
- }), t.postData && (e.body = t.postData.text, t.postData.mimeType === "application/json" && (e.body = `JSON.stringify(${h(
114
- JSON.parse(e.body)
115
- )})`));
116
- const c = Object.keys(e).length ? `, ${h(e)}` : "";
117
- return {
118
- target: "js",
119
- client: "fetch",
120
- code: `fetch('${t.url}${o}'${c})`
121
- };
122
- }
123
- function y() {
124
- const s = [$, g, m];
125
- return {
126
- get(t, e, n) {
127
- const o = this.findPlugin(t, e);
128
- if (o)
129
- return o(n);
130
- },
131
- print(t, e, n) {
132
- var o;
133
- return (o = this.get(t, e, n)) == null ? void 0 : o.code;
134
- },
135
- targets() {
136
- return s.map((t) => t().target).filter((t, e, n) => n.indexOf(t) === e);
137
- },
138
- clients() {
139
- return s.map((t) => t().client);
140
- },
141
- plugins() {
142
- return s.map((t) => {
143
- const e = t();
144
- return {
145
- target: e.target,
146
- client: e.client
147
- };
148
- });
149
- },
150
- findPlugin(t, e) {
151
- return s.find((n) => {
152
- const o = n();
153
- return o.target === t && o.client === e;
154
- });
155
- },
156
- hasPlugin(t, e) {
157
- return !!this.findPlugin(t, e);
158
- }
159
- };
160
- }
161
- export {
162
- y as snippetz
163
- };
1
+ export { snippetz } from './snippetz.js';
@@ -0,0 +1,3 @@
1
+ import { type Source, type Request } from '../../../core/index.js';
2
+ export declare function fetch(request?: Partial<Request>): Source;
3
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,OAAO,EAGb,MAAM,eAAe,CAAA;AAEtB,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
@@ -0,0 +1,65 @@
1
+ import { arrayToObject } from '../../../core/utils/arrayToObject.js';
2
+ import { objectToString } from '../../../core/utils/objectToString.js';
3
+
4
+ function fetch(request) {
5
+ // Defaults
6
+ const normalizedRequest = {
7
+ method: 'GET',
8
+ ...request,
9
+ };
10
+ // Normalization
11
+ normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
+ // Reset fetch defaults
13
+ const options = {
14
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
+ };
16
+ // Query
17
+ const searchParams = new URLSearchParams(normalizedRequest.queryString
18
+ ? arrayToObject(normalizedRequest.queryString)
19
+ : undefined);
20
+ const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
21
+ // Headers
22
+ if (normalizedRequest.headers?.length) {
23
+ options.headers = {};
24
+ normalizedRequest.headers.forEach((header) => {
25
+ options.headers[header.name] = header.value;
26
+ });
27
+ }
28
+ // Cookies
29
+ if (normalizedRequest.cookies?.length) {
30
+ options.headers = options.headers || {};
31
+ normalizedRequest.cookies.forEach((cookie) => {
32
+ options.headers['Set-Cookie'] = options.headers['Set-Cookie']
33
+ ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
34
+ : `${cookie.name}=${cookie.value}`;
35
+ });
36
+ }
37
+ // Remove undefined keys
38
+ Object.keys(options).forEach((key) => {
39
+ if (options[key] === undefined) {
40
+ delete options[key];
41
+ }
42
+ });
43
+ // Add body
44
+ if (normalizedRequest.postData) {
45
+ // Plain text
46
+ options.body = normalizedRequest.postData.text;
47
+ // JSON
48
+ if (normalizedRequest.postData.mimeType === 'application/json') {
49
+ options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
50
+ }
51
+ }
52
+ // Transform to JSON
53
+ const jsonOptions = Object.keys(options).length
54
+ ? `, ${objectToString(options)}`
55
+ : '';
56
+ // Code Template
57
+ const code = `fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`;
58
+ return {
59
+ target: 'js',
60
+ client: 'fetch',
61
+ code,
62
+ };
63
+ }
64
+
65
+ export { fetch };
@@ -0,0 +1,2 @@
1
+ export * from './fetch.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1 @@
1
+ export { fetch } from './fetch.js';
@@ -0,0 +1,2 @@
1
+ export * from './ofetch.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -0,0 +1 @@
1
+ export { ofetch } from './ofetch.js';
@@ -0,0 +1,3 @@
1
+ import { type Source, type Request } from '../../../core/index.js';
2
+ export declare function ofetch(request?: Partial<Request>): Source;
3
+ //# sourceMappingURL=ofetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,OAAO,EAGb,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAiFzD"}
@@ -0,0 +1,70 @@
1
+ import { arrayToObject } from '../../../core/utils/arrayToObject.js';
2
+ import { objectToString } from '../../../core/utils/objectToString.js';
3
+
4
+ function ofetch(request) {
5
+ // Defaults
6
+ const normalizedRequest = {
7
+ method: 'GET',
8
+ ...request,
9
+ };
10
+ // Normalization
11
+ normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
+ // Reset fetch defaults
13
+ const options = {
14
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
+ };
16
+ // Query
17
+ const searchParams = new URLSearchParams(normalizedRequest.queryString
18
+ ? arrayToObject(normalizedRequest.queryString)
19
+ : undefined);
20
+ if (searchParams.size) {
21
+ options.query = {};
22
+ searchParams.forEach((value, key) => {
23
+ options.query[key] = value;
24
+ });
25
+ }
26
+ // Headers
27
+ if (normalizedRequest.headers?.length) {
28
+ options.headers = {};
29
+ normalizedRequest.headers.forEach((header) => {
30
+ options.headers[header.name] = header.value;
31
+ });
32
+ }
33
+ // Cookies
34
+ if (normalizedRequest.cookies?.length) {
35
+ options.headers = options.headers || {};
36
+ normalizedRequest.cookies.forEach((cookie) => {
37
+ options.headers['Set-Cookie'] = options.headers['Set-Cookie']
38
+ ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
39
+ : `${cookie.name}=${cookie.value}`;
40
+ });
41
+ }
42
+ // Remove undefined keys
43
+ Object.keys(options).forEach((key) => {
44
+ if (options[key] === undefined) {
45
+ delete options[key];
46
+ }
47
+ });
48
+ // Add body
49
+ if (normalizedRequest.postData) {
50
+ // Plain text
51
+ options.body = normalizedRequest.postData.text;
52
+ // JSON
53
+ if (normalizedRequest.postData.mimeType === 'application/json') {
54
+ options.body = JSON.parse(options.body);
55
+ }
56
+ }
57
+ // Transform to JSON
58
+ const jsonOptions = Object.keys(options).length
59
+ ? `, ${objectToString(options)}`
60
+ : '';
61
+ // Code Template
62
+ const code = `ofetch('${normalizedRequest.url}'${jsonOptions})`;
63
+ return {
64
+ target: 'js',
65
+ client: 'ofetch',
66
+ code,
67
+ };
68
+ }
69
+
70
+ export { ofetch };
@@ -0,0 +1,3 @@
1
+ import { type Source, type Request } from '../../../core/index.js';
2
+ export declare function fetch(request?: Partial<Request>): Source;
3
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,OAAO,EAGb,MAAM,eAAe,CAAA;AAEtB,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
@@ -0,0 +1,65 @@
1
+ import { arrayToObject } from '../../../core/utils/arrayToObject.js';
2
+ import { objectToString } from '../../../core/utils/objectToString.js';
3
+
4
+ function fetch(request) {
5
+ // Defaults
6
+ const normalizedRequest = {
7
+ method: 'GET',
8
+ ...request,
9
+ };
10
+ // Normalization
11
+ normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
+ // Reset fetch defaults
13
+ const options = {
14
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
+ };
16
+ // Query
17
+ const searchParams = new URLSearchParams(normalizedRequest.queryString
18
+ ? arrayToObject(normalizedRequest.queryString)
19
+ : undefined);
20
+ const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
21
+ // Headers
22
+ if (normalizedRequest.headers?.length) {
23
+ options.headers = {};
24
+ normalizedRequest.headers.forEach((header) => {
25
+ options.headers[header.name] = header.value;
26
+ });
27
+ }
28
+ // Cookies
29
+ if (normalizedRequest.cookies?.length) {
30
+ options.headers = options.headers || {};
31
+ normalizedRequest.cookies.forEach((cookie) => {
32
+ options.headers['Set-Cookie'] = options.headers['Set-Cookie']
33
+ ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
34
+ : `${cookie.name}=${cookie.value}`;
35
+ });
36
+ }
37
+ // Remove undefined keys
38
+ Object.keys(options).forEach((key) => {
39
+ if (options[key] === undefined) {
40
+ delete options[key];
41
+ }
42
+ });
43
+ // Add body
44
+ if (normalizedRequest.postData) {
45
+ // Plain text
46
+ options.body = normalizedRequest.postData.text;
47
+ // JSON
48
+ if (normalizedRequest.postData.mimeType === 'application/json') {
49
+ options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
50
+ }
51
+ }
52
+ // Transform to JSON
53
+ const jsonOptions = Object.keys(options).length
54
+ ? `, ${objectToString(options)}`
55
+ : '';
56
+ // Code Template
57
+ const code = `fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`;
58
+ return {
59
+ target: 'node',
60
+ client: 'fetch',
61
+ code,
62
+ };
63
+ }
64
+
65
+ export { fetch };
@@ -0,0 +1,2 @@
1
+ export * from './fetch.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1 @@
1
+ export { fetch } from './fetch.js';
@@ -0,0 +1,2 @@
1
+ export * from './ofetch.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -0,0 +1 @@
1
+ export { ofetch } from './ofetch.js';
@@ -0,0 +1,3 @@
1
+ import { type Source, type Request } from '../../../core/index.js';
2
+ export declare function ofetch(request?: Partial<Request>): Source;
3
+ //# sourceMappingURL=ofetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,OAAO,EAGb,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAiFzD"}
@@ -0,0 +1,70 @@
1
+ import { arrayToObject } from '../../../core/utils/arrayToObject.js';
2
+ import { objectToString } from '../../../core/utils/objectToString.js';
3
+
4
+ function ofetch(request) {
5
+ // Defaults
6
+ const normalizedRequest = {
7
+ method: 'GET',
8
+ ...request,
9
+ };
10
+ // Normalization
11
+ normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
+ // Reset fetch defaults
13
+ const options = {
14
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
+ };
16
+ // Query
17
+ const searchParams = new URLSearchParams(normalizedRequest.queryString
18
+ ? arrayToObject(normalizedRequest.queryString)
19
+ : undefined);
20
+ if (searchParams.size) {
21
+ options.query = {};
22
+ searchParams.forEach((value, key) => {
23
+ options.query[key] = value;
24
+ });
25
+ }
26
+ // Headers
27
+ if (normalizedRequest.headers?.length) {
28
+ options.headers = {};
29
+ normalizedRequest.headers.forEach((header) => {
30
+ options.headers[header.name] = header.value;
31
+ });
32
+ }
33
+ // Cookies
34
+ if (normalizedRequest.cookies?.length) {
35
+ options.headers = options.headers || {};
36
+ normalizedRequest.cookies.forEach((cookie) => {
37
+ options.headers['Set-Cookie'] = options.headers['Set-Cookie']
38
+ ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
39
+ : `${cookie.name}=${cookie.value}`;
40
+ });
41
+ }
42
+ // Remove undefined keys
43
+ Object.keys(options).forEach((key) => {
44
+ if (options[key] === undefined) {
45
+ delete options[key];
46
+ }
47
+ });
48
+ // Add body
49
+ if (normalizedRequest.postData) {
50
+ // Plain text
51
+ options.body = normalizedRequest.postData.text;
52
+ // JSON
53
+ if (normalizedRequest.postData.mimeType === 'application/json') {
54
+ options.body = JSON.parse(options.body);
55
+ }
56
+ }
57
+ // Transform to JSON
58
+ const jsonOptions = Object.keys(options).length
59
+ ? `, ${objectToString(options)}`
60
+ : '';
61
+ // Code Template
62
+ const code = `ofetch('${normalizedRequest.url}'${jsonOptions})`;
63
+ return {
64
+ target: 'node',
65
+ client: 'ofetch',
66
+ code,
67
+ };
68
+ }
69
+
70
+ export { ofetch };
@@ -0,0 +1,2 @@
1
+ export * from './undici.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -0,0 +1 @@
1
+ export { undici } from './undici.js';
@@ -0,0 +1,3 @@
1
+ import { type Source, type Request } from '../../../core/index.js';
2
+ export declare function undici(request?: Partial<Request>): Source;
3
+ //# sourceMappingURL=undici.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,OAAO,EAGb,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA+EzD"}
@@ -0,0 +1,67 @@
1
+ import { arrayToObject } from '../../../core/utils/arrayToObject.js';
2
+ import { objectToString } from '../../../core/utils/objectToString.js';
3
+
4
+ function undici(request) {
5
+ // Defaults
6
+ const normalizedRequest = {
7
+ method: 'GET',
8
+ ...request,
9
+ };
10
+ // Normalization
11
+ normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
+ // Reset undici defaults
13
+ const options = {
14
+ method: normalizedRequest.method === 'GET' ? undefined : normalizedRequest.method,
15
+ };
16
+ // Query
17
+ const searchParams = new URLSearchParams(normalizedRequest.queryString
18
+ ? arrayToObject(normalizedRequest.queryString)
19
+ : undefined);
20
+ const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
21
+ // Headers
22
+ if (normalizedRequest.headers?.length) {
23
+ options.headers = {};
24
+ normalizedRequest.headers.forEach((header) => {
25
+ options.headers[header.name] = header.value;
26
+ });
27
+ }
28
+ // Cookies
29
+ if (normalizedRequest.cookies?.length) {
30
+ options.headers = options.headers || {};
31
+ normalizedRequest.cookies.forEach((cookie) => {
32
+ options.headers['Set-Cookie'] = options.headers['Set-Cookie']
33
+ ? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
34
+ : `${cookie.name}=${cookie.value}`;
35
+ });
36
+ }
37
+ // Remove undefined keys
38
+ Object.keys(options).forEach((key) => {
39
+ if (options[key] === undefined) {
40
+ delete options[key];
41
+ }
42
+ });
43
+ // Add body
44
+ if (normalizedRequest.postData) {
45
+ // Plain text
46
+ options.body = normalizedRequest.postData.text;
47
+ // JSON
48
+ if (normalizedRequest.postData.mimeType === 'application/json') {
49
+ options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
50
+ }
51
+ }
52
+ // Transform to JSON
53
+ const jsonOptions = Object.keys(options).length
54
+ ? `, ${objectToString(options)}`
55
+ : '';
56
+ // Code Template
57
+ const code = `import { request } from 'undici'
58
+
59
+ const { statusCode, body } = await request('${normalizedRequest.url}${queryString}'${jsonOptions})`;
60
+ return {
61
+ target: 'node',
62
+ client: 'undici',
63
+ code,
64
+ };
65
+ }
66
+
67
+ export { undici };
@@ -1,7 +1,7 @@
1
- import type { TargetId, ClientId, Request } from '@scalar/snippetz-core';
2
- import { undici } from '@scalar/snippetz-plugin-node-undici';
1
+ import type { TargetId, ClientId, Request } from './core/index.js';
2
+ import { undici } from './plugins/node/undici/index.js';
3
3
  export declare function snippetz(): {
4
- get(target: TargetId, client: ClientId, request: Partial<Request>): import("@scalar/snippetz-core").Source | undefined;
4
+ get(target: TargetId, client: ClientId, request: Partial<Request>): import("./core/index.js").Source | undefined;
5
5
  print(target: TargetId, client: ClientId, request: Partial<Request>): string | undefined;
6
6
  targets(): TargetId[];
7
7
  clients(): ClientId[];
@@ -10,6 +10,6 @@ export declare function snippetz(): {
10
10
  client: ClientId;
11
11
  }[];
12
12
  findPlugin(target: TargetId, client: ClientId): typeof undici | undefined;
13
- hasPlugin(target: string, client: ClientId): boolean;
13
+ hasPlugin(target: string, client: string): boolean;
14
14
  };
15
15
  //# sourceMappingURL=snippetz.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAA;AAI5D,wBAAgB,QAAQ;gBAIR,QAAQ,UAAU,QAAQ,WAAW,QAAQ,OAAO,CAAC;kBAOnD,QAAQ,UAAU,QAAQ,WAAW,QAAQ,OAAO,CAAC;;;;;;;uBAyBhD,QAAQ,UAAU,QAAQ;sBAO3B,MAAM,UAAU,QAAQ;EAI7C"}
1
+ {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAM9C,wBAAgB,QAAQ;gBAIR,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;kBAOnD,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;;;;;;;uBAyBhD,QAAQ,UAAU,QAAQ;sBAO3B,MAAM,UAAU,MAAM;EAI3C"}
@@ -0,0 +1,50 @@
1
+ import { undici } from './plugins/node/undici/undici.js';
2
+ import { fetch } from './plugins/node/fetch/fetch.js';
3
+ import { fetch as fetch$1 } from './plugins/js/fetch/fetch.js';
4
+ import { ofetch } from './plugins/js/ofetch/ofetch.js';
5
+ import { ofetch as ofetch$1 } from './plugins/node/ofetch/ofetch.js';
6
+
7
+ function snippetz() {
8
+ const plugins = [undici, fetch, fetch$1, ofetch, ofetch$1];
9
+ return {
10
+ get(target, client, request) {
11
+ const plugin = this.findPlugin(target, client);
12
+ if (plugin) {
13
+ return plugin(request);
14
+ }
15
+ },
16
+ print(target, client, request) {
17
+ return this.get(target, client, request)?.code;
18
+ },
19
+ targets() {
20
+ return (plugins
21
+ // all targets
22
+ .map((plugin) => plugin().target)
23
+ // unique values
24
+ .filter((value, index, self) => self.indexOf(value) === index));
25
+ },
26
+ clients() {
27
+ return plugins.map((plugin) => plugin().client);
28
+ },
29
+ plugins() {
30
+ return plugins.map((plugin) => {
31
+ const details = plugin();
32
+ return {
33
+ target: details.target,
34
+ client: details.client,
35
+ };
36
+ });
37
+ },
38
+ findPlugin(target, client) {
39
+ return plugins.find((plugin) => {
40
+ const details = plugin();
41
+ return details.target === target && details.client === client;
42
+ });
43
+ },
44
+ hasPlugin(target, client) {
45
+ return Boolean(this.findPlugin(target, client));
46
+ },
47
+ };
48
+ }
49
+
50
+ export { snippetz };
package/package.json CHANGED
@@ -1,35 +1,58 @@
1
1
  {
2
2
  "name": "@scalar/snippetz",
3
- "version": "0.1.5",
4
- "type": "module",
5
- "devDependencies": {
6
- "@vitest/ui": "^1.0.4",
7
- "typescript": "^5.2.2",
8
- "vite": "^5.0.0",
9
- "vitest": "^1.0.4"
10
- },
11
- "dependencies": {
12
- "@scalar/snippetz-core": "0.1.3",
13
- "@scalar/snippetz-plugin-node-undici": "0.1.5",
14
- "@scalar/snippetz-plugin-node-fetch": "0.1.1",
15
- "@scalar/snippetz-plugin-js-fetch": "0.1.0"
3
+ "license": "MIT",
4
+ "author": "Scalar (https://github.com/scalar)",
5
+ "homepage": "https://github.com/scalar/snippetz",
6
+ "bugs": "https://github.com/scalar/snippetz/issues/new/choose",
7
+ "engines": {
8
+ "node": ">=18"
16
9
  },
10
+ "version": "0.2.0",
11
+ "type": "module",
17
12
  "files": [
18
- "dist"
13
+ "dist",
14
+ "CHANGELOG"
19
15
  ],
20
16
  "types": "./dist/index.d.ts",
21
- "main": "./dist/index.umd.cjs",
22
17
  "module": "./dist/index.js",
23
18
  "exports": {
24
19
  ".": {
25
20
  "import": "./dist/index.js",
26
- "require": "./dist/index.umd.cjs"
21
+ "types": "./dist/index.d.ts"
22
+ },
23
+ "./plugins/node/undici": {
24
+ "import": "./dist/plugins/node/undici/index.js",
25
+ "types": "./dist/plugins/node/undici/index.d.ts"
26
+ },
27
+ "./plugins/node/ofetch": {
28
+ "import": "./dist/plugins/node/ofetch/index.js",
29
+ "types": "./dist/plugins/node/ofetch/index.d.ts"
30
+ },
31
+ "./plugins/node/fetch": {
32
+ "import": "./dist/plugins/node/fetch/index.js",
33
+ "types": "./dist/plugins/node/fetch/index.d.ts"
34
+ },
35
+ "./plugins/js/ofetch": {
36
+ "import": "./dist/plugins/js/ofetch/index.js",
37
+ "types": "./dist/plugins/js/ofetch/index.d.ts"
38
+ },
39
+ "./plugins/js/fetch": {
40
+ "import": "./dist/plugins/js/fetch/index.js",
41
+ "types": "./dist/plugins/js/fetch/index.d.ts"
42
+ },
43
+ "./core": {
44
+ "import": "./dist/core/index.js",
45
+ "types": "./dist/core/index.d.ts"
27
46
  }
28
47
  },
48
+ "devDependencies": {
49
+ "@scalar/build-tooling": "^0.1.10",
50
+ "@types/har-format": "^1.2.15"
51
+ },
29
52
  "scripts": {
30
- "build": "vite build && tsc -p tsconfig.build.json",
53
+ "build": "scalar-build-rollup",
31
54
  "test": "vitest",
32
- "test:ui": "vitest --ui",
33
- "types:check": "tsc --noEmit --skipLibCheck"
55
+ "types:build": "scalar-types-build",
56
+ "types:check": "scalar-types-check"
34
57
  }
35
58
  }
@@ -1,8 +0,0 @@
1
- (function(f,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(f=typeof globalThis<"u"?globalThis:f||self,u(f["@scalar/snippetz"]={}))})(this,function(f){"use strict";function u(s){return s.reduce((t,e)=>(t[e.name]=e.value,t),{})}function p(s){return/\s|-/.test(s)}function h(s,t=0){let e=[],r=" ".repeat(t),o=" ".repeat(t+2);for(const[c,i]of Object.entries(s)){let d=p(c)?`'${c}'`:c;if(Array.isArray(i)){const a=i.map(n=>typeof n=="string"?`'${n}'`:n&&typeof n=="object"?h(n,t+2):n).join(`, ${o}`);e.push(`${o}${d}: [${a}]`)}else if(i&&typeof i=="object")e.push(`${o}${d}: ${h(i,t+2)}`);else if(typeof i=="string"){let a=`${i}`;if(i.startsWith("JSON.stringify")){const n=i.split(`
2
- `);n.length>1&&(a=n.map((l,S)=>S===0?l:`${o}${l}`).join(`
3
- `))}else a=`'${i}'`;e.push(`${o}${d}: ${a}`)}else e.push(`${o}${d}: ${i}`)}return`{
4
- ${e.join(`,
5
- `)}
6
- ${r}}`}function $(s){var d,a;const t={method:"GET",...s};t.method=t.method.toUpperCase();const e={method:t.method==="GET"?void 0:t.method},r=new URLSearchParams(t.queryString?u(t.queryString):void 0),o=r.size?`?${r.toString()}`:"";(d=t.headers)!=null&&d.length&&(e.headers={},t.headers.forEach(n=>{e.headers[n.name]=n.value})),(a=t.cookies)!=null&&a.length&&(e.headers=e.headers||{},t.cookies.forEach(n=>{e.headers["Set-Cookie"]=e.headers["Set-Cookie"]?`${e.headers["Set-Cookie"]}; ${n.name}=${n.value}`:`${n.name}=${n.value}`})),Object.keys(e).forEach(n=>{e[n]===void 0&&delete e[n]}),t.postData&&(e.body=t.postData.text,t.postData.mimeType==="application/json"&&(e.body=`JSON.stringify(${h(JSON.parse(e.body))})`));const c=Object.keys(e).length?`, ${h(e)}`:"";return{target:"node",client:"undici",code:`import { request } from 'undici'
7
-
8
- const { statusCode, body } = await request('${t.url}${o}'${c})`}}function g(s){var d,a;const t={method:"GET",...s};t.method=t.method.toUpperCase();const e={method:t.method==="GET"?void 0:t.method},r=new URLSearchParams(t.queryString?u(t.queryString):void 0),o=r.size?`?${r.toString()}`:"";(d=t.headers)!=null&&d.length&&(e.headers={},t.headers.forEach(n=>{e.headers[n.name]=n.value})),(a=t.cookies)!=null&&a.length&&(e.headers=e.headers||{},t.cookies.forEach(n=>{e.headers["Set-Cookie"]=e.headers["Set-Cookie"]?`${e.headers["Set-Cookie"]}; ${n.name}=${n.value}`:`${n.name}=${n.value}`})),Object.keys(e).forEach(n=>{e[n]===void 0&&delete e[n]}),t.postData&&(e.body=t.postData.text,t.postData.mimeType==="application/json"&&(e.body=`JSON.stringify(${h(JSON.parse(e.body))})`));const c=Object.keys(e).length?`, ${h(e)}`:"";return{target:"node",client:"fetch",code:`fetch('${t.url}${o}'${c})`}}function m(s){var d,a;const t={method:"GET",...s};t.method=t.method.toUpperCase();const e={method:t.method==="GET"?void 0:t.method},r=new URLSearchParams(t.queryString?u(t.queryString):void 0),o=r.size?`?${r.toString()}`:"";(d=t.headers)!=null&&d.length&&(e.headers={},t.headers.forEach(n=>{e.headers[n.name]=n.value})),(a=t.cookies)!=null&&a.length&&(e.headers=e.headers||{},t.cookies.forEach(n=>{e.headers["Set-Cookie"]=e.headers["Set-Cookie"]?`${e.headers["Set-Cookie"]}; ${n.name}=${n.value}`:`${n.name}=${n.value}`})),Object.keys(e).forEach(n=>{e[n]===void 0&&delete e[n]}),t.postData&&(e.body=t.postData.text,t.postData.mimeType==="application/json"&&(e.body=`JSON.stringify(${h(JSON.parse(e.body))})`));const c=Object.keys(e).length?`, ${h(e)}`:"";return{target:"js",client:"fetch",code:`fetch('${t.url}${o}'${c})`}}function y(){const s=[$,g,m];return{get(t,e,r){const o=this.findPlugin(t,e);if(o)return o(r)},print(t,e,r){var o;return(o=this.get(t,e,r))==null?void 0:o.code},targets(){return s.map(t=>t().target).filter((t,e,r)=>r.indexOf(t)===e)},clients(){return s.map(t=>t().client)},plugins(){return s.map(t=>{const e=t();return{target:e.target,client:e.client}})},findPlugin(t,e){return s.find(r=>{const o=r();return o.target===t&&o.client===e})},hasPlugin(t,e){return!!this.findPlugin(t,e)}}}f.snippetz=y,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});