v-transform 2.1.1 → 2.2.1

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.
@@ -0,0 +1,260 @@
1
+ {
2
+ "101": {
3
+ "id": 101,
4
+ "result": {
5
+ "description": "情商爆表的"
6
+ },
7
+ "condition": "EQ>=18"
8
+ },
9
+ "102": {
10
+ "id": 102,
11
+ "result": {
12
+ "description": "情商很高的"
13
+ },
14
+ "condition": "(EQ>=10)&(EQ<18)"
15
+ },
16
+ "103": {
17
+ "id": 103,
18
+ "result": {
19
+ "description": "情商较高的"
20
+ },
21
+ "condition": "(EQ>=1)&(EQ<10)"
22
+ },
23
+ "104": {
24
+ "id": 104,
25
+ "result": {
26
+ "description": "情商进步空间较大的"
27
+ },
28
+ "condition": "(EQ>=-6)&(EQ<1)"
29
+ },
30
+ "105": {
31
+ "id": 105,
32
+ "result": {
33
+ "description": "情商进步空间很大的"
34
+ },
35
+ "condition": "(EQ>=-12)&(EQ<-6)"
36
+ },
37
+ "106": {
38
+ "id": 106,
39
+ "result": {
40
+ "description": "情商进步空间爆表的"
41
+ },
42
+ "condition": "EQ<-12"
43
+ },
44
+ "201": {
45
+ "id": 201,
46
+ "result": {
47
+ "description": "哲学家型的",
48
+ "addition": "INFP",
49
+ "types": "内向 直觉 情感 感知"
50
+ },
51
+ "condition": "(EI<=0)&(SN<=0)&(TF<=0)&(JP<=0)"
52
+ },
53
+ "202": {
54
+ "id": 202,
55
+ "result": {
56
+ "description": "学者型的",
57
+ "addition": "INTP",
58
+ "types": "内向 直觉 逻辑 感知"
59
+ },
60
+ "condition": "(EI<=0)&(SN<=0)&(TF>0)&(JP<=0)"
61
+ },
62
+ "203": {
63
+ "id": 203,
64
+ "result": {
65
+ "description": "作家型的",
66
+ "addition": "INFJ",
67
+ "types": "内向 直觉 情感 判断"
68
+ },
69
+ "condition": "(EI<=0)&(SN<=0)&(TF<=0)&(JP>0)"
70
+ },
71
+ "204": {
72
+ "id": 204,
73
+ "result": {
74
+ "description": "专家型的",
75
+ "addition": "INTJ",
76
+ "types": "内向 直觉 逻辑 判断"
77
+ },
78
+ "condition": "(EI<=0)&(SN<=0)&(TF>0)&(JP>0)"
79
+ },
80
+ "205": {
81
+ "id": 205,
82
+ "result": {
83
+ "description": "艺术家型的",
84
+ "addition": "ISFP",
85
+ "types": "内向 经验 情感 感知"
86
+ },
87
+ "condition": "(EI<=0)&(SN>0)&(TF<=0)&(JP<=0)"
88
+ },
89
+ "206": {
90
+ "id": 206,
91
+ "result": {
92
+ "description": "匠人型的",
93
+ "addition": "ISTP",
94
+ "types": "内向 经验 逻辑 感知"
95
+ },
96
+ "condition": "(EI<=0)&(SN>0)&(TF>0)&(JP<=0)"
97
+ },
98
+ "207": {
99
+ "id": 207,
100
+ "result": {
101
+ "description": "保护者型的",
102
+ "addition": "ISFJ",
103
+ "types": "内向 经验 情感 判断"
104
+ },
105
+ "condition": "(EI<=0)&(SN>0)&(TF<=0)&(JP>0)"
106
+ },
107
+ "208": {
108
+ "id": 208,
109
+ "result": {
110
+ "description": "调查者型的",
111
+ "addition": "ISTJ",
112
+ "types": "内向 经验 逻辑 判断"
113
+ },
114
+ "condition": "(EI<=0)&(SN>0)&(TF>0)&(JP>0)"
115
+ },
116
+ "209": {
117
+ "id": 209,
118
+ "result": {
119
+ "description": "追梦人型的",
120
+ "addition": "ENFP",
121
+ "types": "外向 直觉 情感 感知"
122
+ },
123
+ "condition": "(EI>0)&(SN<=0)&(TF<=0)&(JP<=0)"
124
+ },
125
+ "210": {
126
+ "id": 210,
127
+ "result": {
128
+ "description": "发明家型的",
129
+ "addition": "ENTP",
130
+ "types": "外向 直觉 逻辑 感知"
131
+ },
132
+ "condition": "(EI>0)&(SN<=0)&(TF>0)&(JP<=0)"
133
+ },
134
+ "211": {
135
+ "id": 211,
136
+ "result": {
137
+ "description": "主人公型的",
138
+ "addition": "ENFJ",
139
+ "types": "外向 直觉 情感 判断"
140
+ },
141
+ "condition": "(EI>0)&(SN<=0)&(TF<=0)&(JP>0)"
142
+ },
143
+ "212": {
144
+ "id": 212,
145
+ "result": {
146
+ "description": "指挥官型的",
147
+ "addition": "ENTJ",
148
+ "types": "外向 直觉 逻辑 判断"
149
+ },
150
+ "condition": "(EI>0)&(SN<=0)&(TF>0)&(JP>0)"
151
+ },
152
+ "213": {
153
+ "id": 213,
154
+ "result": {
155
+ "description": "表演者型的",
156
+ "addition": "ESFP",
157
+ "types": "外向 经验 情感 感知"
158
+ },
159
+ "condition": "(EI>0)&(SN>0)&(TF<=0)&(JP<=0)"
160
+ },
161
+ "214": {
162
+ "id": 214,
163
+ "result": {
164
+ "description": "挑战者型的",
165
+ "addition": "ESTP",
166
+ "types": "外向 经验 逻辑 感知"
167
+ },
168
+ "condition": "(EI>0)&(SN>0)&(TF>0)&(JP<=0)"
169
+ },
170
+ "215": {
171
+ "id": 215,
172
+ "result": {
173
+ "description": "供给者型的",
174
+ "addition": "ESFJ",
175
+ "types": "外向 经验 情感 判断"
176
+ },
177
+ "condition": "(EI>0)&(SN>0)&(TF<=0)&(JP>0)"
178
+ },
179
+ "216": {
180
+ "id": 216,
181
+ "result": {
182
+ "description": "监管者型的",
183
+ "addition": "ESTJ",
184
+ "types": "外向 经验 逻辑 判断"
185
+ },
186
+ "condition": "(EI>0)&(SN>0)&(TF>0)&(JP>0)"
187
+ },
188
+ "301": {
189
+ "id": 301,
190
+ "result": {
191
+ "description": "守序善良",
192
+ "addition": "的"
193
+ },
194
+ "condition": "(OR>9)&(GD>8)"
195
+ },
196
+ "302": {
197
+ "id": 302,
198
+ "result": {
199
+ "description": "中立善良",
200
+ "addition": "的"
201
+ },
202
+ "condition": "(OR>-5)&(OR<=9)&(GD>8)"
203
+ },
204
+ "303": {
205
+ "id": 303,
206
+ "result": {
207
+ "description": "混乱善良",
208
+ "addition": "的"
209
+ },
210
+ "condition": "(OR<=-5)&(GD>8)"
211
+ },
212
+ "304": {
213
+ "id": 304,
214
+ "result": {
215
+ "description": "守序中立",
216
+ "addition": "的"
217
+ },
218
+ "condition": "(OR>9)&(GD>-1)&(GD<=8)"
219
+ },
220
+ "305": {
221
+ "id": 305,
222
+ "result": {
223
+ "description": "绝对中立",
224
+ "addition": "的"
225
+ },
226
+ "condition": "(OR>-5)&(OR<=9)&(GD>-1)&(GD<=8)"
227
+ },
228
+ "306": {
229
+ "id": 306,
230
+ "result": {
231
+ "description": "混乱中立",
232
+ "addition": "的"
233
+ },
234
+ "condition": "(OR<=-5)&(GD>-1)&(GD<=8)"
235
+ },
236
+ "307": {
237
+ "id": 307,
238
+ "result": {
239
+ "description": "守序邪恶",
240
+ "addition": "的"
241
+ },
242
+ "condition": "(OR>9)&(GD<=-1)"
243
+ },
244
+ "308": {
245
+ "id": 308,
246
+ "result": {
247
+ "description": "中立邪恶",
248
+ "addition": "的"
249
+ },
250
+ "condition": "(OR>-5)&(OR<=9)&(GD<=-1)"
251
+ },
252
+ "309": {
253
+ "id": 309,
254
+ "result": {
255
+ "description": "混乱邪恶",
256
+ "addition": "的"
257
+ },
258
+ "condition": "(OR<=-5)&(GD<=-1)"
259
+ }
260
+ }
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
- {
2
- "name": "v-transform",
3
- "bin": {
4
- "vt": "src/index.js"
5
- },
6
- "type": "module",
7
- "version": "2.1.1",
8
- "main": "index.js",
9
- "scripts": {
10
- "clean": "npx rimraf test",
11
- "vt": "node src/index.js",
12
- "transform": "node src/index.js transform"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/VickScarlet/vTransform.git"
17
- },
18
- "author": "Vick Scarlet <scarlet_vick@outlook.com>",
19
- "license": "MIT",
20
- "dependencies": {
21
- "commander": "^8.2.0",
22
- "glob": "^8.0.3",
23
- "js-yaml": "^4.1.0",
24
- "xlsx": "^0.17.1"
25
- }
26
- }
1
+ {
2
+ "name": "v-transform",
3
+ "bin": {
4
+ "vt": "src/index.js"
5
+ },
6
+ "type": "module",
7
+ "version": "2.2.1",
8
+ "main": "index.js",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/VickScarlet/vTransform.git"
12
+ },
13
+ "author": "Vick Scarlet <scarlet_vick@outlook.com>",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "commander": "^14.0.3",
17
+ "glob": "^13.0.1",
18
+ "js-yaml": "^4.1.1",
19
+ "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
20
+ },
21
+ "scripts": {
22
+ "clean": "npx rimraf test",
23
+ "vt": "node src/index.js",
24
+ "transform": "node src/index.js transform"
25
+ }
26
+ }
package/src/dump.js CHANGED
@@ -1,62 +1,66 @@
1
- import yaml from 'js-yaml';
2
- import path from 'path';
3
- import { writeFile, stat, mkdir } from 'fs/promises';
1
+ import yaml from 'js-yaml'
2
+ import path from 'node:path'
3
+ import { writeFile, stat, mkdir } from 'node:fs/promises'
4
4
 
