@markuplint/types 3.11.0 → 3.12.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.
@@ -1,2 +1,5 @@
1
1
  import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
- export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types").MatchedResult | UnmatchedResult;
2
+ export declare function checkMultiTypes(
3
+ value: string,
4
+ checks: readonly CustomSyntaxCheck[],
5
+ ): UnmatchedResult | import('./types').MatchedResult;
package/lib/defs.js CHANGED
@@ -753,7 +753,7 @@ exports.types = {
753
753
  syntax: {
754
754
  apply: '<view-box>',
755
755
  def: {
756
- 'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
756
+ 'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>', // As '[<min-x>,? <min-y>,? <width>,? <height>]',
757
757
  'min-x': '<number>',
758
758
  'min-y': '<number>',
759
759
  width: '<number>',
@@ -1,3 +1,6 @@
1
1
  type NullableString = string | null | undefined;
2
- export declare function getCandidate(value: NullableString, ...candidates: readonly (NullableString | readonly NullableString[])[]): string | undefined;
2
+ export declare function getCandidate(
3
+ value: NullableString,
4
+ ...candidates: readonly (NullableString | readonly NullableString[])[]
5
+ ): string | undefined;
3
6
  export {};
@@ -1,9 +1,22 @@
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;
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
+ readonly ref?: string;
12
+ readonly reason?: UnmatchedResultReason;
13
+ },
14
+ ): (value: string) => UnmatchedResult | MatchedResult;
6
15
  export declare function matched(): MatchedResult;
7
- export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
8
- readonly ref?: string;
9
- }): UnmatchedResult;
16
+ export declare function unmatched(
17
+ value: string,
18
+ reason?: UnmatchedResultReason,
19
+ options?: UnmatchedResultOptions & {
20
+ readonly ref?: string;
21
+ },
22
+ ): UnmatchedResult;
@@ -4,4 +4,8 @@
4
4
  * @param units
5
5
  * @param numberType
6
6
  */
7
- export declare function isQuantity(value: string, units: readonly string[], numberType?: 'int' | 'uint' | 'float'): boolean;
7
+ export declare function isQuantity(
8
+ value: string,
9
+ units: readonly string[],
10
+ numberType?: 'int' | 'uint' | 'float',
11
+ ): boolean;
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * @param value
5
5
  */
6
- export declare function isUint(value: string, options?: {
7
- readonly gt?: number;
8
- }): boolean;
6
+ export declare function isUint(
7
+ value: string,
8
+ options?: {
9
+ readonly gt?: number;
10
+ },
11
+ ): boolean;
@@ -4,6 +4,6 @@
4
4
  * @returns
5
5
  */
6
6
  export declare function splitUnit(value: string): {
7
- num: string;
8
- unit: string;
7
+ num: string;
8
+ unit: string;
9
9
  };
@@ -2,62 +2,73 @@ import type { TokenValue } from './types';
2
2
  import type { UnmatchedResult } from '..';
3
3
  import type { Expect, Result, List } from '../types';
4
4
  import { Token } from './token';
5
- type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
6
- specificSeparator: string | string[];
7
- }>;
5
+ type TokenCollectionOptions = Partial<
6
+ Omit<List, 'token'> & {
7
+ specificSeparator: string | string[];
8
+ }
9
+ >;
8
10
  export type TokenEachCheck = (head: Readonly<Token> | null, tail: TokenCollection) => Result | void;
