@markuplint/types 3.0.0-dev.25 → 3.0.0-dev.300
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/README.md +63 -61
- package/lib/check-multi-types.d.ts +2 -2
- package/lib/check-multi-types.js +9 -13
- package/lib/check.d.ts +7 -6
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +60 -63
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +163 -91
- package/lib/enum.d.ts +4 -3
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -1
- package/lib/get-candidate.js +3 -8
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -6
- package/lib/keyword-type.d.ts +2 -2
- package/lib/keyword-type.js +17 -21
- package/lib/list.d.ts +4 -3
- package/lib/list.js +9 -13
- package/lib/match-result.d.ts +4 -4
- package/lib/match-result.js +6 -12
- package/lib/number.d.ts +3 -3
- package/lib/number.js +11 -15
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +1 -5
- package/lib/primitive/is-int.js +1 -5
- package/lib/primitive/is-non-zero-uint.js +1 -5
- package/lib/primitive/is-quantity.d.ts +1 -1
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +1 -1
- package/lib/primitive/is-uint.js +1 -5
- package/lib/primitive/range.js +1 -5
- package/lib/primitive/split-unit.js +3 -7
- package/lib/rfc/is-bcp-47.d.ts +1 -1
- package/lib/rfc/is-bcp-47.js +3 -7
- package/lib/token/index.d.ts +2 -2
- package/lib/token/index.js +2 -7
- package/lib/token/token-collection.d.ts +13 -13
- package/lib/token/token-collection.js +55 -50
- package/lib/token/token.d.ts +11 -10
- package/lib/token/token.js +16 -24
- package/lib/token/types.d.ts +3 -0
- package/lib/types.d.ts +47 -46
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +2 -2
- package/lib/types.schema.js +1 -3
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +16 -20
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +28 -32
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +9 -13
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +48 -44
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
- package/lib/whatwg/check-datetime/index.d.ts +1 -1
- package/lib/whatwg/check-datetime/index.js +25 -29
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
- package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/month-string.js +9 -13
- package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-string.js +9 -13
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +9 -13
- package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/year-string.js +9 -13
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
- package/lib/whatwg/check-mime-type.d.ts +1 -1
- package/lib/whatwg/check-mime-type.js +12 -18
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +1 -5
- package/lib/whatwg/is-browser-context-name.d.ts +3 -1
- package/lib/whatwg/is-browser-context-name.js +3 -5
- package/lib/whatwg/is-custom-element-name.d.ts +1 -1
- package/lib/whatwg/is-custom-element-name.js +1 -5
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +2 -6
- package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
- package/lib/whatwg/is-navigable-target-name.js +20 -0
- package/package.json +19 -14
- package/types.schema.json +314 -311
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/lib/check.spec.js +0 -76
- package/lib/css-syntax.spec.d.ts +0 -1
- package/lib/css-syntax.spec.js +0 -157
- package/lib/list.spec.d.ts +0 -1
- package/lib/list.spec.js +0 -129
- package/lib/primitive/index.spec.d.ts +0 -1
- package/lib/primitive/index.spec.js +0 -62
- package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
- package/lib/rfc/is-bcp-47.spec.js +0 -19
- package/lib/token/token-collection.spec.d.ts +0 -1
- package/lib/token/token-collection.spec.js +0 -144
- package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
- package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
- package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
- package/lib/whatwg/check-autocomplete.spec.js +0 -379
- package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
- package/lib/whatwg/check-datetime/index.spec.js +0 -318
- package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
- package/lib/whatwg/check-mime-type.spec.js +0 -58
- package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
- package/lib/whatwg/is-abs-url.spec.js +0 -8
- package/patches/css-tree+2.3.1.patch +0 -23
- package/src/check-multi-types.ts +0 -35
- package/src/check.spec.ts +0 -83
- package/src/check.ts +0 -48
- package/src/css-syntax.spec.ts +0 -167
- package/src/css-syntax.ts +0 -188
- package/src/debug.ts +0 -3
- package/src/defs.ts +0 -811
- package/src/enum.ts +0 -25
- package/src/get-candidate.ts +0 -24
- package/src/index.ts +0 -3
- package/src/keyword-type.ts +0 -64
- package/src/list.spec.ts +0 -133
- package/src/list.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- package/src/primitive/index.spec.ts +0 -65
- package/src/primitive/index.ts +0 -7
- package/src/primitive/is-float.ts +0 -8
- package/src/primitive/is-int.ts +0 -8
- package/src/primitive/is-non-zero-uint.ts +0 -8
- package/src/primitive/is-quantity.ts +0 -38
- package/src/primitive/is-uint.ts +0 -15
- package/src/primitive/range.ts +0 -14
- package/src/primitive/split-unit.ts +0 -20
- package/src/rfc/is-bcp-47.spec.ts +0 -23
- package/src/rfc/is-bcp-47.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.spec.ts +0 -147
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1113
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- package/src/whatwg/check-autocomplete.spec.ts +0 -387
- package/src/whatwg/check-autocomplete.ts +0 -380
- package/src/whatwg/check-datetime/date-string.ts +0 -44
- package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
- package/src/whatwg/check-datetime/duration-string.ts +0 -399
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
- package/src/whatwg/check-datetime/index.spec.ts +0 -333
- package/src/whatwg/check-datetime/index.ts +0 -36
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
- package/src/whatwg/check-datetime/month-string.ts +0 -31
- package/src/whatwg/check-datetime/time-string.ts +0 -49
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
- package/src/whatwg/check-datetime/week-string.ts +0 -41
- package/src/whatwg/check-datetime/year-string.ts +0 -26
- package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
- package/src/whatwg/check-mime-type.spec.ts +0 -59
- package/src/whatwg/check-mime-type.ts +0 -46
- package/src/whatwg/is-abs-url.spec.ts +0 -8
- package/src/whatwg/is-abs-url.ts +0 -31
- package/src/whatwg/is-browser-context-name.ts +0 -16
- package/src/whatwg/is-custom-element-name.ts +0 -76
- package/src/whatwg/is-itemprop-name.ts +0 -17
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
- /package/lib/{check.spec.d.ts → token/types.js} +0 -0
package/lib/keyword-type.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const debug_1 = require("./debug");
|
|
7
|
-
const defs_1 = require("./defs");
|
|
8
|
-
const match_result_1 = require("./match-result");
|
|
1
|
+
import { isCSSSyntax } from './check.js';
|
|
2
|
+
import { cssSyntaxMatch } from './css-syntax.js';
|
|
3
|
+
import { log } from './debug.js';
|
|
4
|
+
import { types } from './defs.js';
|
|
5
|
+
import { matched } from './match-result.js';
|
|
9
6
|
const resultCache = new Map();
|
|
10
7
|
const CACHE_KEY_PREFIX = '@markuplint/types/checkKeywordType/cache:::';
|
|
11
|
-
function checkKeywordType(value, type, cache = true) {
|
|
8
|
+
export function checkKeywordType(value, type, cache = true) {
|
|
12
9
|
const key = `${CACHE_KEY_PREFIX}${value}${type}`;
|
|
13
10
|
if (cache) {
|
|
14
11
|
const cachedResult = resultCache.get(key);
|
|
15
12
|
if (cachedResult) {
|
|
16
|
-
|
|
13
|
+
log('Restore cache: %s / %s', value, type);
|
|
17
14
|
return cachedResult;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
17
|
const result = _checkKeywordType(value, type);
|
|
21
18
|
if (cache) {
|
|
22
19
|
resultCache.set(key, result);
|
|
23
|
-
if (
|
|
24
|
-
|
|
20
|
+
if (log.enabled) {
|
|
21
|
+
log('Cache checking: %O', {
|
|
25
22
|
input: value,
|
|
26
23
|
type,
|
|
27
24
|
key,
|
|
@@ -31,28 +28,27 @@ function checkKeywordType(value, type, cache = true) {
|
|
|
31
28
|
}
|
|
32
29
|
return result;
|
|
33
30
|
}
|
|
34
|
-
exports.checkKeywordType = checkKeywordType;
|
|
35
31
|
function _checkKeywordType(value, type) {
|
|
36
|
-
const def =
|
|
32
|
+
const def = types[type];
|
|
37
33
|
if (!def) {
|
|
38
|
-
|
|
34
|
+
log('The "%s" type is not defined in custom type identifier markuplint specified', type);
|
|
39
35
|
try {
|
|
40
|
-
return
|
|
36
|
+
return cssSyntaxMatch(value, type);
|
|
41
37
|
}
|
|
42
38
|
catch (e) {
|
|
43
39
|
if (e instanceof Error && e.message === 'MARKUPLINT_TYPE_NO_EXIST') {
|
|
44
|
-
|
|
45
|
-
return
|
|
40
|
+
log("Allow all of any value because the type doesn't exist");
|
|
41
|
+
return matched();
|
|
46
42
|
}
|
|
47
43
|
throw e;
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
|
-
const matches =
|
|
46
|
+
const matches = isCSSSyntax(def) ? cssSyntaxMatch(value, def) : def.is(value);
|
|
51
47
|
if (!matches.matched) {
|
|
52
48
|
return {
|
|
53
49
|
...matches,
|
|
54
|
-
ref: matches.ref
|
|
55
|
-
expects: matches.expects
|
|
50
|
+
ref: matches.ref ?? def.ref,
|
|
51
|
+
expects: matches.expects ?? def.expects,
|
|
56
52
|
};
|
|
57
53
|
}
|
|
58
54
|
return matches;
|
package/lib/list.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Result } from './types';
|
|
2
|
-
import type { List } from './types.schema';
|
|
3
|
-
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { List } from './types.schema.js';
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
+
export declare function checkList(value: string, type: ReadonlyDeep<List>, ref?: string, cache?: boolean): Result;
|
package/lib/list.js
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const token_1 = require("./token");
|
|
7
|
-
function checkList(value, type, ref, cache = true) {
|
|
8
|
-
const tokens = new token_1.TokenCollection(value, type);
|
|
1
|
+
import { check } from './check.js';
|
|
2
|
+
import { matched } from './match-result.js';
|
|
3
|
+
import { Token, TokenCollection } from './token/index.js';
|
|
4
|
+
export function checkList(value, type, ref, cache = true) {
|
|
5
|
+
const tokens = new TokenCollection(value, type);
|
|
9
6
|
const matches = tokens.check({ ref });
|
|
10
7
|
if (!matches.matched) {
|
|
11
8
|
return matches;
|
|
12
9
|
}
|
|
13
10
|
const identTokens = tokens.getIdentTokens();
|
|
14
11
|
for (const token of identTokens) {
|
|
15
|
-
const res =
|
|
12
|
+
const res = check(token.value, type.token, ref, cache);
|
|
16
13
|
if (!res.matched) {
|
|
17
|
-
const { offset, line, column } =
|
|
14
|
+
const { offset, line, column } = Token.shiftLocation(token, res.offset);
|
|
18
15
|
return {
|
|
19
16
|
...res,
|
|
20
|
-
partName: res.partName
|
|
17
|
+
partName: res.partName ?? 'the content of the list',
|
|
21
18
|
offset,
|
|
22
19
|
line,
|
|
23
20
|
column,
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
return
|
|
24
|
+
return matched();
|
|
28
25
|
}
|
|
29
|
-
exports.checkList = checkList;
|
package/lib/match-result.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types';
|
|
1
|
+
import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types.js';
|
|
2
2
|
export declare function matches(checker: FormattedPrimitiveTypeCheck, options?: UnmatchedResultOptions & {
|
|
3
|
-
ref?: string;
|
|
4
|
-
reason?: UnmatchedResultReason;
|
|
3
|
+
readonly ref?: string;
|
|
4
|
+
readonly reason?: UnmatchedResultReason;
|
|
5
5
|
}): (value: string) => MatchedResult | UnmatchedResult;
|
|
6
6
|
export declare function matched(): MatchedResult;
|
|
7
7
|
export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
|
|
8
|
-
ref?: string;
|
|
8
|
+
readonly ref?: string;
|
|
9
9
|
}): UnmatchedResult;
|
package/lib/match-result.js
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unmatched = exports.matched = exports.matches = void 0;
|
|
4
|
-
function matches(checker, options) {
|
|
1
|
+
export function matches(checker, options) {
|
|
5
2
|
return (value) => {
|
|
6
3
|
const valid = checker(value);
|
|
7
4
|
if (!valid && !value) {
|
|
8
5
|
return unmatched(value, 'empty-token', options);
|
|
9
6
|
}
|
|
10
|
-
return valid ? matched() : unmatched(value, options
|
|
7
|
+
return valid ? matched() : unmatched(value, options?.reason, options);
|
|
11
8
|
};
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
function matched() {
|
|
10
|
+
export function matched() {
|
|
15
11
|
return {
|
|
16
12
|
matched: true,
|
|
17
13
|
};
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
function unmatched(value, reason, options) {
|
|
15
|
+
export function unmatched(value, reason, options) {
|
|
21
16
|
return {
|
|
22
17
|
...options,
|
|
23
18
|
matched: false,
|
|
24
|
-
ref:
|
|
19
|
+
ref: options?.ref ?? null,
|
|
25
20
|
raw: value,
|
|
26
21
|
offset: 0,
|
|
27
22
|
length: value.length,
|
|
28
23
|
line: 1,
|
|
29
24
|
column: 1,
|
|
30
|
-
reason: reason
|
|
25
|
+
reason: reason ?? 'syntax-error',
|
|
31
26
|
};
|
|
32
27
|
}
|
|
33
|
-
exports.unmatched = unmatched;
|
package/lib/number.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Result } from './types';
|
|
2
|
-
import type { Number } from './types.schema';
|
|
3
|
-
export declare function checkNumber(value: string, type: Number
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { Number } from './types.schema.js';
|
|
3
|
+
export declare function checkNumber(value: string, type: Readonly<Number>, ref?: string): Result;
|
package/lib/number.js
CHANGED
|
@@ -1,41 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const match_result_1 = require("./match-result");
|
|
5
|
-
const primitive_1 = require("./primitive");
|
|
6
|
-
function checkNumber(value, type, ref) {
|
|
1
|
+
import { matched, unmatched } from './match-result.js';
|
|
2
|
+
import { isFloat, isInt } from './primitive/index.js';
|
|
3
|
+
export function checkNumber(value, type, ref) {
|
|
7
4
|
if (!value) {
|
|
8
|
-
return
|
|
5
|
+
return unmatched(value, 'empty-token');
|
|
9
6
|
}
|
|
10
|
-
const syntaxMatched = type.type === 'float' ?
|
|
7
|
+
const syntaxMatched = type.type === 'float' ? isFloat(value) : isInt(value);
|
|
11
8
|
if (syntaxMatched) {
|
|
12
9
|
const n = parseFloat(value);
|
|
13
10
|
if (!isFinite(n)) {
|
|
14
|
-
return
|
|
11
|
+
return unmatched(value, 'unexpected-token');
|
|
15
12
|
}
|
|
16
13
|
const clampable = type.clampable;
|
|
17
14
|
const isInt = type.type === 'integer';
|
|
18
15
|
if (type.gt != null && n <= type.gt) {
|
|
19
|
-
return
|
|
16
|
+
return unmatched(value, 'out-of-range', {
|
|
20
17
|
candidate: clampable && isInt ? `${type.gt + 1}` : undefined,
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
20
|
if (type.gte != null && n < type.gte) {
|
|
24
|
-
return
|
|
21
|
+
return unmatched(value, 'out-of-range', {
|
|
25
22
|
candidate: clampable ? `${type.gte}` : undefined,
|
|
26
23
|
});
|
|
27
24
|
}
|
|
28
25
|
if (type.lt != null && type.lt <= n) {
|
|
29
|
-
return
|
|
26
|
+
return unmatched(value, 'out-of-range', {
|
|
30
27
|
candidate: clampable && isInt ? `${type.lt - 1}` : undefined,
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
30
|
if (type.lte != null && type.lte < n) {
|
|
34
|
-
return
|
|
31
|
+
return unmatched(value, 'out-of-range', {
|
|
35
32
|
candidate: clampable ? `${type.lte}` : undefined,
|
|
36
33
|
});
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
return syntaxMatched ?
|
|
36
|
+
return syntaxMatched ? matched() : unmatched(value, 'unexpected-token');
|
|
40
37
|
}
|
|
41
|
-
exports.checkNumber = checkNumber;
|
package/lib/primitive/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { isInt } from './is-int';
|
|
2
|
-
export { isUint } from './is-uint';
|
|
3
|
-
export { isFloat } from './is-float';
|
|
4
|
-
export { isNonZeroUint } from './is-non-zero-uint';
|
|
5
|
-
export { isQuantity } from './is-quantity';
|
|
6
|
-
export { splitUnit } from './split-unit';
|
|
7
|
-
export { range } from './range';
|
|
1
|
+
export { isInt } from './is-int.js';
|
|
2
|
+
export { isUint } from './is-uint.js';
|
|
3
|
+
export { isFloat } from './is-float.js';
|
|
4
|
+
export { isNonZeroUint } from './is-non-zero-uint.js';
|
|
5
|
+
export { isQuantity } from './is-quantity.js';
|
|
6
|
+
export { splitUnit } from './split-unit.js';
|
|
7
|
+
export { range } from './range.js';
|
package/lib/primitive/index.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var is_float_1 = require("./is-float");
|
|
9
|
-
Object.defineProperty(exports, "isFloat", { enumerable: true, get: function () { return is_float_1.isFloat; } });
|
|
10
|
-
var is_non_zero_uint_1 = require("./is-non-zero-uint");
|
|
11
|
-
Object.defineProperty(exports, "isNonZeroUint", { enumerable: true, get: function () { return is_non_zero_uint_1.isNonZeroUint; } });
|
|
12
|
-
var is_quantity_1 = require("./is-quantity");
|
|
13
|
-
Object.defineProperty(exports, "isQuantity", { enumerable: true, get: function () { return is_quantity_1.isQuantity; } });
|
|
14
|
-
var split_unit_1 = require("./split-unit");
|
|
15
|
-
Object.defineProperty(exports, "splitUnit", { enumerable: true, get: function () { return split_unit_1.splitUnit; } });
|
|
16
|
-
var range_1 = require("./range");
|
|
17
|
-
Object.defineProperty(exports, "range", { enumerable: true, get: function () { return range_1.range; } });
|
|
1
|
+
export { isInt } from './is-int.js';
|
|
2
|
+
export { isUint } from './is-uint.js';
|
|
3
|
+
export { isFloat } from './is-float.js';
|
|
4
|
+
export { isNonZeroUint } from './is-non-zero-uint.js';
|
|
5
|
+
export { isQuantity } from './is-quantity.js';
|
|
6
|
+
export { splitUnit } from './split-unit.js';
|
|
7
|
+
export { range } from './range.js';
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isFloat = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#floating-point-numbers
|
|
6
3
|
*
|
|
7
4
|
* @param value
|
|
8
5
|
*/
|
|
9
|
-
function isFloat(value) {
|
|
6
|
+
export function isFloat(value) {
|
|
10
7
|
return value === value.trim() && Number.isFinite(parseFloat(value));
|
|
11
8
|
}
|
|
12
|
-
exports.isFloat = isFloat;
|
package/lib/primitive/is-int.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isInt = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#signed-integers
|
|
6
3
|
*
|
|
7
4
|
* @param value
|
|
8
5
|
*/
|
|
9
|
-
function isInt(value) {
|
|
6
|
+
export function isInt(value) {
|
|
10
7
|
return /^-?[0-9]+$/.test(value);
|
|
11
8
|
}
|
|
12
|
-
exports.isInt = isInt;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNonZeroUint = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Non-negative integer greater than zero
|
|
6
3
|
*
|
|
7
4
|
* @param value
|
|
8
5
|
*/
|
|
9
|
-
function isNonZeroUint(value) {
|
|
6
|
+
export function isNonZeroUint(value) {
|
|
10
7
|
return /^[0-9]+$/.test(value) && !/^0+$/.test(value);
|
|
11
8
|
}
|
|
12
|
-
exports.isNonZeroUint = isNonZeroUint;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param units
|
|
5
5
|
* @param numberType
|
|
6
6
|
*/
|
|
7
|
-
export declare function isQuantity(value: string, units: string[], numberType?: 'int' | 'uint' | 'float'): boolean;
|
|
7
|
+
export declare function isQuantity(value: string, units: readonly string[], numberType?: 'int' | 'uint' | 'float'): boolean;
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const is_int_1 = require("./is-int");
|
|
6
|
-
const is_uint_1 = require("./is-uint");
|
|
7
|
-
const split_unit_1 = require("./split-unit");
|
|
1
|
+
import { isFloat } from './is-float.js';
|
|
2
|
+
import { isInt } from './is-int.js';
|
|
3
|
+
import { isUint } from './is-uint.js';
|
|
4
|
+
import { splitUnit } from './split-unit.js';
|
|
8
5
|
/**
|
|
9
6
|
*
|
|
10
7
|
* @param value
|
|
11
8
|
* @param units
|
|
12
9
|
* @param numberType
|
|
13
10
|
*/
|
|
14
|
-
function isQuantity(value, units, numberType = 'float') {
|
|
15
|
-
const { num, unit } =
|
|
11
|
+
export function isQuantity(value, units, numberType = 'float') {
|
|
12
|
+
const { num, unit } = splitUnit(value);
|
|
16
13
|
if (!units.includes(unit.toLowerCase())) {
|
|
17
14
|
return false;
|
|
18
15
|
}
|
|
19
16
|
switch (numberType) {
|
|
20
17
|
case 'int': {
|
|
21
|
-
if (!
|
|
18
|
+
if (!isInt(num)) {
|
|
22
19
|
return false;
|
|
23
20
|
}
|
|
24
21
|
break;
|
|
25
22
|
}
|
|
26
23
|
case 'uint': {
|
|
27
|
-
if (!
|
|
24
|
+
if (!isUint(num)) {
|
|
28
25
|
return false;
|
|
29
26
|
}
|
|
30
27
|
break;
|
|
31
28
|
}
|
|
32
29
|
case 'float': {
|
|
33
|
-
if (!
|
|
30
|
+
if (!isFloat(num)) {
|
|
34
31
|
return false;
|
|
35
32
|
}
|
|
36
33
|
break;
|
|
@@ -38,4 +35,3 @@ function isQuantity(value, units, numberType = 'float') {
|
|
|
38
35
|
}
|
|
39
36
|
return true;
|
|
40
37
|
}
|
|
41
|
-
exports.isQuantity = isQuantity;
|
package/lib/primitive/is-uint.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUint = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#non-negative-integers
|
|
6
3
|
*
|
|
7
4
|
* @param value
|
|
8
5
|
*/
|
|
9
|
-
function isUint(value, options) {
|
|
6
|
+
export function isUint(value, options) {
|
|
10
7
|
const matched = /^[0-9]+$/.test(value);
|
|
11
8
|
if (matched && options) {
|
|
12
9
|
const n = parseInt(value, 10);
|
|
@@ -16,4 +13,3 @@ function isUint(value, options) {
|
|
|
16
13
|
}
|
|
17
14
|
return matched;
|
|
18
15
|
}
|
|
19
|
-
exports.isUint = isUint;
|
package/lib/primitive/range.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.range = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* It is in the range between `from` and `to`.
|
|
6
3
|
*
|
|
@@ -8,11 +5,10 @@ exports.range = void 0;
|
|
|
8
5
|
* @param from
|
|
9
6
|
* @param to
|
|
10
7
|
*/
|
|
11
|
-
function range(value, from, to) {
|
|
8
|
+
export function range(value, from, to) {
|
|
12
9
|
const num = parseFloat(value);
|
|
13
10
|
if (isNaN(num)) {
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
16
13
|
return from <= num && num <= to;
|
|
17
14
|
}
|
|
18
|
-
exports.range = range;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitUnit = void 0;
|
|
4
1
|
/**
|
|
5
2
|
*
|
|
6
3
|
* @param value
|
|
7
4
|
* @returns
|
|
8
5
|
*/
|
|
9
|
-
function splitUnit(value) {
|
|
6
|
+
export function splitUnit(value) {
|
|
10
7
|
value = value.trim().toLowerCase();
|
|
11
8
|
const matched = value.match(/(^-?\.[0-9]+|^-?[0-9]+(?:\.[0-9]+(?:e[+-][0-9]+)?)?)([a-z]+$)/i);
|
|
12
9
|
if (!matched) {
|
|
@@ -17,8 +14,7 @@ function splitUnit(value) {
|
|
|
17
14
|
}
|
|
18
15
|
const [, num, unit] = matched;
|
|
19
16
|
return {
|
|
20
|
-
num,
|
|
21
|
-
unit,
|
|
17
|
+
num: num ?? value,
|
|
18
|
+
unit: unit ?? '',
|
|
22
19
|
};
|
|
23
20
|
}
|
|
24
|
-
exports.splitUnit = splitUnit;
|
package/lib/rfc/is-bcp-47.d.ts
CHANGED
package/lib/rfc/is-bcp-47.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBCP47 = void 0;
|
|
4
|
-
const bcp_47_1 = require("bcp-47");
|
|
1
|
+
import { parse } from 'bcp-47';
|
|
5
2
|
/**
|
|
6
3
|
* @see https://tools.ietf.org/rfc/bcp/bcp47.html
|
|
7
4
|
*/
|
|
8
|
-
const isBCP47 = () => {
|
|
5
|
+
export const isBCP47 = () => {
|
|
9
6
|
return value => {
|
|
10
|
-
const { language } =
|
|
7
|
+
const { language } = parse(value);
|
|
11
8
|
return !!language;
|
|
12
9
|
};
|
|
13
10
|
};
|
|
14
|
-
exports.isBCP47 = isBCP47;
|
package/lib/token/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Token } from './token';
|
|
2
|
-
export { TokenCollection } from './token-collection';
|
|
1
|
+
export { Token } from './token.js';
|
|
2
|
+
export { TokenCollection } from './token-collection.js';
|
package/lib/token/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TokenCollection = exports.Token = void 0;
|
|
4
|
-
var token_1 = require("./token");
|
|
5
|
-
Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return token_1.Token; } });
|
|
6
|
-
var token_collection_1 = require("./token-collection");
|
|
7
|
-
Object.defineProperty(exports, "TokenCollection", { enumerable: true, get: function () { return token_collection_1.TokenCollection; } });
|
|
1
|
+
export { Token } from './token.js';
|
|
2
|
+
export { TokenCollection } from './token-collection.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Expect, Result, List } from '../types';
|
|
3
|
-
import { Token } from './token';
|
|
1
|
+
import type { TokenValue } from './types.js';
|
|
2
|
+
import type { Expect, Result, List, UnmatchedResult } from '../types.js';
|
|
3
|
+
import { Token } from './token.js';
|
|
4
4
|
type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
|
|
5
5
|
specificSeparator: string | string[];
|
|
6
6
|
}>;
|
|
7
|
-
export type TokenEachCheck = (head: Token | null, tail: TokenCollection) => Result | void;
|
|
7
|
+
export type TokenEachCheck = (head: Readonly<Token> | null, tail: TokenCollection) => Result | void;
|
|
8
8
|
export declare class TokenCollection extends Array<Token> {
|
|
9
|
-
static fromPatterns(value: Token | string, patterns: RegExp[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
|
|
9
|
+
static fromPatterns(value: Readonly<Token> | string, patterns: readonly Readonly<RegExp>[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
|
|
10
10
|
repeat?: boolean;
|
|
11
11
|
}): TokenCollection;
|
|
12
12
|
static get [Symbol.species](): ArrayConstructor;
|
|
@@ -24,20 +24,20 @@ export declare class TokenCollection extends Array<Token> {
|
|
|
24
24
|
expects?: Expect[];
|
|
25
25
|
ref?: string;
|
|
26
26
|
cache?: boolean;
|
|
27
|
-
}): import("
|
|
27
|
+
}): import("../types.js").MatchedResult | UnmatchedResult;
|
|
28
28
|
chunk(split: number): TokenCollection[];
|
|
29
|
-
compareTokens(callback: (prev: Token
|
|
29
|
+
compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
|
|
30
30
|
divide(position: number): readonly [TokenCollection, TokenCollection];
|
|
31
|
-
eachCheck(...callbacks: TokenEachCheck[]): Result;
|
|
32
|
-
filter(callback:
|
|
33
|
-
getConsecutiveToken(tokenType: number): Token | null;
|
|
31
|
+
eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
|
|
32
|
+
filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
|
|
33
|
+
getConsecutiveToken(tokenType: number): Readonly<Token> | null;
|
|
34
34
|
getDuplicated(): Token | null;
|
|
35
35
|
getIdentTokens(): TokenCollection;
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
38
38
|
* @param value The token value or the token type or its list
|
|
39
39
|
*/
|
|
40
|
-
has(value:
|
|
40
|
+
has(value: TokenValue): boolean;
|
|
41
41
|
headAndTail(): {
|
|
42
42
|
head: Token | null;
|
|
43
43
|
tail: TokenCollection;
|
|
@@ -46,10 +46,10 @@ export declare class TokenCollection extends Array<Token> {
|
|
|
46
46
|
*
|
|
47
47
|
* @param value The token value or the token type or its list
|
|
48
48
|
*/
|
|
49
|
-
search(value:
|
|
49
|
+
search(value: TokenValue): Token | null;
|
|
50
50
|
takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
|
|
51
51
|
unexpectedLastToken: boolean;
|
|
52
|
-
expectedTokenNumber: number;
|
|
52
|
+
expectedTokenNumber: number | undefined;
|
|
53
53
|
token: Token;
|
|
54
54
|
} | null;
|
|
55
55
|
toJSON(): {
|