@markuplint/types 2.0.0 → 2.2.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,5 +1,2 @@
1
1
  import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
- export declare function checkMultiTypes(
3
- value: string,
4
- checks: CustomSyntaxCheck[],
5
- ): import('./types').MatchedResult | UnmatchedResult;
2
+ export declare function checkMultiTypes(value: string, checks: CustomSyntaxCheck[]): import("./types").MatchedResult | UnmatchedResult;
package/lib/css-syntax.js CHANGED
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cssSyntaxMatch = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  // @ts-ignore
6
- const css_tree_1 = (0, tslib_1.__importDefault)(require("css-tree"));
6
+ const css_tree_1 = tslib_1.__importDefault(require("css-tree"));
7
7
  // @ts-ignore
8
8
  const error_js_1 = require("css-tree/lib/lexer/error.js");
9
9
  // @ts-ignore
10
10
  const match_js_1 = require("css-tree/lib/lexer/match.js");
11
11
  // @ts-ignore
12
- const prepare_tokens_js_1 = (0, tslib_1.__importDefault)(require("css-tree/lib/lexer/prepare-tokens.js"));
12
+ const prepare_tokens_js_1 = tslib_1.__importDefault(require("css-tree/lib/lexer/prepare-tokens.js"));
13
13
  const debug_1 = require("./debug");
14
14
  const defs_1 = require("./defs");
15
15
  const match_result_1 = require("./match-result");
package/lib/debug.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.log = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
6
  exports.log = (0, debug_1.default)('@markuplint/types');
@@ -1,6 +1,3 @@
1
1
  declare type NullableString = string | null | undefined;
2
- export declare function getCandicate(
3
- value: NullableString,
4
- ...candicates: (NullableString | NullableString[])[]
5
- ): string | undefined;
2
+ export declare function getCandicate(value: NullableString, ...candicates: (NullableString | NullableString[])[]): string | undefined;
6
3
  export {};
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCandicate = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const leven_1 = (0, tslib_1.__importDefault)(require("leven"));
5
+ const leven_1 = tslib_1.__importDefault(require("leven"));
6
6
  function getCandicate(value, ...candicates) {
7
7
  if (!value) {
8
8
  return;
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./whatwg/is-custom-element-name"), exports);
5
- (0, tslib_1.__exportStar)(require("./check"), exports);
6
- (0, tslib_1.__exportStar)(require("./types"), exports);
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,22 +1,9 @@
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;
1
+ import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from './types';
2
+ export declare function matches(checker: FormattedPrimitiveTypeCheck, options?: UnmatchedResultOptions & {
3
+ ref?: string;
4
+ reason?: UnmatchedResultReason;
5
+ }): (value: string) => MatchedResult | UnmatchedResult;
15
6
  export declare function matched(): MatchedResult;
16
- export declare function unmatched(
17
- value: string,
18
- reason?: UnmatchedResultReason,
19
- options?: UnmatchedResultOptions & {
20
- ref?: string;
21
- },
22
- ): UnmatchedResult;
7
+ export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
8
+ ref?: string;
9
+ }): UnmatchedResult;
@@ -3,9 +3,6 @@
3
3
  *
4
4
  * @param value
5
5
  */
6
- export declare function isUint(
7
- value: string,
8
- opions?: {
9
- gt?: number;
10
- },
11
- ): boolean;
6
+ export declare function isUint(value: string, opions?: {
7
+ gt?: number;
8
+ }): 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
  };
@@ -1,71 +1,62 @@
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
- Omit<List, 'token'> & {
6
- speificSeparator: string | string[];
7
- }
8
- >;
4
+ declare type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
5
+ speificSeparator: string | string[];
6
+ }>;
9
7
  export declare type TokenEachCheck = (head: Token | null, tail: TokenCollection) => Result | void;
