@markuplint/types 3.4.0 → 3.5.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
+ ): import('./types').MatchedResult | UnmatchedResult;
@@ -4,6 +4,7 @@ exports.checkMultiTypes = void 0;
4
4
  const debug_1 = require("./debug");
5
5
  const match_result_1 = require("./match-result");
6
6
  function checkMultiTypes(value, checks) {
7
+ var _a, _b, _c;
7
8
  let unmatched;
8
9
  for (const check of checks) {
9
10
  const res = check(value);
@@ -14,15 +15,15 @@ function checkMultiTypes(value, checks) {
14
15
  res._fn = check.name;
15
16
  // @ts-ignore
16
17
  (0, debug_1.log)('%s(%d) vs %s(%d)', unmatched === null || unmatched === void 0 ? void 0 : unmatched._fn, unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount, res._fn, res.passCount);
17
- const passedA = (unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount) || 0;
18
- const passedB = res.passCount || 0;
19
- const offsetA = (unmatched === null || unmatched === void 0 ? void 0 : unmatched.offset) || 0;
18
+ const passedA = (_a = unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount) !== null && _a !== void 0 ? _a : 0;
19
+ const passedB = (_b = res.passCount) !== null && _b !== void 0 ? _b : 0;
20
+ const offsetA = (_c = unmatched === null || unmatched === void 0 ? void 0 : unmatched.offset) !== null && _c !== void 0 ? _c : 0;
20
21
  const offsetB = res.offset;
21
22
  if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
22
23
  unmatched = res;
23
24
  }
24
25
  }
25
- const result = unmatched || (0, match_result_1.matched)();
26
+ const result = unmatched !== null && unmatched !== void 0 ? unmatched : (0, match_result_1.matched)();
26
27
  (0, debug_1.log)('%d checks result: %O', checks.length, result);
27
28
  return result;
28
29
  }
package/lib/css-syntax.js CHANGED
@@ -9,6 +9,7 @@ const MIMIC_TAG_L = 'mimiccases---';
9
9
  const MIMIC_TAG_R = '---mimiccases';
10
10
  const MIMIC_LENGTH = (MIMIC_TAG_L + MIMIC_TAG_R).length;
