@markuplint/types 3.0.0-dev.25 → 3.0.0-dev.290
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/README.md +63 -61
- package/lib/check-multi-types.d.ts +2 -2
- package/lib/check-multi-types.js +9 -13
- package/lib/check.d.ts +7 -6
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +60 -63
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +163 -91
- package/lib/enum.d.ts +4 -3
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -1
- package/lib/get-candidate.js +3 -8
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -6
- package/lib/keyword-type.d.ts +2 -2
- package/lib/keyword-type.js +17 -21
- package/lib/list.d.ts +4 -3
- package/lib/list.js +9 -13
- package/lib/match-result.d.ts +4 -4
- package/lib/match-result.js +6 -12
- package/lib/number.d.ts +3 -3
- package/lib/number.js +11 -15
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +1 -5
- package/lib/primitive/is-int.js +1 -5
- package/lib/primitive/is-non-zero-uint.js +1 -5
- package/lib/primitive/is-quantity.d.ts +1 -1
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +1 -1
- package/lib/primitive/is-uint.js +1 -5
- package/lib/primitive/range.js +1 -5
- package/lib/primitive/split-unit.js +3 -7
- package/lib/rfc/is-bcp-47.d.ts +1 -1
- package/lib/rfc/is-bcp-47.js +3 -7
- package/lib/token/index.d.ts +2 -2
- package/lib/token/index.js +2 -7
- package/lib/token/token-collection.d.ts +13 -13
- package/lib/token/token-collection.js +55 -50
- package/lib/token/token.d.ts +11 -10
- package/lib/token/token.js +16 -24
- package/lib/token/types.d.ts +3 -0
- package/lib/types.d.ts +47 -46
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +2 -2
- package/lib/types.schema.js +1 -3
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +16 -20
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +28 -32
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +9 -13
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +48 -44
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
- package/lib/whatwg/check-datetime/index.d.ts +1 -1
- package/lib/whatwg/check-datetime/index.js +25 -29
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
- package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/month-string.js +9 -13
- package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-string.js +9 -13
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +9 -13
- package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/year-string.js +9 -13
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
- package/lib/whatwg/check-mime-type.d.ts +1 -1
- package/lib/whatwg/check-mime-type.js +12 -18
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +1 -5
- package/lib/whatwg/is-browser-context-name.d.ts +3 -1
- package/lib/whatwg/is-browser-context-name.js +3 -5
- package/lib/whatwg/is-custom-element-name.d.ts +1 -1
- package/lib/whatwg/is-custom-element-name.js +1 -5
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +2 -6
- package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
- package/lib/whatwg/is-navigable-target-name.js +20 -0
- package/package.json +19 -14
- package/types.schema.json +314 -311
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/lib/check.spec.js +0 -76
- package/lib/css-syntax.spec.d.ts +0 -1
- package/lib/css-syntax.spec.js +0 -157
- package/lib/list.spec.d.ts +0 -1
- package/lib/list.spec.js +0 -129
- package/lib/primitive/index.spec.d.ts +0 -1
- package/lib/primitive/index.spec.js +0 -62
- package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
- package/lib/rfc/is-bcp-47.spec.js +0 -19
- package/lib/token/token-collection.spec.d.ts +0 -1
- package/lib/token/token-collection.spec.js +0 -144
- package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
- package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
- package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
- package/lib/whatwg/check-autocomplete.spec.js +0 -379
- package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
- package/lib/whatwg/check-datetime/index.spec.js +0 -318
- package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
- package/lib/whatwg/check-mime-type.spec.js +0 -58
- package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
- package/lib/whatwg/is-abs-url.spec.js +0 -8
- package/patches/css-tree+2.3.1.patch +0 -23
- package/src/check-multi-types.ts +0 -35
- package/src/check.spec.ts +0 -83
- package/src/check.ts +0 -48
- package/src/css-syntax.spec.ts +0 -167
- package/src/css-syntax.ts +0 -188
- package/src/debug.ts +0 -3
- package/src/defs.ts +0 -811
- package/src/enum.ts +0 -25
- package/src/get-candidate.ts +0 -24
- package/src/index.ts +0 -3
- package/src/keyword-type.ts +0 -64
- package/src/list.spec.ts +0 -133
- package/src/list.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- package/src/primitive/index.spec.ts +0 -65
- package/src/primitive/index.ts +0 -7
- package/src/primitive/is-float.ts +0 -8
- package/src/primitive/is-int.ts +0 -8
- package/src/primitive/is-non-zero-uint.ts +0 -8
- package/src/primitive/is-quantity.ts +0 -38
- package/src/primitive/is-uint.ts +0 -15
- package/src/primitive/range.ts +0 -14
- package/src/primitive/split-unit.ts +0 -20
- package/src/rfc/is-bcp-47.spec.ts +0 -23
- package/src/rfc/is-bcp-47.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.spec.ts +0 -147
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1113
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- package/src/whatwg/check-autocomplete.spec.ts +0 -387
- package/src/whatwg/check-autocomplete.ts +0 -380
- package/src/whatwg/check-datetime/date-string.ts +0 -44
- package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
- package/src/whatwg/check-datetime/duration-string.ts +0 -399
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
- package/src/whatwg/check-datetime/index.spec.ts +0 -333
- package/src/whatwg/check-datetime/index.ts +0 -36
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
- package/src/whatwg/check-datetime/month-string.ts +0 -31
- package/src/whatwg/check-datetime/time-string.ts +0 -49
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
- package/src/whatwg/check-datetime/week-string.ts +0 -41
- package/src/whatwg/check-datetime/year-string.ts +0 -26
- package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
- package/src/whatwg/check-mime-type.spec.ts +0 -59
- package/src/whatwg/check-mime-type.ts +0 -46
- package/src/whatwg/is-abs-url.spec.ts +0 -8
- package/src/whatwg/is-abs-url.ts +0 -31
- package/src/whatwg/is-browser-context-name.ts +0 -16
- package/src/whatwg/is-custom-element-name.ts +0 -76
- package/src/whatwg/is-itemprop-name.ts +0 -17
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
- /package/lib/{check.spec.d.ts → token/types.js} +0 -0
package/README.md
CHANGED
|
@@ -33,67 +33,69 @@ check('2020-02-30', 'DateTime');
|
|
|
33
33
|
|
|
34
34
|
## Type Identifiers
|
|
35
35
|
|
|
36
|
-
| Identifier
|
|
37
|
-
|
|
|
38
|
-
| `Any`
|
|
39
|
-
| `NoEmptyAny`
|
|
40
|
-
| `OneLineAny`
|
|
41
|
-
| `Zero`
|
|
42
|
-
| `Number`
|
|
43
|
-
| `Uint`
|
|
44
|
-
| `XMLName`
|
|
45
|
-
| `DOMID`
|
|
46
|
-
| `FunctionBody`
|
|
47
|
-
| `Pattern`
|
|
48
|
-
| `DateTime`
|
|
49
|
-
| `TabIndex`
|
|
50
|
-
| `BCP47`
|
|
51
|
-
| `URL`
|
|
52
|
-
| `AbsoluteURL`
|
|
53
|
-
| `HashName`
|
|
54
|
-
| `OneCodePointChar`
|
|
55
|
-
| `CustomElementName`
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
| `<
|
|
70
|
-
| `<
|
|
71
|
-
| `<
|
|
72
|
-
| `<
|
|
73
|
-
| `<'
|
|
74
|
-
| `<
|
|
75
|
-
| `<
|
|
76
|
-
| `<
|
|
77
|
-
| `<
|
|
78
|
-
| `<
|
|
79
|
-
| `<
|
|
80
|
-
| `<
|
|
81
|
-
| `<
|
|
82
|
-
| `<
|
|
83
|
-
| `<
|
|
84
|
-
| `<key-
|
|
85
|
-
| `<
|
|
86
|
-
| `<
|
|
87
|
-
| `<
|
|
88
|
-
| `<
|
|
89
|
-
| `<
|
|
90
|
-
| `<
|
|
91
|
-
| `<
|
|
92
|
-
| `<
|
|
93
|
-
| `<
|
|
94
|
-
| `<
|
|
95
|
-
| `<list-of-
|
|
96
|
-
| `<
|
|
36
|
+
| Identifier | Use on | Spec | Supported |
|
|
37
|
+
| ---------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------- |
|
|
38
|
+
| `Any` | Some attributes | | ✅ |
|
|
39
|
+
| `NoEmptyAny` | Some attributes | | ✅ |
|
|
40
|
+
| `OneLineAny` | Some attributes | | ✅ |
|
|
41
|
+
| `Zero` | Some attributes | | ✅ |
|
|
42
|
+
| `Number` | Some attributes | | ✅ |
|
|
43
|
+
| `Uint` | Some attributes | | ✅ |
|
|
44
|
+
| `XMLName` | `svg\|[attributeName]` and more | [XML](https://www.w3.org/TR/xml/#d0e804) | ✅ |
|
|
45
|
+
| `DOMID` | The `id` attribute and more | [WHATWG](https://html.spec.whatwg.org/multipage/dom.html#global-attributes:concept-id) | ✅ |
|
|
46
|
+
| `FunctionBody` | Event handler attributes | | 🚧 |
|
|
47
|
+
| `Pattern` | `input[pattern]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression) | ✅ |
|
|
48
|
+
| `DateTime` | `time[datetime]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value) | ✅ |
|
|
49
|
+
| `TabIndex` | The `tabindex` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex) | ✅ |
|
|
50
|
+
| `BCP47` | The `lang` attribute and more | [RFC](https://tools.ietf.org/rfc/bcp/bcp47.html) | ✅ |
|
|
51
|
+
| `URL` | Some attributes | [WHATWG](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces) | ✅ |
|
|
52
|
+
| `AbsoluteURL` | The `itemtype` attribute (as list) | [WHATWG](https://url.spec.whatwg.org/#syntax-url-absolute) | ✅ |
|
|
53
|
+
| `HashName` | `img[usemap]` | [WHATWG](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference) | ✅ |
|
|
54
|
+
| `OneCodePointChar` | The `accesskey` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute) | ✅ |
|
|
55
|
+
| `CustomElementName` | The `is` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name) | ✅ |
|
|
56
|
+
| ~~`BrowsingContextName`~~ | Use `NavigableTargetName` instead. | **Obsolated** | ✅ |
|
|
57
|
+
| ~~`BrowsingContextNameOrKeyword`~~ | Use `NavigableTargetNameOrKeyword` instead. | **Obsolated** | ✅ |
|
|
58
|
+
| `NavigableTargetName` | `iframe[name]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name) | ✅ |
|
|
59
|
+
| `NavigableTargetNameOrKeyword` | `a[target]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword) | ✅ |
|
|
60
|
+
| `HTTPSchemaURL` | `a[ping]` (as list) and more | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#ping) | ✅ |
|
|
61
|
+
| `MIMEType` | `embed[type]` and more | [WHATWG](https://mimesniff.spec.whatwg.org/#valid-mime-type) | ✅ |
|
|
62
|
+
| `ItemProp` | The `itemprop` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute) | ✅ |
|
|
63
|
+
| `Srcset` | `img[srcset]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#srcset-attributes) | ✅ |
|
|
64
|
+
| `SourceSizeList` | `img[sizes]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#sizes-attributes) | ✅ |
|
|
65
|
+
| `IconSize` | `link[sizes]` (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes) | ✅ |
|
|
66
|
+
| `AutoComplete` | `input[autocomplete]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete) | ✅ |
|
|
67
|
+
| `Accept` | `input[accept]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#attr-input-accept) | ✅ |
|
|
68
|
+
| `SerializedPermissionsPolicy` | `iframe[allow]` | [W3C](https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy) | ✅ |
|
|
69
|
+
| `<css-declaration-list>` | The `style` attribute | [CSS](https://drafts.csswg.org/css-style-attr/#syntax) | ✅ |
|
|
70
|
+
| `<class-list>` | The `class` attribute | [SVG](https://www.w3.org/TR/SVG/styling.html#ClassAttribute) | ✅ |
|
|
71
|
+
| `<svg-font-size>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size) | 🚧 |
|
|
72
|
+
| `<svg-font-size-adjust>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust) | 🚧 |
|
|
73
|
+
| `<'color-profile'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty) | 🚧 |
|
|
74
|
+
| `<'color-rendering'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty) | 🚧 |
|
|
75
|
+
| `<'enable-background'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty) | 🚧 |
|
|
76
|
+
| `<list-of-svg-feature-string>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/feature.html) | 🚧 |
|
|
77
|
+
| `<animatable-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#FromAttribute) | 🚧 |
|
|
78
|
+
| `<begin-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#BeginValueListSyntax) | 🚧 |
|
|
79
|
+
| `<end-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#EndValueListSyntax) | 🚧 |
|
|
80
|
+
| `<list-of-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#ValuesAttribute) | 🚧 |
|
|
81
|
+
| `<clock-value>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax) | 🚧 |
|
|
82
|
+
| `<color-matrix>` | Some attributes for SVG | [W3C](https://drafts.fxtf.org/filter-effects/#element-attrdef-fecolormatrix-values) | ✅ |
|
|
83
|
+
| `<dasharray>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/painting.html#StrokeDasharrayProperty) | ✅ |
|
|
84
|
+
| `<key-points>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyPointsAttribute) | ✅ |
|
|
85
|
+
| `<key-splines>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | ✅ |
|
|
86
|
+
| `<key-times>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | ✅ |
|
|
87
|
+
| `<system-language>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/struct.html#SystemLanguageAttribute) | ✅ |
|
|
88
|
+
| `<origin>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#MotionOriginAttribute) | ✅ |
|
|
89
|
+
| `<svg-path>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/paths.html#PathDataBNF) | 🚧 |
|
|
90
|
+
| `<points>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/shapes.html#DataTypePoints) | ✅ |
|
|
91
|
+
| `<preserve-aspect-ratio>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#PreserveAspectRatioAttribute) | ✅ |
|
|
92
|
+
| `<view-box>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute) | ✅ |
|
|
93
|
+
| `<rotate>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#RotateAttribute) | ✅ |
|
|
94
|
+
| `<text-coordinate>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/text.html#TSpanAttributes) | ✅ |
|
|
95
|
+
| `<list-of-lengths>` | Some attributes for SVG | | ✅ |
|
|
96
|
+
| `<list-of-numbers>` | Some attributes for SVG | | ✅ |
|
|
97
|
+
| `<list-of-percentages>` | Some attributes for SVG | | ✅ |
|
|
98
|
+
| `<number-optional-number>` | Some attributes for SVG | | ✅ |
|
|
97
99
|
|
|
98
100
|
In addition, you can use types **[CSSTree](https://github.com/csstree/csstree)** defined.
|
|
99
101
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CustomSyntaxCheck, UnmatchedResult } from './types';
|
|
2
|
-
export declare function checkMultiTypes(value: string, checks: CustomSyntaxCheck[]): import("./types").MatchedResult | UnmatchedResult;
|
|
1
|
+
import type { CustomSyntaxCheck, UnmatchedResult } from './types.js';
|
|
2
|
+
export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types.js").MatchedResult | UnmatchedResult;
|
package/lib/check-multi-types.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("./debug");
|
|
5
|
-
const match_result_1 = require("./match-result");
|
|
6
|
-
function checkMultiTypes(value, checks) {
|
|
1
|
+
import { log } from './debug.js';
|
|
2
|
+
import { matched } from './match-result.js';
|
|
3
|
+
export function checkMultiTypes(value, checks) {
|
|
7
4
|
let unmatched;
|
|
8
5
|
for (const check of checks) {
|
|
9
6
|
const res = check(value);
|
|
@@ -13,17 +10,16 @@ function checkMultiTypes(value, checks) {
|
|
|
13
10
|
// @ts-ignore
|
|
14
11
|
res._fn = check.name;
|
|
15
12
|
// @ts-ignore
|
|
16
|
-
|
|
17
|
-
const passedA =
|
|
18
|
-
const passedB = res.passCount
|
|
19
|
-
const offsetA =
|
|
13
|
+
log('%s(%d) vs %s(%d)', unmatched?._fn, unmatched?.passCount, res._fn, res.passCount);
|
|
14
|
+
const passedA = unmatched?.passCount ?? 0;
|
|
15
|
+
const passedB = res.passCount ?? 0;
|
|
16
|
+
const offsetA = unmatched?.offset ?? 0;
|
|
20
17
|
const offsetB = res.offset;
|
|
21
18
|
if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
|
|
22
19
|
unmatched = res;
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
const result = unmatched
|
|
26
|
-
|
|
22
|
+
const result = unmatched ?? matched();
|
|
23
|
+
log('%d checks result: %O', checks.length, result);
|
|
27
24
|
return result;
|
|
28
25
|
}
|
|
29
|
-
exports.checkMultiTypes = checkMultiTypes;
|
package/lib/check.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
1
|
+
import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types.js';
|
|
2
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
|
+
export declare function check(value: string, type: ReadonlyDeep<Type>, ref?: string, cache?: boolean): Result;
|
|
4
|
+
export declare function isKeyword(type: ReadonlyDeep<Type>): type is ReadonlyDeep<KeywordDefinedType>;
|
|
5
|
+
export declare function isList(type: ReadonlyDeep<Type>): type is ReadonlyDeep<List>;
|
|
6
|
+
export declare function isEnum(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Enum>;
|
|
7
|
+
export declare function isNumber(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Number>;
|
|
7
8
|
export declare function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax;
|
|
8
9
|
export declare function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax;
|
package/lib/check.js
CHANGED
|
@@ -1,49 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const list_1 = require("./list");
|
|
8
|
-
const number_1 = require("./number");
|
|
9
|
-
function check(value, type, ref, cache = true) {
|
|
1
|
+
import { log } from './debug.js';
|
|
2
|
+
import { checkEnum } from './enum.js';
|
|
3
|
+
import { checkKeywordType } from './keyword-type.js';
|
|
4
|
+
import { checkList } from './list.js';
|
|
5
|
+
import { checkNumber } from './number.js';
|
|
6
|
+
export function check(value, type, ref, cache = true) {
|
|
10
7
|
if (isKeyword(type)) {
|
|
11
|
-
|
|
12
|
-
return
|
|
8
|
+
log('Check keyword: %s', type);
|
|
9
|
+
return checkKeywordType(value, type, cache);
|
|
13
10
|
}
|
|
14
11
|
if (isList(type)) {
|
|
15
|
-
|
|
16
|
-
return
|
|
12
|
+
log('Check list: %O', type);
|
|
13
|
+
return checkList(value, type, ref, cache);
|
|
17
14
|
}
|
|
18
15
|
if (isEnum(type)) {
|
|
19
|
-
|
|
20
|
-
return
|
|
16
|
+
log('Check enum: %O', type);
|
|
17
|
+
return checkEnum(value, type, ref);
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
return
|
|
19
|
+
log('Check number: %O', type);
|
|
20
|
+
return checkNumber(value, type, ref);
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
function isKeyword(type) {
|
|
22
|
+
export function isKeyword(type) {
|
|
27
23
|
return typeof type === 'string';
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
function isList(type) {
|
|
25
|
+
export function isList(type) {
|
|
31
26
|
return typeof type !== 'string' && 'token' in type;
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
function isEnum(type) {
|
|
28
|
+
export function isEnum(type) {
|
|
35
29
|
return typeof type !== 'string' && 'enum' in type;
|
|
36
30
|
}
|
|
37
|
-
|
|
38
|
-
function isNumber(type) {
|
|
31
|
+
export function isNumber(type) {
|
|
39
32
|
return typeof type !== 'string' && 'enum' in type;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
function isCSSSyntax(type) {
|
|
34
|
+
export function isCSSSyntax(type) {
|
|
43
35
|
return typeof type === 'string' || 'syntax' in type;
|
|
44
36
|
}
|
|
45
|
-
|
|
46
|
-
function isCustomSyntax(type) {
|
|
37
|
+
export function isCustomSyntax(type) {
|
|
47
38
|
return !isCSSSyntax(type);
|
|
48
39
|
}
|
|
49
|
-
exports.isCustomSyntax = isCustomSyntax;
|
package/lib/css-syntax.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CustomCssSyntax, Result, CssSyntax } from './types';
|
|
1
|
+
import type { CustomCssSyntax, Result, CssSyntax } from './types.js';
|
|
2
2
|
export declare function cssSyntaxMatch(value: string, type: CssSyntax | CustomCssSyntax): Result;
|
package/lib/css-syntax.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const match_1 = require("css-tree/lexer/match");
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
const prepare_tokens_1 = tslib_1.__importDefault(require("css-tree/lexer/prepare-tokens"));
|
|
13
|
-
const debug_1 = require("./debug");
|
|
14
|
-
const defs_1 = require("./defs");
|
|
15
|
-
const match_result_1 = require("./match-result");
|
|
16
|
-
function cssSyntaxMatch(value, type) {
|
|
17
|
-
(0, debug_1.log)('Search CSS Syntax: "%s"', type);
|
|
1
|
+
import { fork } from 'css-tree';
|
|
2
|
+
import { log } from './debug.js';
|
|
3
|
+
import { tokenizers } from './defs.js';
|
|
4
|
+
import { matched } from './match-result.js';
|
|
5
|
+
const MIMIC_TAG_L = 'mimiccases---';
|
|
6
|
+
const MIMIC_TAG_R = '---mimiccases';
|
|
7
|
+
const MIMIC_LENGTH = (MIMIC_TAG_L + MIMIC_TAG_R).length;
|
|
8
|
+
export function cssSyntaxMatch(value, type) {
|
|
9
|
+
log('Search CSS Syntax: "%s"', type);
|
|
18
10
|
const origin = value;
|
|
19
11
|
let defName;
|
|
20
12
|
const typesExtended = {};
|
|
@@ -29,13 +21,13 @@ function cssSyntaxMatch(value, type) {
|
|
|
29
21
|
}
|
|
30
22
|
else {
|
|
31
23
|
defName = type.syntax.apply;
|
|
32
|
-
ebnf = type.syntax.ebnf
|
|
24
|
+
ebnf = type.syntax.ebnf ?? null;
|
|
33
25
|
if (ebnf) {
|
|
34
26
|
// Work in progress
|
|
35
|
-
return
|
|
27
|
+
return matched();
|
|
36
28
|
}
|
|
37
29
|
const types = {
|
|
38
|
-
...
|
|
30
|
+
...tokenizers,
|
|
39
31
|
...type.syntax.def,
|
|
40
32
|
};
|
|
41
33
|
Object.keys(types).forEach(key => {
|
|
@@ -43,7 +35,7 @@ function cssSyntaxMatch(value, type) {
|
|
|
43
35
|
if (typeof valueOrChecker === 'string') {
|
|
44
36
|
typesExtended[key] = valueOrChecker;
|
|
45
37
|
}
|
|
46
|
-
else {
|
|
38
|
+
else if (valueOrChecker) {
|
|
47
39
|
typesCheckers[key] = valueOrChecker;
|
|
48
40
|
}
|
|
49
41
|
});
|
|
@@ -57,54 +49,53 @@ function cssSyntaxMatch(value, type) {
|
|
|
57
49
|
ref = type.ref;
|
|
58
50
|
}
|
|
59
51
|
// @ts-ignore
|
|
60
|
-
const lexer =
|
|
52
|
+
const lexer = fork({
|
|
61
53
|
types: typesExtended,
|
|
62
54
|
properties: propsExtended,
|
|
63
55
|
}).lexer;
|
|
64
56
|
Object.keys(typesCheckers).forEach(key => {
|
|
65
57
|
const checker = typesCheckers[key];
|
|
66
|
-
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
lexer.addType_(key, (token, getNextToken) => checker?.(token, getNextToken, cssSyntaxMatch));
|
|
67
60
|
});
|
|
68
|
-
const { isProp, name
|
|
61
|
+
const { isProp, name } = detectName(defName);
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
const matcher = isProp ? lexer.properties[name] : lexer.types[name];
|
|
64
|
+
if (!matcher) {
|
|
65
|
+
log('"%s" CSS syntax not found', defName);
|
|
66
|
+
throw new Error('MARKUPLINT_TYPE_NO_EXIST');
|
|
67
|
+
}
|
|
69
68
|
const refParam = isProp ? 'Property' : 'Type';
|
|
70
|
-
ref = ref
|
|
69
|
+
ref = ref ?? `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
|
|
71
70
|
// eslint-disable-next-line no-console
|
|
72
71
|
const _w = console.warn;
|
|
73
|
-
if (
|
|
72
|
+
if (log.enabled) {
|
|
74
73
|
// eslint-disable-next-line no-console
|
|
75
|
-
console.warn = warn =>
|
|
76
|
-
}
|
|
77
|
-
const tokens = (0, prepare_tokens_1.default)(value, lexer.syntax);
|
|
78
|
-
const result = (0, match_1.matchAsTree)(tokens, matcher.match, lexer);
|
|
79
|
-
if (caseSensitive) {
|
|
80
|
-
if (result.tokens && Array.isArray(result.tokens)) {
|
|
81
|
-
let reducer = 0;
|
|
82
|
-
result.tokens = result.tokens.map((token) => {
|
|
83
|
-
const value = token.value;
|
|
84
|
-
const originValue = deMimicCases(value || '');
|
|
85
|
-
const isMimiced = value !== originValue;
|
|
86
|
-
reducer += isMimiced ? 'mimiccases------mimiccases'.length : 0;
|
|
87
|
-
token.value = originValue;
|
|
88
|
-
token.balance = token.balance - reducer;
|
|
89
|
-
return token;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
74
|
+
console.warn = warn => log('WARNING: %s (by %s => %s)', warn, value, type);
|
|
92
75
|
}
|
|
93
|
-
|
|
76
|
+
const result = lexer.match(defName, value);
|
|
77
|
+
log('css-tree/result: %O', result);
|
|
94
78
|
// eslint-disable-next-line no-console
|
|
95
79
|
console.warn = _w;
|
|
96
|
-
if (result.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
80
|
+
if (!result.error) {
|
|
81
|
+
return matched();
|
|
82
|
+
}
|
|
83
|
+
if (!('css' in result.error)) {
|
|
84
|
+
throw result.error;
|
|
101
85
|
}
|
|
102
|
-
const error =
|
|
86
|
+
const error = result.error;
|
|
103
87
|
if (caseSensitive) {
|
|
104
|
-
|
|
88
|
+
const offset = error.mismatchOffset % MIMIC_LENGTH;
|
|
89
|
+
const diff = error.mismatchOffset - offset;
|
|
90
|
+
error.message = deMimicCases(error.message).replace('-'.repeat(diff), '');
|
|
105
91
|
error.syntax = deMimicCases(error.syntax);
|
|
92
|
+
error.css = deMimicCases(error.css);
|
|
93
|
+
error.mismatchOffset = offset;
|
|
94
|
+
error.column = error.column % MIMIC_LENGTH;
|
|
95
|
+
const mismatchLength = error.mismatchLength - MIMIC_LENGTH;
|
|
96
|
+
error.mismatchLength = mismatchLength < 0 ? error.mismatchLength : mismatchLength;
|
|
106
97
|
}
|
|
107
|
-
|
|
98
|
+
log('css-tree/SyntaxMatchError: %O', error);
|
|
108
99
|
return {
|
|
109
100
|
matched: false,
|
|
110
101
|
ref,
|
|
@@ -123,28 +114,34 @@ function cssSyntaxMatch(value, type) {
|
|
|
123
114
|
reason: 'syntax-error',
|
|
124
115
|
};
|
|
125
116
|
}
|
|
126
|
-
|
|
127
|
-
function defToMatcher(lexer, def) {
|
|
117
|
+
function detectName(def) {
|
|
128
118
|
const isProp = def.search("<'") === 0;
|
|
129
119
|
const name = def.replace(/^<'?|'?>$/g, '');
|
|
130
|
-
const matcher = isProp ? lexer.properties[name] : lexer.types[name];
|
|
131
|
-
if (!matcher) {
|
|
132
|
-
(0, debug_1.log)('"%s" CSS syntax not found', def);
|
|
133
|
-
throw new Error('MARKUPLINT_TYPE_NO_EXIST');
|
|
134
|
-
}
|
|
135
120
|
return {
|
|
136
121
|
isProp,
|
|
137
122
|
name,
|
|
138
|
-
matcher,
|
|
139
123
|
};
|
|
140
124
|
}
|
|
141
|
-
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @param key
|
|
128
|
+
* @param obj
|
|
129
|
+
* @modifies obj
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
function eachMimicCases(key,
|
|
133
|
+
// Mutable
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
135
|
+
obj) {
|
|
142
136
|
const value = obj[key];
|
|
137
|
+
if (!value) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
143
140
|
obj[key] = mimicCases(value);
|
|
144
141
|
}
|
|
145
142
|
function mimicCases(value) {
|
|
146
|
-
return value.replace(/[A-Z]/g, $0 =>
|
|
143
|
+
return value.replace(/[A-Z]/g, $0 => `${MIMIC_TAG_L}${$0}${MIMIC_TAG_R}`);
|
|
147
144
|
}
|
|
148
145
|
function deMimicCases(value) {
|
|
149
|
-
return value.replace(
|
|
146
|
+
return value.replace(new RegExp(`${MIMIC_TAG_L}([A-Z])${MIMIC_TAG_R}`, 'g'), (_, $1) => $1);
|
|
150
147
|
}
|
package/lib/debug.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.log = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
-
exports.log = (0, debug_1.default)('@markuplint/types');
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
export const log = debug('@markuplint/types');
|
package/lib/defs.d.ts
CHANGED