5
5
  function jsonify(data, space) {
6
- return JSON.stringify(data, null, space);
6
+ return JSON.stringify(data, null, space)
7
7
  }
8
8
 
9
9
  function cjsify(data, space) {
10
- return `module.exports = ${jsonify(data, space)}`;
10
+ return `module.exports = ${jsonify(data, space)}`
11
11
  }
12
12
 
13
13
  function esmify(data, space) {
14
- return `export default ${jsonify(data, space)}`;
14
+ return `export default ${jsonify(data, space)}`
15
15
  }
16
16
 
17
17
  function yamlify(data, space) {
18
18
  return yaml.dump(data, {
19
19
  indent: space || undefined,
20
- });
20
+ })
21
21
  }
22
22
 
23
23
  async function mkdirs(dir) {
24
24
  try {
25
- await stat(dir);
26
- } catch(e) {
27
- await mkdir(dir, { recursive: true });
25
+ await stat(dir)
26
+ } catch (e) {
27
+ if (e.code !== 'ENOENT') {
28
+ throw e
29
+ }
30
+ await mkdirs(path.dirname(dir))
31
+ await mkdir(dir)
28
32
  }
29
- };
33
+ }
30
34
 
31
35
  async function write(sheet, data) {
32
- console.info(`Dump ${sheet}`);
33
- await mkdirs(path.dirname(sheet));
34
- await writeFile(sheet, data);
36
+ console.info(`Dump ${sheet}`)
37
+ await mkdirs(path.dirname(sheet))
38
+ await writeFile(sheet, data)
35
39
  }
