@chaoswise/intl 1.1.0 → 1.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.
Files changed (32) hide show
  1. package/bin/scripts/collect.js +32 -15
  2. package/bin/scripts/conf/default.js +17 -14
  3. package/bin/scripts/conf/initConfig.js +2 -2
  4. package/bin/scripts/service/index.js +13 -3
  5. package/bin/scripts/update.js +4 -3
  6. package/bin/scripts/util/FormPath/contexts.d.ts +10 -0
  7. package/bin/scripts/util/FormPath/contexts.js +23 -0
  8. package/bin/scripts/util/FormPath/destructor.d.ts +15 -0
  9. package/bin/scripts/util/FormPath/destructor.js +124 -0
  10. package/bin/scripts/util/FormPath/index.d.ts +49 -0
  11. package/bin/scripts/util/FormPath/index.js +536 -0
  12. package/bin/scripts/util/FormPath/lru.d.ts +1 -0
  13. package/bin/scripts/util/FormPath/lru.js +246 -0
  14. package/bin/scripts/util/FormPath/matcher.d.ts +33 -0
  15. package/bin/scripts/util/FormPath/matcher.js +216 -0
  16. package/bin/scripts/util/FormPath/parser.d.ts +28 -0
  17. package/bin/scripts/util/FormPath/parser.js +302 -0
  18. package/bin/scripts/util/FormPath/tokenizer.d.ts +26 -0
  19. package/bin/scripts/util/FormPath/tokenizer.js +280 -0
  20. package/bin/scripts/util/FormPath/tokens.d.ts +26 -0
  21. package/bin/scripts/util/FormPath/tokens.js +212 -0
  22. package/bin/scripts/util/FormPath/types.d.ts +76 -0
  23. package/bin/scripts/util/FormPath/types.js +17 -0
  24. package/bin/scripts/util/FormPath/utils.d.ts +10 -0
  25. package/bin/scripts/util/FormPath/utils.js +63 -0
  26. package/bin/scripts/util/file.js +31 -0
  27. package/bin/scripts/util/log.js +25 -4
  28. package/bin/scripts/util/makeVisitorCollect.js +84 -29
  29. package/bin/scripts/util/makeVisitorUpdate.js +1 -1
  30. package/bin/scripts/util/transformAst.js +13 -2
  31. package/bin/scripts/util/writeNewWordsFile.js +30 -0
  32. package/package.json +4 -3
