@scalar/snippetz 0.2.0 → 0.2.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/LICENSE +1 -1
- package/README.md +91 -0
- package/dist/core/utils/objectToString.js +4 -4
- package/dist/plugins/js/fetch/fetch.d.ts +1 -1
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.d.ts +1 -1
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.d.ts +1 -1
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.d.ts +1 -1
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.d.ts +1 -1
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/snippetz.d.ts +1 -1
- package/dist/snippetz.d.ts.map +1 -1
- package/package.json +15 -10
package/LICENSE
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Snippetz
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@scalar/snippetz)
|
|
4
|
+
[](https://www.npmjs.com/package/@scalar/snippetz)
|
|
5
|
+
[](https://www.npmjs.com/package/@scalar/snippetz)
|
|
6
|
+
[](https://discord.gg/scalar)
|
|
7
|
+
|
|
8
|
+
A modern way to generate HTTP request examples for different languages and libraries.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @scalar/snippetz
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { snippetz } from '@scalar/snippetz'
|
|
20
|
+
|
|
21
|
+
const snippet = snippetz().print('node', 'undici', {
|
|
22
|
+
url: 'https://example.com',
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
/* Output */
|
|
26
|
+
|
|
27
|
+
// import { request } from 'undici'
|
|
28
|
+
//
|
|
29
|
+
// const { statusCode, body } = await request(
|
|
30
|
+
// 'https://example.com',
|
|
31
|
+
// )
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
### Get all plugins
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { snippetz } from '@scalar/snippetz'
|
|
40
|
+
|
|
41
|
+
const snippet = snippetz().plugins()
|
|
42
|
+
|
|
43
|
+
/* Output */
|
|
44
|
+
|
|
45
|
+
// [
|
|
46
|
+
// {
|
|
47
|
+
// target: 'node',
|
|
48
|
+
// client: 'undici',
|
|
49
|
+
// }
|
|
50
|
+
// ]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Check if a plugin is loaded
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { snippetz } from '@scalar/snippetz'
|
|
57
|
+
|
|
58
|
+
const snippet = snippetz().hasPlugin('node', 'undici')
|
|
59
|
+
|
|
60
|
+
/* Output */
|
|
61
|
+
|
|
62
|
+
// true
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Lean usage
|
|
66
|
+
|
|
67
|
+
You can also just use one specific plugin to keep your bundle size small.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { undici } from '@scalar/snippetz/plugins/node/undici'
|
|
71
|
+
|
|
72
|
+
const source = undici({
|
|
73
|
+
url: 'https://example.com',
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
console.log(source.code)
|
|
77
|
+
|
|
78
|
+
// import { request } from 'undici'
|
|
79
|
+
|
|
80
|
+
// const { statusCode, body } = await request(
|
|
81
|
+
// 'url': 'https://example.com',
|
|
82
|
+
// )
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Community
|
|
86
|
+
|
|
87
|
+
We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
The source code in this repository is licensed under [MIT](https://github.com/scalar/scalar/blob/main/LICENSE).
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { isKeyNeedsQuotes } from './isKeyNeedsQuotes.js';
|
|
2
2
|
|
|
3
3
|
function objectToString(obj, indent = 0) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const parts = [];
|
|
5
|
+
const indentation = ' '.repeat(indent);
|
|
6
|
+
const innerIndentation = ' '.repeat(indent + 2);
|
|
7
7
|
for (const [key, value] of Object.entries(obj)) {
|
|
8
|
-
|
|
8
|
+
const formattedKey = isKeyNeedsQuotes(key) ? `'${key}'` : key;
|
|
9
9
|
if (Array.isArray(value)) {
|
|
10
10
|
const arrayString = value
|
|
11
11
|
.map((item) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAiFzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAiFzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA+EzD"}
|
package/dist/snippetz.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ClientId, Request, TargetId } from './core/index.js';
|
|
2
2
|
import { undici } from './plugins/node/undici/index.js';
|
|
3
3
|
export declare function snippetz(): {
|
|
4
4
|
get(target: TargetId, client: ClientId, request: Partial<Request>): import("./core/index.js").Source | undefined;
|
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,
|
|
1
|
+
{"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAKzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAE9C,wBAAgB,QAAQ;gBAIR,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;kBAOnD,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;;;;;;;uBAyBhD,QAAQ,UAAU,QAAQ;sBAO3B,MAAM,UAAU,MAAM;EAI3C"}
|
package/package.json
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
"name": "@scalar/snippetz",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"author": "Scalar (https://github.com/scalar)",
|
|
5
|
-
"homepage": "https://github.com/scalar/
|
|
6
|
-
"bugs": "https://github.com/scalar/
|
|
5
|
+
"homepage": "https://github.com/scalar/scalar",
|
|
6
|
+
"bugs": "https://github.com/scalar/scalar/issues/new/choose",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/scalar/scalar.git",
|
|
10
|
+
"directory": "packages/snippetz"
|
|
11
|
+
},
|
|
12
|
+
"version": "0.2.2",
|
|
7
13
|
"engines": {
|
|
8
14
|
"node": ">=18"
|
|
9
15
|
},
|
|
10
|
-
"version": "0.2.0",
|
|
11
16
|
"type": "module",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist",
|
|
14
|
-
"CHANGELOG"
|
|
15
|
-
],
|
|
16
17
|
"types": "./dist/index.d.ts",
|
|
17
|
-
"module": "./dist/index.js",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"import": "./dist/index.js",
|
|
@@ -45,9 +45,14 @@
|
|
|
45
45
|
"types": "./dist/core/index.d.ts"
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"CHANGELOG"
|
|
51
|
+
],
|
|
52
|
+
"module": "./dist/index.js",
|
|
48
53
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
54
|
+
"@types/har-format": "^1.2.15",
|
|
55
|
+
"@scalar/build-tooling": "0.1.10"
|
|
51
56
|
},
|
|
52
57
|
"scripts": {
|
|
53
58
|
"build": "scalar-build-rollup",
|