@scalar/snippetz 0.1.0 → 0.1.2

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.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- export * from './format';
2
1
  export * from './snippetz';
3
- export * from './types';
4
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1,28 +1,95 @@
1
- import e from "prettier/plugins/babel";
2
- import a from "prettier/plugins/estree";
3
- import * as n from "prettier";
4
- async function o(t) {
5
- if (t.target === "javascript")
6
- return await n.format(t.code, {
7
- semi: !1,
8
- parser: "babel",
9
- plugins: [e, a],
10
- singleQuote: !0
11
- });
12
- throw new Error(`Unsupported target: ${t.target}`);
1
+ function p(o) {
2
+ return o.reduce((e, t) => (e[t.name] = t.value, e), {});
13
3
  }
14
- const i = {};
15
- function f() {
4
+ function l(o) {
5
+ return /\s|-/.test(o);
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,
18
+ e + 2
19
+ )}`
20
+ ) : typeof s == "string" ? t.push(`${r}${a}: '${s}'`) : t.push(`${r}${a}: ${s}`);
21
+ }
22
+ return `{
23
+ ${t.join(`,
24
+ `)}
25
+ ${i}}`;
26
+ }
27
+ function h(o) {
28
+ var a, c;
29
+ const e = {
30
+ method: "GET",
31
+ ...o
32
+ };
33
+ e.method = e.method.toUpperCase();
34
+ const t = {
35
+ 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)}` : "";
47
+ return {
48
+ target: "node",
49
+ client: "undici",
50
+ code: `import { request } from 'undici'
51
+
52
+ const { statusCode, body } = await request('${e.url}${r}'${u})`
53
+ };
54
+ }
55
+ function $() {
56
+ const o = [h];
16
57
  return {
17
- get(t, r) {
18
- return r = {
19
- ...i,
20
- ...r
21
- }, o(t);
58
+ get(e, t, i) {
59
+ const r = this.findPlugin(e, t);
60
+ if (r)
61
+ return r(i);
62
+ },
63
+ print(e, t, i) {
64
+ var r;
65
+ return (r = this.get(e, t, i)) == null ? void 0 : r.code;
66
+ },
67
+ targets() {
68
+ return o.map((e) => e().target);
69
+ },
70
+ clients() {
71
+ return o.map((e) => e().client);
72
+ },
73
+ plugins() {
74
+ return o.map((e) => {
75
+ const t = e();
76
+ return {
77
+ target: t.target,
78
+ client: t.client
79
+ };
80
+ });
81
+ },
82
+ findPlugin(e, t) {
83
+ return o.find((i) => {
84
+ const r = i();
85
+ return r.target === e && r.client === t;
86
+ });
87
+ },
88
+ hasPlugin(e, t) {
89
+ return !!this.findPlugin(e, t);
22
90
  }
23
91
  };
24
92
  }
25
93
  export {
26
- o as format,
27
- f as snippetz
94
+ $ as snippetz
28
95
  };
@@ -1 +1,6 @@
1
- (function(t,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("prettier/plugins/babel"),require("prettier/plugins/estree"),require("prettier")):typeof define=="function"&&define.amd?define(["exports","prettier/plugins/babel","prettier/plugins/estree","prettier"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t["@scalar/snippetz"]={},t.babel,t.estree,t.prettier))})(this,function(t,n,s,a){"use strict";function o(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const i in e)if(i!=="default"){const u=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(r,i,u.get?u:{enumerable:!0,get:()=>e[i]})}}return r.default=e,Object.freeze(r)}const f=o(a);async function p(e){if(e.target==="javascript")return await f.format(e.code,{semi:!1,parser:"babel",plugins:[n,s],singleQuote:!0});throw new Error(`Unsupported target: ${e.target}`)}const c={};function l(){return{get(e,r){return r={...c,...r},p(e)}}}t.format=p,t.snippetz=l,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
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`{
2
+ ${t.join(`,
3
+ `)}
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'
5
+
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"})});
@@ -1,6 +1,15 @@
1
- import type { Source } from './types';
2
- export type SnippetOptions = {};
1
+ import type { TargetId, ClientId, Request } from '../../snippetz-core/dist';
2
+ import { undici } from '@scalar/snippetz-plugin-undici';
3
3
  export declare function snippetz(): {
4
- get(source: Source, options?: Partial<SnippetOptions>): Promise<string>;
4
+ get(target: TargetId, client: ClientId, request: Request): import("../../snippetz-core/dist").Source | undefined;
5
+ print(target: TargetId, client: ClientId, request: Request): string | undefined;
6
+ targets(): "node"[];
7
+ clients(): string[];
8
+ plugins(): {
9
+ target: "node";
10
+ client: string;
11
+ }[];
12
+ findPlugin(target: TargetId, client: ClientId): typeof undici | undefined;
13
+ hasPlugin(target: TargetId, client: ClientId): boolean;
5
14
  };
6
15
  //# sourceMappingURL=snippetz.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,MAAM,MAAM,cAAc,GAAG,EAAE,CAAA;AAI/B,wBAAgB,QAAQ;gBAER,MAAM,YAAY,QAAQ,cAAc,CAAC;EASxD"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalar/snippetz",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@vitest/ui": "^1.0.4",
@@ -9,7 +9,8 @@
9
9
  "vitest": "^1.0.4"
10
10
  },
11
11
  "dependencies": {
12
- "prettier": "^3.1.1"
12
+ "@scalar/snippetz-core": "0.1.0",
13
+ "@scalar/snippetz-plugin-undici": "0.1.2"
13
14
  },
14
15
  "files": [
15
16
  "dist"
package/dist/format.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function format(source: any): Promise<string>;
2
- //# sourceMappingURL=format.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAIA,wBAAsB,MAAM,CAAC,MAAM,EAAE,GAAG,mBAavC"}
package/dist/types.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export type Source = {
2
- target: 'javascript';
3
- code: string;
4
- };
5
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA"}