@markuplint/types 3.3.0 → 3.4.0
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/check-multi-types.d.ts +1 -4
- package/lib/check.d.ts +6 -5
- package/lib/css-syntax.js +11 -1
- package/lib/enum.d.ts +2 -1
- package/lib/enum.js +1 -1
- package/lib/get-candidate.d.ts +1 -4
- package/lib/list.d.ts +2 -1
- package/lib/match-result.d.ts +8 -21
- package/lib/number.d.ts +1 -1
- package/lib/primitive/is-quantity.d.ts +1 -1
- package/lib/primitive/is-uint.d.ts +3 -6
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/token/token-collection.d.ts +58 -65
- package/lib/token/token-collection.js +5 -5
- package/lib/token/token.d.ts +53 -57
- package/lib/token/token.js +8 -12
- package/lib/token/types.d.ts +3 -0
- package/lib/token/types.js +2 -0
- package/lib/types.d.ts +55 -79
- package/lib/types.schema.d.ts +31 -1084
- package/lib/whatwg/check-autocomplete.js +2 -2
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -21
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
- package/lib/whatwg/check-mime-type.d.ts +4 -4
- package/package.json +4 -3
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
import type { CustomSyntaxCheck, UnmatchedResult } from './types';
|
|
2
|
-
export declare function checkMultiTypes(
|
|
3
|
-
value: string,
|
|
4
|
-
checks: CustomSyntaxCheck[],
|
|
5
|
-
): UnmatchedResult | import('./types').MatchedResult;
|
|
2
|
+
export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types").MatchedResult | UnmatchedResult;
|
package/lib/check.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
2
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
|
+
export declare function check(value: string, type: ReadonlyDeep<Type>, ref?: string, cache?: boolean): Result;
|
|
4
|
+
export declare function isKeyword(type: ReadonlyDeep<Type>): type is ReadonlyDeep<KeywordDefinedType>;
|
|
5
|
+
export declare function isList(type: ReadonlyDeep<Type>): type is ReadonlyDeep<List>;
|
|
6
|
+
export declare function isEnum(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Enum>;
|
|
7
|
+
export declare function isNumber(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Number>;
|
|
7
8
|
export declare function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax;
|
|
8
9
|
export declare function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax;
|
package/lib/css-syntax.js
CHANGED
|
@@ -126,7 +126,17 @@ function detectName(def) {
|
|
|
126
126
|
name,
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* @param key
|
|
132
|
+
* @param obj
|
|
133
|
+
* @modifies obj
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
function eachMimicCases(key,
|
|
137
|
+
// Mutable
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
139
|
+
obj) {
|
|
130
140
|
const value = obj[key];
|
|
131
141
|
if (!value) {
|
|
132
142
|
return;
|
package/lib/enum.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Result } from './types';
|
|
2
2
|
import type { Enum } from './types.schema';
|
|
3
|
-
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
+
export declare function checkEnum(value: string, type: ReadonlyDeep<Enum>, ref?: string): Result;
|
package/lib/enum.js
CHANGED
|
@@ -9,7 +9,7 @@ function checkEnum(value, type, ref) {
|
|
|
9
9
|
if (!disallowToSurroundBySpaces) {
|
|
10
10
|
value = value.trim();
|
|
11
11
|
}
|
|
12
|
-
let values = type.enum;
|
|
12
|
+
let values = type.enum.slice();
|
|
13
13
|
if (caseInsensitive) {
|
|
14
14
|
value = value.toLowerCase();
|
|
15
15
|
values = type.enum.map(v => v.toLowerCase());
|
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: (NullableString | NullableString[])[]
|
|
5
|
-
): string | undefined;
|
|
2
|
+
export declare function getCandidate(value: NullableString, ...candidates: readonly (NullableString | readonly NullableString[])[]): string | undefined;
|
|
6
3
|
export {};
|
package/lib/list.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Result } from './types';
|
|
2
2
|
import type { List } from './types.schema';
|
|
3
|
-
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
+
export declare function checkList(value: string, type: ReadonlyDeep<List>, ref?: string, cache?: boolean): Result;
|
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
|
-
ref?: string;
|
|
12
|
-
reason?: UnmatchedResultReason;
|
|
13
|
-
},
|
|
14
|
-
): (value: string) => UnmatchedResult | MatchedResult;
|
|
1
|
+
import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types';
|
|
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
|
-
ref?: string;
|
|
21
|
-
},
|
|
22
|
-
): UnmatchedResult;
|
|
7
|
+
export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
|
|
8
|
+
readonly ref?: string;
|
|
9
|
+
}): UnmatchedResult;
|
package/lib/number.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Result } from './types';
|
|
2
2
|
import type { Number } from './types.schema';
|
|
3
|
-
export declare function checkNumber(value: string, type: Number
|
|
3
|
+
export declare function checkNumber(value: string, type: Readonly<Number>, ref?: string): Result;
|
|
@@ -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,71 +1,64 @@
|
|
|
1
|
+
import type { TokenValue } from './types';
|
|
1
2
|
import type { UnmatchedResult } from '..';
|
|
2
3
|
import type { Expect, Result, List } from '../types';
|
|
4
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
5
|
import { Token } from './token';
|
|
4
|
-
type TokenCollectionOptions = Partial<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
>;
|
|
9
|
-
export type TokenEachCheck = (head: Token | null, tail: TokenCollection) => Result | void;
|
|
6
|
+
type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
|
|
7
|
+
specificSeparator: string | string[];
|
|
8
|
+
}>;
|
|
9
|
+
export type TokenEachCheck = (head: Readonly<Token> | null, tail: ReadonlyDeep<TokenCollection>) => Result | void;
|
|
10
10
|
export declare class TokenCollection extends Array<Token> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
} | null;
|
|
64
|
-
toJSON(): {
|
|
65
|
-
type: number;
|
|
66
|
-
value: string;
|
|
67
|
-
offset: number;
|
|
68
|
-
}[];
|
|
69
|
-
private static _new;
|
|
11
|
+
static fromPatterns(value: Readonly<Token> | string, patterns: readonly Readonly<RegExp>[], typeOptions?: ReadonlyDeep<Omit<TokenCollectionOptions, 'specificSeparator'> & {
|
|
12
|
+
repeat?: boolean;
|
|
13
|
+
}>): TokenCollection;
|
|
14
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
15
|
+
readonly allowEmpty: NonNullable<List['allowEmpty']>;
|
|
16
|
+
readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
|
|
17
|
+
readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
|
|
18
|
+
readonly number: List['number'];
|
|
19
|
+
readonly ordered: NonNullable<List['ordered']>;
|
|
20
|
+
readonly separator: NonNullable<List['separator']>;
|
|
21
|
+
readonly unique: NonNullable<List['unique']>;
|
|
22
|
+
constructor(value?: string, typeOptions?: ReadonlyDeep<TokenCollectionOptions>);
|
|
23
|
+
constructor(value?: number);
|
|
24
|
+
get value(): string;
|
|
25
|
+
check(options?: {
|
|
26
|
+
expects?: Expect[];
|
|
27
|
+
ref?: string;
|
|
28
|
+
cache?: boolean;
|
|
29
|
+
}): import("..").MatchedResult | UnmatchedResult;
|
|
30
|
+
chunk(split: number): TokenCollection[];
|
|
31
|
+
compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
|
|
32
|
+
divide(position: number): readonly [TokenCollection, TokenCollection];
|
|
33
|
+
eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
|
|
34
|
+
filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
|
|
35
|
+
getConsecutiveToken(tokenType: number): Readonly<Token> | null;
|
|
36
|
+
getDuplicated(): Token | null;
|
|
37
|
+
getIdentTokens(): TokenCollection;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param value The token value or the token type or its list
|
|
41
|
+
*/
|
|
42
|
+
has(value: TokenValue): boolean;
|
|
43
|
+
headAndTail(): {
|
|
44
|
+
head: Token | null;
|
|
45
|
+
tail: TokenCollection;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param value The token value or the token type or its list
|
|
50
|
+
*/
|
|
51
|
+
search(value: TokenValue): Token | null;
|
|
52
|
+
takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
|
|
53
|
+
unexpectedLastToken: boolean;
|
|
54
|
+
expectedTokenNumber: number | undefined;
|
|
55
|
+
token: Token;
|
|
56
|
+
} | null;
|
|
57
|
+
toJSON(): {
|
|
58
|
+
type: number;
|
|
59
|
+
value: string;
|
|
60
|
+
offset: number;
|
|
61
|
+
}[];
|
|
62
|
+
private static _new;
|
|
70
63
|
}
|
|
71
64
|
export {};
|
|
@@ -5,12 +5,12 @@ const match_result_1 = require("../match-result");
|
|
|
5
5
|
const token_1 = require("./token");
|
|
6
6
|
class TokenCollection extends Array {
|
|
7
7
|
static fromPatterns(value, patterns, typeOptions) {
|
|
8
|
-
const
|
|
8
|
+
const originalValue = typeof value === 'string' ? value : value.originalValue;
|
|
9
9
|
let strings = typeof value === 'string' ? value : value.value;
|
|
10
10
|
let cumulativeOffset = typeof value === 'string' ? 0 : value.offset;
|
|
11
11
|
const tokens = [];
|
|
12
12
|
function addToken(tokenValue) {
|
|
13
|
-
const token = new token_1.Token(tokenValue, cumulativeOffset,
|
|
13
|
+
const token = new token_1.Token(tokenValue, cumulativeOffset, originalValue);
|
|
14
14
|
tokens.push(token);
|
|
15
15
|
strings = strings.slice(tokenValue.length);
|
|
16
16
|
cumulativeOffset += tokenValue.length;
|
|
@@ -71,11 +71,11 @@ class TokenCollection extends Array {
|
|
|
71
71
|
separators.push(',');
|
|
72
72
|
}
|
|
73
73
|
if (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.specificSeparator) {
|
|
74
|
-
if (
|
|
75
|
-
separators.push(
|
|
74
|
+
if (typeof typeOptions.specificSeparator === 'string') {
|
|
75
|
+
separators.push(typeOptions.specificSeparator);
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
|
-
separators.push(typeOptions.specificSeparator);
|
|
78
|
+
separators.push(...typeOptions.specificSeparator);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
const chars = value.split('');
|
package/lib/token/token.d.ts
CHANGED
|
@@ -1,60 +1,56 @@
|
|
|
1
|
+
import type { TokenValue } from './types';
|
|
1
2
|
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
|
|
2
3
|
export declare class Token {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
options?: UnmatchedResultOptions & {
|
|
56
|
-
ref?: string;
|
|
57
|
-
reason?: UnmatchedResultReason;
|
|
58
|
-
},
|
|
59
|
-
): UnmatchedResult;
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
6
|
+
*/
|
|
7
|
+
static readonly Comma = 18;
|
|
8
|
+
static readonly Ident = 1;
|
|
9
|
+
static readonly WhiteSpace = 13;
|
|
10
|
+
/**
|
|
11
|
+
* ASCII whitespace is
|
|
12
|
+
* - U+0009 TAB
|
|
13
|
+
* - U+000A LF
|
|
14
|
+
* - U+000C FF
|
|
15
|
+
* - U+000D CR
|
|
16
|
+
* - U+0020 SPACE.
|
|
17
|
+
*
|
|
18
|
+
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
19
|
+
*/
|
|
20
|
+
static readonly whitespace: ReadonlyArray<string>;
|
|
21
|
+
static getCol(value: string, offset: number): number;
|
|
22
|
+
static getLine(value: string, offset: number): number;
|
|
23
|
+
static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
|
|
24
|
+
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
25
|
+
offset: number;
|
|
26
|
+
line: number;
|
|
27
|
+
column: number;
|
|
28
|
+
};
|
|
29
|
+
readonly offset: number;
|
|
30
|
+
readonly originalValue: string;
|
|
31
|
+
readonly type: number;
|
|
32
|
+
readonly value: string;
|
|
33
|
+
constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
|
|
34
|
+
get length(): number;
|
|
35
|
+
clone(): Token;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param value The token value or the token type or its list
|
|
39
|
+
*/
|
|
40
|
+
includes(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param value The token value or the token type or its list
|
|
44
|
+
*/
|
|
45
|
+
match(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
46
|
+
toJSON(): {
|
|
47
|
+
type: number;
|
|
48
|
+
value: string;
|
|
49
|
+
offset: number;
|
|
50
|
+
};
|
|
51
|
+
toNumber(): number;
|
|
52
|
+
unmatched(options?: UnmatchedResultOptions & {
|
|
53
|
+
readonly ref?: string;
|
|
54
|
+
readonly reason?: UnmatchedResultReason;
|
|
55
|
+
}): UnmatchedResult;
|
|
60
56
|
}
|
package/lib/token/token.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _Token_originalValue;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.Token = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
4
|
class Token {
|
|
7
5
|
static getCol(value, offset) {
|
|
8
6
|
var _a;
|
|
@@ -29,22 +27,21 @@ class Token {
|
|
|
29
27
|
const shifted = token.offset + offset;
|
|
30
28
|
return {
|
|
31
29
|
offset: shifted,
|
|
32
|
-
line: Token.getLine(
|
|
33
|
-
column: Token.getCol(
|
|
30
|
+
line: Token.getLine(token.originalValue, shifted),
|
|
31
|
+
column: Token.getCol(token.originalValue, shifted),
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
34
|
constructor(value, offset, originalValue, separators) {
|
|
37
|
-
_Token_originalValue.set(this, void 0);
|
|
38
35
|
this.type = Token.getType(value, separators);
|
|
39
36
|
this.value = value;
|
|
40
37
|
this.offset = offset;
|
|
41
|
-
|
|
38
|
+
this.originalValue = originalValue;
|
|
42
39
|
}
|
|
43
40
|
get length() {
|
|
44
41
|
return this.value.length;
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
return
|
|
43
|
+
clone() {
|
|
44
|
+
return new Token(this.value, this.offset, this.originalValue);
|
|
48
45
|
}
|
|
49
46
|
/**
|
|
50
47
|
*
|
|
@@ -103,14 +100,12 @@ class Token {
|
|
|
103
100
|
raw: this.value,
|
|
104
101
|
offset: this.offset,
|
|
105
102
|
length: this.value.length,
|
|
106
|
-
line: Token.getLine(
|
|
107
|
-
column: Token.getCol(
|
|
103
|
+
line: Token.getLine(this.originalValue, this.offset),
|
|
104
|
+
column: Token.getCol(this.originalValue, this.offset),
|
|
108
105
|
reason: (_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : 'syntax-error',
|
|
109
106
|
};
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
|
-
exports.Token = Token;
|
|
113
|
-
_Token_originalValue = new WeakMap();
|
|
114
109
|
/**
|
|
115
110
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
116
111
|
*/
|
|
@@ -128,3 +123,4 @@ Token.WhiteSpace = 13;
|
|
|
128
123
|
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
129
124
|
*/
|
|
130
125
|
Token.whitespace = ['\u0009', '\u000A', '\u000C', '\u000D', '\u0020'];
|
|
126
|
+
exports.Token = Token;
|
package/lib/types.d.ts
CHANGED
|
@@ -2,101 +2,77 @@ import type { cssSyntaxMatch } from './css-syntax';
|
|
|
2
2
|
export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number } from './types.schema';
|
|
3
3
|
export type Result = UnmatchedResult | MatchedResult;
|
|
4
4
|
export type UnmatchedResult = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
readonly matched: false;
|
|
6
|
+
readonly ref: string | null;
|
|
7
|
+
readonly raw: string;
|
|
8
|
+
readonly length: number;
|
|
9
|
+
readonly offset: number;
|
|
10
|
+
readonly line: number;
|
|
11
|
+
readonly column: number;
|
|
12
|
+
readonly reason: UnmatchedResultReason;
|
|
13
|
+
readonly passCount?: number;
|
|
14
14
|
} & UnmatchedResultOptions;
|
|
15
15
|
export type UnmatchedResultOptions = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
readonly partName?: string;
|
|
17
|
+
readonly expects?: readonly Expect[];
|
|
18
|
+
readonly extra?: Expect;
|
|
19
|
+
readonly candidate?: string;
|
|
20
|
+
};
|
|
21
|
+
export type UnmatchedResultReason = 'syntax-error' | 'typo' | 'missing-token' | 'missing-comma' | 'unexpected-token' | 'unexpected-space' | 'unexpected-newline' | 'unexpected-comma' | 'empty-token' | 'out-of-range' | 'doesnt-exist-in-enum' | 'duplicated' | 'illegal-combination' | 'illegal-order' | 'extra-token' | 'must-be-percent-encoded' | 'must-be-serialized' | {
|
|
22
|
+
readonly type: 'out-of-range';
|
|
23
|
+
readonly gt?: number;
|
|
24
|
+
readonly gte?: number;
|
|
25
|
+
readonly lt?: number;
|
|
26
|
+
readonly lte?: number;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: 'out-of-range-length-char';
|
|
29
|
+
readonly gte: number;
|
|
30
|
+
readonly lte?: number;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: 'out-of-range-length-digit';
|
|
33
|
+
readonly gte: number;
|
|
34
|
+
readonly lte?: number;
|
|
20
35
|
};
|
|
21
|
-
export type UnmatchedResultReason =
|
|
22
|
-
| 'syntax-error'
|
|
23
|
-
| 'typo'
|
|
24
|
-
| 'missing-token'
|
|
25
|
-
| 'missing-comma'
|
|
26
|
-
| 'unexpected-token'
|
|
27
|
-
| 'unexpected-space'
|
|
28
|
-
| 'unexpected-newline'
|
|
29
|
-
| 'unexpected-comma'
|
|
30
|
-
| 'empty-token'
|
|
31
|
-
| 'out-of-range'
|
|
32
|
-
| 'doesnt-exist-in-enum'
|
|
33
|
-
| 'duplicated'
|
|
34
|
-
| 'illegal-combination'
|
|
35
|
-
| 'illegal-order'
|
|
36
|
-
| 'extra-token'
|
|
37
|
-
| 'must-be-percent-encoded'
|
|
38
|
-
| 'must-be-serialized'
|
|
39
|
-
| {
|
|
40
|
-
type: 'out-of-range';
|
|
41
|
-
gt?: number;
|
|
42
|
-
gte?: number;
|
|
43
|
-
lt?: number;
|
|
44
|
-
lte?: number;
|
|
45
|
-
}
|
|
46
|
-
| {
|
|
47
|
-
type: 'out-of-range-length-char';
|
|
48
|
-
gte: number;
|
|
49
|
-
lte?: number;
|
|
50
|
-
}
|
|
51
|
-
| {
|
|
52
|
-
type: 'out-of-range-length-digit';
|
|
53
|
-
gte: number;
|
|
54
|
-
lte?: number;
|
|
55
|
-
};
|
|
56
36
|
export type MatchedResult = {
|
|
57
|
-
|
|
37
|
+
readonly matched: true;
|
|
58
38
|
};
|
|
59
39
|
export type Expect = {
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
|
|
41
|
+
readonly value: string;
|
|
62
42
|
};
|
|
63
43
|
export type FormattedPrimitiveTypeCheck = (value: string) => boolean;
|
|
64
44
|
export type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
|
|
65
45
|
export type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
|
|
66
46
|
export type CustomSyntax = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
readonly ref: string;
|
|
48
|
+
readonly expects?: readonly Expect[];
|
|
49
|
+
readonly is: CustomSyntaxCheck;
|
|
70
50
|
};
|
|
71
51
|
export type CustomSyntaxCheck = (value: string) => Result;
|
|
72
52
|
export type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
|
|
73
53
|
export type CustomCssSyntax = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
readonly ref: string;
|
|
55
|
+
readonly caseSensitive?: boolean;
|
|
56
|
+
readonly expects?: readonly Expect[];
|
|
57
|
+
readonly syntax: {
|
|
58
|
+
readonly apply: `<${string}>`;
|
|
59
|
+
readonly def: Readonly<Record<string, string | CssSyntaxTokenizer>>;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated
|
|
62
|
+
*/
|
|
63
|
+
readonly ebnf?: Readonly<Record<string, string | readonly string[]>>;
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated
|
|
66
|
+
*/
|
|
67
|
+
readonly properties?: Readonly<Record<string, string>>;
|
|
68
|
+
};
|
|
89
69
|
};
|
|
90
70
|
export type CSSSyntaxToken = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
71
|
+
readonly type: number;
|
|
72
|
+
readonly value: string;
|
|
73
|
+
readonly index: number;
|
|
74
|
+
readonly balance: number;
|
|
75
|
+
readonly node?: any;
|
|
96
76
|
};
|
|
97
|
-
export type CssSyntaxTokenizer = (
|
|
98
|
-
token: CSSSyntaxToken | null,
|
|
99
|
-
getNextToken: GetNextToken,
|
|
100
|
-
match: typeof cssSyntaxMatch,
|
|
101
|
-
) => number;
|
|
77
|
+
export type CssSyntaxTokenizer = (token: Readonly<CSSSyntaxToken> | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
|
|
102
78
|
export type GetNextToken = (length: number) => CSSSyntaxToken | null;
|