@@ -0,0 +1,536 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ }
12
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
13
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
14
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
15
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
16
+ r[k] = a[j];
17
+ return r;
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.Path = void 0;
21
+ var parser_1 = require("./parser");
22
+ var utils_1 = require("./utils");
23
+ var destructor_1 = require("./destructor");
24
+ __exportStar(require("./types"), exports);
25
+ var lru_1 = require("./lru");
26
+ var matcher_1 = require("./matcher");
27
+ var pathCache = new lru_1.LRUMap(1000);
28
+ var isMatcher = Symbol('PATH_MATCHER');
29
+ var isValid = function (val) { return val !== undefined && val !== null; };
30
+ var arrayExist = function (obj, key) {
31
+ if (Array.isArray(obj)) {
32
+ var index = Number(key);
33
+ if (index < 0 || index > obj.length - 1)
34
+ return false;
35
+ }
36
+ return true;
37
+ };
38
+ var getIn = function (segments, source) {
39
+ for (var i = 0; i < segments.length; i++) {
40
+ var index = segments[i];
41
+ var rules = destructor_1.getDestructor(index);
42
+ if (!rules) {
43
+ if (!isValid(source)) {
44
+ if (i !== segments.length - 1) {
45
+ return source;
46
+ }
47
+ break;
48
+ }
49
+ if (arrayExist(source, index)) {
50
+ source = source[index];
51
+ }
52
+ else {
53
+ return;
54
+ }
55
+ }
56
+ else {
57
+ source = destructor_1.getInByDestructor(source, rules, { setIn: setIn, getIn: getIn });
58
+ break;
59
+ }
60
+ }
61
+ return source;
62
+ };
63
+ var setIn = function (segments, source, value) {
64
+ for (var i = 0; i < segments.length; i++) {
65
+ var index = segments[i];
66
+ var rules = destructor_1.getDestructor(index);
67
+ if (!rules) {
68
+ if (!isValid(source))
69
+ return;
70
+ if (!isValid(source[index])) {
71
+ if (!isValid(source[index]) && !isValid(value)) {
72
+ return;
73
+ }
74
+ if (utils_1.isNum(segments[i + 1])) {
75
+ source[index] = [];
76
+ }
77
+ else {
78
+ source[index] = {};
79
+ }
80
+ }
81
+ if (i === segments.length - 1) {
82
+ source[index] = value;
83
+ }
84
+ if (arrayExist(source, index)) {
85
+ source = source[index];
86
+ }
87
+ }
88
+ else {
89
+ destructor_1.setInByDestructor(source, rules, value, { setIn: setIn, getIn: getIn });
90
+ break;
91
+ }
92
+ }
93
+ };
94
+ var deleteIn = function (segments, source) {
95
+ for (var i = 0; i < segments.length; i++) {
96
+ var index = segments[i];
97
+ var rules = destructor_1.getDestructor(index);
98
+ if (!rules) {
99
+ if (i === segments.length - 1 && isValid(source)) {
100
+ if (utils_1.isArr(source)) {
101
+ source.splice(Number(index), 1);
102
+ }
103
+ else {
104
+ delete source[index];
105
+ }
106
+ return;
107
+ }
108
+ if (!isValid(source))
109
+ return;
110
+ if (arrayExist(source, index)) {
111
+ source = source[index];
112
+ }
113
+ else {
114
+ return;
115
+ }
116
+ if (!utils_1.isObj(source)) {
117
+ return;
118
+ }
119
+ }
120
+ else {
121
+ destructor_1.deleteInByDestructor(source, rules, {
122
+ setIn: setIn,
123
+ getIn: getIn,
124
+ deleteIn: deleteIn,
125
+ });
126
+ break;
127
+ }
128
+ }
129
+ };
130
+ var existIn = function (segments, source, start) {
131
+ if (start instanceof Path) {
132
+ start = start.length;
133
+ }
134
+ for (var i = start; i < segments.length; i++) {
135
+ var index = segments[i];
136
+ var rules = destructor_1.getDestructor(index);
137
+ if (!rules) {
138
+ if (i === segments.length - 1) {
139
+ if (source && index in source) {
140
+ return true;
141
+ }
142
+ return false;
143
+ }
144
+ if (!isValid(source))
145
+ return false;
146
+ if (arrayExist(source, index)) {
147
+ source = source[index];
148
+ }
149
+ else {
150
+ return false;
151
+ }
152
+ if (!utils_1.isObj(source)) {
153
+ return false;
154
+ }
155
+ }
156
+ else {
157
+ return destructor_1.existInByDestructor(source, rules, start, {
158
+ setIn: setIn,
159
+ getIn: getIn,
160
+ deleteIn: deleteIn,
161
+ existIn: existIn,
162
+ });
163
+ }
164
+ }
165
+ };
166
+ var Path = (function () {
167
+ function Path(input) {
168
+ var _this = this;
169
+ this.concat = function () {
170
+ var _a;
171
+ var args = [];
172
+ for (var _i = 0; _i < arguments.length; _i++) {
173
+ args[_i] = arguments[_i];
174
+ }
175
+ if (_this.isMatchPattern) {
176
+ throw new Error(_this.entire + " cannot be concat");
177
+ }
178
+ var path = new Path('');
179
+ path.segments = (_a = _this.segments).concat.apply(_a, args.map(function (s) { return _this.parseString(s); }));
180
+ path.entire = path.segments.join('.');
181
+ return path;
182
+ };
183
+ this.slice = function (start, end) {
184
+ if (_this.isMatchPattern) {
185
+ throw new Error(_this.entire + " cannot be slice");
186
+ }
187
+ var path = new Path('');
188
+ path.segments = _this.segments.slice(start, end);
189
+ path.entire = path.segments.join('.');
190
+ return path;
191
+ };
192
+ this.push = function (item) {
193
+ if (_this.isMatchPattern) {
194
+ throw new Error(_this.entire + " cannot be push");
195
+ }
196
+ _this.segments.push(_this.parseString(item));
197
+ _this.entire = _this.segments.join('.');
198
+ return _this;
199
+ };
200
+ this.pop = function () {
201
+ if (_this.isMatchPattern) {
202
+ throw new Error(_this.entire + " cannot be pop");
203
+ }
204
+ _this.segments.pop();
205
+ _this.entire = _this.segments.join('.');
206
+ };
207
+ this.splice = function (start, deleteCount) {
208
+ var _a;
209
+ var items = [];
210
+ for (var _i = 2; _i < arguments.length; _i++) {
211
+ items[_i - 2] = arguments[_i];
212
+ }
213
+ if (_this.isMatchPattern) {
214
+ throw new Error(_this.entire + " cannot be splice");
215
+ }
216
+ if (deleteCount === 0) {
217
+ items = items.map(function (item) { return _this.parseString(item); });
218
+ }
219
+ (_a = _this.segments).splice.apply(_a, __spreadArrays([start, deleteCount], items));
220
+ _this.entire = _this.segments.join('.');
221
+ return _this;
222
+ };
223
+ this.forEach = function (callback) {
224
+ if (_this.isMatchPattern) {
225
+ throw new Error(_this.entire + " cannot be each");
226
+ }
227
+ _this.segments.forEach(callback);
228
+ };
229
+ this.map = function (callback) {
230
+ if (_this.isMatchPattern) {
231
+ throw new Error(_this.entire + " cannot be map");
232
+ }
233
+ return _this.segments.map(callback);
234
+ };
235
+ this.reduce = function (callback, initial) {
236
+ if (_this.isMatchPattern) {
237
+ throw new Error(_this.entire + " cannot be reduce");
238
+ }
239
+ return _this.segments.reduce(callback, initial);
240
+ };
241
+ this.getNearestChildPathBy = function (target) {
242
+ var path = Path.parse(target);
243
+ if (path.length < _this.length)
244
+ return _this;
245
+ return _this.concat(path.segments[_this.length]);
246
+ };
247
+ this.parent = function () {
248
+ return _this.slice(0, _this.length - 1);
249
+ };
250
+ this.includes = function (pattern) {
251
+ var _a = Path.getPath(pattern), entire = _a.entire, segments = _a.segments, isMatchPattern = _a.isMatchPattern;
252
+ var cache = _this.includesCache.get(entire);
253
+ if (cache !== undefined)
254
+ return cache;
255
+ var cacheWith = function (value) {
256
+ _this.includesCache.set(entire, value);
257
+ return value;
258
+ };
259
+ if (_this.isMatchPattern) {
260
+ if (!isMatchPattern) {
261
+ return cacheWith(_this.match(segments));
262
+ }
263
+ else {
264
+ throw new Error(_this.entire + " cannot be used to match " + entire);
265
+ }
266
+ }
267
+ if (isMatchPattern) {
268
+ throw new Error(_this.entire + " cannot be used to match " + entire);
269
+ }
270
+ if (segments.length > _this.segments.length)
271
+ return cacheWith(false);
272
+ for (var i = 0; i < segments.length; i++) {
273
+ if (!utils_1.isEqual(String(segments[i]), String(_this.segments[i]))) {
274
+ return cacheWith(false);
275
+ }
276
+ }
277
+ return cacheWith(true);
278
+ };
279
+ this.transform = function (regexp, callback) {
280
+ if (!utils_1.isFn(callback))
281
+ return '';
282
+ if (_this.isMatchPattern) {
283
+ throw new Error(_this.entire + " cannot be transformed");
284
+ }
285
+ var args = _this.segments.reduce(function (buf, key) {
286
+ return new RegExp(regexp).test(key) ? buf.concat(key) : buf;
287
+ }, []);
288
+ return callback.apply(void 0, args);
289
+ };
290
+ this.match = function (pattern) {
291
+ var path = Path.getPath(pattern);
292
+ var cache = _this.matchCache.get(path.entire);
293
+ if (cache !== undefined) {
294
+ if (cache.record && cache.record.score !== undefined) {
295
+ _this.matchScore = cache.record.score;
296
+ }
297
+ return cache.matched;
298
+ }
299
+ var cacheWith = function (value) {
300
+ _this.matchCache.set(path.entire, value);
301
+ return value;
302
+ };
303
+ if (path.isMatchPattern) {
304
+ if (_this.isMatchPattern) {
305
+ throw new Error(path.entire + " cannot match " + _this.entire);
306
+ }
307
+ else {
308
+ _this.matchScore = 0;
309
+ return cacheWith(path.match(_this.segments));
310
+ }
311
+ }
312
+ else {
313
+ if (_this.isMatchPattern) {
314
+ var record = {
315
+ score: 0,
316
+ };
317
+ var result = cacheWith(new matcher_1.Matcher(_this.tree, record).match(path.segments));
318
+ _this.matchScore = record.score;
319
+ return result.matched;
320
+ }
321
+ else {
322
+ var record = {
323
+ score: 0,
324
+ };
325
+ var result = cacheWith(matcher_1.Matcher.matchSegments(_this.segments, path.segments, record));
326
+ _this.matchScore = record.score;
327
+ return result.matched;
328
+ }
329
+ }
330
+ };
331
+ this.matchAliasGroup = function (name, alias) {
332
+ var namePath = Path.parse(name);
333
+ var aliasPath = Path.parse(alias);
334
+ var nameMatched = _this.match(namePath);
335
+ var nameMatchedScore = _this.matchScore;
336
+ var aliasMatched = _this.match(aliasPath);
337
+ var aliasMatchedScore = _this.matchScore;
338
+ if (_this.haveExcludePattern) {
339
+ if (nameMatchedScore >= aliasMatchedScore) {
340
+ return nameMatched;
341
+ }
342
+ else {
343
+ return aliasMatched;
344
+ }
345
+ }
346
+ else {
347
+ return nameMatched || aliasMatched;
348
+ }
349
+ };
350
+ this.existIn = function (source, start) {
351
+ if (start === void 0) { start = 0; }
352
+ return existIn(_this.segments, source, start);
353
+ };
354
+ this.getIn = function (source) {
355
+ return getIn(_this.segments, source);
356
+ };
357
+ this.setIn = function (source, value) {
358
+ setIn(_this.segments, source, value);
359
+ return source;
360
+ };
361
+ this.deleteIn = function (source) {
362
+ deleteIn(_this.segments, source);
363
+ return source;
364
+ };
365
+ var _a = this.parse(input), tree = _a.tree, segments = _a.segments, entire = _a.entire, isMatchPattern = _a.isMatchPattern, isWildMatchPattern = _a.isWildMatchPattern, haveExcludePattern = _a.haveExcludePattern;
366
+ this.entire = entire;
367
+ this.segments = segments;
368
+ this.isMatchPattern = isMatchPattern;
369
+ this.isWildMatchPattern = isWildMatchPattern;
370
+ this.haveExcludePattern = haveExcludePattern;
371
+ this.tree = tree;
372
+ this.matchCache = new lru_1.LRUMap(200);
373
+ this.includesCache = new lru_1.LRUMap(200);
374
+ }
375
+ Path.prototype.toString = function () {
376
+ return this.entire;
377
+ };
378
+ Path.prototype.toArray = function () {
379
+ return this.segments;
380
+ };
381
+ Object.defineProperty(Path.prototype, "length", {
382
+ get: function () {
383
+ return this.segments.length;
384
+ },
385
+ enumerable: false,
386
+ configurable: true
387
+ });
388
+ Path.prototype.parse = function (pattern) {
389
+ var _this = this;
390
+ if (pattern instanceof Path) {
391
+ return {
392
+ entire: pattern.entire,
393
+ segments: pattern.segments.slice(),
394
+ isWildMatchPattern: pattern.isWildMatchPattern,
395
+ isMatchPattern: pattern.isMatchPattern,
396
+ haveExcludePattern: pattern.haveExcludePattern,
397
+ tree: pattern.tree,
398
+ };
399
+ }
400
+ else if (utils_1.isStr(pattern)) {
401
+ if (!pattern)
402
+ return {
403
+ entire: '',
404
+ segments: [],
405
+ isWildMatchPattern: false,
406
+ haveExcludePattern: false,
407
+ isMatchPattern: false,
408
+ };
409
+ var parser = new parser_1.Parser(pattern);
410
+ var tree = parser.parse();
411
+ if (!parser.isMatchPattern) {
412
+ var segments = parser.data.segments;
413
+ return {
414
+ entire: segments.join('.'),
415
+ segments: segments,
416
+ tree: tree,
417
+ isWildMatchPattern: false,
418
+ haveExcludePattern: false,
419
+ isMatchPattern: false,
420
+ };
421
+ }
422
+ else {
423
+ return {
424
+ entire: pattern,
425
+ segments: [],
426
+ isWildMatchPattern: parser.isWildMatchPattern,
427
+ haveExcludePattern: parser.haveExcludePattern,
428
+ isMatchPattern: true,
429
+ tree: tree,
430
+ };
431
+ }
432
+ }
433
+ else if (utils_1.isFn(pattern) && pattern[isMatcher]) {
434
+ return this.parse(pattern['path']);
435
+ }
436
+ else if (utils_1.isArr(pattern)) {
437
+ return {
438
+ entire: pattern.join('.'),
439
+ segments: pattern.reduce(function (buf, key) {
440
+ return buf.concat(_this.parseString(key));
441
+ }, []),
442
+ isWildMatchPattern: false,
443
+ haveExcludePattern: false,
444
+ isMatchPattern: false,
445
+ };
446
+ }
447
+ else {
448
+ return {
449
+ entire: '',
450
+ segments: pattern !== undefined ? [pattern] : [],
451
+ isWildMatchPattern: false,
452
+ haveExcludePattern: false,
453
+ isMatchPattern: false,
454
+ };
455
+ }
456
+ };
457
+ Path.prototype.parseString = function (source) {
458
+ if (utils_1.isStr(source)) {
459
+ source = source.replace(/\s*/g, '');
460
+ try {
461
+ var _a = this.parse(source), segments = _a.segments, isMatchPattern = _a.isMatchPattern;
462
+ return !isMatchPattern ? segments : source;
463
+ }
464
+ catch (e) {
465
+ return source;
466
+ }
467
+ }
468
+ else if (source instanceof Path) {
469
+ return source.segments;
470
+ }
471
+ return source;
472
+ };
473
+ Path.match = function (pattern) {
474
+ var path = Path.getPath(pattern);
475
+ var matcher = function (target) {
476
+ return path.match(target);
477
+ };
478
+ matcher[isMatcher] = true;
479
+ matcher.path = path;
480
+ return matcher;
481
+ };
482
+ Path.transform = function (pattern, regexp, callback) {
483
+ return Path.getPath(pattern).transform(regexp, callback);
484
+ };
485
+ Path.parse = function (path) {
486
+ if (path === void 0) { path = ''; }
487
+ return Path.getPath(path);
488
+ };
489
+ Path.getPath = function (path) {
490
+ if (path === void 0) { path = ''; }
491
+ if (path instanceof Path) {
492
+ var found = pathCache.get(path.entire);
493
+ if (found) {
494
+ return found;
495
+ }
496
+ else {
497
+ pathCache.set(path.entire, path);
498
+ return path;
499
+ }
500
+ }
501
+ else if (path && path[isMatcher]) {
502
+ return Path.getPath(path['path']);
503
+ }
504
+ else {
505
+ var key = path.toString();
506
+ var found = pathCache.get(key);
507
+ if (found) {
508
+ return found;
509
+ }
510
+ else {
511
+ path = new Path(path);
512
+ pathCache.set(key, path);
513
+ return path;
514
+ }
515
+ }
516
+ };
517
+ Path.getIn = function (source, pattern) {
518
+ var path = Path.getPath(pattern);
519
+ return path.getIn(source);
520
+ };
521
+ Path.setIn = function (source, pattern, value) {
522
+ var path = Path.getPath(pattern);
523
+ return path.setIn(source, value);
524
+ };
525
+ Path.deleteIn = function (source, pattern) {
526
+ var path = Path.getPath(pattern);
527
+ return path.deleteIn(source);
528
+ };
529
+ Path.existIn = function (source, pattern, start) {
530
+ var path = Path.getPath(pattern);
531
+ return path.existIn(source, start);
532
+ };
533
+ return Path;
534
+ }());
535
+ exports.Path = Path;
536
+ exports.default = Path;
@@ -0,0 +1 @@
1
+ export declare function LRUMap(limit: number, entries?: any): void;