@scalar/snippetz 0.1.2 → 0.1.4

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