36
40
 
37
41
  export async function dump(sheet, data, type, space) {
38
- let ext, ify;
39
- switch(type) {
42
+ let ext, ify
43
+ switch (type) {
40
44
  case 'cjs':
41
- ext = '.js';
42
- ify = cjsify;
43
- break;
45
+ ext = '.js'
46
+ ify = cjsify
47
+ break
44
48
  case 'js':
45
49
  case 'mjs':
46
50
  case 'esm':
47
- ext = '.js';
48
- ify = esmify;
49
- break;
51
+ ext = '.js'
52
+ ify = esmify
53
+ break
50
54
  case 'yaml':
51
55
  case 'yml':
52
- ext = '.yaml';
53
- ify = yamlify;
54
- break;
56
+ ext = '.yaml'
57
+ ify = yamlify
58
+ break
55
59
  case 'json':
56
60
  default:
57
- ext = '.json';
58
- ify = jsonify;
59
- break;
61
+ ext = '.json'
62
+ ify = jsonify
63
+ break
60
64
  }
61
- return write(`${sheet}${ext}`, ify(data, space));
62
- }
65
+ return write(`${sheet}${ext}`, ify(data, space))
66
+ }
package/src/index.js CHANGED
@@ -1,29 +1,29 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { readFile } from 'fs/promises';
4
- import { transform } from './transform.js';
2
+ import { Command } from 'commander'
3
+ import { readFile } from 'node:fs/promises'
4
+ import { transform } from './transform.js'
5
5
 
