@markuplint/ml-config 3.5.0 → 3.6.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/lib/merge-config.d.ts +2 -1
- package/lib/merge-config.js +3 -3
- package/lib/types.d.ts +1 -1
- package/lib/utils.d.ts +7 -2
- package/lib/utils.js +5 -5
- package/package.json +4 -3
package/lib/merge-config.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Config,
|
|
1
|
+
import type { Config, AnyRule, AnyRuleV2 } from './types';
|
|
2
|
+
import type { Nullable } from '@markuplint/shared';
|
|
2
3
|
export declare function mergeConfig(a: Config, b: Config): Config;
|
|
3
4
|
export declare function mergeRule(a: Nullable<AnyRule | AnyRuleV2>, b: AnyRule | AnyRuleV2): AnyRule;
|
package/lib/merge-config.js
CHANGED
|
@@ -70,10 +70,10 @@ function mergeRule(a, b) {
|
|
|
70
70
|
exports.mergeRule = mergeRule;
|
|
71
71
|
function mergeObject(a, b) {
|
|
72
72
|
if (a == null) {
|
|
73
|
-
return b
|
|
73
|
+
return b !== null && b !== void 0 ? b : undefined;
|
|
74
74
|
}
|
|
75
75
|
if (b == null) {
|
|
76
|
-
return a
|
|
76
|
+
return a !== null && a !== void 0 ? a : undefined;
|
|
77
77
|
}
|
|
78
78
|
const res = (0, deepmerge_1.default)(a, b);
|
|
79
79
|
(0, utils_1.deleteUndefProp)(res);
|
|
@@ -135,7 +135,7 @@ function mergeRules(a, b) {
|
|
|
135
135
|
return b && optimizeRules(b);
|
|
136
136
|
}
|
|
137
137
|
if (b == null) {
|
|
138
|
-
return
|
|
138
|
+
return optimizeRules(a);
|
|
139
139
|
}
|
|
140
140
|
const res = optimizeRules(a);
|
|
141
141
|
for (const [key, rule] of Object.entries(b)) {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ParserOptions } from '@markuplint/ml-ast';
|
|
2
2
|
import type { RegexSelector } from '@markuplint/selector';
|
|
3
|
+
import type { Nullable } from '@markuplint/shared';
|
|
3
4
|
export type { RegexSelector } from '@markuplint/selector';
|
|
4
5
|
export type Config = {
|
|
5
6
|
readonly $schema?: string;
|
|
@@ -184,4 +185,3 @@ export type GlobalRuleInfo<T extends RuleConfigValue, O extends PlainData = unde
|
|
|
184
185
|
nodeRules: RuleInfo<T, O>[];
|
|
185
186
|
childNodeRules: RuleInfo<T, O>[];
|
|
186
187
|
};
|
|
187
|
-
export type Nullable<T> = T | null | undefined;
|
package/lib/utils.d.ts
CHANGED
|
@@ -7,8 +7,13 @@ import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfi
|
|
|
7
7
|
* @param data Captured string for replacement
|
|
8
8
|
*/
|
|
9
9
|
export declare function provideValue(template: string, data: Readonly<Record<string, string>>): string | undefined;
|
|
10
|
-
export declare function exchangeValueOnRule(
|
|
11
|
-
|
|
10
|
+
export declare function exchangeValueOnRule(
|
|
11
|
+
rule: AnyRule | AnyRuleV2,
|
|
12
|
+
data: Readonly<Record<string, string>>,
|
|
13
|
+
): AnyRule | undefined;
|
|
14
|
+
export declare function cleanOptions(
|
|
15
|
+
rule: RuleConfig<RuleConfigValue, PlainData> | RuleConfigV2<RuleConfigValue, PlainData>,
|
|
16
|
+
): RuleConfig<RuleConfigValue, PlainData>;
|
|
12
17
|
export declare function isRuleConfigValue(v: any): v is RuleConfigValue;
|
|
13
18
|
/**
|
|
14
19
|
*
|
package/lib/utils.js
CHANGED
|
@@ -39,7 +39,7 @@ function exchangeValueOnRule(rule, data) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
const options = extractOptions(result);
|
|
42
|
-
if (options) {
|
|
42
|
+
if (options != null && options !== '' && options !== 0) {
|
|
43
43
|
const newOptions = exchangeOption(options, data);
|
|
44
44
|
result = {
|
|
45
45
|
...result,
|
|
@@ -54,7 +54,7 @@ function exchangeValueOnRule(rule, data) {
|
|
|
54
54
|
const exchangedValue = exchangeValue(result.reason, data);
|
|
55
55
|
result = {
|
|
56
56
|
...result,
|
|
57
|
-
reason: exchangedValue ? `${exchangedValue}` : undefined,
|
|
57
|
+
reason: exchangedValue != null ? `${exchangedValue}` : undefined,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
deleteUndefProp(result);
|
|
@@ -109,10 +109,10 @@ exports.deleteUndefProp = deleteUndefProp;
|
|
|
109
109
|
* @returns
|
|
110
110
|
*/
|
|
111
111
|
function extractOptions(rule) {
|
|
112
|
-
if ('options' in rule && rule.options) {
|
|
112
|
+
if ('options' in rule && rule.options != null) {
|
|
113
113
|
return rule.options;
|
|
114
114
|
}
|
|
115
|
-
if ('option' in rule && rule.option) {
|
|
115
|
+
if ('option' in rule && rule.option != null) {
|
|
116
116
|
return rule.option;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -132,7 +132,7 @@ function exchangeValue(rule, data) {
|
|
|
132
132
|
return val;
|
|
133
133
|
})
|
|
134
134
|
.filter((item) => item !== undefined);
|
|
135
|
-
return ruleArray.length ? ruleArray : undefined;
|
|
135
|
+
return ruleArray.length > 0 ? ruleArray : undefined;
|
|
136
136
|
}
|
|
137
137
|
return rule;
|
|
138
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "JSON Schema and TypeScript types of markuplint configure JSON",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@markuplint/ml-ast": "3.1.0",
|
|
23
|
+
"@markuplint/shared": "3.5.0",
|
|
23
24
|
"@types/mustache": "^4.2.2"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@markuplint/selector": "3.
|
|
27
|
+
"@markuplint/selector": "3.6.1",
|
|
27
28
|
"deepmerge": "^4.2.2",
|
|
28
29
|
"is-plain-object": "^5.0.0",
|
|
29
30
|
"mustache": "^4.2.0",
|
|
30
31
|
"type-fest": "^3.6.1"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "3cdf5a088b2da03773d5d4461d0e65ec32290a00"
|
|
33
34
|
}
|