10
8
  export declare class TokenCollection extends Array<Token> {
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
- }[];
9
+ private static _new;
10
+ static fromPatterns(value: Token | string, patterns: RegExp[], typeOptions?: Omit<TokenCollectionOptions, 'speificSeparator'> & {
11
+ repeat?: boolean;
12
+ }): TokenCollection;
13
+ static get [Symbol.species](): ArrayConstructor;
14
+ readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
15
+ readonly allowEmpty: NonNullable<List['allowEmpty']>;
16
+ readonly ordered: NonNullable<List['ordered']>;
17
+ readonly unique: NonNullable<List['unique']>;
18
+ readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
19
+ readonly number: List['number'];
20
+ readonly separator: NonNullable<List['separator']>;
21
+ constructor(value?: string, typeOptions?: TokenCollectionOptions);
22
+ constructor(value?: number);
23
+ get value(): string;
24
+ filter(callback: (value: Token, index: number, array: Token[]) => boolean): TokenCollection;
25
+ headAndTail(): {
26
+ head: Token | null;
27
+ tail: TokenCollection;
28
+ };
29
+ getIdentTokens(): TokenCollection;
30
+ compareTokens(callback: (prev: Token, current: Token) => Token | null | void): Token | null | undefined;
31
+ /**
32
+ *
33
+ * @param value The token value or the token type or its list
34
+ */
35
+ has(value: string | RegExp | number | (string | RegExp | number)[]): boolean;
36
+ /**
37
+ *
38
+ * @param value The token value or the token type or its list
39
+ */
40
+ search(value: string | RegExp | number | (string | RegExp | number)[]): Token | null;
41
+ check(options?: {
42
+ expects?: Expect[];
43
+ ref?: string;
44
+ cache?: boolean;
45
+ }): import("..").MatchedResult | UnmatchedResult;
46
+ getConsecutiveToken(tokenType: number): Token | null;
47
+ takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
48
+ unexpectedLastToken: boolean;
49
+ expectedTokenNumber: number;
50
+ token: Token;
51
+ } | null;
52
+ eachCheck(...callbacks: TokenEachCheck[]): Result;
53
+ getDuplicated(): Token | null;
54
+ divide(position: number): readonly [TokenCollection, TokenCollection];
55
+ chunk(split: number): TokenCollection[];
56
+ toJSON(): {
57
+ type: number;
58
+ value: string;
59
+ offset: number;
60
+ }[];
70
61
  }
71
62
  export {};
@@ -1,60 +1,55 @@
1
1
  import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
2
2
  export declare class Token {
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
- };
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(token: Token, offset: number): {
8
+ offset: number;
9
+ line: number;
10
+ column: number;
11
+ };
12
+ /**
13
+ * ASCII whitespace is
14
+ * - U+0009 TAB
15
+ * - U+000A LF
16
+ * - U+000C FF
17
+ * - U+000D CR
18
+ * - U+0020 SPACE.
19
+ *
20
+ * @see https://infra.spec.whatwg.org/#ascii-whitespace
21
+ */
22
+ static readonly whitespace: ReadonlyArray<string>;
23
+ /**
24
+ * @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
25
+ */
26
+ static readonly Ident = 1;
27
+ static readonly WhiteSpace = 13;
28
+ static readonly Comma = 18;
29
+ readonly type: number;
30
+ readonly value: string;
31
+ readonly offset: number;
32
+ constructor(value: string, offset: number, originalValue: string, separators?: string[]);
33
+ get length(): number;
34
+ get origin(): string;
35
+ unmatched(options?: UnmatchedResultOptions & {
36
+ ref?: string;
37
+ reason?: UnmatchedResultReason;
38
+ }): UnmatchedResult;
39
+ /**
40
+ *
41
+ * @param value The token value or the token type or its list
42
+ */
43
+ match(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
44
+ /**
45
+ *
46
+ * @param value The token value or the token type or its list
47
+ */
48
+ includes(value: string | RegExp | number | (string | RegExp | number)[], caseInsensitive?: boolean): boolean;
49
+ toNumber(): number;
50
+ toJSON(): {
51
+ type: number;
52
+ value: string;
53
+ offset: number;
54
+ };
60
55
  }
@@ -9,7 +9,7 @@ class Token {
9
9
  this.type = Token.getType(value, separators);
10
10
  this.value = value;
11
11
  this.offset = offset;
12
- (0, tslib_1.__classPrivateFieldSet)(this, _Token_originalValue, originalValue, "f");
12
+ tslib_1.__classPrivateFieldSet(this, _Token_originalValue, originalValue, "f");
13
13
  }
