@markuplint/types 4.0.1 → 4.0.3-alpha.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/token/token.d.ts +10 -0
- package/lib/token/token.js +18 -4
- package/package.json +10 -10
package/lib/token/token.d.ts
CHANGED
|
@@ -18,8 +18,18 @@ export declare class Token {
|
|
|
18
18
|
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
19
19
|
*/
|
|
20
20
|
static readonly whitespace: ReadonlyArray<string>;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use {@link getPosition} instead. Will be removed in v5.0.0.
|
|
23
|
+
*/
|
|
21
24
|
static getCol(value: string, offset: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use {@link getPosition} instead. Will be removed in v5.0.0.
|
|
27
|
+
*/
|
|
22
28
|
static getLine(value: string, offset: number): number;
|
|
29
|
+
static getPosition(value: string, offset: number): {
|
|
30
|
+
line: number;
|
|
31
|
+
column: number;
|
|
32
|
+
};
|
|
23
33
|
static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
|
|
24
34
|
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
25
35
|
offset: number;
|
package/lib/token/token.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
export class Token {
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use {@link getPosition} instead. Will be removed in v5.0.0.
|
|
4
|
+
*/
|
|
2
5
|
static getCol(value, offset) {
|
|
3
6
|
const lines = value.slice(0, offset).split(/\n/);
|
|
4
7
|
return (lines.at(-1) ?? '').length + 1;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use {@link getPosition} instead. Will be removed in v5.0.0.
|
|
11
|
+
*/
|
|
6
12
|
static getLine(value, offset) {
|
|
7
13
|
return value.slice(0, offset).split(/\n/).length;
|
|
8
14
|
}
|
|
15
|
+
static getPosition(value, offset) {
|
|
16
|
+
const lines = value.slice(0, offset).split(/\n/);
|
|
17
|
+
const line = lines.length;
|
|
18
|
+
const column = (lines.at(-1) ?? '').length + 1;
|
|
19
|
+
return { line, column };
|
|
20
|
+
}
|
|
9
21
|
static getType(value, separators) {
|
|
10
22
|
if (Token.whitespace.includes(value[0] ?? '')) {
|
|
11
23
|
return Token.WhiteSpace;
|
|
@@ -21,10 +33,11 @@ export class Token {
|
|
|
21
33
|
}
|
|
22
34
|
static shiftLocation(token, offset) {
|
|
23
35
|
const shifted = token.offset + offset;
|
|
36
|
+
const { line, column } = Token.getPosition(token.originalValue, shifted);
|
|
24
37
|
return {
|
|
25
38
|
offset: shifted,
|
|
26
|
-
line
|
|
27
|
-
column
|
|
39
|
+
line,
|
|
40
|
+
column,
|
|
28
41
|
};
|
|
29
42
|
}
|
|
30
43
|
constructor(value, offset, originalValue, separators) {
|
|
@@ -89,6 +102,7 @@ export class Token {
|
|
|
89
102
|
return Number.isNaN(num) ? 0 : num;
|
|
90
103
|
}
|
|
91
104
|
unmatched(options) {
|
|
105
|
+
const { line, column } = Token.getPosition(this.originalValue, this.offset);
|
|
92
106
|
return {
|
|
93
107
|
...options,
|
|
94
108
|
matched: false,
|
|
@@ -96,8 +110,8 @@ export class Token {
|
|
|
96
110
|
raw: this.value,
|
|
97
111
|
offset: this.offset,
|
|
98
112
|
length: this.value.length,
|
|
99
|
-
line
|
|
100
|
-
column
|
|
113
|
+
line,
|
|
114
|
+
column,
|
|
101
115
|
reason: options?.reason ?? 'syntax-error',
|
|
102
116
|
};
|
|
103
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/types",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3-alpha.0",
|
|
4
4
|
"description": "Type declaration and value checker",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"schema:prettier": "prettier --write \"./src/types.schema.ts\" \"./types.schema.json\" --log-level warn"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@types/css-tree": "
|
|
33
|
-
"@types/debug": "
|
|
32
|
+
"@types/css-tree": "2.3.7",
|
|
33
|
+
"@types/debug": "4.1.12",
|
|
34
34
|
"@types/whatwg-mimetype": "3.0.2",
|
|
35
|
-
"bcp-47": "
|
|
36
|
-
"css-tree": "
|
|
37
|
-
"debug": "
|
|
38
|
-
"leven": "
|
|
39
|
-
"type-fest": "
|
|
40
|
-
"whatwg-mimetype": "
|
|
35
|
+
"bcp-47": "2.1.0",
|
|
36
|
+
"css-tree": "2.3.1",
|
|
37
|
+
"debug": "4.3.4",
|
|
38
|
+
"leven": "4.0.0",
|
|
39
|
+
"type-fest": "4.12.0",
|
|
40
|
+
"whatwg-mimetype": "4.0.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "02b8ba8440aeeafbf9507ea0ef84bc258fced2c6"
|
|
43
43
|
}
|