@scalar/snippetz 0.1.3 → 0.1.5

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/dist/index.js CHANGED
@@ -1,107 +1,163 @@
1
- function p(s) {
2
- return s.reduce((e, t) => (e[t.name] = t.value, e), {});
1
+ function u(s) {
2
+ return s.reduce((t, e) => (t[e.name] = e.value, t), {});
3
3
  }
4
- function h(s) {
4
+ function p(s) {
5
5
  return /\s|-/.test(s);
6
6
  }
7
- function l(s, e = 0) {
8
- let t = [], i = " ".repeat(e), r = " ".repeat(e + 2);
9
- for (const [c, o] of Object.entries(s)) {
10
- let u = h(c) ? `'${c}'` : c;
11
- if (Array.isArray(o)) {
12
- const a = o.map((n) => typeof n == "string" ? `'${n}'` : n && typeof n == "object" ? l(n, e + 2) : n).join(`, ${r}`);
13
- t.push(`${r}${u}: [${a}]`);
14
- } else if (o && typeof o == "object")
15
- t.push(
16
- `${r}${u}: ${l(
17
- o,
18
- e + 2
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
19
  )}`
20
20
  );
21
- else if (typeof o == "string") {
22
- let a = `${o}`;
23
- if (o.startsWith("JSON.stringify")) {
24
- const n = o.split(`
21
+ else if (typeof a == "string") {
22
+ let i = `${a}`;
23
+ if (a.startsWith("JSON.stringify")) {
24
+ const r = a.split(`
25
25
  `);
26
- n.length > 1 && (a = n.map((d, f) => f === 0 ? d : `${r}${d}`).join(`
26
+ r.length > 1 && (i = r.map((f, l) => l === 0 ? f : `${o}${f}`).join(`
27
27
  `));
28
28
  } else
29
- a = `'${o}'`;
30
- t.push(`${r}${u}: ${a}`);
29
+ i = `'${a}'`;
30
+ e.push(`${o}${d}: ${i}`);
31
31
  } else
32
- t.push(`${r}${u}: ${o}`);
32
+ e.push(`${o}${d}: ${a}`);
33
33
  }
34
34
  return `{
35
- ${t.join(`,
35
+ ${e.join(`,
36
36
  `)}
37
- ${i}}`;
37
+ ${n}}`;
38
38
  }
39
39
  function $(s) {
40
- var u, a;
41
- const e = {
40
+ var d, i;
41
+ const t = {
42
42
  method: "GET",
43
43
  ...s
44
44
  };
45
- e.method = e.method.toUpperCase();
46
- const t = {
47
- method: e.method === "GET" ? void 0 : e.method
48
- }, i = new URLSearchParams(
49
- e.queryString ? p(e.queryString) : void 0
50
- ), r = i.size ? `?${i.toString()}` : "";
51
- (u = e.headers) != null && u.length && (t.headers = {}, e.headers.forEach((n) => {
52
- t.headers[n.name] = n.value;
53
- })), (a = e.cookies) != null && a.length && (t.headers = t.headers || {}, e.cookies.forEach((n) => {
54
- t.headers["Set-Cookie"] = t.headers["Set-Cookie"] ? `${t.headers["Set-Cookie"]}; ${n.name}=${n.value}` : `${n.name}=${n.value}`;
55
- })), Object.keys(t).forEach((n) => {
56
- t[n] === void 0 && delete t[n];
57
- }), e.postData && (t.body = e.postData.text, e.postData.mimeType === "application/json" && (t.body = `JSON.stringify(${l(JSON.parse(t.body))})`));
58
- const c = Object.keys(t).length ? `, ${l(t)}` : "";
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
59
  return {
60
60
  target: "node",
61
61
  client: "undici",
62
62
  code: `import { request } from 'undici'
63
63
 
64
- const { statusCode, body } = await request('${e.url}${r}'${c})`
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})`
65
121
  };
66
122
  }
67
- function g() {
68
- const s = [$];
123
+ function y() {
124
+ const s = [$, g, m];
69
125
  return {
70
- get(e, t, i) {
71
- const r = this.findPlugin(e, t);
72
- if (r)
73
- return r(i);
126
+ get(t, e, n) {
127
+ const o = this.findPlugin(t, e);
128
+ if (o)
129
+ return o(n);
74
130
  },
75
- print(e, t, i) {
76
- var r;
77
- return (r = this.get(e, t, i)) == null ? void 0 : r.code;
131
+ print(t, e, n) {
132
+ var o;
133
+ return (o = this.get(t, e, n)) == null ? void 0 : o.code;
78
134
  },
79
135
  targets() {
80
- return s.map((e) => e().target);
136
+ return s.map((t) => t().target).filter((t, e, n) => n.indexOf(t) === e);
81
137
  },
82
138
  clients() {
83
- return s.map((e) => e().client);
139
+ return s.map((t) => t().client);
84
140
  },
85
141
  plugins() {
86
- return s.map((e) => {
87
- const t = e();
142
+ return s.map((t) => {
143
+ const e = t();
88
144
  return {
89
- target: t.target,
90
- client: t.client
145
+ target: e.target,
146
+ client: e.client
91
147
  };
92
148
  });
93
149
  },
94
- findPlugin(e, t) {
95
- return s.find((i) => {
96
- const r = i();
97
- return r.target === e && r.client === t;
150
+ findPlugin(t, e) {
151
+ return s.find((n) => {
152
+ const o = n();
153
+ return o.target === t && o.client === e;
98
154
  });
99
155
  },
100
- hasPlugin(e, t) {
101
- return !!this.findPlugin(e, t);
156
+ hasPlugin(t, e) {
157
+ return !!this.findPlugin(t, e);
102
158
  }
103
159
  };
104
160
  }
105
161
  export {
106
- g as snippetz
162
+ y as snippetz
107
163
  };
@@ -1,8 +1,8 @@
1
- (function(d,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(d=typeof globalThis<"u"?globalThis:d||self,f(d["@scalar/snippetz"]={}))})(this,function(d){"use strict";function f(i){return i.reduce((e,t)=>(e[t.name]=t.value,e),{})}function h(i){return/\s|-/.test(i)}function c(i,e=0){let t=[],o=" ".repeat(e),r=" ".repeat(e+2);for(const[l,s]of Object.entries(i)){let u=h(l)?`'${l}'`:l;if(Array.isArray(s)){const a=s.map(n=>typeof n=="string"?`'${n}'`:n&&typeof n=="object"?c(n,e+2):n).join(`, ${r}`);t.push(`${r}${u}: [${a}]`)}else if(s&&typeof s=="object")t.push(`${r}${u}: ${c(s,e+2)}`);else if(typeof s=="string"){let a=`${s}`;if(s.startsWith("JSON.stringify")){const n=s.split(`
2
- `);n.length>1&&(a=n.map((p,y)=>y===0?p:`${r}${p}`).join(`
3
- `))}else a=`'${s}'`;t.push(`${r}${u}: ${a}`)}else t.push(`${r}${u}: ${s}`)}return`{
4
- ${t.join(`,
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
5
  `)}
6
- ${o}}`}function $(i){var u,a;const e={method:"GET",...i};e.method=e.method.toUpperCase();const t={method:e.method==="GET"?void 0:e.method},o=new URLSearchParams(e.queryString?f(e.queryString):void 0),r=o.size?`?${o.toString()}`:"";(u=e.headers)!=null&&u.length&&(t.headers={},e.headers.forEach(n=>{t.headers[n.name]=n.value})),(a=e.cookies)!=null&&a.length&&(t.headers=t.headers||{},e.cookies.forEach(n=>{t.headers["Set-Cookie"]=t.headers["Set-Cookie"]?`${t.headers["Set-Cookie"]}; ${n.name}=${n.value}`:`${n.name}=${n.value}`})),Object.keys(t).forEach(n=>{t[n]===void 0&&delete t[n]}),e.postData&&(t.body=e.postData.text,e.postData.mimeType==="application/json"&&(t.body=`JSON.stringify(${c(JSON.parse(t.body))})`));const l=Object.keys(t).length?`, ${c(t)}`:"";return{target:"node",client:"undici",code:`import { request } from 'undici'
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
7
 
8
- const { statusCode, body } = await request('${e.url}${r}'${l})`}}function g(){const i=[$];return{get(e,t,o){const r=this.findPlugin(e,t);if(r)return r(o)},print(e,t,o){var r;return(r=this.get(e,t,o))==null?void 0:r.code},targets(){return i.map(e=>e().target)},clients(){return i.map(e=>e().client)},plugins(){return i.map(e=>{const t=e();return{target:t.target,client:t.client}})},findPlugin(e,t){return i.find(o=>{const r=o();return r.target===e&&r.client===t})},hasPlugin(e,t){return!!this.findPlugin(e,t)}}}d.snippetz=g,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
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"})});
@@ -1,15 +1,15 @@
1
1
  import type { TargetId, ClientId, Request } from '@scalar/snippetz-core';
2
2
  import { undici } from '@scalar/snippetz-plugin-node-undici';
3
3
  export declare function snippetz(): {
4
- get(target: TargetId, client: ClientId, request: Request): import("@scalar/snippetz-core").Source | undefined;
5
- print(target: TargetId, client: ClientId, request: Request): string | undefined;
6
- targets(): "node"[];
7
- clients(): string[];
4
+ get(target: TargetId, client: ClientId, request: Partial<Request>): import("@scalar/snippetz-core").Source | undefined;
5
+ print(target: TargetId, client: ClientId, request: Partial<Request>): string | undefined;
6
+ targets(): TargetId[];
7
+ clients(): ClientId[];
8
8
  plugins(): {
9
- target: "node";
10
- client: string;
9
+ target: TargetId;
10
+ client: ClientId;
11
11
  }[];
12
12
  findPlugin(target: TargetId, client: ClientId): typeof undici | undefined;
13
- hasPlugin(target: TargetId, client: ClientId): boolean;
13
+ hasPlugin(target: string, client: ClientId): 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;AAE5D,wBAAgB,QAAQ;gBAIR,QAAQ,UAAU,QAAQ,WAAW,OAAO;kBAO1C,QAAQ,UAAU,QAAQ,WAAW,OAAO;;;;;;;uBAmBvC,QAAQ,UAAU,QAAQ;sBAO3B,QAAQ,UAAU,QAAQ;EAI/C"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalar/snippetz",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@vitest/ui": "^1.0.4",
@@ -9,8 +9,10 @@
9
9
  "vitest": "^1.0.4"
10
10
  },
11
11
  "dependencies": {
12
- "@scalar/snippetz-core": "0.1.1",
13
- "@scalar/snippetz-plugin-node-undici": "0.1.3"
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"
14
16
  },
15
17
  "files": [
16
18
  "dist"