9
11
  export declare class TokenCollection extends Array<Token> {
10
- static fromPatterns(value: Readonly<Token> | string, patterns: readonly Readonly<RegExp>[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
11
- repeat?: boolean;
12
- }): TokenCollection;
13
- static get [Symbol.species](): ArrayConstructor;
14
- readonly allowEmpty: NonNullable<List['allowEmpty']>;
15
- readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
16
- readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
17
- readonly number: List['number'];
18
- readonly ordered: NonNullable<List['ordered']>;
19
- readonly separator: NonNullable<List['separator']>;
20
- readonly unique: NonNullable<List['unique']>;
21
- constructor(value?: string, typeOptions?: TokenCollectionOptions);
22
- constructor(value?: number);
23
- get value(): string;
24
- check(options?: {
25
- expects?: Expect[];
26
- ref?: string;
27
- cache?: boolean;
28
- }): import("..").MatchedResult | UnmatchedResult;
29
- chunk(split: number): TokenCollection[];
30
- compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
31
- divide(position: number): readonly [TokenCollection, TokenCollection];
32
- eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
33
- filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
34
- getConsecutiveToken(tokenType: number): Readonly<Token> | null;
35
- getDuplicated(): Token | null;
36
- getIdentTokens(): TokenCollection;
37
- /**
38
- *
39
- * @param value The token value or the token type or its list
40
- */
41
- has(value: TokenValue): boolean;
42
- headAndTail(): {
43
- head: Token | null;
44
- tail: TokenCollection;
45
- };
46
- /**
47
- *
48
- * @param value The token value or the token type or its list
49
- */
50
- search(value: TokenValue): Token | null;
51
- takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
52
- unexpectedLastToken: boolean;
53
- expectedTokenNumber: number | undefined;
54
- token: Token;
55
- } | null;
56
- toJSON(): {
57
- type: number;
58
- value: string;
59
- offset: number;
60
- }[];
61
- private static _new;
12
+ static fromPatterns(
13
+ value: Readonly<Token> | string,
14
+ patterns: readonly Readonly<RegExp>[],
15
+ typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
16
+ repeat?: boolean;
17
+ },
18
+ ): TokenCollection;
19
+ static get [Symbol.species](): ArrayConstructor;
20
+ readonly allowEmpty: NonNullable<List['allowEmpty']>;
21
+ readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
22
+ readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
23
+ readonly number: List['number'];
24
+ readonly ordered: NonNullable<List['ordered']>;
25
+ readonly separator: NonNullable<List['separator']>;
26
+ readonly unique: NonNullable<List['unique']>;
27
+ constructor(value?: string, typeOptions?: TokenCollectionOptions);
28
+ constructor(value?: number);
29
+ get value(): string;
30
+ check(options?: {
31
+ expects?: Expect[];
32
+ ref?: string;
33
+ cache?: boolean;
34
+ }): UnmatchedResult | import('..').MatchedResult;
35
+ chunk(split: number): TokenCollection[];
36
+ compareTokens(
37
+ callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void,
38
+ ): Readonly<Token> | null | undefined;
39
+ divide(position: number): readonly [TokenCollection, TokenCollection];
40
+ eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
41
+ filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
42
+ getConsecutiveToken(tokenType: number): Readonly<Token> | null;
43
+ getDuplicated(): Token | null;
44
+ getIdentTokens(): TokenCollection;
45
+ /**
46
+ *
47
+ * @param value The token value or the token type or its list
48
+ */
49
+ has(value: TokenValue): boolean;
50
+ headAndTail(): {
51
+ head: Token | null;
52
+ tail: TokenCollection;
53
+ };
54
+ /**
55
+ *
56
+ * @param value The token value or the token type or its list
57
+ */
58
+ search(value: TokenValue): Token | null;
59
+ takeTurns(
60
+ tokenNumbers: ReadonlyArray<number>,
61
+ lastTokenNumber?: number,
62
+ ): {
63
+ unexpectedLastToken: boolean;
64
+ expectedTokenNumber: number | undefined;
65
+ token: Token;
66
+ } | null;
67
+ toJSON(): {
68
+ type: number;
69
+ value: string;
70
+ offset: number;
71
+ }[];
72
+ private static _new;
62
73
  }
63
74
  export {};
@@ -1,56 +1,61 @@
1
1
  import type { TokenValue } from './types';
2
2
  import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
3
3
  export declare class Token {
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;
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(
25
+ token: Readonly<Token>,
26
+ offset: number,
27
+ ): {
28
+ offset: number;
29
+ line: number;
30
+ column: number;
31
+ };
32
+ readonly offset: number;
33
+ readonly originalValue: string;
34
+ readonly type: number;
35
+ readonly value: string;
36
+ constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
37
+ get length(): number;
38
+ clone(): Token;
39
+ /**
40
+ *
41
+ * @param value The token value or the token type or its list
42
+ */
43
+ includes(value: TokenValue, caseInsensitive?: boolean): boolean;
44
+ /**
45
+ *
46
+ * @param value The token value or the token type or its list
47
+ */
48
+ match(value: TokenValue, caseInsensitive?: boolean): boolean;
49
+ toJSON(): {
50
+ type: number;
51
+ value: string;
52
+ offset: number;
53
+ };
54
+ toNumber(): number;
55
+ unmatched(
56
+ options?: UnmatchedResultOptions & {
57
+ readonly ref?: string;
58
+ readonly reason?: UnmatchedResultReason;
59
+ },
60
+ ): UnmatchedResult;
56
61
  }
