@markuplint/types 4.8.0 → 4.8.2
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/ARCHITECTURE.ja.md +252 -0
- package/ARCHITECTURE.md +252 -0
- package/CHANGELOG.md +11 -9
- package/README.md +37 -2
- package/SKILL.md +100 -0
- package/docs/check-pipeline.ja.md +494 -0
- package/docs/check-pipeline.md +494 -0
- package/docs/token-system.ja.md +584 -0
- package/docs/token-system.md +584 -0
- package/docs/type-system.ja.md +556 -0
- package/docs/type-system.md +556 -0
- package/docs/validators.ja.md +514 -0
- package/docs/validators.md +514 -0
- package/lib/check-base.d.ts +71 -0
- package/lib/check-base.js +71 -0
- package/lib/check-multi-types.d.ts +12 -1
- package/lib/check-multi-types.js +11 -0
- package/lib/check.d.ts +13 -0
- package/lib/check.js +13 -0
- package/lib/css-defs.d.ts +8 -0
- package/lib/css-defs.js +8 -0
- package/lib/css-overrides.d.ts +7 -0
- package/lib/css-overrides.js +7 -0
- package/lib/css-syntax.d.ts +11 -0
- package/lib/css-syntax.js +12 -1
- package/lib/css-tokenizers.d.ts +6 -0
- package/lib/css-tokenizers.js +6 -0
- package/lib/debug.d.ts +3 -0
- package/lib/debug.js +3 -0
- package/lib/defs.d.ts +8 -0
- package/lib/defs.js +8 -0
- package/lib/directive.d.ts +14 -0
- package/lib/directive.js +14 -0
- package/lib/enum.d.ts +11 -0
- package/lib/enum.js +11 -0
- package/lib/get-candidate.d.ts +11 -0
- package/lib/get-candidate.js +11 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/keyword-type.d.ts +13 -0
- package/lib/keyword-type.js +13 -0
- package/lib/list.d.ts +13 -0
- package/lib/list.js +13 -0
- package/lib/match-result.d.ts +22 -1
- package/lib/match-result.js +21 -0
- package/lib/number.d.ts +12 -0
- package/lib/number.js +12 -0
- package/lib/primitive/is-float.d.ts +4 -1
- package/lib/primitive/is-float.js +4 -1
- package/lib/primitive/is-int.d.ts +4 -1
- package/lib/primitive/is-int.js +4 -1
- package/lib/primitive/is-non-zero-uint.d.ts +3 -2
- package/lib/primitive/is-non-zero-uint.js +3 -2
- package/lib/primitive/is-quantity.d.ts +5 -3
- package/lib/primitive/is-quantity.js +5 -3
- package/lib/primitive/is-uint.d.ts +5 -1
- package/lib/primitive/is-uint.js +5 -1
- package/lib/primitive/range.d.ts +5 -4
- package/lib/primitive/range.js +5 -4
- package/lib/primitive/split-unit.d.ts +3 -2
- package/lib/primitive/split-unit.js +3 -2
- package/lib/rfc/is-bcp-47.d.ts +2 -0
- package/lib/rfc/is-bcp-47.js +2 -0
- package/lib/token/token-collection.d.ts +107 -2
- package/lib/token/token-collection.js +103 -3
- package/lib/token/token.d.ts +66 -2
- package/lib/token/token.js +66 -2
- package/lib/token/types.d.ts +9 -0
- package/lib/types.d.ts +107 -0
- package/lib/w3c/check-serialized-permissions-policy.d.ts +2 -0
- package/lib/w3c/check-serialized-permissions-policy.js +2 -0
- package/lib/whatwg/check-autocomplete.d.ts +5 -0
- package/lib/whatwg/check-autocomplete.js +6 -0
- package/lib/whatwg/check-datetime/date-string.d.ts +2 -0
- package/lib/whatwg/check-datetime/date-string.js +2 -0
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +13 -0
- package/lib/whatwg/check-datetime/datetime-tokens.js +13 -0
- package/lib/whatwg/check-datetime/duration-string.d.ts +7 -0
- package/lib/whatwg/check-datetime/duration-string.js +7 -0
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +2 -0
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +2 -0
- package/lib/whatwg/check-datetime/index.d.ts +5 -0
- package/lib/whatwg/check-datetime/index.js +5 -0
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +4 -0
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +4 -0
- package/lib/whatwg/check-datetime/month-string.d.ts +2 -0
- package/lib/whatwg/check-datetime/month-string.js +2 -0
- package/lib/whatwg/check-datetime/time-string.d.ts +2 -0
- package/lib/whatwg/check-datetime/time-string.js +2 -0
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +8 -0
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +8 -0
- package/lib/whatwg/check-datetime/week-string.d.ts +2 -0
- package/lib/whatwg/check-datetime/week-string.js +2 -0
- package/lib/whatwg/check-datetime/year-string.d.ts +2 -0
- package/lib/whatwg/check-datetime/year-string.js +2 -0
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +2 -0
- package/lib/whatwg/check-datetime/yearless-date-string.js +2 -0
- package/lib/whatwg/check-link-type.d.ts +5 -1
- package/lib/whatwg/check-link-type.js +5 -1
- package/lib/whatwg/check-mime-type.d.ts +4 -1
- package/lib/whatwg/check-mime-type.js +4 -1
- package/lib/whatwg/is-abs-url.d.ts +2 -0
- package/lib/whatwg/is-abs-url.js +2 -0
- package/lib/whatwg/is-browser-context-name.d.ts +2 -2
- package/lib/whatwg/is-browser-context-name.js +2 -2
- package/lib/whatwg/is-custom-element-name.d.ts +1 -1
- package/lib/whatwg/is-custom-element-name.js +1 -1
- package/lib/whatwg/is-itemprop-name.d.ts +1 -0
- package/lib/whatwg/is-itemprop-name.js +1 -0
- package/lib/whatwg/is-navigable-target-name.d.ts +2 -0
- package/lib/whatwg/is-navigable-target-name.js +2 -0
- package/package.json +6 -6
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# @markuplint/types
|
|
2
|
+
|
|
3
|
+
## 概要
|
|
4
|
+
|
|
5
|
+
`@markuplint/types` は、markuplint における HTML/SVG 属性値の型バリデーションシステムです。HTML Living Standard、CSS 仕様、その他の Web 標準に基づく型定義に対して属性値を検証します。
|
|
6
|
+
|
|
7
|
+
文字列値と型定義を受け取り、値が型に適合するかどうかを判定します。不適合の場合は、不一致箇所の位置情報・理由・期待される値・修正候補を含む詳細なエラー結果を生成します。
|
|
8
|
+
|
|
9
|
+
## ディレクトリ構成
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
src/
|
|
13
|
+
├── index.ts # パッケージのエントリーポイント。公開APIを再エクスポート
|
|
14
|
+
├── types.ts # 主要な型定義 (Result, Defs, CustomSyntax など)
|
|
15
|
+
├── types.schema.ts # JSONスキーマから自動生成された型 (Type, List, Enum, Number, Directive)
|
|
16
|
+
├── check.ts # 公開エントリーポイント: 組み込みdefsを使う check()
|
|
17
|
+
├── check-base.ts # コアディスパッチャー: 型の形状に応じてチェッカーを振り分け
|
|
18
|
+
├── check-multi-types.ts # 複数チェッカーを試行し、最良の結果を返す
|
|
19
|
+
├── match-result.ts # ファクトリ関数: matched(), unmatched(), matches()
|
|
20
|
+
├── defs.ts # 組み込みHTML型定義レジストリ (Any, URL, DateTime など)
|
|
21
|
+
├── css-defs.ts # CSS/SVG型定義 (viewBox, dasharray など)
|
|
22
|
+
├── css-syntax.ts # css-tree フォークによるCSS構文マッチング
|
|
23
|
+
├── css-overrides.ts # css-tree組み込み構文のオーバーライド (SVGトランスフォーム)
|
|
24
|
+
├── css-tokenizers.ts # css-tree用カスタムトークナイザー (BCP-47)
|
|
25
|
+
├── keyword-type.ts # キーワード型の解決とキャッシュ
|
|
26
|
+
├── enum.ts # 列挙型チェッカー (大文字小文字非区別の集合メンバーシップ)
|
|
27
|
+
├── list.ts # リスト型チェッカー (カンマ/スペース区切りのトークン列)
|
|
28
|
+
├── number.ts # 数値型チェッカー (整数/浮動小数点と範囲制約)
|
|
29
|
+
├── directive.ts # ディレクティブ型チェッカー (プレフィックスパターン + トークン検証)
|
|
30
|
+
├── get-candidate.ts # レーベンシュタイン距離によるタイプミス修正候補の提示
|
|
31
|
+
├── debug.ts # デバッグロガーインスタンス
|
|
32
|
+
├── primitive/ # プリミティブ数値バリデーター
|
|
33
|
+
│ ├── index.ts # 全プリミティブバリデーターの再エクスポート
|
|
34
|
+
│ ├── is-float.ts # 浮動小数点数の検証
|
|
35
|
+
│ ├── is-int.ts # 符号付き整数の検証
|
|
36
|
+
│ ├── is-uint.ts # 符号なし整数の検証
|
|
37
|
+
│ ├── is-non-zero-uint.ts # 0以外の符号なし整数の検証
|
|
38
|
+
│ ├── is-quantity.ts # CSS数量 (数値 + 単位) の検証
|
|
39
|
+
│ ├── split-unit.ts # 数値部分と単位接尾辞の分離
|
|
40
|
+
│ ├── range.ts # 数値範囲チェックユーティリティ
|
|
41
|
+
│ └── index.spec.ts # テスト
|
|
42
|
+
├── token/ # 位置追跡トークンシステム
|
|
43
|
+
│ ├── index.ts # Token と TokenCollection の再エクスポート
|
|
44
|
+
│ ├── token.ts # Token クラス: オフセット・行・列の追跡
|
|
45
|
+
│ ├── token-collection.ts # TokenCollection: パース済みトークン列と検証機能
|
|
46
|
+
│ ├── types.ts # トークン値の型 (スカラー、配列、正規表現、数値)
|
|
47
|
+
│ └── index.spec.ts # テスト
|
|
48
|
+
├── whatwg/ # WHATWG HTML Standard に基づくバリデーター
|
|
49
|
+
│ ├── check-autocomplete.ts # autocomplete 属性の検証
|
|
50
|
+
│ ├── check-datetime/ # DateTime マイクロシンタックスバリデーター群
|
|
51
|
+
│ │ ├── index.ts # 全日時フォーマットのディスパッチャー
|
|
52
|
+
│ │ ├── date-string.ts # YYYY-MM-DD
|
|
53
|
+
│ │ ├── time-string.ts # HH:MM:SS
|
|
54
|
+
│ │ ├── month-string.ts # YYYY-MM
|
|
55
|
+
│ │ ├── week-string.ts # YYYY-Www
|
|
56
|
+
│ │ ├── year-string.ts # YYYY
|
|
57
|
+
│ │ ├── yearless-date-string.ts # MM-DD
|
|
58
|
+
│ │ ├── duration-string.ts # 期間フォーマット
|
|
59
|
+
│ │ ├── global-date-and-time-string.ts
|
|
60
|
+
│ │ ├── local-date-and-time-string.ts
|
|
61
|
+
│ │ ├── time-zone-offset-string.ts
|
|
62
|
+
│ │ ├── datetime-tokens.ts # 共通トークンパターン
|
|
63
|
+
│ │ └── index.spec.ts # テスト
|
|
64
|
+
│ ├── check-link-type.ts # リンクタイプの検証 (rel 属性)
|
|
65
|
+
│ ├── check-mime-type.ts # MIMEタイプの検証
|
|
66
|
+
│ ├── is-abs-url.ts # 絶対URLの判定
|
|
67
|
+
│ ├── is-browser-context-name.ts # ブラウジングコンテキスト名の判定 (非推奨)
|
|
68
|
+
│ ├── is-custom-element-name.ts # カスタム要素名の判定
|
|
69
|
+
│ ├── is-itemprop-name.ts # itemprop 名の判定
|
|
70
|
+
│ └── is-navigable-target-name.ts # ナビゲーションターゲット名の判定
|
|
71
|
+
├── rfc/ # RFC仕様に基づくバリデーター
|
|
72
|
+
│ ├── is-bcp-47.ts # BCP 47 言語タグの検証
|
|
73
|
+
│ └── is-bcp-47.spec.ts # テスト
|
|
74
|
+
└── w3c/ # W3C仕様に基づくバリデーター
|
|
75
|
+
├── check-serialized-permissions-policy.ts # Permissions Policy の検証
|
|
76
|
+
└── check-serialized-permissions-policy.spec.ts # テスト
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## アーキテクチャ図
|
|
80
|
+
|
|
81
|
+
```mermaid
|
|
82
|
+
flowchart TD
|
|
83
|
+
subgraph entry ["エントリーポイント"]
|
|
84
|
+
check["check(value, type)"]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
subgraph dispatch ["コアディスパッチャー"]
|
|
88
|
+
checkBase["checkBase(value, type, defs)"]
|
|
89
|
+
isKeyword{"キーワード型?"}
|
|
90
|
+
isList{"リスト型?"}
|
|
91
|
+
isEnum{"列挙型?"}
|
|
92
|
+
isNumber{"数値型?"}
|
|
93
|
+
isDirective{"ディレクティブ型?"}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
subgraph checkers ["個別チェッカー"]
|
|
97
|
+
checkKeywordType["checkKeywordType()"]
|
|
98
|
+
checkListFn["checkList()"]
|
|
99
|
+
checkEnumFn["checkEnum()"]
|
|
100
|
+
checkNumberFn["checkNumber()"]
|
|
101
|
+
checkDirectiveFn["checkDirective()"]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
subgraph resolution ["キーワード解決"]
|
|
105
|
+
defsRegistry["defs + cssDefs レジストリ"]
|
|
106
|
+
cssSyntaxMatch["cssSyntaxMatch()"]
|
|
107
|
+
customSyntax["CustomSyntax.is()"]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
subgraph result ["結果"]
|
|
111
|
+
matched["MatchedResult"]
|
|
112
|
+
unmatched["UnmatchedResult"]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
check --> checkBase
|
|
116
|
+
checkBase --> isKeyword
|
|
117
|
+
isKeyword -->|文字列| checkKeywordType
|
|
118
|
+
isKeyword -->|オブジェクト| isList
|
|
119
|
+
isList -->|separator あり| checkListFn
|
|
120
|
+
isList -->|なし| isEnum
|
|
121
|
+
isEnum -->|enum あり| checkEnumFn
|
|
122
|
+
isEnum -->|なし| isNumber
|
|
123
|
+
isNumber -->|float/integer| checkNumberFn
|
|
124
|
+
isNumber -->|なし| isDirective
|
|
125
|
+
isDirective -->|directive あり| checkDirectiveFn
|
|
126
|
+
|
|
127
|
+
checkKeywordType --> defsRegistry
|
|
128
|
+
defsRegistry -->|CustomCssSyntax| cssSyntaxMatch
|
|
129
|
+
defsRegistry -->|CustomSyntax| customSyntax
|
|
130
|
+
defsRegistry -->|未定義| cssSyntaxMatch
|
|
131
|
+
|
|
132
|
+
checkListFn -->|各トークン| checkBase
|
|
133
|
+
checkDirectiveFn -->|トークン部分| checkBase
|
|
134
|
+
|
|
135
|
+
cssSyntaxMatch --> matched
|
|
136
|
+
cssSyntaxMatch --> unmatched
|
|
137
|
+
customSyntax --> matched
|
|
138
|
+
customSyntax --> unmatched
|
|
139
|
+
checkEnumFn --> matched
|
|
140
|
+
checkEnumFn --> unmatched
|
|
141
|
+
checkNumberFn --> matched
|
|
142
|
+
checkNumberFn --> unmatched
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## 主要コンポーネント
|
|
146
|
+
|
|
147
|
+
### 1. 型システム
|
|
148
|
+
|
|
149
|
+
型システムは、属性値の制約を表現する型定義と、検証結果の表現方法を定めています。
|
|
150
|
+
|
|
151
|
+
| ファイル | 役割 |
|
|
152
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
153
|
+
| `types.ts` | 主要な型: `Result`, `MatchedResult`, `UnmatchedResult`, `Defs`, `CustomSyntax`, `CustomCssSyntax` |
|
|
154
|
+
| `types.schema.ts` | 自動生成された判別共用体 `Type` とそのバリアント: `KeywordDefinedType`, `List`, `Enum`, `Number`, `Directive` |
|
|
155
|
+
| `match-result.ts` | ファクトリ関数 `matched()`, `unmatched()` および `matches()` ラッパー |
|
|
156
|
+
| `defs.ts` | 組み込みHTML定義レジストリ (30以上の型: `Any`, `URL`, `DateTime`, `DOMID`, `BCP47` など) |
|
|
157
|
+
| `css-defs.ts` | CSS/SVG定義 (25以上の型: `<view-box>`, `<preserve-aspect-ratio>`, `<dasharray>` など) |
|
|
158
|
+
|
|
159
|
+
`Type` 共用体は5つの形状に分岐する判別共用体です:
|
|
160
|
+
|
|
161
|
+
- **文字列** (キーワード) -- 例: `"URL"`, `"<color>"`, `"DateTime"`
|
|
162
|
+
- **`separator` を持つオブジェクト** (リスト) -- スペース区切りまたはカンマ区切りのトークン列
|
|
163
|
+
- **`enum` を持つオブジェクト** (列挙) -- 許容される文字列値の固定集合
|
|
164
|
+
- **`type: "float" | "integer"` を持つオブジェクト** (数値) -- 範囲制約付きの数値
|
|
165
|
+
- **`directive` を持つオブジェクト** (ディレクティブ) -- プレフィックスパターンに続く型付きトークン
|
|
166
|
+
|
|
167
|
+
### 2. チェックパイプライン
|
|
168
|
+
|
|
169
|
+
バリデーションパイプラインは、型定義の形状を判別して適切なチェッカーに処理を振り分けます。
|
|
170
|
+
|
|
171
|
+
| ファイル | 役割 |
|
|
172
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
173
|
+
| `check.ts` | 公開関数 `check()`。`defs` と `cssDefs` を結合し、`checkBase()` に委譲 |
|
|
174
|
+
| `check-base.ts` | ディスパッチャー。`isKeyword()`, `isList()`, `isEnum()`, `isNumber()`, `isDirective()` で型を判別し、対応するチェッカーを呼び出す |
|
|
175
|
+
| `keyword-type.ts` | キーワード型の解決: `Defs` レジストリを参照し、見つからなければ `cssSyntaxMatch()` にフォールバック。結果をキャッシュ |
|
|
176
|
+
| `css-syntax.ts` | `css-tree` のフォークを使い、カスタム型とトークナイザーを組み込んだ CSS 値定義構文マッチング |
|
|
177
|
+
| `enum.ts` | 許容値の集合に対する検証 (デフォルトで大文字小文字非区別) |
|
|
178
|
+
| `list.ts` | セパレータで値を分割し、各トークンを `checkBase()` で再帰的に検証 |
|
|
179
|
+
| `number.ts` | 整数/浮動小数点のフォーマット検証と範囲制約 (gt, gte, lt, lte) のチェック |
|
|
180
|
+
| `directive.ts` | プレフィックスパターン (文字列または正規表現) のマッチング後、トークン部分を `checkBase()` で再帰的に検証 |
|
|
181
|
+
| `check-multi-types.ts` | 複数のチェッカーを順に試行し、最初にマッチした結果、またはパス数・オフセットが最大の不一致結果を返す |
|
|
182
|
+
| `get-candidate.ts` | レーベンシュタイン距離を用いたタイプミスの修正候補提示 |
|
|
183
|
+
|
|
184
|
+
### 3. トークンシステム
|
|
185
|
+
|
|
186
|
+
トークンシステムは、位置情報を保持したまま文字列を解析し、正確なエラー位置を報告するための基盤です。
|
|
187
|
+
|
|
188
|
+
| ファイル | 役割 |
|
|
189
|
+
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
190
|
+
| `token/token.ts` | `Token` クラス。値・オフセット・行・列を保持。位置情報付きエラー結果を生成する `unmatched()` メソッドを提供 |
|
|
191
|
+
| `token/token-collection.ts` | `TokenCollection` クラス (`Array<Token>` を継承)。設定可能なセパレータで文字列をトークンに分割。ユニーク制約・順序チェック・パターンマッチングに対応 |
|
|
192
|
+
| `token/types.ts` | トークン値の型定義: `TokenValueScalar` (文字列、RegExp、数値)、`TokenValueArray` |
|
|
193
|
+
|
|
194
|
+
### 4. バリデーター群
|
|
195
|
+
|
|
196
|
+
Web標準の仕様に基づいた、個別の値検証ロジックを実装しています。
|
|
197
|
+
|
|
198
|
+
| ディレクトリ | バリデーター |
|
|
199
|
+
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
200
|
+
| `primitive/` | `isFloat`, `isInt`, `isUint`, `isNonZeroUint`, `isQuantity`, `splitUnit`, `range` |
|
|
201
|
+
| `whatwg/` | `checkDateTime` (8種のサブバリデーター), `checkAutoComplete`, `checkMIMEType`, `checkLinkType`, `isAbsURL`, `isCustomElementName`, `isNavigableTargetName`, `isBrowserContextName`, `isItempropName` |
|
|
202
|
+
| `rfc/` | `isBCP47` (BCP 47 言語タグ検証) |
|
|
203
|
+
| `w3c/` | `checkSerializedPermissionsPolicy` (Permissions Policy 検証) |
|
|
204
|
+
|
|
205
|
+
## 外部依存パッケージ
|
|
206
|
+
|
|
207
|
+
| パッケージ | 用途 | 使用箇所 |
|
|
208
|
+
| ----------------- | -------------------------------------------------- | ------------------------------------------ |
|
|
209
|
+
| `css-tree` | CSS値定義構文のレキサーフォークによるマッチング | `css-syntax.ts` |
|
|
210
|
+
| `bcp-47` | BCP 47 言語タグのパースと検証 | `rfc/is-bcp-47.ts`, `css-tokenizers.ts` |
|
|
211
|
+
| `whatwg-mimetype` | WHATWG MIMEタイプのパース | `whatwg/check-mime-type.ts` |
|
|
212
|
+
| `leven` | タイプミス検出のためのレーベンシュタイン距離計算 | `get-candidate.ts` |
|
|
213
|
+
| `debug` | 名前空間 `@markuplint/types` のデバッグログ | `debug.ts` |
|
|
214
|
+
| `type-fest` | 深い不変性のための `ReadonlyDeep` ユーティリティ型 | `check.ts`, `check-base.ts` 他各チェッカー |
|
|
215
|
+
|
|
216
|
+
## 他パッケージとの連携
|
|
217
|
+
|
|
218
|
+
```mermaid
|
|
219
|
+
flowchart LR
|
|
220
|
+
subgraph upstream ["上流パッケージ"]
|
|
221
|
+
mlSpec["@markuplint/ml-spec"]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
subgraph pkg ["@markuplint/types"]
|
|
225
|
+
defs["defs レジストリ"]
|
|
226
|
+
check["check()"]
|
|
227
|
+
types["型定義"]
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
subgraph downstream ["下流パッケージ"]
|
|
231
|
+
rules["@markuplint/rules"]
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
mlSpec -->|"Defs を提供\n(型定義)"| defs
|
|
235
|
+
mlSpec -->|"Type 共用体を使用\n(属性仕様の記述)"| types
|
|
236
|
+
rules -->|"check() を呼び出し\n属性値を検証"| check
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### 上流: `@markuplint/ml-spec`
|
|
240
|
+
|
|
241
|
+
`@markuplint/ml-spec` は、要素仕様の中で属性値の制約を表現するために `Type` 共用体と関連する型 (`List`, `Enum`, `Number`, `Directive`, `KeywordDefinedType`) を利用します。また、組み込み定義レジストリを拡張する `Defs` エントリを生成します。
|
|
242
|
+
|
|
243
|
+
### 下流: `@markuplint/rules`
|
|
244
|
+
|
|
245
|
+
`@markuplint/rules` は、パース済み HTML ドキュメント中の属性値を検証するために `check(value, type)` を呼び出します。`Result` 型がエラー報告を駆動し、`UnmatchedResult` に含まれるオフセット・行・列・理由・期待値・修正候補の情報を、ルールがリント診断メッセージに変換します。
|
|
246
|
+
|
|
247
|
+
## ドキュメントマップ
|
|
248
|
+
|
|
249
|
+
- [型システム](docs/type-system.ja.md) -- 型共用体、Result型、Defsレジストリ、スキーマ生成
|
|
250
|
+
- [チェックパイプライン](docs/check-pipeline.ja.md) -- `check()` から個別チェッカーまでのバリデーションフロー
|
|
251
|
+
- [トークンシステム](docs/token-system.ja.md) -- Token クラス、TokenCollection、パースパターン
|
|
252
|
+
- [バリデーター](docs/validators.ja.md) -- プリミティブ、WHATWG、RFC、W3C バリデーター
|
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# @markuplint/types
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`@markuplint/types` is the attribute value type validation system for markuplint. It validates HTML and SVG attribute values against type definitions derived from the HTML Living Standard, CSS specifications, and related web standards.
|
|
6
|
+
|
|
7
|
+
Given a string value and a type definition, the package determines whether the value conforms to the type and, when it does not, produces a detailed error result including the mismatch position, reason, expected values, and suggested corrections.
|
|
8
|
+
|
|
9
|
+
## Directory Structure
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
src/
|
|
13
|
+
├── index.ts # Package entry point; re-exports public API
|
|
14
|
+
├── types.ts # Core type definitions (Result, Defs, CustomSyntax, etc.)
|
|
15
|
+
├── types.schema.ts # Auto-generated types from JSON schema (Type, List, Enum, Number, Directive)
|
|
16
|
+
├── check.ts # Primary entry point: check() with built-in defs
|
|
17
|
+
├── check-base.ts # Core dispatcher: routes to checkers by type shape
|
|
18
|
+
├── check-multi-types.ts # Tries multiple checkers, returns best result
|
|
19
|
+
├── match-result.ts # Factory functions: matched(), unmatched(), matches()
|
|
20
|
+
├── defs.ts # Built-in HTML type definitions registry (Any, URL, DateTime, etc.)
|
|
21
|
+
├── css-defs.ts # CSS/SVG type definitions (viewBox, dasharray, etc.)
|
|
22
|
+
├── css-syntax.ts # CSS syntax matching via css-tree fork
|
|
23
|
+
├── css-overrides.ts # Overrides for css-tree built-in syntax (SVG transforms)
|
|
24
|
+
├── css-tokenizers.ts # Custom tokenizers for css-tree (BCP-47)
|
|
25
|
+
├── keyword-type.ts # Keyword type resolution with caching
|
|
26
|
+
├── enum.ts # Enum checker (case-insensitive set membership)
|
|
27
|
+
├── list.ts # List checker (comma/space-separated token sequences)
|
|
28
|
+
├── number.ts # Number checker (int/float with range constraints)
|
|
29
|
+
├── directive.ts # Directive checker (prefix pattern + token validation)
|
|
30
|
+
├── get-candidate.ts # Typo correction via Levenshtein distance
|
|
31
|
+
├── debug.ts # Debug logger instance
|
|
32
|
+
├── primitive/ # Primitive numeric validators
|
|
33
|
+
│ ├── index.ts # Re-exports all primitive validators
|
|
34
|
+
│ ├── is-float.ts # Floating-point number validation
|
|
35
|
+
│ ├── is-int.ts # Signed integer validation
|
|
36
|
+
│ ├── is-uint.ts # Unsigned integer validation
|
|
37
|
+
│ ├── is-non-zero-uint.ts # Non-zero unsigned integer validation
|
|
38
|
+
│ ├── is-quantity.ts # CSS quantity (number + unit) validation
|
|
39
|
+
│ ├── split-unit.ts # Splits numeric value from unit suffix
|
|
40
|
+
│ ├── range.ts # Numeric range checking utility
|
|
41
|
+
│ └── index.spec.ts # Tests
|
|
42
|
+
├── token/ # Position-tracked token system
|
|
43
|
+
│ ├── index.ts # Re-exports Token and TokenCollection
|
|
44
|
+
│ ├── token.ts # Token class with offset, line, column tracking
|
|
45
|
+
│ ├── token-collection.ts # TokenCollection: parsed token sequence with validation
|
|
46
|
+
│ ├── types.ts # Token value types (scalar, array, regex, number)
|
|
47
|
+
│ └── index.spec.ts # Tests
|
|
48
|
+
├── whatwg/ # WHATWG HTML Standard validators
|
|
49
|
+
│ ├── check-autocomplete.ts # Autocomplete attribute validation
|
|
50
|
+
│ ├── check-datetime/ # DateTime microsyntax validators (date, time, month, etc.)
|
|
51
|
+
│ │ ├── index.ts # Dispatcher for all datetime formats
|
|
52
|
+
│ │ ├── date-string.ts # YYYY-MM-DD
|
|
53
|
+
│ │ ├── time-string.ts # HH:MM:SS
|
|
54
|
+
│ │ ├── month-string.ts # YYYY-MM
|
|
55
|
+
│ │ ├── week-string.ts # YYYY-Www
|
|
56
|
+
│ │ ├── year-string.ts # YYYY
|
|
57
|
+
│ │ ├── yearless-date-string.ts # MM-DD
|
|
58
|
+
│ │ ├── duration-string.ts # Duration format
|
|
59
|
+
│ │ ├── global-date-and-time-string.ts
|
|
60
|
+
│ │ ├── local-date-and-time-string.ts
|
|
61
|
+
│ │ ├── time-zone-offset-string.ts
|
|
62
|
+
│ │ ├── datetime-tokens.ts # Shared token patterns
|
|
63
|
+
│ │ └── index.spec.ts # Tests
|
|
64
|
+
│ ├── check-link-type.ts # Link type validation (rel attribute)
|
|
65
|
+
│ ├── check-mime-type.ts # MIME type validation
|
|
66
|
+
│ ├── is-abs-url.ts # Absolute URL check
|
|
67
|
+
│ ├── is-browser-context-name.ts # Browsing context name check (deprecated)
|
|
68
|
+
│ ├── is-custom-element-name.ts # Custom element name check
|
|
69
|
+
│ ├── is-itemprop-name.ts # Itemprop name check
|
|
70
|
+
│ └── is-navigable-target-name.ts # Navigable target name check
|
|
71
|
+
├── rfc/ # RFC-based validators
|
|
72
|
+
│ ├── is-bcp-47.ts # BCP 47 language tag validation
|
|
73
|
+
│ └── is-bcp-47.spec.ts # Tests
|
|
74
|
+
└── w3c/ # W3C specification validators
|
|
75
|
+
├── check-serialized-permissions-policy.ts # Permissions Policy validation
|
|
76
|
+
└── check-serialized-permissions-policy.spec.ts # Tests
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Architecture Diagram
|
|
80
|
+
|
|
81
|
+
```mermaid
|
|
82
|
+
flowchart TD
|
|
83
|
+
subgraph entry ["Entry Point"]
|
|
84
|
+
check["check(value, type)"]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
subgraph dispatch ["Core Dispatcher"]
|
|
88
|
+
checkBase["checkBase(value, type, defs)"]
|
|
89
|
+
isKeyword{"isKeyword?"}
|
|
90
|
+
isList{"isList?"}
|
|
91
|
+
isEnum{"isEnum?"}
|
|
92
|
+
isNumber{"isNumber?"}
|
|
93
|
+
isDirective{"isDirective?"}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
subgraph checkers ["Individual Checkers"]
|
|
97
|
+
checkKeywordType["checkKeywordType()"]
|
|
98
|
+
checkListFn["checkList()"]
|
|
99
|
+
checkEnumFn["checkEnum()"]
|
|
100
|
+
checkNumberFn["checkNumber()"]
|
|
101
|
+
checkDirectiveFn["checkDirective()"]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
subgraph resolution ["Keyword Resolution"]
|
|
105
|
+
defsRegistry["defs + cssDefs registry"]
|
|
106
|
+
cssSyntaxMatch["cssSyntaxMatch()"]
|
|
107
|
+
customSyntax["CustomSyntax.is()"]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
subgraph result ["Result"]
|
|
111
|
+
matched["MatchedResult"]
|
|
112
|
+
unmatched["UnmatchedResult"]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
check --> checkBase
|
|
116
|
+
checkBase --> isKeyword
|
|
117
|
+
isKeyword -->|string| checkKeywordType
|
|
118
|
+
isKeyword -->|object| isList
|
|
119
|
+
isList -->|separator| checkListFn
|
|
120
|
+
isList -->|no| isEnum
|
|
121
|
+
isEnum -->|enum| checkEnumFn
|
|
122
|
+
isEnum -->|no| isNumber
|
|
123
|
+
isNumber -->|float/integer| checkNumberFn
|
|
124
|
+
isNumber -->|no| isDirective
|
|
125
|
+
isDirective -->|directive| checkDirectiveFn
|
|
126
|
+
|
|
127
|
+
checkKeywordType --> defsRegistry
|
|
128
|
+
defsRegistry -->|CustomCssSyntax| cssSyntaxMatch
|
|
129
|
+
defsRegistry -->|CustomSyntax| customSyntax
|
|
130
|
+
defsRegistry -->|not found| cssSyntaxMatch
|
|
131
|
+
|
|
132
|
+
checkListFn -->|each token| checkBase
|
|
133
|
+
checkDirectiveFn -->|token part| checkBase
|
|
134
|
+
|
|
135
|
+
cssSyntaxMatch --> matched
|
|
136
|
+
cssSyntaxMatch --> unmatched
|
|
137
|
+
customSyntax --> matched
|
|
138
|
+
customSyntax --> unmatched
|
|
139
|
+
checkEnumFn --> matched
|
|
140
|
+
checkEnumFn --> unmatched
|
|
141
|
+
checkNumberFn --> matched
|
|
142
|
+
checkNumberFn --> unmatched
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Core Components
|
|
146
|
+
|
|
147
|
+
### 1. Type System
|
|
148
|
+
|
|
149
|
+
The type system defines what kinds of attribute values can be expressed and how validation results are represented.
|
|
150
|
+
|
|
151
|
+
| File | Purpose |
|
|
152
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
153
|
+
| `types.ts` | Core types: `Result`, `MatchedResult`, `UnmatchedResult`, `Defs`, `CustomSyntax`, `CustomCssSyntax` |
|
|
154
|
+
| `types.schema.ts` | Auto-generated union type `Type` and its variants: `KeywordDefinedType`, `List`, `Enum`, `Number`, `Directive` |
|
|
155
|
+
| `match-result.ts` | Factory functions `matched()`, `unmatched()`, and the `matches()` wrapper |
|
|
156
|
+
| `defs.ts` | Built-in HTML definitions registry (30+ types: `Any`, `URL`, `DateTime`, `DOMID`, `BCP47`, etc.) |
|
|
157
|
+
| `css-defs.ts` | CSS/SVG definitions (25+ types: `<view-box>`, `<preserve-aspect-ratio>`, `<dasharray>`, etc.) |
|
|
158
|
+
|
|
159
|
+
The `Type` union is the central discriminated union:
|
|
160
|
+
|
|
161
|
+
- **String** (keyword) -- e.g., `"URL"`, `"<color>"`, `"DateTime"`
|
|
162
|
+
- **Object with `separator`** (list) -- space-separated or comma-separated token sequences
|
|
163
|
+
- **Object with `enum`** (enum) -- fixed set of allowed string values
|
|
164
|
+
- **Object with `type: "float" | "integer"`** (number) -- numeric with range constraints
|
|
165
|
+
- **Object with `directive`** (directive) -- prefix pattern followed by a typed token
|
|
166
|
+
|
|
167
|
+
### 2. Check Pipeline
|
|
168
|
+
|
|
169
|
+
The validation pipeline routes a value through the correct checker based on the type definition's shape.
|
|
170
|
+
|
|
171
|
+
| File | Purpose |
|
|
172
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
173
|
+
| `check.ts` | Public `check()` function. Merges `defs` and `cssDefs`, delegates to `checkBase()` |
|
|
174
|
+
| `check-base.ts` | Dispatcher. Inspects type shape via `isKeyword()`, `isList()`, `isEnum()`, `isNumber()`, `isDirective()` and calls the matching checker |
|
|
175
|
+
| `keyword-type.ts` | Resolves keyword types: looks up in `Defs` registry, falls back to `cssSyntaxMatch()`. Caches results |
|
|
176
|
+
| `css-syntax.ts` | Matches values against CSS value definition syntax using a `css-tree` fork with custom types and tokenizers |
|
|
177
|
+
| `enum.ts` | Validates against a set of allowed string values (case-insensitive by default) |
|
|
178
|
+
| `list.ts` | Splits value into tokens by separator, validates each token recursively via `checkBase()` |
|
|
179
|
+
| `number.ts` | Validates integer/float format and checks range constraints (gt, gte, lt, lte) |
|
|
180
|
+
| `directive.ts` | Matches prefix patterns (string or regex), extracts token portion, validates recursively via `checkBase()` |
|
|
181
|
+
| `check-multi-types.ts` | Tries multiple checkers, returns first match or best unmatched result |
|
|
182
|
+
| `get-candidate.ts` | Suggests corrections for typos using Levenshtein distance |
|
|
183
|
+
|
|
184
|
+
### 3. Token System
|
|
185
|
+
|
|
186
|
+
The token system provides position-tracked string parsing for generating precise error locations.
|
|
187
|
+
|
|
188
|
+
| File | Purpose |
|
|
189
|
+
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
190
|
+
| `token/token.ts` | `Token` class. Tracks value, offset, line, column. Provides `unmatched()` for position-aware error results |
|
|
191
|
+
| `token/token-collection.ts` | `TokenCollection` class (extends `Array<Token>`). Parses strings into tokens with configurable separators. Supports uniqueness, ordering, and pattern matching |
|
|
192
|
+
| `token/types.ts` | Token value types for matching: `TokenValueScalar` (string, RegExp, number), `TokenValueArray` |
|
|
193
|
+
|
|
194
|
+
### 4. Validators
|
|
195
|
+
|
|
196
|
+
Domain-specific validators implementing checks for values defined in web standards.
|
|
197
|
+
|
|
198
|
+
| Directory | Validators |
|
|
199
|
+
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
200
|
+
| `primitive/` | `isFloat`, `isInt`, `isUint`, `isNonZeroUint`, `isQuantity`, `splitUnit`, `range` |
|
|
201
|
+
| `whatwg/` | `checkDateTime` (8 sub-validators), `checkAutoComplete`, `checkMIMEType`, `checkLinkType`, `isAbsURL`, `isCustomElementName`, `isNavigableTargetName`, `isBrowserContextName`, `isItempropName` |
|
|
202
|
+
| `rfc/` | `isBCP47` (BCP 47 language tag validation) |
|
|
203
|
+
| `w3c/` | `checkSerializedPermissionsPolicy` (Permissions Policy) |
|
|
204
|
+
|
|
205
|
+
## External Dependencies
|
|
206
|
+
|
|
207
|
+
| Dependency | Purpose | Where Used |
|
|
208
|
+
| ----------------- | --------------------------------------------------- | ----------------------------------------- |
|
|
209
|
+
| `css-tree` | CSS value definition syntax matching via lexer fork | `css-syntax.ts` |
|
|
210
|
+
| `bcp-47` | BCP 47 language tag parsing and validation | `rfc/is-bcp-47.ts`, `css-tokenizers.ts` |
|
|
211
|
+
| `whatwg-mimetype` | WHATWG MIME type parsing | `whatwg/check-mime-type.ts` |
|
|
212
|
+
| `leven` | Levenshtein distance for typo detection | `get-candidate.ts` |
|
|
213
|
+
| `debug` | Debug logging with namespace `@markuplint/types` | `debug.ts` |
|
|
214
|
+
| `type-fest` | `ReadonlyDeep` utility type for deep immutability | `check.ts`, `check-base.ts`, and checkers |
|
|
215
|
+
|
|
216
|
+
## Integration Points
|
|
217
|
+
|
|
218
|
+
```mermaid
|
|
219
|
+
flowchart LR
|
|
220
|
+
subgraph upstream ["Upstream"]
|
|
221
|
+
mlSpec["@markuplint/ml-spec"]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
subgraph pkg ["@markuplint/types"]
|
|
225
|
+
defs["defs registry"]
|
|
226
|
+
check["check()"]
|
|
227
|
+
types["Type definitions"]
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
subgraph downstream ["Downstream"]
|
|
231
|
+
rules["@markuplint/rules"]
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
mlSpec -->|"provides Defs\n(type definitions)"| defs
|
|
235
|
+
mlSpec -->|"uses Type union\nfor attribute specs"| types
|
|
236
|
+
rules -->|"calls check()\nto validate attribute values"| check
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Upstream: `@markuplint/ml-spec`
|
|
240
|
+
|
|
241
|
+
`@markuplint/ml-spec` consumes the `Type` union and related types (`List`, `Enum`, `Number`, `Directive`, `KeywordDefinedType`) to describe attribute value constraints in element specifications. It also produces `Defs` entries that extend the built-in definitions registry.
|
|
242
|
+
|
|
243
|
+
### Downstream: `@markuplint/rules`
|
|
244
|
+
|
|
245
|
+
`@markuplint/rules` calls `check(value, type)` to validate attribute values found in parsed HTML documents. The `Result` type drives error reporting: an `UnmatchedResult` provides the offset, line, column, reason, expected values, and candidate corrections that rules translate into lint diagnostics.
|
|
246
|
+
|
|
247
|
+
## Documentation Map
|
|
248
|
+
|
|
249
|
+
- [Type System](docs/type-system.md) -- Type unions, Result types, Defs registry, schema generation
|
|
250
|
+
- [Check Pipeline](docs/check-pipeline.md) -- Validation flow from `check()` through individual checkers
|
|
251
|
+
- [Token System](docs/token-system.md) -- Token class, TokenCollection, parse patterns
|
|
252
|
+
- [Validators](docs/validators.md) -- Primitive, WHATWG, RFC, W3C validators
|
package/CHANGELOG.md
CHANGED
|
@@ -3,23 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
## [4.8.2](https://github.com/markuplint/markuplint/compare/@markuplint/types@4.8.1...@markuplint/types@4.8.2) (2026-02-10)
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* **types:** adjust type checking for css-tree update ([7fff913](https://github.com/markuplint/markuplint/commit/7fff913f4630eab6017861934142636d3c267336))
|
|
12
|
-
* **types:** fix bug that spaces are invalid even if separator is 'space' when disallowToSurroundBySpaces is enabled ([3b81c3b](https://github.com/markuplint/markuplint/commit/3b81c3b525cd406275936236f8b793efed8864d7))
|
|
8
|
+
**Note:** Version bump only for package @markuplint/types
|
|
13
9
|
|
|
10
|
+
## [4.8.1](https://github.com/markuplint/markuplint/compare/@markuplint/types@4.8.0...@markuplint/types@4.8.1) (2025-11-05)
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
**Note:** Version bump only for package @markuplint/types
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
* **types:** add link type validation for HTML elements ([ed7cc6c](https://github.com/markuplint/markuplint/commit/ed7cc6c2b703e14b8572087eb07c63a97d864187))
|
|
14
|
+
# [4.8.0](https://github.com/markuplint/markuplint/compare/@markuplint/types@4.7.7...@markuplint/types@4.8.0) (2025-08-24)
|
|
19
15
|
|
|
16
|
+
### Bug Fixes
|
|
20
17
|
|
|
18
|
+
- **types:** adjust type checking for css-tree update ([7fff913](https://github.com/markuplint/markuplint/commit/7fff913f4630eab6017861934142636d3c267336))
|
|
19
|
+
- **types:** fix bug that spaces are invalid even if separator is 'space' when disallowToSurroundBySpaces is enabled ([3b81c3b](https://github.com/markuplint/markuplint/commit/3b81c3b525cd406275936236f8b793efed8864d7))
|
|
21
20
|
|
|
21
|
+
### Features
|
|
22
22
|
|
|
23
|
+
- **types:** add link type definitions for specific HTML elements ([7199a8e](https://github.com/markuplint/markuplint/commit/7199a8eb4eaf334855ba78064c4340e040d8614c))
|
|
24
|
+
- **types:** add link type validation for HTML elements ([ed7cc6c](https://github.com/markuplint/markuplint/commit/ed7cc6c2b703e14b8572087eb07c63a97d864187))
|
|
23
25
|
|
|
24
26
|
## [4.7.7](https://github.com/markuplint/markuplint/compare/@markuplint/types@4.7.6...@markuplint/types@4.7.7) (2025-08-13)
|
|
25
27
|
|
package/README.md
CHANGED
|
@@ -31,6 +31,41 @@ check('2020-02-30', 'DateTime');
|
|
|
31
31
|
// }
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
### `checkBase`
|
|
35
|
+
|
|
36
|
+
Validates a value against a type definition object (enum, list, number, directive, or keyword type).
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { checkBase } from '@markuplint/types';
|
|
40
|
+
|
|
41
|
+
checkBase('hello', { enum: ['hello', 'world'] }, {});
|
|
42
|
+
// => { matched: true }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `isCustomElementName`
|
|
46
|
+
|
|
47
|
+
Checks whether a string is a valid custom element name according to the WHATWG specification.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { isCustomElementName } from '@markuplint/types';
|
|
51
|
+
|
|
52
|
+
isCustomElementName()('my-element'); // => true
|
|
53
|
+
isCustomElementName()('div'); // => false
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Type Exports
|
|
57
|
+
|
|
58
|
+
The package also exports the following types:
|
|
59
|
+
|
|
60
|
+
| Type | Description |
|
|
61
|
+
| --------------------- | ---------------------------------------------------------- |
|
|
62
|
+
| `Result` | Union type of `MatchedResult` and `UnmatchedResult` |
|
|
63
|
+
| `MatchedResult` | Represents a successful match (`{ matched: true }`) |
|
|
64
|
+
| `UnmatchedResult` | Represents a failed match with location and reason details |
|
|
65
|
+
| `Type` | Union of all type definition shapes (enum, list, etc.) |
|
|
66
|
+
| `Defs` | Registry mapping type identifiers to their definitions |
|
|
67
|
+
| `CustomSyntaxChecker` | Factory function type for creating value checkers |
|
|
68
|
+
|
|
34
69
|
## Type Identifiers
|
|
35
70
|
|
|
36
71
|
| Identifier | Use on | Spec | Supported |
|
|
@@ -54,8 +89,8 @@ check('2020-02-30', 'DateTime');
|
|
|
54
89
|
| `HashName` | `img[usemap]` | [WHATWG](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference) | ✅ |
|
|
55
90
|
| `OneCodePointChar` | The `accesskey` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute) | ✅ |
|
|
56
91
|
| `CustomElementName` | The `is` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name) | ✅ |
|
|
57
|
-
| ~~`BrowsingContextName`~~ | Use `NavigableTargetName` instead. | **
|
|
58
|
-
| ~~`BrowsingContextNameOrKeyword`~~ | Use `NavigableTargetNameOrKeyword` instead. | **
|
|
92
|
+
| ~~`BrowsingContextName`~~ | Use `NavigableTargetName` instead. | **Obsoleted** | ✅ |
|
|
93
|
+
| ~~`BrowsingContextNameOrKeyword`~~ | Use `NavigableTargetNameOrKeyword` instead. | **Obsoleted** | ✅ |
|
|
59
94
|
| `NavigableTargetName` | `iframe[name]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name) | ✅ |
|
|
60
95
|
| `NavigableTargetNameOrKeyword` | `a[target]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword) | ✅ |
|
|
61
96
|
| `HTTPSchemaURL` | `a[ping]` (as list) and more | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#ping) | ✅ |
|