@scalar/snippetz 0.2.4 → 0.2.6

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 (50) hide show
  1. package/README.md +3 -3
  2. package/dist/core/index.d.ts +1 -1
  3. package/dist/core/index.d.ts.map +1 -1
  4. package/dist/core/index.js +1 -1
  5. package/dist/core/types.d.ts +30 -5
  6. package/dist/core/types.d.ts.map +1 -1
  7. package/dist/core/types.test-d.d.ts +2 -0
  8. package/dist/core/types.test-d.d.ts.map +1 -0
  9. package/dist/core/utils/arrayToObject.d.ts +6 -1
  10. package/dist/core/utils/arrayToObject.d.ts.map +1 -1
  11. package/dist/core/utils/arrayToObject.js +6 -1
  12. package/dist/core/utils/needsQuotes.d.ts +7 -0
  13. package/dist/core/utils/needsQuotes.d.ts.map +1 -0
  14. package/dist/core/utils/needsQuotes.js +10 -0
  15. package/dist/core/utils/objectToString.d.ts +5 -0
  16. package/dist/core/utils/objectToString.d.ts.map +1 -1
  17. package/dist/core/utils/objectToString.js +7 -2
  18. package/dist/plugins/js/fetch/fetch.d.ts +5 -2
  19. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
  20. package/dist/plugins/js/fetch/fetch.js +63 -59
  21. package/dist/plugins/js/fetch/index.js +1 -1
  22. package/dist/plugins/js/ofetch/index.js +1 -1
  23. package/dist/plugins/js/ofetch/ofetch.d.ts +5 -2
  24. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
  25. package/dist/plugins/js/ofetch/ofetch.js +70 -64
  26. package/dist/plugins/node/fetch/fetch.d.ts +5 -2
  27. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
  28. package/dist/plugins/node/fetch/fetch.js +63 -59
  29. package/dist/plugins/node/fetch/index.js +1 -1
  30. package/dist/plugins/node/ofetch/index.js +1 -1
  31. package/dist/plugins/node/ofetch/ofetch.d.ts +5 -2
  32. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
  33. package/dist/plugins/node/ofetch/ofetch.js +70 -64
  34. package/dist/plugins/node/undici/index.js +1 -1
  35. package/dist/plugins/node/undici/undici.d.ts +5 -2
  36. package/dist/plugins/node/undici/undici.d.ts.map +1 -1
  37. package/dist/plugins/node/undici/undici.js +63 -59
  38. package/dist/plugins/shell/curl/curl.d.ts +6 -0
  39. package/dist/plugins/shell/curl/curl.d.ts.map +1 -0
  40. package/dist/plugins/shell/curl/curl.js +105 -0
  41. package/dist/plugins/shell/curl/index.d.ts +2 -0
  42. package/dist/plugins/shell/curl/index.d.ts.map +1 -0
  43. package/dist/plugins/shell/curl/index.js +1 -0
  44. package/dist/snippetz.d.ts +9 -12
  45. package/dist/snippetz.d.ts.map +1 -1
  46. package/dist/snippetz.js +22 -22
  47. package/package.json +7 -2
  48. package/dist/core/utils/isKeyNeedsQuotes.d.ts +0 -2
  49. package/dist/core/utils/isKeyNeedsQuotes.d.ts.map +0 -1
  50. package/dist/core/utils/isKeyNeedsQuotes.js +0 -5
package/dist/snippetz.js CHANGED
@@ -1,50 +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';
1
+ import { nodeUndici } from './plugins/node/undici/undici.js';
2
+ import { nodeFetch } from './plugins/node/fetch/fetch.js';
3
+ import { jsFetch } from './plugins/js/fetch/fetch.js';
4
+ import { jsOfetch } from './plugins/js/ofetch/ofetch.js';
5
+ import { nodeOfetch } from './plugins/node/ofetch/ofetch.js';
6
+ import { shellCurl } from './plugins/shell/curl/curl.js';
6
7
 
7
8
  /**
8
9
  * Generate code examples for HAR requests
9
10
  */
10
11
  function snippetz() {
11
- const plugins = [undici, fetch, fetch$1, ofetch, ofetch$1];
12
+ const plugins = [
13
+ nodeUndici,
14
+ nodeFetch,
15
+ jsFetch,
16
+ jsOfetch,
17
+ nodeOfetch,
18
+ shellCurl,
19
+ ];
12
20
  return {
13
- get(target, client, request) {
14
- const plugin = this.findPlugin(target, client);
15
- if (plugin) {
16
- return plugin(request);
17
- }
18
- return {
19
- code: '',
20
- };
21
+ get(target, client) {
22
+ return this.findPlugin(target, client);
21
23
  },
22
24
  print(target, client, request) {
23
- return this.get(target, client, request)?.code;
25
+ return this.get(target, client)?.generate(request);
24
26
  },
25
27
  targets() {
26
28
  return (plugins
27
29
  // all targets
28
- .map((plugin) => plugin().target)
30
+ .map((plugin) => plugin.target)
29
31
  // unique values
30
32
  .filter((value, index, self) => self.indexOf(value) === index));
31
33
  },
32
34
  clients() {
33
- return plugins.map((plugin) => plugin().client);
35
+ return plugins.map((plugin) => plugin.client);
34
36
  },
35
37
  plugins() {
36
38
  return plugins.map((plugin) => {
37
- const details = plugin();
38
39
  return {
39
- target: details.target,
40
- client: details.client,
40
+ target: plugin.target,
41
+ client: plugin.client,
41
42
  };
42
43
  });
43
44
  },
44
45
  findPlugin(target, client) {
45
46
  return plugins.find((plugin) => {
46
- const details = plugin();
47
- return details.target === target && details.client === client;
47
+ return plugin.target === target && plugin.client === client;
48
48
  });
49
49
  },
50
50
  hasPlugin(target, client) {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/scalar/scalar.git",
10
10
  "directory": "packages/snippetz"
11
11
  },
12
- "version": "0.2.4",
12
+ "version": "0.2.6",
13
13
  "engines": {
14
14
  "node": ">=18"
15
15
  },
@@ -21,6 +21,11 @@
21
21
  "types": "./dist/index.d.ts",
22
22
  "default": "./dist/index.js"
23
23
  },
24
+ "./plugins/shell/curl": {
25
+ "import": "./dist/plugins/shell/curl/index.js",
26
+ "types": "./dist/plugins/shell/curl/index.d.ts",
27
+ "default": "./dist/plugins/shell/curl/index.js"
28
+ },
24
29
  "./plugins/node/undici": {
25
30
  "import": "./dist/plugins/node/undici/index.js",
26
31
  "types": "./dist/plugins/node/undici/index.d.ts",
@@ -59,7 +64,7 @@
59
64
  "module": "./dist/index.js",
60
65
  "devDependencies": {
61
66
  "@types/har-format": "^1.2.15",
62
- "@scalar/build-tooling": "0.1.11"
67
+ "@scalar/build-tooling": "0.1.12"
63
68
  },
64
69
  "scripts": {
65
70
  "build": "scalar-build-rollup",
@@ -1,2 +0,0 @@
1
- export declare function isKeyNeedsQuotes(key: string): boolean;
2
- //# sourceMappingURL=isKeyNeedsQuotes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isKeyNeedsQuotes.d.ts","sourceRoot":"","sources":["../../../src/core/utils/isKeyNeedsQuotes.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,WAE3C"}
@@ -1,5 +0,0 @@
1
- function isKeyNeedsQuotes(key) {
2
- return /\s|-/.test(key);
3
- }
4
-
5
- export { isKeyNeedsQuotes };