@markuplint/types 1.0.0-rc.1 → 2.0.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/README.md +0 -15
- package/lib/check-multi-types.d.ts +4 -1
- package/lib/get-candicate.d.ts +4 -1
- package/lib/match-result.d.ts +21 -8
- package/lib/primitive/is-uint.d.ts +6 -3
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/token/token-collection.d.ts +64 -55
- package/lib/token/token.d.ts +57 -52
- package/lib/types.d.ts +79 -55
- package/lib/types.schema.d.ts +1030 -28
- package/lib/w3c/check-serialized-permissions-policy.d.ts +8 -0
- package/lib/w3c/check-serialized-permissions-policy.js +24 -9
- package/lib/w3c/check-serialized-permissions-policy.spec.js +12 -4
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +21 -1
- 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 -4
- package/src/types.schema.ts +5 -5
- package/src/w3c/check-serialized-permissions-policy.spec.ts +15 -4
- package/src/w3c/check-serialized-permissions-policy.ts +25 -9
- package/tsconfig.tsbuildinfo +1 -1
- package/types.schema.json +5 -5
package/README.md
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
Prerequisites: [Node.js](https://nodejs.org) (Version 12.4.0 or later)
|
|
10
|
-
|
|
11
9
|
```sh
|
|
12
10
|
$ npm install @markuplint/types
|
|
13
11
|
|
|
@@ -102,16 +100,3 @@ check('2020-02-30', 'DateTime');
|
|
|
102
100
|
| `<number-optional-number>` | Some attributes for SVG | | ✅ |
|
|
103
101
|
|
|
104
102
|
In addition, you can use types **[CSSTree](https://github.com/csstree/csstree)** defined.
|
|
105
|
-
|
|
106
|
-
## Contributing
|
|
107
|
-
|
|
108
|
-
```
|
|
109
|
-
$ git clone git@github.com:markuplint/markuplint.git -b main
|
|
110
|
-
$ yarn
|
|
111
|
-
$ yarn build
|
|
112
|
-
$ yarn test
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
Copyright © 2021 markuplint. Under the MIT License.
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { CustomSyntaxCheck, UnmatchedResult } from './types';
|
|
2
|
-
export declare function checkMultiTypes(
|
|
2
|
+
export declare function checkMultiTypes(
|
|
3
|
+
value: string,
|
|
4
|
+
checks: CustomSyntaxCheck[],
|
|
5
|
+
): import('./types').MatchedResult | UnmatchedResult;
|
package/lib/get-candicate.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
declare type NullableString = string | null | undefined;
|
|
2
|
-
export declare function getCandicate(
|
|
2
|
+
export declare function getCandicate(
|
|
3
|
+
value: NullableString,
|
|
4
|
+
...candicates: (NullableString | NullableString[])[]
|
|
5
|
+
): string | undefined;
|
|
3
6
|
export {};
|
package/lib/match-result.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
FormattedPrimitiveTypeCheck,
|
|
3
|
+
MatchedResult,
|
|
4
|
+
UnmatchedResult,
|
|
5
|
+
UnmatchedResultOptions,
|
|
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) => MatchedResult | UnmatchedResult;
|
|
6
15
|
export declare function matched(): MatchedResult;
|
|
7
|
-
export declare function unmatched(
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
export declare function unmatched(
|
|
17
|
+
value: string,
|
|
18
|
+
reason?: UnmatchedResultReason,
|
|
19
|
+
options?: UnmatchedResultOptions & {
|
|
20
|
+
ref?: string;
|
|
21
|
+
},
|
|
22
|
+
): UnmatchedResult;
|
|
@@ -1,62 +1,71 @@
|
|
|
1
1
|
import type { UnmatchedResult } from '..';
|
|
2
2
|
import type { Expect, Result, List } from '../types';
|
|
3
3
|
import { Token } from './token';
|
|
4
|
-
declare type TokenCollectionOptions = Partial<
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
declare type TokenCollectionOptions = Partial<
|
|
5
|
+
Omit<List, 'token'> & {
|
|
6
|
+
speificSeparator: string | string[];
|
|
7
|
+
}
|
|
8
|
+
>;
|
|
7
9
|
export declare type TokenEachCheck = (head: Token | null, tail: TokenCollection) => Result | void;
|
|
8
10
|
export declare class TokenCollection extends Array<Token> {
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
11
|
+
private static _new;
|
|
12
|
+
static fromPatterns(
|
|
13
|
+
value: Token | string,
|
|
14
|
+
patterns: RegExp[],
|
|
15
|
+
typeOptions?: Omit<TokenCollectionOptions, 'speificSeparator'> & {
|
|
16
|
+
repeat?: boolean;
|
|
17
|
+
},
|
|
18
|
+
): TokenCollection;
|
|
19
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
20
|
+
readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
|
|
21
|
+
readonly allowEmpty: NonNullable<List['allowEmpty']>;
|
|
22
|
+
readonly ordered: NonNullable<List['ordered']>;
|
|
23
|
+
readonly unique: NonNullable<List['unique']>;
|
|
24
|
+
readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
|
|
25
|
+
readonly number: List['number'];
|
|
26
|
+
readonly separator: NonNullable<List['separator']>;
|
|
27
|
+
constructor(value?: string, typeOptions?: TokenCollectionOptions);
|
|
28
|
+
constructor(value?: number);
|
|
29
|
+
get value(): string;
|
|
30
|
+
filter(callback: (value: Token, index: number, array: Token[]) => boolean): TokenCollection;
|
|
31
|
+
headAndTail(): {
|
|
32
|
+
head: Token | null;
|
|
33
|
+
tail: TokenCollection;
|
|
34
|
+
};
|
|
35
|
+
getIdentTokens(): TokenCollection;
|
|
36
|
+
compareTokens(callback: (prev: Token, current: Token) => Token | null | void): Token | null | undefined;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param value The token value or the token type or its list
|
|
40
|
+
*/
|
|
41
|
+
has(value: string | RegExp | number | (string | RegExp | number)[]): boolean;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param value The token value or the token type or its list
|
|
45
|
+
*/
|
|
46
|
+
search(value: string | RegExp | number | (string | RegExp | number)[]): Token | null;
|
|
47
|
+
check(options?: {
|
|
48
|
+
expects?: Expect[];
|
|
49
|
+
ref?: string;
|
|
50
|
+
cache?: boolean;
|
|
51
|
+
}): import('..').MatchedResult | UnmatchedResult;
|
|
52
|
+
getConsecutiveToken(tokenType: number): Token | null;
|
|
53
|
+
takeTurns(
|
|
54
|
+
tokenNumbers: ReadonlyArray<number>,
|
|
55
|
+
lastTokenNumber?: number,
|
|
56
|
+
): {
|
|
57
|
+
unexpectedLastToken: boolean;
|
|
58
|
+
expectedTokenNumber: number;
|
|
59
|
+
token: Token;
|
|
60
|
+
} | null;
|
|
61
|
+
eachCheck(...callbacks: TokenEachCheck[]): Result;
|
|
62
|
+
getDuplicated(): Token | null;
|
|
63
|
+
divide(position: number): readonly [TokenCollection, TokenCollection];
|
|
64
|
+
chunk(split: number): TokenCollection[];
|
|
65
|
+
toJSON(): {
|
|
66
|
+
type: number;
|
|
67
|
+
value: string;
|
|
68
|
+
offset: number;
|
|
69
|
+
}[];
|
|
61
70
|
}
|
|
62
71
|
export {};
|
package/lib/token/token.d.ts
CHANGED
|
@@ -1,55 +1,60 @@
|
|
|
1
1
|
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
|
|
2
2
|
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
|
-
|
|
3
|
+
#private;
|
|
4
|
+
static getType(value: string, separators?: string[]): 1 | 13 | 18;
|
|
5
|
+
static getLine(value: string, offset: number): number;
|
|
6
|
+
static getCol(value: string, offset: number): number;
|
|
7
|
+
static shiftLocation(
|
|
8
|
+
token: Token,
|
|
9
|
+
offset: number,
|
|
10
|
+
): {
|
|
11
|
+
offset: number;
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* ASCII whitespace is
|
|
17
|
+
* - U+0009 TAB
|
|
18
|
+
* - U+000A LF
|
|
19
|
+
* - U+000C FF
|
|
20
|
+
* - U+000D CR
|
|
21
|
+
* - U+0020 SPACE.
|
|
22
|
+
*
|
|
23
|
+
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
24
|
+
*/
|
|
25
|
+
static readonly whitespace: ReadonlyArray<string>;
|
|
26
|
+
/**
|
|
27
|
+
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
28
|
+
*/
|
|
29
|
+
static readonly Ident = 1;
|
|
30
|
+
static readonly WhiteSpace = 13;
|
|
31
|
+
static readonly Comma = 18;
|
|
32
|
+
readonly type: number;
|
|
33
|
+
readonly value: string;
|
|
34
|
+
readonly offset: number;
|
|
35
|
+
constructor(value: string, offset: number, originalValue: string, separators?: string[]);
|
|
36
|
+
get length(): number;
|
|
37
|
+
get origin(): string;
|
|
38
|
+
unmatched(
|
|
39
|
+
options?: UnmatchedResultOptions & {
|
|
40
|
+
ref?: string;
|
|
41
|
+
reason?: UnmatchedResultReason;
|
|
42
|
+
},
|
|
43
|
+
): UnmatchedResult;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param value The token value or the token type or its list
|
|
47
|
+
*/
|
|
48
|
+
match(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param value The token value or the token type or its list
|
|
52
|
+
*/
|
|
53
|
+
includes(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
|
|
54
|
+
toNumber(): number;
|
|
55
|
+
toJSON(): {
|
|
56
|
+
type: number;
|
|
57
|
+
value: string;
|
|
58
|
+
offset: number;
|
|
59
|
+
};
|
|
55
60
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -2,77 +2,101 @@ import type { cssSyntaxMatch } from './css-syntax';
|
|
|
2
2
|
export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number } from './types.schema';
|
|
3
3
|
export declare type Result = UnmatchedResult | MatchedResult;
|
|
4
4
|
export declare type UnmatchedResult = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
matched: false;
|
|
6
|
+
ref: string | null;
|
|
7
|
+
raw: string;
|
|
8
|
+
length: number;
|
|
9
|
+
offset: number;
|
|
10
|
+
line: number;
|
|
11
|
+
column: number;
|
|
12
|
+
reason: UnmatchedResultReason;
|
|
13
|
+
passCount?: number;
|
|
14
14
|
} & UnmatchedResultOptions;
|
|
15
15
|
export declare type UnmatchedResultOptions = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
export declare 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
|
-
type: 'out-of-range';
|
|
23
|
-
gt?: number;
|
|
24
|
-
gte?: number;
|
|
25
|
-
lt?: number;
|
|
26
|
-
lte?: number;
|
|
27
|
-
} | {
|
|
28
|
-
type: 'out-of-range-length-char';
|
|
29
|
-
gte: number;
|
|
30
|
-
lte?: number;
|
|
31
|
-
} | {
|
|
32
|
-
type: 'out-of-range-length-digit';
|
|
33
|
-
gte: number;
|
|
34
|
-
lte?: number;
|
|
16
|
+
partName?: string;
|
|
17
|
+
expects?: Expect[];
|
|
18
|
+
extra?: Expect;
|
|
19
|
+
candicate?: string;
|
|
35
20
|
};
|
|
21
|
+
export declare 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
|
+
};
|
|
36
56
|
export declare type MatchedResult = {
|
|
37
|
-
|
|
57
|
+
matched: true;
|
|
38
58
|
};
|
|
39
59
|
export declare type Expect = {
|
|
40
|
-
|
|
41
|
-
|
|
60
|
+
type: 'const' | 'format' | 'syntax' | 'regxp' | 'common';
|
|
61
|
+
value: string;
|
|
42
62
|
};
|
|
43
63
|
export declare type FormattedPrimitiveTypeCheck = (value: string) => boolean;
|
|
44
64
|
export declare type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
|
|
45
65
|
export declare type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
|
|
46
66
|
export declare type CustomSyntax = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
ref: string;
|
|
68
|
+
expects?: Expect[];
|
|
69
|
+
is: CustomSyntaxCheck;
|
|
50
70
|
};
|
|
51
71
|
export declare type CustomSyntaxCheck = (value: string) => Result;
|
|
52
72
|
export declare type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
|
|
53
73
|
export declare type CustomCssSyntax = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
ref: string;
|
|
75
|
+
caseSensitive?: boolean;
|
|
76
|
+
expects?: Expect[];
|
|
77
|
+
syntax: {
|
|
78
|
+
apply: `<${string}>`;
|
|
79
|
+
def: Record<string, string | CssSyntaxTokenizer>;
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated
|
|
82
|
+
*/
|
|
83
|
+
ebnf?: Record<string, string | string[]>;
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated
|
|
86
|
+
*/
|
|
87
|
+
properties?: Record<string, string>;
|
|
88
|
+
};
|
|
69
89
|
};
|
|
70
90
|
export declare type CSSSyntaxToken = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
type: number;
|
|
92
|
+
value: string;
|
|
93
|
+
index: number;
|
|
94
|
+
balance: number;
|
|
95
|
+
node?: any;
|
|
76
96
|
};
|
|
77
|
-
export declare type CssSyntaxTokenizer = (
|
|
97
|
+
export declare type CssSyntaxTokenizer = (
|
|
98
|
+
token: CSSSyntaxToken | null,
|
|
99
|
+
getNextToken: GetNextToken,
|
|
100
|
+
match: typeof cssSyntaxMatch,
|
|
101
|
+
) => number;
|
|
78
102
|
export declare type GetNextToken = (length: number) => CSSSyntaxToken | null;
|