@scalar/snippetz 0.1.2 → 0.1.3
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 +42 -30
- package/dist/index.umd.cjs +5 -3
- package/dist/snippetz.d.ts +3 -3
- package/dist/snippetz.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,34 +1,46 @@
|
|
|
1
|
-
function p(
|
|
2
|
-
return
|
|
1
|
+
function p(s) {
|
|
2
|
+
return s.reduce((e, t) => (e[t.name] = t.value, e), {});
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return /\s|-/.test(
|
|
4
|
+
function h(s) {
|
|
5
|
+
return /\s|-/.test(s);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function l(s, e = 0) {
|
|
8
8
|
let t = [], i = " ".repeat(e), r = " ".repeat(e + 2);
|
|
9
|
-
for (const [
|
|
10
|
-
let
|
|
11
|
-
if (Array.isArray(
|
|
12
|
-
const
|
|
13
|
-
t.push(`${r}${
|
|
14
|
-
} else
|
|
15
|
-
|
|
16
|
-
`${r}${
|
|
17
|
-
|
|
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
18
|
e + 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(`
|
|
25
|
+
`);
|
|
26
|
+
n.length > 1 && (a = n.map((d, f) => f === 0 ? d : `${r}${d}`).join(`
|
|
27
|
+
`));
|
|
28
|
+
} else
|
|
29
|
+
a = `'${o}'`;
|
|
30
|
+
t.push(`${r}${u}: ${a}`);
|
|
31
|
+
} else
|
|
32
|
+
t.push(`${r}${u}: ${o}`);
|
|
21
33
|
}
|
|
22
34
|
return `{
|
|
23
35
|
${t.join(`,
|
|
24
36
|
`)}
|
|
25
37
|
${i}}`;
|
|
26
38
|
}
|
|
27
|
-
function
|
|
28
|
-
var
|
|
39
|
+
function $(s) {
|
|
40
|
+
var u, a;
|
|
29
41
|
const e = {
|
|
30
42
|
method: "GET",
|
|
31
|
-
...
|
|
43
|
+
...s
|
|
32
44
|
};
|
|
33
45
|
e.method = e.method.toUpperCase();
|
|
34
46
|
const t = {
|
|
@@ -36,24 +48,24 @@ function h(o) {
|
|
|
36
48
|
}, i = new URLSearchParams(
|
|
37
49
|
e.queryString ? p(e.queryString) : void 0
|
|
38
50
|
), r = i.size ? `?${i.toString()}` : "";
|
|
39
|
-
(
|
|
51
|
+
(u = e.headers) != null && u.length && (t.headers = {}, e.headers.forEach((n) => {
|
|
40
52
|
t.headers[n.name] = n.value;
|
|
41
|
-
})), (
|
|
53
|
+
})), (a = e.cookies) != null && a.length && (t.headers = t.headers || {}, e.cookies.forEach((n) => {
|
|
42
54
|
t.headers["Set-Cookie"] = t.headers["Set-Cookie"] ? `${t.headers["Set-Cookie"]}; ${n.name}=${n.value}` : `${n.name}=${n.value}`;
|
|
43
55
|
})), Object.keys(t).forEach((n) => {
|
|
44
56
|
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
|
|
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)}` : "";
|
|
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}'${
|
|
64
|
+
const { statusCode, body } = await request('${e.url}${r}'${c})`
|
|
53
65
|
};
|
|
54
66
|
}
|
|
55
|
-
function
|
|
56
|
-
const
|
|
67
|
+
function g() {
|
|
68
|
+
const s = [$];
|
|
57
69
|
return {
|
|
58
70
|
get(e, t, i) {
|
|
59
71
|
const r = this.findPlugin(e, t);
|
|
@@ -65,13 +77,13 @@ function $() {
|
|
|
65
77
|
return (r = this.get(e, t, i)) == null ? void 0 : r.code;
|
|
66
78
|
},
|
|
67
79
|
targets() {
|
|
68
|
-
return
|
|
80
|
+
return s.map((e) => e().target);
|
|
69
81
|
},
|
|
70
82
|
clients() {
|
|
71
|
-
return
|
|
83
|
+
return s.map((e) => e().client);
|
|
72
84
|
},
|
|
73
85
|
plugins() {
|
|
74
|
-
return
|
|
86
|
+
return s.map((e) => {
|
|
75
87
|
const t = e();
|
|
76
88
|
return {
|
|
77
89
|
target: t.target,
|
|
@@ -80,7 +92,7 @@ function $() {
|
|
|
80
92
|
});
|
|
81
93
|
},
|
|
82
94
|
findPlugin(e, t) {
|
|
83
|
-
return
|
|
95
|
+
return s.find((i) => {
|
|
84
96
|
const r = i();
|
|
85
97
|
return r.target === e && r.client === t;
|
|
86
98
|
});
|
|
@@ -91,5 +103,5 @@ function $() {
|
|
|
91
103
|
};
|
|
92
104
|
}
|
|
93
105
|
export {
|
|
94
|
-
|
|
106
|
+
g as snippetz
|
|
95
107
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
(function(
|
|
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`{
|
|
2
4
|
${t.join(`,
|
|
3
5
|
`)}
|
|
4
|
-
${
|
|
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'
|
|
5
7
|
|
|
6
|
-
const { statusCode, body } = await request('${e.url}${
|
|
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"})});
|
package/dist/snippetz.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TargetId, ClientId, Request } from '
|
|
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("
|
|
4
|
+
get(target: TargetId, client: ClientId, request: Request): import("@scalar/snippetz-core").Source | undefined;
|
|
5
5
|
print(target: TargetId, client: ClientId, request: Request): string | undefined;
|
|
6
6
|
targets(): "node"[];
|
|
7
7
|
clients(): string[];
|
package/dist/snippetz.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalar/snippetz",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@vitest/ui": "^1.0.4",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"vitest": "^1.0.4"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@scalar/snippetz-core": "0.1.
|
|
13
|
-
"@scalar/snippetz-plugin-undici": "0.1.
|
|
12
|
+
"@scalar/snippetz-core": "0.1.1",
|
|
13
|
+
"@scalar/snippetz-plugin-node-undici": "0.1.3"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|