node-shortcuts 1.0.5 → 1.1.0
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/package.json +1 -1
- package/snippets/node.json +0 -38
- package/sync-snippets.js +56 -48
package/package.json
CHANGED
package/snippets/node.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"Node.js HTTP Import": {
|
|
3
3
|
"prefix": "@http",
|
|
4
|
-
"scope": "javascript",
|
|
5
4
|
"body": [
|
|
6
5
|
"import http from 'node:http';"
|
|
7
6
|
],
|
|
@@ -9,7 +8,6 @@
|
|
|
9
8
|
},
|
|
10
9
|
"Node.js HTTPS Import": {
|
|
11
10
|
"prefix": "@https",
|
|
12
|
-
"scope": "javascript",
|
|
13
11
|
"body": [
|
|
14
12
|
"import https from 'node:https';"
|
|
15
13
|
],
|
|
@@ -17,7 +15,6 @@
|
|
|
17
15
|
},
|
|
18
16
|
"Node.js NET Import": {
|
|
19
17
|
"prefix": "@net",
|
|
20
|
-
"scope": "javascript",
|
|
21
18
|
"body": [
|
|
22
19
|
"import net from 'node:net';"
|
|
23
20
|
],
|
|
@@ -25,7 +22,6 @@
|
|
|
25
22
|
},
|
|
26
23
|
"Node.js DGRAM Import": {
|
|
27
24
|
"prefix": "@dgram",
|
|
28
|
-
"scope": "javascript",
|
|
29
25
|
"body": [
|
|
30
26
|
"import dgram from 'node:dgram';"
|
|
31
27
|
],
|
|
@@ -33,7 +29,6 @@
|
|
|
33
29
|
},
|
|
34
30
|
"Node.js FS Import": {
|
|
35
31
|
"prefix": "@fs",
|
|
36
|
-
"scope": "javascript",
|
|
37
32
|
"body": [
|
|
38
33
|
"import fs from 'node:fs';"
|
|
39
34
|
],
|
|
@@ -41,7 +36,6 @@
|
|
|
41
36
|
},
|
|
42
37
|
"Node.js fsPromises Import": {
|
|
43
38
|
"prefix": ["@fspromises", "@fsp"],
|
|
44
|
-
"scope": "javascript",
|
|
45
39
|
"body": [
|
|
46
40
|
"import fsPromises from 'node:fs/promises';"
|
|
47
41
|
],
|
|
@@ -49,7 +43,6 @@
|
|
|
49
43
|
},
|
|
50
44
|
"Node.js Path Import": {
|
|
51
45
|
"prefix": "@path",
|
|
52
|
-
"scope": "javascript",
|
|
53
46
|
"body": [
|
|
54
47
|
"import path from 'node:path';"
|
|
55
48
|
],
|
|
@@ -57,7 +50,6 @@
|
|
|
57
50
|
},
|
|
58
51
|
"Node.js OS Import": {
|
|
59
52
|
"prefix": "@os",
|
|
60
|
-
"scope": "javascript",
|
|
61
53
|
"body": [
|
|
62
54
|
"import os from 'node:os';"
|
|
63
55
|
],
|
|
@@ -65,7 +57,6 @@
|
|
|
65
57
|
},
|
|
66
58
|
"Node.js PROCESS Import": {
|
|
67
59
|
"prefix": "@process",
|
|
68
|
-
"scope": "javascript",
|
|
69
60
|
"body": [
|
|
70
61
|
"import process from 'node:process';"
|
|
71
62
|
],
|
|
@@ -73,7 +64,6 @@
|
|
|
73
64
|
},
|
|
74
65
|
"Node.js STREAM Import": {
|
|
75
66
|
"prefix": "@stream",
|
|
76
|
-
"scope": "javascript",
|
|
77
67
|
"body": [
|
|
78
68
|
"import stream from 'node:stream';"
|
|
79
69
|
],
|
|
@@ -81,7 +71,6 @@
|
|
|
81
71
|
},
|
|
82
72
|
"Node.js BUFFER Import": {
|
|
83
73
|
"prefix": "@buffer",
|
|
84
|
-
"scope": "javascript",
|
|
85
74
|
"body": [
|
|
86
75
|
"import buffer from 'node:buffer';"
|
|
87
76
|
],
|
|
@@ -89,7 +78,6 @@
|
|
|
89
78
|
},
|
|
90
79
|
"Node.js URL Import": {
|
|
91
80
|
"prefix": "@url",
|
|
92
|
-
"scope": "javascript",
|
|
93
81
|
"body": [
|
|
94
82
|
"import url from 'node:url';"
|
|
95
83
|
],
|
|
@@ -97,7 +85,6 @@
|
|
|
97
85
|
},
|
|
98
86
|
"Node.js QUERYSTRING Import": {
|
|
99
87
|
"prefix": ["@querystring", "@qs"],
|
|
100
|
-
"scope": "javascript",
|
|
101
88
|
"body": [
|
|
102
89
|
"import querystring from 'node:querystring';"
|
|
103
90
|
],
|
|
@@ -105,7 +92,6 @@
|
|
|
105
92
|
},
|
|
106
93
|
"Node.js PUNYCODE Import": {
|
|
107
94
|
"prefix": ["@punycode", "@pc", "@puny"],
|
|
108
|
-
"scope": "javascript",
|
|
109
95
|
"body": [
|
|
110
96
|
"import punycode from 'node:punycode';"
|
|
111
97
|
],
|
|
@@ -113,7 +99,6 @@
|
|
|
113
99
|
},
|
|
114
100
|
"Node.js CRYPTO Import": {
|
|
115
101
|
"prefix": "@crypto",
|
|
116
|
-
"scope": "javascript",
|
|
117
102
|
"body": [
|
|
118
103
|
"import crypto from 'node:crypto';"
|
|
119
104
|
],
|
|
@@ -121,7 +106,6 @@
|
|
|
121
106
|
},
|
|
122
107
|
"Node.js TLS Import": {
|
|
123
108
|
"prefix": "@tls",
|
|
124
|
-
"scope": "javascript",
|
|
125
109
|
"body": [
|
|
126
110
|
"import tls from 'node:tls';"
|
|
127
111
|
],
|
|
@@ -129,7 +113,6 @@
|
|
|
129
113
|
},
|
|
130
114
|
"Node.js ZLIB Import": {
|
|
131
115
|
"prefix": "@zlib",
|
|
132
|
-
"scope": "javascript",
|
|
133
116
|
"body": [
|
|
134
117
|
"import zlib from 'node:zlib';"
|
|
135
118
|
],
|
|
@@ -137,7 +120,6 @@
|
|
|
137
120
|
},
|
|
138
121
|
"Node.js UTIL Import": {
|
|
139
122
|
"prefix": "@util",
|
|
140
|
-
"scope": "javascript",
|
|
141
123
|
"body": [
|
|
142
124
|
"import util from 'node:util';"
|
|
143
125
|
],
|
|
@@ -145,7 +127,6 @@
|
|
|
145
127
|
},
|
|
146
128
|
"Node.js EVENTS Import": {
|
|
147
129
|
"prefix": "@events",
|
|
148
|
-
"scope": "javascript",
|
|
149
130
|
"body": [
|
|
150
131
|
"import events from 'node:events';"
|
|
151
132
|
],
|
|
@@ -153,7 +134,6 @@
|
|
|
153
134
|
},
|
|
154
135
|
"Node.js ASSERT Import": {
|
|
155
136
|
"prefix": "@assert",
|
|
156
|
-
"scope": "javascript",
|
|
157
137
|
"body": [
|
|
158
138
|
"import assert from 'node:assert';"
|
|
159
139
|
],
|
|
@@ -161,7 +141,6 @@
|
|
|
161
141
|
},
|
|
162
142
|
"Node.js STRING DECODER Import": {
|
|
163
143
|
"prefix": ["@stringdecoder", "@sd"],
|
|
164
|
-
"scope": "javascript",
|
|
165
144
|
"body": [
|
|
166
145
|
"import stringDecoder from 'node:string_decoder';"
|
|
167
146
|
],
|
|
@@ -169,7 +148,6 @@
|
|
|
169
148
|
},
|
|
170
149
|
"Node.js CHILD PROCESS Import": {
|
|
171
150
|
"prefix": ["@childprocess", "@cp"],
|
|
172
|
-
"scope": "javascript",
|
|
173
151
|
"body": [
|
|
174
152
|
"import childProcess from 'node:child_process';"
|
|
175
153
|
],
|
|
@@ -177,7 +155,6 @@
|
|
|
177
155
|
},
|
|
178
156
|
"Node.js WORKER THREADS Import": {
|
|
179
157
|
"prefix": ["@workerthreads", "@wt"],
|
|
180
|
-
"scope": "javascript",
|
|
181
158
|
"body": [
|
|
182
159
|
"import workerThreads from 'node:worker_threads';"
|
|
183
160
|
],
|
|
@@ -185,7 +162,6 @@
|
|
|
185
162
|
},
|
|
186
163
|
"Node.js CLUSTER Import": {
|
|
187
164
|
"prefix": "@cluster",
|
|
188
|
-
"scope": "javascript",
|
|
189
165
|
"body": [
|
|
190
166
|
"import cluster from 'node:cluster';"
|
|
191
167
|
],
|
|
@@ -193,7 +169,6 @@
|
|
|
193
169
|
},
|
|
194
170
|
"Node.js PERF HOOKS Import": {
|
|
195
171
|
"prefix": ["@perfhooks", "@perf"],
|
|
196
|
-
"scope": "javascript",
|
|
197
172
|
"body": [
|
|
198
173
|
"import perfHooks from 'node:perf_hooks';"
|
|
199
174
|
],
|
|
@@ -201,7 +176,6 @@
|
|
|
201
176
|
},
|
|
202
177
|
"Node.js INSPECTOR Import": {
|
|
203
178
|
"prefix": "@inspector",
|
|
204
|
-
"scope": "javascript",
|
|
205
179
|
"body": [
|
|
206
180
|
"import inspector from 'node:inspector';"
|
|
207
181
|
],
|
|
@@ -209,7 +183,6 @@
|
|
|
209
183
|
},
|
|
210
184
|
"Node.js DIAGNOSTICS CHANNEL Import": {
|
|
211
185
|
"prefix": ["@diagnostics", "@dc"],
|
|
212
|
-
"scope": "javascript",
|
|
213
186
|
"body": [
|
|
214
187
|
"import diagnosticsChannel from 'node:diagnostics_channel';"
|
|
215
188
|
],
|
|
@@ -217,7 +190,6 @@
|
|
|
217
190
|
},
|
|
218
191
|
"Node.js MODULE Import": {
|
|
219
192
|
"prefix": "@module",
|
|
220
|
-
"scope": "javascript",
|
|
221
193
|
"body": [
|
|
222
194
|
"import module from 'node:module';"
|
|
223
195
|
],
|
|
@@ -225,7 +197,6 @@
|
|
|
225
197
|
},
|
|
226
198
|
"Node.js VM Import": {
|
|
227
199
|
"prefix": "@vm",
|
|
228
|
-
"scope": "javascript",
|
|
229
200
|
"body": [
|
|
230
201
|
"import vm from 'node:vm';"
|
|
231
202
|
],
|
|
@@ -233,7 +204,6 @@
|
|
|
233
204
|
},
|
|
234
205
|
"Node.js TIMERS Import": {
|
|
235
206
|
"prefix": "@timers",
|
|
236
|
-
"scope": "javascript",
|
|
237
207
|
"body": [
|
|
238
208
|
"import timers from 'node:timers';"
|
|
239
209
|
],
|
|
@@ -241,7 +211,6 @@
|
|
|
241
211
|
},
|
|
242
212
|
"Node.js TIMERS PROMISES Import": {
|
|
243
213
|
"prefix": ["@timerspromises", "@tp"],
|
|
244
|
-
"scope": "javascript",
|
|
245
214
|
"body": [
|
|
246
215
|
"import timersPromises from 'node:timers/promises';"
|
|
247
216
|
],
|
|
@@ -249,7 +218,6 @@
|
|
|
249
218
|
},
|
|
250
219
|
"Node.js REPL Import": {
|
|
251
220
|
"prefix": "@repl",
|
|
252
|
-
"scope": "javascript",
|
|
253
221
|
"body": [
|
|
254
222
|
"import repl from 'node:repl';"
|
|
255
223
|
],
|
|
@@ -257,7 +225,6 @@
|
|
|
257
225
|
},
|
|
258
226
|
"Node.js READLINE Import": {
|
|
259
227
|
"prefix": "@readline",
|
|
260
|
-
"scope": "javascript",
|
|
261
228
|
"body": [
|
|
262
229
|
"import readline from 'node:readline';"
|
|
263
230
|
],
|
|
@@ -265,7 +232,6 @@
|
|
|
265
232
|
},
|
|
266
233
|
"Node.js TTY Import": {
|
|
267
234
|
"prefix": "@tty",
|
|
268
|
-
"scope": "javascript",
|
|
269
235
|
"body": [
|
|
270
236
|
"import tty from 'node:tty';"
|
|
271
237
|
],
|
|
@@ -273,7 +239,6 @@
|
|
|
273
239
|
},
|
|
274
240
|
"Node.js DNS Import": {
|
|
275
241
|
"prefix": "@dns",
|
|
276
|
-
"scope": "javascript",
|
|
277
242
|
"body": [
|
|
278
243
|
"import dns from 'node:dns';"
|
|
279
244
|
],
|
|
@@ -281,7 +246,6 @@
|
|
|
281
246
|
},
|
|
282
247
|
"Node.js DNS PROMISES Import": {
|
|
283
248
|
"prefix": ["@dnspromises", "@dnsp"],
|
|
284
|
-
"scope": "javascript",
|
|
285
249
|
"body": [
|
|
286
250
|
"import dnsPromises from 'node:dns/promises';"
|
|
287
251
|
],
|
|
@@ -289,7 +253,6 @@
|
|
|
289
253
|
},
|
|
290
254
|
"Node.js V8 Import": {
|
|
291
255
|
"prefix": "@v8",
|
|
292
|
-
"scope": "javascript",
|
|
293
256
|
"body": [
|
|
294
257
|
"import v8 from 'node:v8';"
|
|
295
258
|
],
|
|
@@ -297,7 +260,6 @@
|
|
|
297
260
|
},
|
|
298
261
|
"Node.js WASI Import": {
|
|
299
262
|
"prefix": "@wasi",
|
|
300
|
-
"scope": "javascript",
|
|
301
263
|
"body": [
|
|
302
264
|
"import wasi from 'node:wasi';"
|
|
303
265
|
],
|
package/sync-snippets.js
CHANGED
|
@@ -5,96 +5,104 @@ import fs from 'fs';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import os from 'os';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
function getSnippetTargets() {
|
|
14
|
-
const platform = process.platform;
|
|
15
|
-
|
|
16
|
-
if (platform === 'win32') {
|
|
17
|
-
return [
|
|
18
|
-
path.join(HOME, 'AppData', 'Roaming', 'Code', 'User', 'snippets', 'javascript.json'),
|
|
19
|
-
path.join(HOME, 'AppData', 'Roaming', 'Code - Insiders', 'User', 'snippets', 'javascript.json')
|
|
20
|
-
];
|
|
21
|
-
}
|
|
8
|
+
// -----------------------------
|
|
9
|
+
// Source file (canonical snippets)
|
|
10
|
+
// -----------------------------
|
|
11
|
+
const SOURCE_FILE = path.resolve('./snippets/node.json');
|
|
22
12
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
// -----------------------------
|
|
14
|
+
// Cross-platform VS Code + Insiders targets
|
|
15
|
+
// -----------------------------
|
|
16
|
+
function getVSCodeTargets() {
|
|
17
|
+
const home = os.homedir();
|
|
18
|
+
const files = ['javascript.json', 'typescript.json']; // Auto JS + TS
|
|
19
|
+
|
|
20
|
+
const bases = (() => {
|
|
21
|
+
switch (process.platform) {
|
|
22
|
+
case 'win32':
|
|
23
|
+
return [
|
|
24
|
+
path.join(home, 'AppData', 'Roaming', 'Code', 'User', 'snippets'),
|
|
25
|
+
path.join(home, 'AppData', 'Roaming', 'Code - Insiders', 'User', 'snippets')
|
|
26
|
+
];
|
|
27
|
+
case 'darwin':
|
|
28
|
+
return [
|
|
29
|
+
path.join(home, 'Library', 'Application Support', 'Code', 'User', 'snippets'),
|
|
30
|
+
path.join(home, 'Library', 'Application Support', 'Code - Insiders', 'User', 'snippets')
|
|
31
|
+
];
|
|
32
|
+
default: // linux
|
|
33
|
+
return [
|
|
34
|
+
path.join(home, '.config', 'Code', 'User', 'snippets'),
|
|
35
|
+
path.join(home, '.config', 'Code - Insiders', 'User', 'snippets')
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
29
39
|
|
|
30
|
-
//
|
|
31
|
-
return
|
|
32
|
-
path.join(HOME, '.config', 'Code', 'User', 'snippets', 'javascript.json'),
|
|
33
|
-
path.join(HOME, '.config', 'Code - Insiders', 'User', 'snippets', 'javascript.json')
|
|
34
|
-
];
|
|
40
|
+
// Return all combinations: each base × each file
|
|
41
|
+
return bases.flatMap(base => files.map(file => path.join(base, file)));
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Read JSONC safely (VS Code compatible)
|
|
42
|
-
*/
|
|
44
|
+
// -----------------------------
|
|
45
|
+
// JSONC-safe read
|
|
46
|
+
// -----------------------------
|
|
43
47
|
function readJSON(file) {
|
|
44
48
|
if (!fs.existsSync(file)) return {};
|
|
45
49
|
|
|
46
50
|
let raw = fs.readFileSync(file, 'utf8');
|
|
47
51
|
if (!raw.trim()) return {};
|
|
48
52
|
|
|
49
|
-
// Strip
|
|
53
|
+
// Strip comments
|
|
50
54
|
raw = raw.replace(/\/\/.*$/gm, '');
|
|
51
|
-
|
|
52
|
-
// Strip /* */ comments
|
|
53
55
|
raw = raw.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
54
|
-
|
|
55
56
|
// Strip trailing commas
|
|
56
57
|
raw = raw.replace(/,\s*([}\]])/g, '$1');
|
|
57
58
|
|
|
58
59
|
return JSON.parse(raw);
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
// -----------------------------
|
|
63
|
+
// Ensure directory exists
|
|
64
|
+
// -----------------------------
|
|
61
65
|
function ensureDir(file) {
|
|
62
66
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
// -----------------------------
|
|
70
|
+
// Write JSON safely
|
|
71
|
+
// -----------------------------
|
|
65
72
|
function writeJSON(file, data) {
|
|
66
73
|
ensureDir(file);
|
|
67
74
|
fs.writeFileSync(file, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
// -----------------------------
|
|
78
|
+
// Sync snippets
|
|
79
|
+
// -----------------------------
|
|
73
80
|
function sync(target) {
|
|
74
|
-
const
|
|
75
|
-
const
|
|
81
|
+
const sourceSnippets = readJSON(SOURCE_FILE);
|
|
82
|
+
const userSnippets = readJSON(target);
|
|
76
83
|
|
|
77
84
|
let added = 0;
|
|
78
85
|
let updated = 0;
|
|
79
86
|
|
|
80
|
-
for (const [key, snippet] of Object.entries(
|
|
81
|
-
if (!
|
|
82
|
-
else if (JSON.stringify(
|
|
87
|
+
for (const [key, snippet] of Object.entries(sourceSnippets)) {
|
|
88
|
+
if (!userSnippets[key]) added++;
|
|
89
|
+
else if (JSON.stringify(userSnippets[key]) !== JSON.stringify(snippet)) updated++;
|
|
83
90
|
|
|
84
|
-
|
|
91
|
+
userSnippets[key] = snippet;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
writeJSON(target,
|
|
94
|
+
writeJSON(target, userSnippets);
|
|
88
95
|
|
|
89
96
|
console.log(`✔ Synced: ${target}`);
|
|
90
97
|
console.log(` ➕ Added: ${added}`);
|
|
91
98
|
console.log(` 🔄 Updated: ${updated}`);
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
// -----------------------------
|
|
102
|
+
// Run sync for all targets
|
|
103
|
+
// -----------------------------
|
|
97
104
|
try {
|
|
105
|
+
const TARGETS = getVSCodeTargets();
|
|
98
106
|
for (const target of TARGETS) {
|
|
99
107
|
try {
|
|
100
108
|
sync(target);
|