@markuplint/types 3.12.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/lib/check-multi-types.d.ts +2 -5
- package/lib/check-multi-types.js +9 -14
- package/lib/check.d.ts +1 -1
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +33 -33
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +2 -1
- package/lib/defs.js +188 -138
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -4
- package/lib/get-candidate.js +5 -10
- 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 +20 -25
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +8 -21
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +3 -3
- package/lib/number.js +13 -17
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +2 -6
- package/lib/primitive/is-int.js +2 -6
- package/lib/primitive/is-non-zero-uint.js +2 -6
- package/lib/primitive/is-quantity.d.ts +1 -5
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +3 -6
- package/lib/primitive/is-uint.js +4 -8
- package/lib/primitive/range.js +3 -7
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +4 -8
- 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 +58 -70
- package/lib/token/token-collection.js +47 -56
- package/lib/token/token.d.ts +54 -59
- package/lib/token/token.js +14 -20
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +58 -82
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +31 -1087
- package/lib/types.schema.js +1 -2
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +21 -25
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +34 -41
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +12 -16
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
- package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +64 -69
- 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 +24 -28
- 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 +37 -41
- 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 +13 -17
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +11 -15
- 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 +11 -15
- package/lib/whatwg/check-mime-type.d.ts +5 -5
- package/lib/whatwg/check-mime-type.js +11 -17
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +8 -12
- package/lib/whatwg/is-browser-context-name.d.ts +1 -1
- package/lib/whatwg/is-browser-context-name.js +1 -5
- package/lib/whatwg/is-custom-element-name.d.ts +10 -5
- package/lib/whatwg/is-custom-element-name.js +22 -38
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +1 -5
- package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
- package/lib/whatwg/is-navigable-target-name.js +1 -5
- package/package.json +17 -9
- package/test/check.spec.js +0 -89
- package/test/css-syntax.spec.js +0 -170
- package/test/list.spec.js +0 -133
- package/test/primitive/index.spec.js +0 -65
- package/test/rfc/is-bcp-47.spec.js +0 -23
- package/test/token/token-collection.spec.js +0 -146
- package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
- package/test/whatwg/check-autocomplete.spec.js +0 -387
- package/test/whatwg/check-datetime/index.spec.js +0 -336
- package/test/whatwg/check-mime-type.spec.js +0 -59
- package/test/whatwg/is-abs-url.spec.js +0 -8
package/lib/enum.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
function checkEnum(value, type, ref) {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
const disallowToSurroundBySpaces = (_a = type.disallowToSurroundBySpaces) !== null && _a !== void 0 ? _a : true;
|
|
8
|
-
const caseInsensitive = (_b = type.caseInsensitive) !== null && _b !== void 0 ? _b : true;
|
|
1
|
+
import { matched, unmatched } from './match-result.js';
|
|
2
|
+
export function checkEnum(value, type, ref) {
|
|
3
|
+
const disallowToSurroundBySpaces = type.disallowToSurroundBySpaces ?? true;
|
|
4
|
+
const caseInsensitive = type.caseInsensitive ?? true;
|
|
9
5
|
if (!disallowToSurroundBySpaces) {
|
|
10
6
|
value = value.trim();
|
|
11
7
|
}
|
|
12
|
-
let values = type.enum
|
|
8
|
+
let values = [...type.enum];
|
|
13
9
|
if (caseInsensitive) {
|
|
14
10
|
value = value.toLowerCase();
|
|
15
11
|
values = type.enum.map(v => v.toLowerCase());
|
|
16
12
|
}
|
|
17
13
|
const res = values.includes(value);
|
|
18
14
|
if (res) {
|
|
19
|
-
return
|
|
15
|
+
return matched();
|
|
20
16
|
}
|
|
21
|
-
return
|
|
17
|
+
return unmatched(value, 'doesnt-exist-in-enum', {
|
|
22
18
|
ref,
|
|
23
19
|
expects: type.enum.map(value => ({ type: 'const', value })),
|
|
24
20
|
});
|
|
25
21
|
}
|
|
26
|
-
exports.checkEnum = checkEnum;
|
package/lib/get-candidate.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
type NullableString = string | null | undefined;
|
|
2
|
-
export declare function getCandidate(
|
|
3
|
-
value: NullableString,
|
|
4
|
-
...candidates: readonly (NullableString | readonly NullableString[])[]
|
|
5
|
-
): string | undefined;
|
|
2
|
+
export declare function getCandidate(value: NullableString, ...candidates: readonly (NullableString | readonly NullableString[])[]): string | undefined;
|
|
6
3
|
export {};
|
package/lib/get-candidate.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getCandidate = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const leven_1 = tslib_1.__importDefault(require("leven"));
|
|
6
|
-
function getCandidate(value, ...candidates) {
|
|
1
|
+
import leven from 'leven';
|
|
2
|
+
export function getCandidate(value, ...candidates) {
|
|
7
3
|
if (!value) {
|
|
8
4
|
return;
|
|
9
5
|
}
|
|
10
6
|
const list = candidates.flat(2).filter((s) => !!s);
|
|
11
7
|
let candidate;
|
|
12
8
|
let maxRatio = 0;
|
|
13
|
-
|
|
14
|
-
const dist = (
|
|
9
|
+
for (const word of list) {
|
|
10
|
+
const dist = leven(value.trim().toLowerCase(), word.trim().toLowerCase());
|
|
15
11
|
const ratio = 1 - dist / word.length;
|
|
16
12
|
if (0.5 <= ratio && maxRatio < ratio) {
|
|
17
13
|
candidate = word;
|
|
18
14
|
}
|
|
19
15
|
maxRatio = Math.max(ratio, maxRatio);
|
|
20
|
-
}
|
|
16
|
+
}
|
|
21
17
|
if (value === candidate) {
|
|
22
18
|
return;
|
|
23
19
|
}
|
|
24
20
|
return candidate;
|
|
25
21
|
}
|
|
26
|
-
exports.getCandidate = getCandidate;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './whatwg/is-custom-element-name';
|
|
2
|
-
export * from './check';
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './whatwg/is-custom-element-name.js';
|
|
2
|
+
export * from './check.js';
|
|
3
|
+
export * from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./whatwg/is-custom-element-name"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./check"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './whatwg/is-custom-element-name.js';
|
|
2
|
+
export * from './check.js';
|
|
3
|
+
export * from './types.js';
|
package/lib/keyword-type.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Result } from './types';
|
|
2
|
-
import type { KeywordDefinedType } from './types.schema';
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { KeywordDefinedType } from './types.schema.js';
|
|
3
3
|
export declare function checkKeywordType(value: string, type: KeywordDefinedType, cache?: boolean): Result;
|
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,29 +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
|
-
|
|
37
|
-
const def = defs_1.types[type];
|
|
32
|
+
const def = types[type];
|
|
38
33
|
if (!def) {
|
|
39
|
-
|
|
34
|
+
log('The "%s" type is not defined in custom type identifier markuplint specified', type);
|
|
40
35
|
try {
|
|
41
|
-
return
|
|
36
|
+
return cssSyntaxMatch(value, type);
|
|
42
37
|
}
|
|
43
|
-
catch (
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
return
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error instanceof Error && error.message === 'MARKUPLINT_TYPE_NO_EXIST') {
|
|
40
|
+
log("Allow all of any value because the type doesn't exist");
|
|
41
|
+
return matched();
|
|
47
42
|
}
|
|
48
|
-
throw
|
|
43
|
+
throw error;
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
|
-
const matches =
|
|
46
|
+
const matches = isCSSSyntax(def) ? cssSyntaxMatch(value, def) : def.is(value);
|
|
52
47
|
if (!matches.matched) {
|
|
53
48
|
return {
|
|
54
49
|
...matches,
|
|
55
|
-
ref:
|
|
56
|
-
expects:
|
|
50
|
+
ref: matches.ref ?? def.ref,
|
|
51
|
+
expects: matches.expects ?? def.expects,
|
|
57
52
|
};
|
|
58
53
|
}
|
|
59
54
|
return matches;
|
package/lib/list.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Result } from './types';
|
|
2
|
-
import type { List } from './types.schema';
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { List } from './types.schema.js';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
4
|
export declare function checkList(value: string, type: ReadonlyDeep<List>, ref?: string, cache?: boolean): Result;
|
package/lib/list.js
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const token_1 = require("./token");
|
|
7
|
-
function checkList(value, type, ref, cache = true) {
|
|
8
|
-
var _a;
|
|
9
|
-
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);
|
|
10
6
|
const matches = tokens.check({ ref });
|
|
11
7
|
if (!matches.matched) {
|
|
12
8
|
return matches;
|
|
13
9
|
}
|
|
14
10
|
const identTokens = tokens.getIdentTokens();
|
|
15
11
|
for (const token of identTokens) {
|
|
16
|
-
const res =
|
|
12
|
+
const res = check(token.value, type.token, ref, cache);
|
|
17
13
|
if (!res.matched) {
|
|
18
|
-
const { offset, line, column } =
|
|
14
|
+
const { offset, line, column } = Token.shiftLocation(token, res.offset);
|
|
19
15
|
return {
|
|
20
16
|
...res,
|
|
21
|
-
partName:
|
|
17
|
+
partName: res.partName ?? 'the content of the list',
|
|
22
18
|
offset,
|
|
23
19
|
line,
|
|
24
20
|
column,
|
|
25
21
|
};
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
return
|
|
24
|
+
return matched();
|
|
29
25
|
}
|
|
30
|
-
exports.checkList = checkList;
|
package/lib/match-result.d.ts
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
UnmatchedResultReason,
|
|
7
|
-
} from './types';
|
|
8
|
-
export declare function matches(
|
|
9
|
-
checker: FormattedPrimitiveTypeCheck,
|
|
10
|
-
options?: UnmatchedResultOptions & {
|
|
11
|
-
readonly ref?: string;
|
|
12
|
-
readonly reason?: UnmatchedResultReason;
|
|
13
|
-
},
|
|
14
|
-
): (value: string) => UnmatchedResult | MatchedResult;
|
|
1
|
+
import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types.js';
|
|
2
|
+
export declare function matches(checker: FormattedPrimitiveTypeCheck, options?: UnmatchedResultOptions & {
|
|
3
|
+
readonly ref?: string;
|
|
4
|
+
readonly reason?: UnmatchedResultReason;
|
|
5
|
+
}): (value: string) => MatchedResult | UnmatchedResult;
|
|
15
6
|
export declare function matched(): MatchedResult;
|
|
16
|
-
export declare function unmatched(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
options?: UnmatchedResultOptions & {
|
|
20
|
-
readonly ref?: string;
|
|
21
|
-
},
|
|
22
|
-
): UnmatchedResult;
|
|
7
|
+
export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
|
|
8
|
+
readonly ref?: string;
|
|
9
|
+
}): UnmatchedResult;
|
package/lib/match-result.js
CHANGED
|
@@ -1,34 +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) {
|
|
21
|
-
var _a;
|
|
15
|
+
export function unmatched(value, reason, options) {
|
|
22
16
|
return {
|
|
23
17
|
...options,
|
|
24
18
|
matched: false,
|
|
25
|
-
ref:
|
|
19
|
+
ref: options?.ref ?? null,
|
|
26
20
|
raw: value,
|
|
27
21
|
offset: 0,
|
|
28
22
|
length: value.length,
|
|
29
23
|
line: 1,
|
|
30
24
|
column: 1,
|
|
31
|
-
reason: reason
|
|
25
|
+
reason: reason ?? 'syntax-error',
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
|
-
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: Readonly<
|
|
1
|
+
import type { Result } from './types.js';
|
|
2
|
+
import type { Number as TypeNumber } from './types.schema.js';
|
|
3
|
+
export declare function checkNumber(value: string, type: Readonly<TypeNumber>, 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
|
-
const n = parseFloat(value);
|
|
13
|
-
if (!isFinite(n)) {
|
|
14
|
-
return
|
|
9
|
+
const n = Number.parseFloat(value);
|
|
10
|
+
if (!Number.isFinite(n)) {
|
|
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) {
|
|
10
|
-
return value === value.trim() && Number.isFinite(parseFloat(value));
|
|
6
|
+
export function isFloat(value) {
|
|
7
|
+
return value === value.trim() && Number.isFinite(Number.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) {
|
|
10
|
-
return
|
|
6
|
+
export function isInt(value) {
|
|
7
|
+
return /^-?\d+$/.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) {
|
|
10
|
-
return
|
|
6
|
+
export function isNonZeroUint(value) {
|
|
7
|
+
return /^\d+$/.test(value) && !/^0+$/.test(value);
|
|
11
8
|
}
|
|
12
|
-
exports.isNonZeroUint = isNonZeroUint;
|
|
@@ -4,8 +4,4 @@
|
|
|
4
4
|
* @param units
|
|
5
5
|
* @param numberType
|
|
6
6
|
*/
|
|
7
|
-
export declare function isQuantity(
|
|
8
|
-
value: string,
|
|
9
|
-
units: readonly string[],
|
|
10
|
-
numberType?: 'int' | 'uint' | 'float',
|
|
11
|
-
): 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,19 +1,15 @@
|
|
|
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) {
|
|
10
|
-
const matched =
|
|
6
|
+
export function isUint(value, options) {
|
|
7
|
+
const matched = /^\d+$/.test(value);
|
|
11
8
|
if (matched && options) {
|
|
12
|
-
const n = parseInt(value, 10);
|
|
9
|
+
const n = Number.parseInt(value, 10);
|
|
13
10
|
if (options.gt != null) {
|
|
14
|
-
return isFinite(n) && options.gt < n;
|
|
11
|
+
return Number.isFinite(n) && options.gt < n;
|
|
15
12
|
}
|
|
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) {
|
|
12
|
-
const num = parseFloat(value);
|
|
13
|
-
if (isNaN(num)) {
|
|
8
|
+
export function range(value, from, to) {
|
|
9
|
+
const num = Number.parseFloat(value);
|
|
10
|
+
if (Number.isNaN(num)) {
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
16
13
|
return from <= num && num <= to;
|
|
17
14
|
}
|
|
18
|
-
exports.range = range;
|
|
@@ -1,14 +1,11 @@
|
|
|
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
|
-
const matched = value.match(/(
|
|
8
|
+
const matched = value.match(/(^-?\.\d+|^-?\d+(?:\.\d+(?:e[+-]\d+)?)?)([a-z]+$)/i);
|
|
12
9
|
if (!matched) {
|
|
13
10
|
return {
|
|
14
11
|
num: value,
|
|
@@ -17,8 +14,7 @@ function splitUnit(value) {
|
|
|
17
14
|
}
|
|
18
15
|
const [, num, unit] = matched;
|
|
19
16
|
return {
|
|
20
|
-
num: num
|
|
21
|
-
unit: 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