11
11
  function cssSyntaxMatch(value, type) {
12
+ var _a;
12
13
  (0, debug_1.log)('Search CSS Syntax: "%s"', type);
13
14
  const origin = value;
14
15
  let defName;
@@ -24,7 +25,7 @@ function cssSyntaxMatch(value, type) {
24
25
  }
25
26
  else {
26
27
  defName = type.syntax.apply;
27
- ebnf = type.syntax.ebnf || null;
28
+ ebnf = (_a = type.syntax.ebnf) !== null && _a !== void 0 ? _a : null;
28
29
  if (ebnf) {
29
30
  // Work in progress
30
31
  return (0, match_result_1.matched)();
@@ -69,7 +70,7 @@ function cssSyntaxMatch(value, type) {
69
70
  throw new Error('MARKUPLINT_TYPE_NO_EXIST');
70
71
  }
71
72
  const refParam = isProp ? 'Property' : 'Type';
72
- ref = ref || `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
73
+ ref = ref !== null && ref !== void 0 ? ref : `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
73
74
  // eslint-disable-next-line no-console
74
75
  const _w = console.warn;
75
76
  if (debug_1.log.enabled) {
package/lib/defs.js CHANGED
@@ -115,7 +115,7 @@ exports.types = {
115
115
  reason: 'unexpected-space',
116
116
  });
117
117
  }
118
- if (!tokens.length) {
118
+ if (tokens.length === 0) {
119
119
  return (0, match_result_1.unmatched)(value, 'empty-token');
120
120
  }
121
121
  return (0, match_result_1.matched)();
@@ -431,7 +431,7 @@ exports.types = {
431
431
  if (!height) {
432
432
  return sep.unmatched({ reason: 'unexpected-token' });
433
433
  }
434
- if (tail && tail[0]) {
434
+ if (tail[0]) {
435
435
  return tail[0].unmatched({ reason: 'extra-token' });
436
436
  }
437
437
  if (!(0, primitive_1.isUint)(width.value)) {
@@ -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 {};
@@ -33,6 +33,7 @@ function checkKeywordType(value, type, cache = true) {
33
33
  }
34
34
  exports.checkKeywordType = checkKeywordType;
35
35
  function _checkKeywordType(value, type) {
36
+ var _a, _b;
36
37
  const def = defs_1.types[type];
37
38
  if (!def) {
38
39
  (0, debug_1.log)('The "%s" type is not defined in custom type identifier markuplint specified', type);
@@ -51,8 +52,8 @@ function _checkKeywordType(value, type) {
51
52
  if (!matches.matched) {
52
53
  return {
53
54
  ...matches,
54
- ref: matches.ref || def.ref,
55
- expects: matches.expects || def.expects,
55
+ ref: (_a = matches.ref) !== null && _a !== void 0 ? _a : def.ref,
56
+ expects: (_b = matches.expects) !== null && _b !== void 0 ? _b : def.expects,
56
57
  };
57
58
  }
58
59
  return matches;
package/lib/list.js CHANGED
@@ -5,6 +5,7 @@ const check_1 = require("./check");
5
5
  const match_result_1 = require("./match-result");
6
6
  const token_1 = require("./token");
7
7
  function checkList(value, type, ref, cache = true) {
8
+ var _a;
8
9
  const tokens = new token_1.TokenCollection(value, type);
9
10
  const matches = tokens.check({ ref });
10
11
  if (!matches.matched) {
@@ -17,7 +18,7 @@ function checkList(value, type, ref, cache = true) {
17
18
  const { offset, line, column } = token_1.Token.shiftLocation(token, res.offset);
18
19
  return {
19
20
  ...res,
20
- partName: res.partName || 'the content of the list',
21
+ partName: (_a = res.partName) !== null && _a !== void 0 ? _a : 'the content of the list',
21
22
  offset,
22
23
  line,
23
24
  column,
@@ -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) => MatchedResult | UnmatchedResult;
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;
@@ -18,10 +18,11 @@ function matched() {
18
18
  }
19
19
  exports.matched = matched;
20
20
  function unmatched(value, reason, options) {
21
+ var _a;
21
22
  return {
22
23
  ...options,
23
24
  matched: false,
24
- ref: (options === null || options === void 0 ? void 0 : options.ref) || null,
25
+ ref: (_a = options === null || options === void 0 ? void 0 : options.ref) !== null && _a !== void 0 ? _a : null,
25
26
  raw: value,
26
27
  offset: 0,
27
28
  length: value.length,
@@ -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
  };
@@ -3,62 +3,75 @@ import type { UnmatchedResult } from '..';
3
3
  import type { Expect, Result, List } from '../types';
4
4
  import type { ReadonlyDeep } from 'type-fest';
5
5
  import { Token } from './token';
6
- type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
7
- specificSeparator: string | string[];
8
- }>;
6
+ type TokenCollectionOptions = Partial<
7
+ Omit<List, 'token'> & {
8
+ specificSeparator: string | string[];
9
+ }
10
+ >;
9
11
  export type TokenEachCheck = (head: Readonly<Token> | null, tail: ReadonlyDeep<TokenCollection>) => Result | void;
10
12
  export declare class TokenCollection extends Array<Token> {
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;
13
+ static fromPatterns(
14
+ value: Readonly<Token> | string,
15
+ patterns: readonly Readonly<RegExp>[],
16
+ typeOptions?: ReadonlyDeep<
17
+ Omit<TokenCollectionOptions, 'specificSeparator'> & {
18
+ repeat?: boolean;
19
+ }
20
+ >,
21
+ ): TokenCollection;
22
+ static get [Symbol.species](): ArrayConstructor;
23
+ readonly allowEmpty: NonNullable<List['allowEmpty']>;
24
+ readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
25
+ readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
26
+ readonly number: List['number'];
27
+ readonly ordered: NonNullable<List['ordered']>;
28
+ readonly separator: NonNullable<List['separator']>;
29
+ readonly unique: NonNullable<List['unique']>;
30
+ constructor(value?: string, typeOptions?: ReadonlyDeep<TokenCollectionOptions>);
31
+ constructor(value?: number);
32
+ get value(): string;
33
+ check(options?: {
34
+ expects?: Expect[];
35
+ ref?: string;
36
+ cache?: boolean;
37
+ }): import('..').MatchedResult | UnmatchedResult;
38
+ chunk(split: number): TokenCollection[];
39
+ compareTokens(
40
+ callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void,
41
+ ): Readonly<Token> | null | undefined;
42
+ divide(position: number): readonly [TokenCollection, TokenCollection];
43
+ eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
44
+ filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
45
+ getConsecutiveToken(tokenType: number): Readonly<Token> | null;
46
+ getDuplicated(): Token | null;
47
+ getIdentTokens(): TokenCollection;
48
+ /**
49
+ *
50
+ * @param value The token value or the token type or its list
51
+ */
52
+ has(value: TokenValue): boolean;
53
+ headAndTail(): {
54
+ head: Token | null;
55
+ tail: TokenCollection;
56
+ };
57
+ /**
58
+ *
59
+ * @param value The token value or the token type or its list
60
+ */
61
+ search(value: TokenValue): Token | null;
62
+ takeTurns(
63
+ tokenNumbers: ReadonlyArray<number>,
64
+ lastTokenNumber?: number,
65
+ ): {
66
+ unexpectedLastToken: boolean;
67
+ expectedTokenNumber: number | undefined;
68
+ token: Token;
69
+ } | null;
70
+ toJSON(): {
71
+ type: number;
72
+ value: string;
73
+ offset: number;
74
+ }[];
75
+ private static _new;
63
76
  }
64
77
  export {};
@@ -5,6 +5,7 @@ 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
+ var _c;
8
9
  const originalValue = typeof value === 'string' ? value : value.originalValue;
9
10
  let strings = typeof value === 'string' ? value : value.value;
10
11
  let cumulativeOffset = typeof value === 'string' ? 0 : value.offset;
@@ -31,7 +32,7 @@ class TokenCollection extends Array {
31
32
  value = strings.slice(res.index + res[0].length);
32
33
  }
33
34
  else {
34
- value = res[0] || '';
35
+ value = (_c = res[0]) !== null && _c !== void 0 ? _c : '';
35
36
  }
36
37
  }
37
38
  const token = addToken(value);
@@ -51,14 +52,15 @@ class TokenCollection extends Array {
51
52
  return Array;
52
53
  }
53
54
  constructor(value, typeOptions) {
55
+ var _c, _d, _e, _f, _g, _h;
54
56
  super();
55
- this.disallowToSurroundBySpaces = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.disallowToSurroundBySpaces) || false;
56
- this.allowEmpty = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.allowEmpty) || true;
57
- this.ordered = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.ordered) || false;
58
- this.unique = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.unique) || false;
59
- this.caseInsensitive = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.caseInsensitive) || true;
57
+ this.disallowToSurroundBySpaces = (_c = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.disallowToSurroundBySpaces) !== null && _c !== void 0 ? _c : false;
58
+ this.allowEmpty = (_d = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.allowEmpty) !== null && _d !== void 0 ? _d : true;
59
+ this.ordered = (_e = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.ordered) !== null && _e !== void 0 ? _e : false;
60
+ this.unique = (_f = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.unique) !== null && _f !== void 0 ? _f : false;
61
+ this.caseInsensitive = (_g = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.caseInsensitive) !== null && _g !== void 0 ? _g : true;
60
62
  this.number = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.number;
61
- this.separator = (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.separator) || 'space';
63
+ this.separator = (_h = typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.separator) !== null && _h !== void 0 ? _h : 'space';
62
64
  if (typeof value === 'number') {
63
65
  this.length = value;
64
66
  return;
@@ -70,7 +72,7 @@ class TokenCollection extends Array {
70
72
  if (this.separator === 'comma') {
71
73
  separators.push(',');
72
74
  }
73
- if (typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.specificSeparator) {
75
+ if ((typeOptions === null || typeOptions === void 0 ? void 0 : typeOptions.specificSeparator) != null) {
74
76
  if (typeof typeOptions.specificSeparator === 'string') {
75
77
  separators.push(typeOptions.specificSeparator);
76
78
  }
@@ -191,7 +193,7 @@ class TokenCollection extends Array {
191
193
  chunk(split) {
192
194
  const chunks = [];
193
195
  const tokens = this.slice();
194
- while (tokens.length) {
196
+ while (tokens.length > 0) {
195
197
  const chunkTokens = tokens.splice(0, split);
196
198
  const chunk = TokenCollection._new(chunkTokens, this);
197
199
  chunks.push(chunk);
@@ -222,6 +224,7 @@ class TokenCollection extends Array {
222
224
  return [a, b];
223
225
  }
224
226
  eachCheck(...callbacks) {
227
+ var _c, _d;
225
228
  let headAndTail = this.headAndTail();
226
229
  let head = headAndTail.head;
227
230
  let tail = headAndTail.tail;
@@ -234,10 +237,10 @@ class TokenCollection extends Array {
234
237
  wait--;
235
238
  const result = callback.call(this, head, tail);
236
239
  if (result && !result.matched) {
237
- passCount += result.passCount || 0;
240
+ passCount += (_c = result.passCount) !== null && _c !== void 0 ? _c : 0;
238
241
  if (prev && result.offset === 0 && result.length === 0) {
239
242
  const { offset, line, column } = token_1.Token.shiftLocation(prev, cumulativeOffset);
240
- firstUnmatched = firstUnmatched || {
243
+ firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
241
244
  ...result,
242
245
  offset,
243
246
  line,
@@ -245,7 +248,7 @@ class TokenCollection extends Array {
245
248
  };
246
249
  }
247
250
  if (!prev && this.value.length === 0) {
248
- firstUnmatched = firstUnmatched || {
251
+ firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : {
249
252
  ...result,
250
253
  reason: 'empty-token',
251
254
  expects: undefined,
@@ -262,7 +265,7 @@ class TokenCollection extends Array {
262
265
  }
263
266
  }
264
267
  }
265
- firstUnmatched = firstUnmatched || result;
268
+ firstUnmatched = firstUnmatched !== null && firstUnmatched !== void 0 ? firstUnmatched : result;
266
269
  }
267
270
  else if (result && !firstUnmatched && result.matched) {
268
271
  return result;
@@ -272,7 +275,7 @@ class TokenCollection extends Array {
272
275
  passCount += 4 * wait;
273
276
  }
274
277
  }
275
- cumulativeOffset = (head === null || head === void 0 ? void 0 : head.length) || 0;
278
+ cumulativeOffset = (_d = head === null || head === void 0 ? void 0 : head.length) !== null && _d !== void 0 ? _d : 0;
276
279
  headAndTail = tail.headAndTail();
277
280
  prev = head;
278
281
  head = headAndTail.head;
@@ -296,7 +299,7 @@ class TokenCollection extends Array {
296
299
  return current;
297
300
  }
298
301
  });
299
- return resultToken || null;
302
+ return resultToken !== null && resultToken !== void 0 ? resultToken : null;
300
303
  }
301
304
  getDuplicated() {
302
305
  const aList = this.slice();
@@ -333,7 +336,7 @@ class TokenCollection extends Array {
333
336
  const copy = this.slice();
334
337
  const head = copy.shift();
335
338
  if (!head) {
336
- return { head: head || null, tail: TokenCollection._new([], this) };
339
+ return { head: head !== null && head !== void 0 ? head : null, tail: TokenCollection._new([], this) };
337
340
  }
338
341
  const tail = TokenCollection._new(copy, this);
339
342
  return { head, tail };
@@ -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
  }
@@ -54,7 +54,7 @@ class Token {
54
54
  if (typeof value === 'string') {
55
55
  const a = caseInsensitive ? this.value.toLowerCase() : this.value;
56
56
  const b = caseInsensitive ? value.toLowerCase() : value;
57
- return a.indexOf(b) !== -1;
57
+ return a.includes(b);
58
58
  }
59
59
  if (value instanceof RegExp) {
60
60
  const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
@@ -89,20 +89,21 @@ class Token {
89
89
  };
90
90
  }
91
91
  toNumber() {
92
- return parseFloat(this.value);
92
+ const num = parseFloat(this.value);
93
+ return isNaN(num) ? 0 : num;
93
94
  }
94
95
  unmatched(options) {
95
- var _a;
96
+ var _a, _b;
96
97
  return {
97
98
  ...options,
98
99
  matched: false,
99
- ref: (options === null || options === void 0 ? void 0 : options.ref) || null,
100
+ ref: (_a = options === null || options === void 0 ? void 0 : options.ref) !== null && _a !== void 0 ? _a : null,
100
101
  raw: this.value,
101
102
  offset: this.offset,
102
103
  length: this.value.length,
103
104
  line: Token.getLine(this.originalValue, this.offset),
104
105
  column: Token.getCol(this.originalValue, this.offset),
105
- reason: (_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : 'syntax-error',
106
+ reason: (_b = options === null || options === void 0 ? void 0 : options.reason) !== null && _b !== void 0 ? _b : 'syntax-error',
106
107
  };
107
108
  }
108
109
  }