package/lib/types.d.ts CHANGED
@@ -2,78 +2,102 @@ 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
- 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;
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
- readonly partName?: string;
17
- readonly expects?: readonly Expect[];
18
- readonly extra?: Expect;
19
- readonly candidate?: string;
20
- readonly fallbackTo?: string;
21
- };
22
- 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' | {
23
- readonly type: 'out-of-range';
24
- readonly gt?: number;
25
- readonly gte?: number;
26
- readonly lt?: number;
27
- readonly lte?: number;
28
- } | {
29
- readonly type: 'out-of-range-length-char';
30
- readonly gte: number;
31
- readonly lte?: number;
32
- } | {
33
- readonly type: 'out-of-range-length-digit';
34
- readonly gte: number;
35
- readonly lte?: number;
16
+ readonly partName?: string;
17
+ readonly expects?: readonly Expect[];
18
+ readonly extra?: Expect;
19
+ readonly candidate?: string;
20
+ readonly fallbackTo?: string;
36
21
  };
22
+ export type UnmatchedResultReason =
23
+ | 'syntax-error'
24
+ | 'typo'
25
+ | 'missing-token'
26
+ | 'missing-comma'
27
+ | 'unexpected-token'
28
+ | 'unexpected-space'
29
+ | 'unexpected-newline'
30
+ | 'unexpected-comma'
31
+ | 'empty-token'
32
+ | 'out-of-range'
33
+ | 'doesnt-exist-in-enum'
34
+ | 'duplicated'
35
+ | 'illegal-combination'
36
+ | 'illegal-order'
37
+ | 'extra-token'
38
+ | 'must-be-percent-encoded'
39
+ | 'must-be-serialized'
40
+ | {
41
+ readonly type: 'out-of-range';
42
+ readonly gt?: number;
43
+ readonly gte?: number;
44
+ readonly lt?: number;
45
+ readonly lte?: number;
46
+ }
47
+ | {
48
+ readonly type: 'out-of-range-length-char';
49
+ readonly gte: number;
50
+ readonly lte?: number;
51
+ }
52
+ | {
53
+ readonly type: 'out-of-range-length-digit';
54
+ readonly gte: number;
55
+ readonly lte?: number;
56
+ };
37
57
  export type MatchedResult = {
38
- readonly matched: true;
58
+ readonly matched: true;
39
59
  };
40
60
  export type Expect = {
41
- readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
42
- readonly value: string;
61
+ readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
62
+ readonly value: string;
43
63
  };
44
64
  export type FormattedPrimitiveTypeCheck = (value: string) => boolean;
45
65
  export type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
46
66
  export type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
47
67
  export type CustomSyntax = {
48
- readonly ref: string;
49
- readonly expects?: readonly Expect[];
50
- readonly is: CustomSyntaxCheck;
68
+ readonly ref: string;
69
+ readonly expects?: readonly Expect[];
70
+ readonly is: CustomSyntaxCheck;
51
71
  };
52
72
  export type CustomSyntaxCheck = (value: string) => Result;
53
73
  export type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
54
74
  export type CustomCssSyntax = {
55
- readonly ref: string;
56
- readonly caseSensitive?: boolean;
57
- readonly expects?: readonly Expect[];
58
- readonly syntax: {
59
- readonly apply: `<${string}>`;
60
- readonly def: Readonly<Record<string, string | CssSyntaxTokenizer>>;
61
- /**
62
- * @deprecated
63
- */
64
- readonly ebnf?: Readonly<Record<string, string | readonly string[]>>;
65
- /**
66
- * @deprecated
67
- */
68
- readonly properties?: Readonly<Record<string, string>>;
69
- };
75
+ readonly ref: string;
76
+ readonly caseSensitive?: boolean;
77
+ readonly expects?: readonly Expect[];
78
+ readonly syntax: {
79
+ readonly apply: `<${string}>`;
80
+ readonly def: Readonly<Record<string, string | CssSyntaxTokenizer>>;
81
+ /**
82
+ * @deprecated
83
+ */
84
+ readonly ebnf?: Readonly<Record<string, string | readonly string[]>>;
85
+ /**
86
+ * @deprecated
87
+ */
88
+ readonly properties?: Readonly<Record<string, string>>;
89
+ };
70
90
  };
71
91
  export type CSSSyntaxToken = {
72
- readonly type: number;
73
- readonly value: string;
74
- readonly index: number;
75
- readonly balance: number;
76
- readonly node?: any;
92
+ readonly type: number;
93
+ readonly value: string;
94
+ readonly index: number;
95
+ readonly balance: number;
96
+ readonly node?: any;
77
97
  };
78
- export type CssSyntaxTokenizer = (token: Readonly<CSSSyntaxToken> | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
98
+ export type CssSyntaxTokenizer = (
99
+ token: Readonly<CSSSyntaxToken> | null,
100
+ getNextToken: GetNextToken,
101
+ match: typeof cssSyntaxMatch,
102
+ ) => number;
79
103
  export type GetNextToken = (length: number) => CSSSyntaxToken | null;