6
- (async () => {
6
+ const program = new Command()
7
7
 
8
- const program = new Command();
8
+ program.name('vt')
9
+ program.version(JSON.parse(await readFile('package.json')).version)
10
+ program
11
+ .command('transform [list...]')
12
+ .option(
13
+ '-t, --type <type>',
14
+ 'type of transform, available: js, esm, cjs, json',
15
+ 'json',
16
+ )
17
+ .option('-s, --space <space>', 'format space number', 0)
18
+ .option('-c, --config <config>', 'configure file', null)
19
+ .option('-w, --cwd <cwd>', 'current work dir', null)
20
+ .option('-o, --output <output>', 'output dir', null)
21
+ .option('-d, --dest <dest>', 'dest dir', null)
22
+ .option('-a, --addition', 'addition version', false)
23
+ .action((list, options) => {
24
+ if (!options.dest) options.dest = options.output
25
+ options.list = list
26
+ transform(options)
27
+ })
9
28
 
10
- program.name('vt');
11
- program.version(JSON.parse(await readFile('package.json')).version);
12
- program
13
- .command('transform [list...]')
14
- .option('-t, --type <type>', 'type of transform, available: js, esm, cjs, json', 'json')
15
- .option('-s, --space <space>', 'format space number', 0)
16
- .option('-c, --config <config>', 'configure file', null)
17
- .option('-w, --cwd <cwd>', 'current work dir', null)
18
- .option('-o, --output <output>', 'output dir', null)
19
- .option('-d, --dest <dest>', 'dest dir', null)
20
- .option('-a, --addition', 'addition version', false)
21
- .action((list, options) => {
22
- if (!options.dest) options.dest = options.output;
23
- options.list = list;
24
- transform(options);
25
- });
26
-
27
- program.parse(process.argv);
28
-
29
- })();
29
+ program.parse(process.argv)
package/src/loader.js CHANGED
@@ -1,41 +1,49 @@
1
- import glob from 'glob';
2
- import yaml from 'js-yaml';
3
- import path from 'path';
4
- import { readFile } from 'fs/promises';
1
+ import { glob } from 'glob'
2
+ import yaml from 'js-yaml'
3
+ import path from 'node:path'
4
+ import { readFile } from 'node:fs/promises'
5
5
 
