@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.
- package/bin/scripts/collect.js +32 -15
- package/bin/scripts/conf/default.js +17 -14
- package/bin/scripts/conf/initConfig.js +2 -2
- package/bin/scripts/service/index.js +13 -3
- package/bin/scripts/update.js +4 -3
- package/bin/scripts/util/FormPath/contexts.d.ts +10 -0
- package/bin/scripts/util/FormPath/contexts.js +23 -0
- package/bin/scripts/util/FormPath/destructor.d.ts +15 -0
- package/bin/scripts/util/FormPath/destructor.js +124 -0
- package/bin/scripts/util/FormPath/index.d.ts +49 -0
- package/bin/scripts/util/FormPath/index.js +536 -0
- package/bin/scripts/util/FormPath/lru.d.ts +1 -0
- package/bin/scripts/util/FormPath/lru.js +246 -0
- package/bin/scripts/util/FormPath/matcher.d.ts +33 -0
- package/bin/scripts/util/FormPath/matcher.js +216 -0
- package/bin/scripts/util/FormPath/parser.d.ts +28 -0
- package/bin/scripts/util/FormPath/parser.js +302 -0
- package/bin/scripts/util/FormPath/tokenizer.d.ts +26 -0
- package/bin/scripts/util/FormPath/tokenizer.js +280 -0
- package/bin/scripts/util/FormPath/tokens.d.ts +26 -0
- package/bin/scripts/util/FormPath/tokens.js +212 -0
- package/bin/scripts/util/FormPath/types.d.ts +76 -0
- package/bin/scripts/util/FormPath/types.js +17 -0
- package/bin/scripts/util/FormPath/utils.d.ts +10 -0
- package/bin/scripts/util/FormPath/utils.js +63 -0
- package/bin/scripts/util/file.js +31 -0
- package/bin/scripts/util/log.js +25 -4
- package/bin/scripts/util/makeVisitorCollect.js +84 -29
- package/bin/scripts/util/makeVisitorUpdate.js +1 -1
- package/bin/scripts/util/transformAst.js +13 -2
- package/bin/scripts/util/writeNewWordsFile.js +30 -0
- package/package.json +4 -3
package/bin/scripts/collect.js
CHANGED
|
@@ -5,22 +5,31 @@ const getTargetFiles = require('./util/getTargetFiles');
|
|
|
5
5
|
const transformAst = require('./util/transformAst');
|
|
6
6
|
const log = require('./util/log');
|
|
7
7
|
const file = require('./util/file');
|
|
8
|
-
const
|
|
8
|
+
const writeNewWordsFile = require('./util/writeNewWordsFile');
|
|
9
9
|
const { readWordJson } = require('./util/getWord');
|
|
10
|
+
const getGroupName = require('./util/getGroupName');
|
|
10
11
|
|
|
11
12
|
const service = require('./service');
|
|
12
13
|
|
|
13
14
|
async function collect() {
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
log.info('工程扫描中...')
|
|
17
|
+
|
|
15
18
|
const conf = getConf();
|
|
19
|
+
const groupName = getGroupName();
|
|
20
|
+
const newWordsFileType = conf.newWordsFileType || 'excel';
|
|
21
|
+
|
|
22
|
+
// 检查newWordsFileType
|
|
23
|
+
if (!['json', 'excel'].includes(newWordsFileType)) {
|
|
24
|
+
log.error(`配置:newWordsFileType 只能为json或者excel`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
16
27
|
|
|
17
28
|
// 读取wordJson
|
|
18
29
|
if (conf.localWordPath && !readWordJson(conf.localWordPath)) {
|
|
19
30
|
log.error('localWordPath配置有误');
|
|
20
31
|
process.exit(1);
|
|
21
32
|
}
|
|
22
|
-
// 读取groupName
|
|
23
|
-
const groupName = getGroupName();
|
|
24
33
|
|
|
25
34
|
// 获取需要遍历的文件
|
|
26
35
|
const files = getTargetFiles(conf);
|
|
@@ -31,6 +40,8 @@ async function collect() {
|
|
|
31
40
|
|
|
32
41
|
// 在国际化平台中获取所有已存在中文信息
|
|
33
42
|
const res = await service.searchByZh(info.allWords);
|
|
43
|
+
// 在国际化平台记录特殊方法
|
|
44
|
+
await service.saveMethod({ groupName, specialMethod: info.specialMethod });
|
|
34
45
|
|
|
35
46
|
if (res.code !== 10000) {
|
|
36
47
|
log.error('请求数据出错:' + res.msg);
|
|
@@ -41,10 +52,13 @@ async function collect() {
|
|
|
41
52
|
|
|
42
53
|
const replaceWords = {}; // { zh: id } 需要在代码中替换的词条id
|
|
43
54
|
const newWords = {}; // { zh1: '待翻译', zh2: '请选择:中文1/中文2' }
|
|
55
|
+
const exist = {}; // 根据中文只查出一条数据的已有词条
|
|
44
56
|
Object.entries(wordsMap).forEach(([word, value]) => {
|
|
45
57
|
// 如果当前中文词条在平台中存在,且对应英文翻译有且只有一条,那么直接替换代码中的中文为当前id,否则生成临时key,让开发者手动确认
|
|
46
58
|
if (value.length === 1) {
|
|
47
|
-
|
|
59
|
+
const { id, key, zh, en } = value[0];
|
|
60
|
+
replaceWords[word] = key;
|
|
61
|
+
exist[id] = { id, key, zh, en };
|
|
48
62
|
} else {
|
|
49
63
|
const id = uuidv4();
|
|
50
64
|
replaceWords[word] = id;
|
|
@@ -60,22 +74,25 @@ async function collect() {
|
|
|
60
74
|
}
|
|
61
75
|
});
|
|
62
76
|
|
|
77
|
+
|
|
78
|
+
// 在国际化平台中保存所有已存在词条
|
|
79
|
+
await service.saveExist({groupName, exist});
|
|
80
|
+
|
|
63
81
|
// 第二次遍历,传入replaceWords,对代码进行国际化通用API转化,把词条替换成数据库的id,或者脚本临时生成的uuid
|
|
64
82
|
transformAst('collect', files, conf, replaceWords);
|
|
65
83
|
|
|
66
|
-
log.success('脚本执行成功');
|
|
67
|
-
log.
|
|
84
|
+
log.success('★★★ 脚本执行成功 ★★★');
|
|
85
|
+
log.info('国际化配置文件: .intlconfig.js,可根据需求自定义修改');
|
|
68
86
|
// 本次扫描出新的待翻译词条,写入到newWords中
|
|
69
87
|
if (Object.keys(newWords).length) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const oldNewWords = file.readJson(newWordsJsonPath) || {};
|
|
73
|
-
file.write(
|
|
74
|
-
newWordsJsonPath,
|
|
75
|
-
JSON.stringify({ ...oldNewWords, ...newWords, groupName }, null, 2)
|
|
76
|
-
);
|
|
88
|
+
writeNewWordsFile(newWordsFileType, newWords);
|
|
89
|
+
}
|
|
77
90
|
|
|
78
|
-
|
|
91
|
+
const warnLogs = log.logs.warn;
|
|
92
|
+
if (warnLogs.length) {
|
|
93
|
+
const fileName = `intl.logs.warn.${(new Date).toLocaleString().replace(/[\/ ]/g, '_')}.txt`;
|
|
94
|
+
file.write(fileName, JSON.stringify(warnLogs, null, 2));
|
|
95
|
+
log.warn(`存在脚本无法处理的情况,具体查看 ${fileName} 手动处理`);
|
|
79
96
|
}
|
|
80
97
|
}
|
|
81
98
|
|
|
@@ -55,30 +55,30 @@ module.exports = function (excludes = []) {
|
|
|
55
55
|
endOfLine: 'lf',
|
|
56
56
|
},
|
|
57
57
|
|
|
58
|
-
// <
|
|
59
|
-
// intlTag 是 '
|
|
60
|
-
// intlTagIdPath 是 'id
|
|
58
|
+
// <FormattedMessage id='id' defaultMessage='中文' />
|
|
59
|
+
// intlTag 是 'FormattedMessage'
|
|
60
|
+
// intlTagIdPath 是 'id'
|
|
61
61
|
// intlTagDefaultWordPath 是 'defaultMessage',并且如果不配置,默认是'defaultMessage'
|
|
62
|
-
intlTag: '',
|
|
63
|
-
intlTagIdPath: '',
|
|
64
|
-
intlTagDefaultWordPath: '',
|
|
62
|
+
intlTag: 'FormattedMessage',
|
|
63
|
+
intlTagIdPath: 'id',
|
|
64
|
+
intlTagDefaultWordPath: 'defaultMessage',
|
|
65
65
|
|
|
66
66
|
// intl.formatMessage({
|
|
67
|
-
//
|
|
67
|
+
// id: 'id',
|
|
68
68
|
// defaultMessage: '默认值',
|
|
69
69
|
// })
|
|
70
70
|
// intlFunctionName 是 intl.formatMessage
|
|
71
|
-
// intlFunctionIdPath 是 '0.
|
|
71
|
+
// intlFunctionIdPath 是 '0.id'。 如果 配置成 'id' 也行,intlFunctionIdPath如果不以数字开头,会在前面加上'0.' 'id' 就会变成 '0.id'
|
|
72
72
|
// intlFunctionDefaultWordPath 是 '0.defaultMessage',其他的说明同intlFunctionIdPath
|
|
73
|
-
intlFunctionName: '',
|
|
74
|
-
intlFunctionIdPath: '',
|
|
75
|
-
intlFunctionDefaultWordPath: '',
|
|
73
|
+
intlFunctionName: 'intl.formatMessage',
|
|
74
|
+
intlFunctionIdPath: 'id',
|
|
75
|
+
intlFunctionDefaultWordPath: 'defaultMessage',
|
|
76
76
|
|
|
77
77
|
// 做过国际化的项目,中文config的路径。例如:'src/local/zh.json'
|
|
78
78
|
localWordPath: '',
|
|
79
79
|
|
|
80
80
|
// 配置 需要被脚本删除的依赖包的名字
|
|
81
|
-
removePkgName: [],
|
|
81
|
+
removePkgName: ['react-intl'],
|
|
82
82
|
|
|
83
83
|
// 需要删除的函数和装饰器 的名称
|
|
84
84
|
removeFunctionName: ['injectIntl'],
|
|
@@ -86,8 +86,11 @@ module.exports = function (excludes = []) {
|
|
|
86
86
|
// package.json中项目名称的key
|
|
87
87
|
groupNameKey: 'packageName',
|
|
88
88
|
|
|
89
|
-
//
|
|
90
|
-
specialFileReg: [/
|
|
89
|
+
// 特殊文件处理数组的每一项为正则或者字符串 这里默认匹配router.config.js
|
|
90
|
+
specialFileReg: ['src/config/router.config.js'],
|
|
91
|
+
|
|
92
|
+
// newWords文件的类型 json或者excel
|
|
93
|
+
newWordsFileType: 'excel',
|
|
91
94
|
|
|
92
95
|
// 国际化平台地址
|
|
93
96
|
baseURL: 'http://10.0.1.133:18000',
|
|
@@ -10,7 +10,7 @@ module.exports = function initConfig() {
|
|
|
10
10
|
const customConfig = getCustomConfig();
|
|
11
11
|
|
|
12
12
|
if (customConfig) {
|
|
13
|
-
|
|
13
|
+
log.error(`${customConfigName}已存在,请删除后重新执行`);
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -33,5 +33,5 @@ module.exports = function initConfig() {
|
|
|
33
33
|
prettier.format(code, { ...defaultConfig.prettier, parser: 'babel' })
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
log.success(
|
|
36
|
+
log.success(`★★★ 初始化配置文件成功:.intlconfig.js ★★★`);
|
|
37
37
|
}
|
|
@@ -3,7 +3,7 @@ const getConf = require('../conf');
|
|
|
3
3
|
|
|
4
4
|
const conf = getConf();
|
|
5
5
|
|
|
6
|
-
axios.defaults.baseURL = (conf.baseURL || '') + '/api/i18n
|
|
6
|
+
axios.defaults.baseURL = (conf.baseURL || '') + '/api/i18n';
|
|
7
7
|
|
|
8
8
|
axios.interceptors.response.use(
|
|
9
9
|
function (response) {
|
|
@@ -20,10 +20,20 @@ axios.interceptors.response.use(
|
|
|
20
20
|
|
|
21
21
|
// 在国际化平台中获取所有已存在中文信息
|
|
22
22
|
exports.searchByZh = (zhs) => {
|
|
23
|
-
return axios.post('/searchByZh', zhs);
|
|
23
|
+
return axios.post('/dictionary/searchByZh', zhs);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// 根据词条id获取所有数据库词条信息
|
|
27
27
|
exports.getJson = ({ groupName, downloadIds }) => {
|
|
28
|
-
return axios.post('/getJson', { groupName, downloadIds });
|
|
28
|
+
return axios.post('/dictionary/getJson', { groupName, downloadIds });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// 保存替换的特殊方法
|
|
32
|
+
exports.saveMethod = (data) => {
|
|
33
|
+
return axios.post('/history/method/save', data);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// 保存已有词条
|
|
37
|
+
exports.saveExist = (data) => {
|
|
38
|
+
return axios.post('/history/exist/save', data);
|
|
29
39
|
};
|
package/bin/scripts/update.js
CHANGED
|
@@ -6,6 +6,7 @@ const log = require('./util/log');
|
|
|
6
6
|
const file = require('./util/file');
|
|
7
7
|
|
|
8
8
|
async function update() {
|
|
9
|
+
log.info('词条更新中...')
|
|
9
10
|
const conf = getConf();
|
|
10
11
|
const files = getTargetFiles(conf);
|
|
11
12
|
|
|
@@ -13,17 +14,17 @@ async function update() {
|
|
|
13
14
|
const relationKey = file.readJson('relationKey.json') || {};
|
|
14
15
|
|
|
15
16
|
const info = transformAst('update', files, conf, relationKey);
|
|
16
|
-
await downloadJson(info.downloadIds);
|
|
17
|
+
await downloadJson(info.downloadIds.filter(Boolean));
|
|
17
18
|
|
|
18
19
|
const needDelete = Boolean(Object.keys(relationKey).length);
|
|
19
20
|
if (needDelete) {
|
|
20
21
|
file.delete('newWords.json');
|
|
21
22
|
file.delete('relationKey.json');
|
|
22
23
|
|
|
23
|
-
log.success('newWords.json和relationKey.json 已删除');
|
|
24
|
+
// log.success('newWords.json和relationKey.json 已删除');
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
log.success('脚本执行成功');
|
|
27
|
+
log.success('★★★ 脚本执行成功 ★★★');
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
// update();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare type Context = {
|
|
2
|
+
flag: string;
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
};
|
|
5
|
+
export declare const bracketContext: Context;
|
|
6
|
+
export declare const bracketArrayContext: Context;
|
|
7
|
+
export declare const bracketDContext: Context;
|
|
8
|
+
export declare const parenContext: Context;
|
|
9
|
+
export declare const braceContext: Context;
|
|
10
|
+
export declare const destructorContext: Context;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.destructorContext = exports.braceContext = exports.parenContext = exports.bracketDContext = exports.bracketArrayContext = exports.bracketContext = void 0;
|
|
15
|
+
var ContextType = function (flag, props) {
|
|
16
|
+
return __assign({ flag: flag }, props);
|
|
17
|
+
};
|
|
18
|
+
exports.bracketContext = ContextType("[]");
|
|
19
|
+
exports.bracketArrayContext = ContextType("[\\d]");
|
|
20
|
+
exports.bracketDContext = ContextType("[[]]");
|
|
21
|
+
exports.parenContext = ContextType("()");
|
|
22
|
+
exports.braceContext = ContextType("{}");
|
|
23
|
+
exports.destructorContext = ContextType("{x}");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Segments, Node, DestrcutorRules } from './types';
|
|
2
|
+
declare type Mutatators = {
|
|
3
|
+
getIn: (segments: Segments, source: any) => any;
|
|
4
|
+
setIn: (segments: Segments, source: any, value: any) => void;
|
|
5
|
+
deleteIn?: (segments: Segments, source: any) => any;
|
|
6
|
+
existIn?: (segments: Segments, source: any, start: number) => boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const getDestructor: (source: string) => any;
|
|
9
|
+
export declare const setDestructor: (source: string, rules: DestrcutorRules) => void;
|
|
10
|
+
export declare const parseDestructorRules: (node: Node) => DestrcutorRules;
|
|
11
|
+
export declare const setInByDestructor: (source: any, rules: DestrcutorRules, value: any, mutators: Mutatators) => void;
|
|
12
|
+
export declare const getInByDestructor: (source: any, rules: DestrcutorRules, mutators: Mutatators) => {};
|
|
13
|
+
export declare const deleteInByDestructor: (source: any, rules: DestrcutorRules, mutators: Mutatators) => void;
|
|
14
|
+
export declare const existInByDestructor: (source: any, rules: DestrcutorRules, start: number, mutators: Mutatators) => boolean;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.existInByDestructor = exports.deleteInByDestructor = exports.getInByDestructor = exports.setInByDestructor = exports.parseDestructorRules = exports.setDestructor = exports.getDestructor = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
var utils_1 = require("./utils");
|
|
6
|
+
var DestrcutorCache = new Map();
|
|
7
|
+
var isValid = function (val) { return val !== undefined && val !== null; };
|
|
8
|
+
exports.getDestructor = function (source) {
|
|
9
|
+
return DestrcutorCache.get(source);
|
|
10
|
+
};
|
|
11
|
+
exports.setDestructor = function (source, rules) {
|
|
12
|
+
DestrcutorCache.set(source, rules);
|
|
13
|
+
};
|
|
14
|
+
exports.parseDestructorRules = function (node) {
|
|
15
|
+
var rules = [];
|
|
16
|
+
if (types_1.isObjectPattern(node)) {
|
|
17
|
+
var index_1 = 0;
|
|
18
|
+
node.properties.forEach(function (child) {
|
|
19
|
+
rules[index_1] = {
|
|
20
|
+
path: []
|
|
21
|
+
};
|
|
22
|
+
rules[index_1].key = child.key.value;
|
|
23
|
+
rules[index_1].path.push(child.key.value);
|
|
24
|
+
if (types_1.isIdentifier(child.value)) {
|
|
25
|
+
rules[index_1].key = child.value.value;
|
|
26
|
+
}
|
|
27
|
+
var basePath = rules[index_1].path;
|
|
28
|
+
var childRules = exports.parseDestructorRules(child.value);
|
|
29
|
+
var k = index_1;
|
|
30
|
+
childRules.forEach(function (rule) {
|
|
31
|
+
if (rules[k]) {
|
|
32
|
+
rules[k].key = rule.key;
|
|
33
|
+
rules[k].path = basePath.concat(rule.path);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
rules[k] = {
|
|
37
|
+
key: rule.key,
|
|
38
|
+
path: basePath.concat(rule.path)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
k++;
|
|
42
|
+
});
|
|
43
|
+
if (k > index_1) {
|
|
44
|
+
index_1 = k;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
index_1++;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return rules;
|
|
51
|
+
}
|
|
52
|
+
else if (types_1.isArrayPattern(node)) {
|
|
53
|
+
var index_2 = 0;
|
|
54
|
+
node.elements.forEach(function (child, key) {
|
|
55
|
+
rules[index_2] = {
|
|
56
|
+
path: []
|
|
57
|
+
};
|
|
58
|
+
rules[index_2].key = key;
|
|
59
|
+
rules[index_2].path.push(key);
|
|
60
|
+
if (types_1.isIdentifier(child)) {
|
|
61
|
+
rules[index_2].key = child.value;
|
|
62
|
+
}
|
|
63
|
+
var basePath = rules[index_2].path;
|
|
64
|
+
var childRules = exports.parseDestructorRules(child);
|
|
65
|
+
var k = index_2;
|
|
66
|
+
childRules.forEach(function (rule) {
|
|
67
|
+
if (rules[k]) {
|
|
68
|
+
rules[k].key = rule.key;
|
|
69
|
+
rules[k].path = basePath.concat(rule.path);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
rules[k] = {
|
|
73
|
+
key: rule.key,
|
|
74
|
+
path: basePath.concat(rule.path)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
k++;
|
|
78
|
+
});
|
|
79
|
+
if (k > index_2) {
|
|
80
|
+
index_2 = k;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
index_2++;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return rules;
|
|
87
|
+
}
|
|
88
|
+
if (types_1.isDestructorExpression(node)) {
|
|
89
|
+
return exports.parseDestructorRules(node.value);
|
|
90
|
+
}
|
|
91
|
+
return rules;
|
|
92
|
+
};
|
|
93
|
+
exports.setInByDestructor = function (source, rules, value, mutators) {
|
|
94
|
+
rules.forEach(function (_a) {
|
|
95
|
+
var key = _a.key, path = _a.path;
|
|
96
|
+
mutators.setIn([key], source, mutators.getIn(path, value));
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
exports.getInByDestructor = function (source, rules, mutators) {
|
|
100
|
+
var response = {};
|
|
101
|
+
if (rules.length) {
|
|
102
|
+
if (utils_1.isNum(rules[0].path[0])) {
|
|
103
|
+
response = [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
source = isValid(source) ? source : {};
|
|
107
|
+
rules.forEach(function (_a) {
|
|
108
|
+
var key = _a.key, path = _a.path;
|
|
109
|
+
mutators.setIn(path, response, source[key]);
|
|
110
|
+
});
|
|
111
|
+
return response;
|
|
112
|
+
};
|
|
113
|
+
exports.deleteInByDestructor = function (source, rules, mutators) {
|
|
114
|
+
rules.forEach(function (_a) {
|
|
115
|
+
var key = _a.key;
|
|
116
|
+
mutators.deleteIn([key], source);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
exports.existInByDestructor = function (source, rules, start, mutators) {
|
|
120
|
+
return rules.every(function (_a) {
|
|
121
|
+
var key = _a.key;
|
|
122
|
+
return mutators.existIn([key], source, start);
|
|
123
|
+
});
|
|
124
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Segments, Node, Pattern } from './types';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export declare class Path {
|
|
4
|
+
entire: string;
|
|
5
|
+
segments: Segments;
|
|
6
|
+
isMatchPattern: boolean;
|
|
7
|
+
isWildMatchPattern: boolean;
|
|
8
|
+
haveExcludePattern: boolean;
|
|
9
|
+
matchScore: number;
|
|
10
|
+
tree: Node;
|
|
11
|
+
private matchCache;
|
|
12
|
+
private includesCache;
|
|
13
|
+
constructor(input: Pattern);
|
|
14
|
+
toString(): string;
|
|
15
|
+
toArray(): Segments;
|
|
16
|
+
get length(): number;
|
|
17
|
+
private parse;
|
|
18
|
+
private parseString;
|
|
19
|
+
concat: (...args: Pattern[]) => Path;
|
|
20
|
+
slice: (start?: number, end?: number) => Path;
|
|
21
|
+
push: (item: Pattern) => this;
|
|
22
|
+
pop: () => void;
|
|
23
|
+
splice: (start: number, deleteCount?: number, ...items: Array<string | number>) => this;
|
|
24
|
+
forEach: (callback: (key: string | number) => any) => void;
|
|
25
|
+
map: (callback: (key: string | number) => any) => any[];
|
|
26
|
+
reduce: <T>(callback: (buf: T, item: string | number, index: number) => T, initial: T) => T;
|
|
27
|
+
getNearestChildPathBy: (target?: Pattern) => Path;
|
|
28
|
+
parent: () => Path;
|
|
29
|
+
includes: (pattern: Pattern) => any;
|
|
30
|
+
transform: <T>(regexp: string | RegExp, callback: (...args: string[]) => T) => string | T;
|
|
31
|
+
match: (pattern: Pattern) => boolean;
|
|
32
|
+
matchAliasGroup: (name: Pattern, alias: Pattern) => boolean;
|
|
33
|
+
existIn: (source?: any, start?: number | Path) => boolean;
|
|
34
|
+
getIn: (source?: any) => any;
|
|
35
|
+
setIn: (source?: any, value?: any) => any;
|
|
36
|
+
deleteIn: (source?: any) => any;
|
|
37
|
+
static match(pattern: Pattern): {
|
|
38
|
+
(target: any): boolean;
|
|
39
|
+
path: Path;
|
|
40
|
+
};
|
|
41
|
+
static transform<T>(pattern: Pattern, regexp: string | RegExp, callback: (...args: string[]) => T): any;
|
|
42
|
+
static parse(path?: Pattern): Path;
|
|
43
|
+
static getPath(path?: Pattern): Path;
|
|
44
|
+
static getIn: (source: any, pattern: Pattern) => any;
|
|
45
|
+
static setIn: (source: any, pattern: Pattern, value: any) => any;
|
|
46
|
+
static deleteIn: (source: any, pattern: Pattern) => any;
|
|
47
|
+
static existIn: (source: any, pattern: Pattern, start?: number | Path) => boolean;
|
|
48
|
+
}
|
|
49
|
+
export default Path;
|