14
14
  static getType(value, separators) {
15
15
  if (Token.whitespace.includes(value[0])) {
@@ -34,15 +34,15 @@ class Token {
34
34
  const shifted = token.offset + offset;
35
35
  return {
36
36
  offset: shifted,
37
- line: Token.getLine((0, tslib_1.__classPrivateFieldGet)(token, _Token_originalValue, "f"), shifted),
38
- column: Token.getCol((0, tslib_1.__classPrivateFieldGet)(token, _Token_originalValue, "f"), shifted),
37
+ line: Token.getLine(tslib_1.__classPrivateFieldGet(token, _Token_originalValue, "f"), shifted),
38
+ column: Token.getCol(tslib_1.__classPrivateFieldGet(token, _Token_originalValue, "f"), shifted),
39
39
  };
40
40
  }
41
41
  get length() {
42
42
  return this.value.length;
43
43
  }
44
44
  get origin() {
45
- return (0, tslib_1.__classPrivateFieldGet)(this, _Token_originalValue, "f");
45
+ return tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f");
46
46
  }
47
47
  unmatched(options) {
48
48
  var _a;
@@ -53,8 +53,8 @@ class Token {
53
53
  raw: this.value,
54
54
  offset: this.offset,
55
55
  length: this.value.length,
56
- line: Token.getLine((0, tslib_1.__classPrivateFieldGet)(this, _Token_originalValue, "f"), this.offset),
57
- column: Token.getCol((0, tslib_1.__classPrivateFieldGet)(this, _Token_originalValue, "f"), this.offset),
56
+ line: Token.getLine(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
57
+ column: Token.getCol(tslib_1.__classPrivateFieldGet(this, _Token_originalValue, "f"), this.offset),
58
58
  reason: (_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : 'syntax-error',
59
59
  };
60
60
  }
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 declare type Result = UnmatchedResult | MatchedResult;
4
4
  export declare type UnmatchedResult = {
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;
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
- partName?: string;
17
- expects?: Expect[];
18
- extra?: Expect;
19
- candicate?: string;
16
+ partName?: string;
17
+ expects?: Expect[];
18
+ extra?: Expect;
19
+ candicate?: string;
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;
20
35
  };
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
- };
56
36
  export declare type MatchedResult = {
57
- matched: true;
37
+ matched: true;
58
38
  };
59
39
  export declare type Expect = {
60
- type: 'const' | 'format' | 'syntax' | 'regxp' | 'common';
61
- value: string;
40
+ type: 'const' | 'format' | 'syntax' | 'regxp' | 'common';
41
+ value: string;
62
42
  };
63
43
  export declare type FormattedPrimitiveTypeCheck = (value: string) => boolean;
64
44
  export declare type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
65
45
  export declare type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
66
46
  export declare type CustomSyntax = {
67
- ref: string;
68
- expects?: Expect[];
69
- is: CustomSyntaxCheck;
47
+ ref: string;
48
+ expects?: Expect[];
49
+ is: CustomSyntaxCheck;
70
50
  };
71
51
  export declare type CustomSyntaxCheck = (value: string) => Result;
72
52
  export declare type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
73
53
  export declare type CustomCssSyntax = {
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
- };
54
+ ref: string;
55
+ caseSensitive?: boolean;
56
+ expects?: Expect[];
57
+ syntax: {
58
+ apply: `<${string}>`;
59
+ def: Record<string, string | CssSyntaxTokenizer>;
60
+ /**
61
+ * @deprecated
62
+ */
63
+ ebnf?: Record<string, string | string[]>;
64
+ /**
65
+ * @deprecated
66
+ */
67
+ properties?: Record<string, string>;
68
+ };
89
69
  };
90
70
  export declare type CSSSyntaxToken = {
91
- type: number;
92
- value: string;
93
- index: number;
94
- balance: number;
95
- node?: any;
71
+ type: number;
72
+ value: string;
73
+ index: number;
74
+ balance: number;
75
+ node?: any;
96
76
  };
97
- export declare type CssSyntaxTokenizer = (
98
- token: CSSSyntaxToken | null,
99
- getNextToken: GetNextToken,
100
- match: typeof cssSyntaxMatch,
101
- ) => number;
77
+ export declare type CssSyntaxTokenizer = (token: CSSSyntaxToken | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
102
78
  export declare type GetNextToken = (length: number) => CSSSyntaxToken | null;