6
6
  export async function load({ type, space, config, dest, list, cwd, addition }) {
7
- const version = new Date().toISOString();
8
- type = type || 'json';
9
- cwd = cwd || process.cwd();
10
- space = Number(space) || 0;
11
- dest = dest || cwd;
12
- const def = { cwd, type, space, dest, addition };
13
- const m = (...l) => globit(Object.assign({}, ...l));
14
- const cfgs = [];
7
+ const version = new Date().toISOString()
8
+ type = type || 'json'
9
+ cwd = cwd || process.cwd()
10
+ space = Number(space) || 0
11
+ dest = dest || cwd
12
+ const def = { cwd, type, space, dest, addition }
13
+ const m = (...l) => globit(Object.assign({}, ...l))
14
+ const cfgs = []
15
15
 
16
- if (list?.length)
17
- cfgs.unshift(await m(def, { glob: list }));
16
+ if (list?.length) cfgs.unshift(await m(def, { glob: list }))
18
17
 
19
18
  if (config) {
20
- const c = await loadConfig(config);
21
- const dir = path.dirname(config);
22
- const cdef = {};
23
- if (c.cwd) cdef.cwd = path.resolve(dir, c.cwd);
24
- if (c.type) cdef.type = c.type;
25
- if (typeof c.space == 'number') cdef.space = c.space;
26
- if (c.dest) cdef.dest = path.resolve(dir, c.dest);
27
- for (const cfg of c.configurations) {
28
- if (cfg.cwd) cfg.cwd = path.resolve(dir, cfg.cwd);
29
- if (cfg.dest) cfg.dest = path.resolve(dir, cfg.dest);
30
- cfgs.push(await m(def, cdef, cfg));
31
- }
19
+ const cfgData = await loadConfigData(config, def, m)
20
+ cfgs.push(...cfgData)
32
21
  }
33
22
 
34
- for (const cfg of cfgs)
35
- if (cfg.addition)
36
- cfg.addition = { version, timestamp: version }
23
+ for (const cfg of cfgs) {
24
+ if (cfg.addition) cfg.addition = { version, timestamp: version }
25
+ }
37
26
 
38
- return cfgs;
27
+ return cfgs
28
+ }
29
+
30
+ async function loadConfigData(config, def, m) {
31
+ const c = await loadConfig(config)
32
+ const dir = path.dirname(config)
33
+ const cdef = {}
34
+ if (c.cwd) cdef.cwd = path.resolve(dir, c.cwd)
35
+ if (c.type) cdef.type = c.type
36
+ if (typeof c.space == 'number') cdef.space = c.space
37
+ if (c.dest) cdef.dest = path.resolve(dir, c.dest)
38
+ const cfgs = []
39
+
40
+ for (const cfg of c.configurations) {
41
+ if (cfg.cwd) cfg.cwd = path.resolve(dir, cfg.cwd)
42
+ if (cfg.dest) cfg.dest = path.resolve(dir, cfg.dest)
43
+ cfgs.push(await m(def, cdef, cfg))
44
+ }
45
+
46
+ return cfgs
39
47
  }
40
48
 
41
49
  async function loadConfig(config) {
@@ -43,30 +51,22 @@ async function loadConfig(config) {
43
51
  case '.json':
44
52
  case '.yaml':
45
53
  case '.yml':
46
- return yaml.load(
47
- await readFile(config)
48
- );
54
+ return yaml.load(await readFile(config))
49
55
  case '.js':
50
56
  case '.mjs':
51
- return (await import(config)).default;
57
+ return (await import(config)).default
52
58
  default:
53
- throw new Error(`Unknown config file type: ${config}`);
59
+ throw new Error(`Unknown config file type: ${config}`)
54
60
  }
55
61
  }
56
62
 
57
63
  async function globit(options) {
58
- const { glob: gs, cwd } = options;
59
- const files = [];
60
- const g = p => new Promise(r => glob(
61
- p, { cwd }, (err, files) => r(err ? [] : files)
62
- ))
63
- if (Array.isArray(gs))
64
- for (const p of gs)
65
- files.push(...await g(p));
66
- else if (typeof gs == 'string')
67
- files.push(...await g(gs));
68
- else
69
- throw new Error(`Unknown glob type: ${gs}`);
64
+ const { glob: gs, cwd } = options
65
+ const files = []
66
+ const g = p => glob(p, { cwd })
67
+ if (Array.isArray(gs)) for (const p of gs) files.push(...(await g(p)))
68
+ else if (typeof gs == 'string') files.push(...(await g(gs)))
69
+ else throw new Error(`Unknown glob type: ${gs}`)
70
70
 
71
- return Object.assign({ files }, options);
72
- }
71
+ return { ...options, files }
72
+ }