@markuplint/types 1.0.0-dev.20211213.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/LICENSE +21 -0
- package/README.md +117 -0
- package/extends.json +12 -0
- package/gen/specific-schema.json +98 -0
- package/gen/types.ts +66 -0
- package/lib/check-multi-types.d.ts +2 -0
- package/lib/check-multi-types.js +29 -0
- package/lib/check.d.ts +8 -0
- package/lib/check.js +49 -0
- package/lib/check.spec.d.ts +1 -0
- package/lib/check.spec.js +57 -0
- package/lib/css-syntax.d.ts +2 -0
- package/lib/css-syntax.js +141 -0
- package/lib/css-syntax.spec.d.ts +1 -0
- package/lib/css-syntax.spec.js +157 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.js +6 -0
- package/lib/defs.d.ts +3 -0
- package/lib/defs.js +752 -0
- package/lib/enum.d.ts +3 -0
- package/lib/enum.js +26 -0
- package/lib/get-candicate.d.ts +3 -0
- package/lib/get-candicate.js +26 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +6 -0
- package/lib/keyword-type.d.ts +3 -0
- package/lib/keyword-type.js +46 -0
- package/lib/list.d.ts +3 -0
- package/lib/list.js +29 -0
- package/lib/list.spec.d.ts +1 -0
- package/lib/list.spec.js +129 -0
- package/lib/match-result.d.ts +9 -0
- package/lib/match-result.js +33 -0
- package/lib/number.d.ts +3 -0
- package/lib/number.js +41 -0
- package/lib/primitive/index.d.ts +7 -0
- package/lib/primitive/index.js +17 -0
- package/lib/primitive/index.spec.d.ts +1 -0
- package/lib/primitive/index.spec.js +62 -0
- package/lib/primitive/is-float.d.ts +6 -0
- package/lib/primitive/is-float.js +12 -0
- package/lib/primitive/is-int.d.ts +6 -0
- package/lib/primitive/is-int.js +12 -0
- package/lib/primitive/is-non-zero-uint.d.ts +6 -0
- package/lib/primitive/is-non-zero-uint.js +12 -0
- package/lib/primitive/is-quantity.d.ts +7 -0
- package/lib/primitive/is-quantity.js +41 -0
- package/lib/primitive/is-uint.d.ts +8 -0
- package/lib/primitive/is-uint.js +19 -0
- package/lib/primitive/range.d.ts +8 -0
- package/lib/primitive/range.js +18 -0
- package/lib/primitive/split-unit.d.ts +9 -0
- package/lib/primitive/split-unit.js +24 -0
- package/lib/rfc/is-bcp-47.d.ts +5 -0
- package/lib/rfc/is-bcp-47.js +14 -0
- package/lib/rfc/is-bcp-47.spec.d.ts +1 -0
- package/lib/rfc/is-bcp-47.spec.js +19 -0
- package/lib/token/index.d.ts +2 -0
- package/lib/token/index.js +7 -0
- package/lib/token/token-collection.d.ts +62 -0
- package/lib/token/token-collection.js +383 -0
- package/lib/token/token-collection.spec.d.ts +1 -0
- package/lib/token/token-collection.spec.js +144 -0
- package/lib/token/token.d.ts +55 -0
- package/lib/token/token.js +128 -0
- package/lib/types.d.ts +78 -0
- package/lib/types.js +2 -0
- package/lib/types.schema.d.ts +54 -0
- package/lib/types.schema.js +8 -0
- package/lib/w3c/check-serialized-permissions-policy.d.ts +15 -0
- package/lib/w3c/check-serialized-permissions-policy.js +251 -0
- package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +1 -0
- package/lib/w3c/check-serialized-permissions-policy.spec.js +26 -0
- package/lib/whatwg/check-autocomplete.d.ts +5 -0
- package/lib/whatwg/check-autocomplete.js +282 -0
- package/lib/whatwg/check-autocomplete.spec.d.ts +1 -0
- package/lib/whatwg/check-autocomplete.spec.js +370 -0
- package/lib/whatwg/check-datetime/date-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/date-string.js +31 -0
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +3 -0
- package/lib/whatwg/check-datetime/datetime-tokens.js +509 -0
- package/lib/whatwg/check-datetime/duration-string.d.ts +6 -0
- package/lib/whatwg/check-datetime/duration-string.js +322 -0
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +66 -0
- package/lib/whatwg/check-datetime/index.d.ts +5 -0
- package/lib/whatwg/check-datetime/index.js +35 -0
- package/lib/whatwg/check-datetime/index.spec.d.ts +1 -0
- package/lib/whatwg/check-datetime/index.spec.js +318 -0
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +9 -0
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +116 -0
- package/lib/whatwg/check-datetime/month-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/month-string.js +20 -0
- package/lib/whatwg/check-datetime/time-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/time-string.js +35 -0
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +7 -0
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +75 -0
- package/lib/whatwg/check-datetime/week-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/week-string.js +29 -0
- package/lib/whatwg/check-datetime/year-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/year-string.js +20 -0
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +5 -0
- package/lib/whatwg/check-datetime/yearless-date-string.js +27 -0
- package/lib/whatwg/check-mime-type.d.ts +11 -0
- package/lib/whatwg/check-mime-type.js +42 -0
- package/lib/whatwg/check-mime-type.spec.d.ts +1 -0
- package/lib/whatwg/check-mime-type.spec.js +58 -0
- package/lib/whatwg/is-abs-url.d.ts +15 -0
- package/lib/whatwg/is-abs-url.js +34 -0
- package/lib/whatwg/is-abs-url.spec.d.ts +1 -0
- package/lib/whatwg/is-abs-url.spec.js +8 -0
- package/lib/whatwg/is-browser-context-name.d.ts +11 -0
- package/lib/whatwg/is-browser-context-name.js +18 -0
- package/lib/whatwg/is-custom-element-name.d.ts +22 -0
- package/lib/whatwg/is-custom-element-name.js +77 -0
- package/lib/whatwg/is-itemprop-name.d.ts +12 -0
- package/lib/whatwg/is-itemprop-name.js +19 -0
- package/package.json +33 -0
- package/src/check-multi-types.ts +35 -0
- package/src/check.spec.ts +62 -0
- package/src/check.ts +48 -0
- package/src/css-syntax.spec.ts +167 -0
- package/src/css-syntax.ts +177 -0
- package/src/debug.ts +3 -0
- package/src/defs.ts +810 -0
- package/src/enum.ts +25 -0
- package/src/get-candicate.ts +24 -0
- package/src/index.ts +3 -0
- package/src/keyword-type.ts +52 -0
- package/src/list.spec.ts +133 -0
- package/src/list.ts +34 -0
- package/src/match-result.ts +49 -0
- package/src/number.ts +46 -0
- package/src/primitive/index.spec.ts +65 -0
- package/src/primitive/index.ts +7 -0
- package/src/primitive/is-float.ts +8 -0
- package/src/primitive/is-int.ts +8 -0
- package/src/primitive/is-non-zero-uint.ts +8 -0
- package/src/primitive/is-quantity.ts +38 -0
- package/src/primitive/is-uint.ts +15 -0
- package/src/primitive/range.ts +14 -0
- package/src/primitive/split-unit.ts +20 -0
- package/src/rfc/is-bcp-47.spec.ts +23 -0
- package/src/rfc/is-bcp-47.ts +13 -0
- package/src/token/index.ts +2 -0
- package/src/token/token-collection.spec.ts +147 -0
- package/src/token/token-collection.ts +444 -0
- package/src/token/token.ts +144 -0
- package/src/types.schema.ts +1059 -0
- package/src/types.ts +118 -0
- package/src/w3c/check-serialized-permissions-policy.spec.ts +27 -0
- package/src/w3c/check-serialized-permissions-policy.ts +287 -0
- package/src/whatwg/check-autocomplete.spec.ts +378 -0
- package/src/whatwg/check-autocomplete.ts +324 -0
- package/src/whatwg/check-datetime/date-string.ts +44 -0
- package/src/whatwg/check-datetime/datetime-tokens.ts +600 -0
- package/src/whatwg/check-datetime/duration-string.ts +399 -0
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +96 -0
- package/src/whatwg/check-datetime/index.spec.ts +333 -0
- package/src/whatwg/check-datetime/index.ts +36 -0
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +163 -0
- package/src/whatwg/check-datetime/month-string.ts +31 -0
- package/src/whatwg/check-datetime/time-string.ts +49 -0
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +93 -0
- package/src/whatwg/check-datetime/week-string.ts +41 -0
- package/src/whatwg/check-datetime/year-string.ts +26 -0
- package/src/whatwg/check-datetime/yearless-date-string.ts +38 -0
- package/src/whatwg/check-mime-type.spec.ts +59 -0
- package/src/whatwg/check-mime-type.ts +46 -0
- package/src/whatwg/is-abs-url.spec.ts +8 -0
- package/src/whatwg/is-abs-url.ts +31 -0
- package/src/whatwg/is-browser-context-name.ts +16 -0
- package/src/whatwg/is-custom-element-name.ts +76 -0
- package/src/whatwg/is-itemprop-name.ts +17 -0
- package/tsconfig.test.json +3 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/types.schema.json +1092 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2019 Yusuke Hirao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @markuplint/types
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@markuplint/types)
|
|
4
|
+
[](https://travis-ci.org/markuplint/markuplint)
|
|
5
|
+
[](https://coveralls.io/github/markuplint/markuplint?branch=main)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Prerequisites: [Node.js](https://nodejs.org) (Version 12.4.0 or later)
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ npm install @markuplint/types
|
|
13
|
+
|
|
14
|
+
$ yarn add @markuplint/types
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { check } from '@markuplint/types';
|
|
21
|
+
|
|
22
|
+
check('2020-01-01', 'DateTime');
|
|
23
|
+
// => { matched: true }
|
|
24
|
+
|
|
25
|
+
check('2020-02-30', 'DateTime');
|
|
26
|
+
// => {
|
|
27
|
+
// matched: false,
|
|
28
|
+
// reason: { type: 'out-of-range', gte: 1, lte: 29 },
|
|
29
|
+
// expects: [],
|
|
30
|
+
// partName: 'date',
|
|
31
|
+
// ref: 'https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value',
|
|
32
|
+
// raw: '30',
|
|
33
|
+
// offset: 8,
|
|
34
|
+
// length: 2,
|
|
35
|
+
// line: 1,
|
|
36
|
+
// column: 9,
|
|
37
|
+
// }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Type Identifiers
|
|
41
|
+
|
|
42
|
+
| Identifier | Use on | Spec | Supported |
|
|
43
|
+
| ------------------------------ | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------- |
|
|
44
|
+
| `Any` | Some attributes | | ✅ |
|
|
45
|
+
| `NoEmptyAny` | Some attributes | | ✅ |
|
|
46
|
+
| `OneLineAny` | Some attributes | | ✅ |
|
|
47
|
+
| `Zero` | Some attributes | | ✅ |
|
|
48
|
+
| `Number` | Some attributes | | ✅ |
|
|
49
|
+
| `Uint` | Some attributes | | ✅ |
|
|
50
|
+
| `XMLName` | `svg\|[attributeName]` and more | [XML](https://www.w3.org/TR/xml/#d0e804) | ✅ |
|
|
51
|
+
| `DOMID` | The `id` attribute and more | [WHATWG](https://html.spec.whatwg.org/multipage/dom.html#global-attributes:concept-id) | ✅ |
|
|
52
|
+
| `FunctionBody` | Event handler attributes | | 🚧 |
|
|
53
|
+
| `Pattern` | `input[pattern]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression) | ✅ |
|
|
54
|
+
| `DateTime` | `time[datetime]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value) | ✅ |
|
|
55
|
+
| `TabIndex` | The `tabindex` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex) | ✅ |
|
|
56
|
+
| `BCP47` | The `lang` attribute and more | [RFC](https://tools.ietf.org/rfc/bcp/bcp47.html) | ✅ |
|
|
57
|
+
| `URL` | Some attributes | [WHATWG](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces) | ✅ |
|
|
58
|
+
| `AbsoluteURL` | The `itemtype` attribute (as list) | [WHATWG](https://url.spec.whatwg.org/#syntax-url-absolute) | ✅ |
|
|
59
|
+
| `HashName` | `img[usemap]` | [WHATWG](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference) | ✅ |
|
|
60
|
+
| `OneCodePointChar` | The `accesskey` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute) | ✅ |
|
|
61
|
+
| `CustomElementName` | The `is` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name) | ✅ |
|
|
62
|
+
| `BrowsingContextName` | `iframe[name]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-names) | ✅ |
|
|
63
|
+
| `BrowsingContextNameOrKeyword` | `a[target]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name-or-keyword) | ✅ |
|
|
64
|
+
| `HTTPSchemaURL` | `a[ping]` (as list) and more | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#ping) | ✅ |
|
|
65
|
+
| `MIMEType` | `embed[type]` and more | [WHATWG](https://mimesniff.spec.whatwg.org/#valid-mime-type) | ✅ |
|
|
66
|
+
| `ItemProp` | The `itemprop` attibute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute) | ✅ |
|
|
67
|
+
| `Srcset` | `img[srcset]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#srcset-attributes) | ✅ |
|
|
68
|
+
| `SourceSizeList` | `img[sizes]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#sizes-attributes) | ✅ |
|
|
69
|
+
| `IconSize` | `link[sizes]` (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes) | ✅ |
|
|
70
|
+
| `AutoComplete` | `input[autocomplete]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete) | ✅ |
|
|
71
|
+
| `Accept` | `input[accept]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#attr-input-accept) | ✅ |
|
|
72
|
+
| `SerializedPermissionsPolicy` | `iframe[allow]` | [W3C](https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy) | ✅ |
|
|
73
|
+
| `<css-declaration-list>` | The `style` attribute | [CSS](https://drafts.csswg.org/css-style-attr/#syntax) | ✅ |
|
|
74
|
+
| `<class-list>` | The `class` attribute | [SVG](https://www.w3.org/TR/SVG/styling.html#ClassAttribute) | ✅ |
|
|
75
|
+
| `<svg-font-size>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size) | 🚧 |
|
|
76
|
+
| `<svg-font-size-adjust>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust) | 🚧 |
|
|
77
|
+
| `<'color-profile'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty) | 🚧 |
|
|
78
|
+
| `<'color-rendering'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty) | 🚧 |
|
|
79
|
+
| `<'enable-background'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty) | 🚧 |
|
|
80
|
+
| `<list-of-svg-feature-string>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/feature.html) | 🚧 |
|
|
81
|
+
| `<animatable-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#FromAttribute) | 🚧 |
|
|
82
|
+
| `<begin-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#BeginValueListSyntax) | 🚧 |
|
|
83
|
+
| `<end-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#EndValueListSyntax) | 🚧 |
|
|
84
|
+
| `<list-of-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#ValuesAttribute) | 🚧 |
|
|
85
|
+
| `<clock-value>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax) | 🚧 |
|
|
86
|
+
| `<color-matrix>` | Some attributes for SVG | [W3C](https://drafts.fxtf.org/filter-effects/#element-attrdef-fecolormatrix-values) | ✅ |
|
|
87
|
+
| `<dasharray>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/painting.html#StrokeDasharrayProperty) | ✅ |
|
|
88
|
+
| `<key-points>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyPointsAttribute) | ✅ |
|
|
89
|
+
| `<key-splines>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | ✅ |
|
|
90
|
+
| `<key-times>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | ✅ |
|
|
91
|
+
| `<system-language>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/struct.html#SystemLanguageAttribute) | ✅ |
|
|
92
|
+
| `<origin>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#MotionOriginAttribute) | ✅ |
|
|
93
|
+
| `<svg-path>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/paths.html#PathDataBNF) | 🚧 |
|
|
94
|
+
| `<points>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/shapes.html#DataTypePoints) | ✅ |
|
|
95
|
+
| `<preserve-aspect-ratio>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#PreserveAspectRatioAttribute) | ✅ |
|
|
96
|
+
| `<view-box>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute) | ✅ |
|
|
97
|
+
| `<rotate>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#RotateAttribute) | ✅ |
|
|
98
|
+
| `<text-coordinate>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/text.html#TSpanAttributes) | ✅ |
|
|
99
|
+
| `<list-of-lengths>` | Some attributes for SVG | | ✅ |
|
|
100
|
+
| `<list-of-numbers>` | Some attributes for SVG | | ✅ |
|
|
101
|
+
| `<list-of-percentages>` | Some attributes for SVG | | ✅ |
|
|
102
|
+
| `<number-optional-number>` | Some attributes for SVG | | ✅ |
|
|
103
|
+
|
|
104
|
+
In addition, you can use types **[CSSTree](https://github.com/csstree/csstree)** defined.
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
$ git clone git@github.com:markuplint/markuplint.git -b main
|
|
110
|
+
$ yarn
|
|
111
|
+
$ yarn build
|
|
112
|
+
$ yarn test
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
Copyright © 2021 markuplint. Under the MIT License.
|
package/extends.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"refs": {
|
|
3
|
+
"source-size-list": "https://html.spec.whatwg.org/multipage/images.html#sizes-attributes",
|
|
4
|
+
"key-times": "https://svgwg.org/specs/animations/#KeyTimesAttribute"
|
|
5
|
+
},
|
|
6
|
+
"types": {
|
|
7
|
+
"source-size-list": "[ <source-size># , ]? <source-size-value>",
|
|
8
|
+
"source-size": "<media-condition> <source-size-value>",
|
|
9
|
+
"source-size-value": "<length>",
|
|
10
|
+
"key-times": "<number> [; <number>]* [;]?"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"definitions": {
|
|
4
|
+
"list": {
|
|
5
|
+
"description": "- [Space-separated tokens](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#space-separated-tokens)\n- [Comma-separated tokens](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#comma-separated-tokens)",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["token", "separator"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"token": {
|
|
11
|
+
"oneOf": [
|
|
12
|
+
{
|
|
13
|
+
"$ref": "#/definitions/extended-type"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"$ref": "#/definitions/enum"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"disallowToSurroundBySpaces": { "type": "boolean" },
|
|
21
|
+
"allowEmpty": { "type": "boolean" },
|
|
22
|
+
"ordered": { "type": "boolean" },
|
|
23
|
+
"unique": { "type": "boolean" },
|
|
24
|
+
"caseInsensitive": { "type": "boolean" },
|
|
25
|
+
"number": {
|
|
26
|
+
"oneOf": [
|
|
27
|
+
{
|
|
28
|
+
"type": "string",
|
|
29
|
+
"enum": ["zeroOrMore", "oneOrMore"]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "object",
|
|
33
|
+
"additionalProperties": false,
|
|
34
|
+
"required": ["min", "max"],
|
|
35
|
+
"properties": {
|
|
36
|
+
"min": { "type": "number" },
|
|
37
|
+
"max": { "type": "number" }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"separator": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"enum": ["space", "comma"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"enum": {
|
|
49
|
+
"description": "[Enumerated attributes](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute)",
|
|
50
|
+
"type": "object",
|
|
51
|
+
"additionalProperties": false,
|
|
52
|
+
"required": ["enum"],
|
|
53
|
+
"properties": {
|
|
54
|
+
"enum": {
|
|
55
|
+
"type": "array",
|
|
56
|
+
"minItems": 1,
|
|
57
|
+
"uniqueItems": true,
|
|
58
|
+
"items": {
|
|
59
|
+
"type": "string"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"disallowToSurroundBySpaces": { "type": "boolean" },
|
|
63
|
+
"caseInsensitive": { "type": "boolean" },
|
|
64
|
+
"invalidValueDefault": { "type": "string" },
|
|
65
|
+
"missingValueDefault": { "type": "string" },
|
|
66
|
+
"sameStates": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"additionalProperties": true,
|
|
69
|
+
"items": {
|
|
70
|
+
"type": "array",
|
|
71
|
+
"minItems": 1,
|
|
72
|
+
"uniqueItems": true,
|
|
73
|
+
"items": {
|
|
74
|
+
"type": "string"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"number": {
|
|
81
|
+
"description": "[Numbers](https://html.spec.whatwg.org/dev/common-microsyntaxes.html#numbers)",
|
|
82
|
+
"type": "object",
|
|
83
|
+
"required": ["type"],
|
|
84
|
+
"additionalProperties": false,
|
|
85
|
+
"properties": {
|
|
86
|
+
"type": {
|
|
87
|
+
"type": "string",
|
|
88
|
+
"enum": ["float", "integer"]
|
|
89
|
+
},
|
|
90
|
+
"gt": { "type": "number" },
|
|
91
|
+
"gte": { "type": "number" },
|
|
92
|
+
"lt": { "type": "number" },
|
|
93
|
+
"lte": { "type": "number" },
|
|
94
|
+
"clampable": { "type": "boolean" }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
package/gen/types.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { lexer } from 'css-tree';
|
|
6
|
+
|
|
7
|
+
import { types as extendedTypes, tokenizers } from '../src/defs';
|
|
8
|
+
|
|
9
|
+
const props = Object.keys(lexer.properties).map(p => `<'${p}'>`);
|
|
10
|
+
const types = Object.keys(lexer.types).map(t => `<${t}>`);
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
13
|
+
const specific = require('./specific-schema.json');
|
|
14
|
+
|
|
15
|
+
fs.writeFileSync(
|
|
16
|
+
path.resolve(__dirname, '..', 'types.schema.json'),
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
19
|
+
type: 'object',
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
definitions: {
|
|
22
|
+
'css-syntax': {
|
|
23
|
+
type: 'string',
|
|
24
|
+
enum: [...Array.from(new Set([...props, ...types])), ...Object.keys(tokenizers).map(t => `<${t}>`)],
|
|
25
|
+
},
|
|
26
|
+
'extended-type': {
|
|
27
|
+
type: 'string',
|
|
28
|
+
enum: Object.keys(extendedTypes),
|
|
29
|
+
},
|
|
30
|
+
'html-attr-requirement': {
|
|
31
|
+
type: 'string',
|
|
32
|
+
enum: ['Boolean'],
|
|
33
|
+
},
|
|
34
|
+
'keyword-defined-type': {
|
|
35
|
+
...oneOf(
|
|
36
|
+
//
|
|
37
|
+
'css-syntax',
|
|
38
|
+
'extended-type',
|
|
39
|
+
'html-attr-requirement',
|
|
40
|
+
),
|
|
41
|
+
},
|
|
42
|
+
...specific.definitions,
|
|
43
|
+
type: {
|
|
44
|
+
...oneOf(
|
|
45
|
+
//
|
|
46
|
+
'keyword-defined-type',
|
|
47
|
+
...Object.keys(specific.definitions),
|
|
48
|
+
),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
properties: {
|
|
52
|
+
type: {
|
|
53
|
+
$ref: '#/definitions/type',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
{ encoding: 'utf-8' },
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
function oneOf(...keys: string[]) {
|
|
61
|
+
return {
|
|
62
|
+
oneOf: keys.map(key => ({
|
|
63
|
+
$ref: `#/definitions/${key}`,
|
|
64
|
+
})),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkMultiTypes = void 0;
|
|
4
|
+
const debug_1 = require("./debug");
|
|
5
|
+
const match_result_1 = require("./match-result");
|
|
6
|
+
function checkMultiTypes(value, checks) {
|
|
7
|
+
let unmatched;
|
|
8
|
+
for (const check of checks) {
|
|
9
|
+
const res = check(value);
|
|
10
|
+
if (res.matched) {
|
|
11
|
+
return res;
|
|
12
|
+
}
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
res._fn = check.name;
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
(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;
|
|
20
|
+
const offsetB = res.offset;
|
|
21
|
+
if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
|
|
22
|
+
unmatched = res;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const result = unmatched || (0, match_result_1.matched)();
|
|
26
|
+
(0, debug_1.log)('%d checks result: %O', checks.length, result);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
exports.checkMultiTypes = checkMultiTypes;
|
package/lib/check.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
|
|
2
|
+
export declare function check(value: string, type: Type, ref?: string, cache?: boolean): Result;
|
|
3
|
+
export declare function isKeyword(type: Type): type is KeywordDefinedType;
|
|
4
|
+
export declare function isList(type: Type): type is List;
|
|
5
|
+
export declare function isEnum(type: Type): type is Enum;
|
|
6
|
+
export declare function isNumber(type: Type): type is Number;
|
|
7
|
+
export declare function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax;
|
|
8
|
+
export declare function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax;
|
package/lib/check.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCustomSyntax = exports.isCSSSyntax = exports.isNumber = exports.isEnum = exports.isList = exports.isKeyword = exports.check = void 0;
|
|
4
|
+
const debug_1 = require("./debug");
|
|
5
|
+
const enum_1 = require("./enum");
|
|
6
|
+
const keyword_type_1 = require("./keyword-type");
|
|
7
|
+
const list_1 = require("./list");
|
|
8
|
+
const number_1 = require("./number");
|
|
9
|
+
function check(value, type, ref, cache = true) {
|
|
10
|
+
if (isKeyword(type)) {
|
|
11
|
+
(0, debug_1.log)('Check keyword: %s', type);
|
|
12
|
+
return (0, keyword_type_1.checkKeywordType)(value, type, cache);
|
|
13
|
+
}
|
|
14
|
+
if (isList(type)) {
|
|
15
|
+
(0, debug_1.log)('Check list: %O', type);
|
|
16
|
+
return (0, list_1.checkList)(value, type, ref, cache);
|
|
17
|
+
}
|
|
18
|
+
if (isEnum(type)) {
|
|
19
|
+
(0, debug_1.log)('Check enum: %O', type);
|
|
20
|
+
return (0, enum_1.checkEnum)(value, type, ref);
|
|
21
|
+
}
|
|
22
|
+
(0, debug_1.log)('Check number: %O', type);
|
|
23
|
+
return (0, number_1.checkNumber)(value, type, ref);
|
|
24
|
+
}
|
|
25
|
+
exports.check = check;
|
|
26
|
+
function isKeyword(type) {
|
|
27
|
+
return typeof type === 'string';
|
|
28
|
+
}
|
|
29
|
+
exports.isKeyword = isKeyword;
|
|
30
|
+
function isList(type) {
|
|
31
|
+
return typeof type !== 'string' && 'token' in type;
|
|
32
|
+
}
|
|
33
|
+
exports.isList = isList;
|
|
34
|
+
function isEnum(type) {
|
|
35
|
+
return typeof type !== 'string' && 'enum' in type;
|
|
36
|
+
}
|
|
37
|
+
exports.isEnum = isEnum;
|
|
38
|
+
function isNumber(type) {
|
|
39
|
+
return typeof type !== 'string' && 'enum' in type;
|
|
40
|
+
}
|
|
41
|
+
exports.isNumber = isNumber;
|
|
42
|
+
function isCSSSyntax(type) {
|
|
43
|
+
return typeof type === 'string' || 'syntax' in type;
|
|
44
|
+
}
|
|
45
|
+
exports.isCSSSyntax = isCSSSyntax;
|
|
46
|
+
function isCustomSyntax(type) {
|
|
47
|
+
return !isCSSSyntax(type);
|
|
48
|
+
}
|
|
49
|
+
exports.isCustomSyntax = isCustomSyntax;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const check_1 = require("./check");
|
|
4
|
+
test('Any', () => {
|
|
5
|
+
expect((0, check_1.check)('', 'Any').matched).toBe(true);
|
|
6
|
+
expect((0, check_1.check)(' ', 'Any').matched).toBe(true);
|
|
7
|
+
expect((0, check_1.check)('a', 'Any').matched).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
test('NoEmptyAny', () => {
|
|
10
|
+
expect((0, check_1.check)('', 'NoEmptyAny').matched).toBe(false);
|
|
11
|
+
expect((0, check_1.check)(' ', 'NoEmptyAny').matched).toBe(true);
|
|
12
|
+
expect((0, check_1.check)('a', 'NoEmptyAny').matched).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
test('OneLineAny', () => {
|
|
15
|
+
expect((0, check_1.check)('', 'OneLineAny').matched).toBe(true);
|
|
16
|
+
expect((0, check_1.check)(' ', 'OneLineAny').matched).toBe(true);
|
|
17
|
+
expect((0, check_1.check)('a', 'OneLineAny').matched).toBe(true);
|
|
18
|
+
expect((0, check_1.check)('a ', 'OneLineAny').matched).toBe(true);
|
|
19
|
+
expect((0, check_1.check)('a b', 'OneLineAny').matched).toBe(true);
|
|
20
|
+
expect((0, check_1.check)('a\n', 'OneLineAny').matched).toBe(false);
|
|
21
|
+
expect((0, check_1.check)('a\nb', 'OneLineAny').matched).toBe(false);
|
|
22
|
+
expect((0, check_1.check)('a\r\nb', 'OneLineAny').matched).toBe(false);
|
|
23
|
+
expect((0, check_1.check)('a\rb', 'OneLineAny').matched).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
test('Pattern', () => {
|
|
26
|
+
expect((0, check_1.check)('.*', 'Pattern').matched).toBe(true);
|
|
27
|
+
expect((0, check_1.check)('[a-z]+', 'Pattern').matched).toBe(true);
|
|
28
|
+
expect((0, check_1.check)(']//[()?!+*', 'Pattern').matched).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
test('BCP47', () => {
|
|
31
|
+
expect((0, check_1.check)('en', 'BCP47').matched).toBe(true);
|
|
32
|
+
expect((0, check_1.check)('en-US', 'BCP47').matched).toBe(true);
|
|
33
|
+
expect((0, check_1.check)('ja', 'BCP47').matched).toBe(true);
|
|
34
|
+
expect((0, check_1.check)(' ja ', 'BCP47').matched).toBe(false);
|
|
35
|
+
expect((0, check_1.check)('', 'BCP47').matched).toBe(false);
|
|
36
|
+
expect((0, check_1.check)('zh/cn', 'BCP47').matched).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
test('Srcset', () => {
|
|
39
|
+
expect((0, check_1.check)('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
|
|
40
|
+
expect((0, check_1.check)('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
|
|
41
|
+
expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
|
|
42
|
+
expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
test('Srcset', () => {
|
|
45
|
+
expect((0, check_1.check)('any', 'IconSize').matched).toBe(true);
|
|
46
|
+
expect((0, check_1.check)('Any', 'IconSize').matched).toBe(true);
|
|
47
|
+
expect((0, check_1.check)('10x10', 'IconSize').matched).toBe(true);
|
|
48
|
+
expect((0, check_1.check)('1x1', 'IconSize').matched).toBe(true);
|
|
49
|
+
expect((0, check_1.check)('1x0', 'IconSize').matched).toBe(false);
|
|
50
|
+
expect((0, check_1.check)('0x1', 'IconSize').matched).toBe(false);
|
|
51
|
+
expect((0, check_1.check)('0x0', 'IconSize').matched).toBe(false);
|
|
52
|
+
expect((0, check_1.check)('', 'IconSize').matched).toBe(false);
|
|
53
|
+
expect((0, check_1.check)(' ', 'IconSize').matched).toBe(false);
|
|
54
|
+
expect((0, check_1.check)('1', 'IconSize').matched).toBe(false);
|
|
55
|
+
expect((0, check_1.check)('1x', 'IconSize').matched).toBe(false);
|
|
56
|
+
expect((0, check_1.check)('x1', 'IconSize').matched).toBe(false);
|
|
57
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cssSyntaxMatch = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const css_tree_1 = (0, tslib_1.__importDefault)(require("css-tree"));
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const error_js_1 = require("css-tree/lib/lexer/error.js");
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const match_js_1 = require("css-tree/lib/lexer/match.js");
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const prepare_tokens_js_1 = (0, tslib_1.__importDefault)(require("css-tree/lib/lexer/prepare-tokens.js"));
|
|
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
|
+
const origin = value;
|
|
18
|
+
let defName;
|
|
19
|
+
const typesExtended = {};
|
|
20
|
+
const typesCheckers = {};
|
|
21
|
+
let propsExtended;
|
|
22
|
+
let ref = undefined;
|
|
23
|
+
let caseSensitive = false;
|
|
24
|
+
let ebnf = null;
|
|
25
|
+
if (typeof type === 'string') {
|
|
26
|
+
defName = type;
|
|
27
|
+
propsExtended = {};
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
defName = type.syntax.apply;
|
|
31
|
+
ebnf = type.syntax.ebnf || null;
|
|
32
|
+
if (ebnf) {
|
|
33
|
+
// Work in progress
|
|
34
|
+
return (0, match_result_1.matched)();
|
|
35
|
+
}
|
|
36
|
+
const types = {
|
|
37
|
+
...defs_1.tokenizers,
|
|
38
|
+
...type.syntax.def,
|
|
39
|
+
};
|
|
40
|
+
Object.keys(types).forEach(key => {
|
|
41
|
+
const valueOrChecker = types[key];
|
|
42
|
+
if (typeof valueOrChecker === 'string') {
|
|
43
|
+
typesExtended[key] = valueOrChecker;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
typesCheckers[key] = valueOrChecker;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
propsExtended = { ...type.syntax.properties };
|
|
50
|
+
if (type.caseSensitive) {
|
|
51
|
+
caseSensitive = true;
|
|
52
|
+
Object.keys(typesExtended).forEach(key => eachMimicCases(key, typesExtended));
|
|
53
|
+
Object.keys(propsExtended).forEach(key => eachMimicCases(key, propsExtended));
|
|
54
|
+
value = mimicCases(value);
|
|
55
|
+
}
|
|
56
|
+
ref = type.ref;
|
|
57
|
+
}
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
const lexer = css_tree_1.default.fork({
|
|
60
|
+
types: typesExtended,
|
|
61
|
+
properties: propsExtended,
|
|
62
|
+
}).lexer;
|
|
63
|
+
Object.keys(typesCheckers).forEach(key => {
|
|
64
|
+
const checker = typesCheckers[key];
|
|
65
|
+
lexer.addType_(key, (token, getNextToken) => checker(token, getNextToken, cssSyntaxMatch));
|
|
66
|
+
});
|
|
67
|
+
const { isProp, name, matcher } = defToMatcher(lexer, defName);
|
|
68
|
+
const refParam = isProp ? 'Property' : 'Type';
|
|
69
|
+
ref = ref || `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
|
|
70
|
+
// eslint-disable-next-line no-console
|
|
71
|
+
const _w = console.warn;
|
|
72
|
+
// eslint-disable-next-line no-console
|
|
73
|
+
console.warn = warn => (0, debug_1.log)('WARNING: %s (by %s => %s)', warn, value, type);
|
|
74
|
+
const tokens = (0, prepare_tokens_js_1.default)(value, lexer.syntax);
|
|
75
|
+
const result = (0, match_js_1.matchAsTree)(tokens, matcher.match, lexer);
|
|
76
|
+
if (caseSensitive) {
|
|
77
|
+
if (result.tokens && Array.isArray(result.tokens)) {
|
|
78
|
+
let reducer = 0;
|
|
79
|
+
result.tokens = result.tokens.map((token) => {
|
|
80
|
+
const value = token.value;
|
|
81
|
+
const originValue = deMimicCases(value || '');
|
|
82
|
+
const isMimiced = value !== originValue;
|
|
83
|
+
reducer += isMimiced ? 'mimiccases------mimiccases'.length : 0;
|
|
84
|
+
token.value = originValue;
|
|
85
|
+
token.balance = token.balance - reducer;
|
|
86
|
+
return token;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
(0, debug_1.log)('css-tree/result: %O', result);
|
|
91
|
+
// eslint-disable-next-line no-console
|
|
92
|
+
console.warn = _w;
|
|
93
|
+
if (result.match) {
|
|
94
|
+
(0, debug_1.log)('css-tree/result.match: %s', JSON.stringify(result.match, null, 2));
|
|
95
|
+
return (0, match_result_1.matched)();
|
|
96
|
+
}
|
|
97
|
+
const error = new error_js_1.SyntaxMatchError(result.reason, matcher.syntax, value, result);
|
|
98
|
+
if (caseSensitive) {
|
|
99
|
+
error.message = deMimicCases(error.message);
|
|
100
|
+
error.syntax = deMimicCases(error.syntax);
|
|
101
|
+
}
|
|
102
|
+
(0, debug_1.log)('css-tree/SyntaxMatchError: %O', error);
|
|
103
|
+
return {
|
|
104
|
+
matched: false,
|
|
105
|
+
ref,
|
|
106
|
+
raw: origin.slice(error.mismatchOffset, error.mismatchOffset + error.mismatchLength),
|
|
107
|
+
offset: error.mismatchOffset,
|
|
108
|
+
length: error.mismatchLength,
|
|
109
|
+
line: error.line,
|
|
110
|
+
column: error.column,
|
|
111
|
+
expects: [
|
|
112
|
+
{
|
|
113
|
+
type: 'syntax',
|
|
114
|
+
value: error.syntax,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
partName: error.mismatchOffset === 0 ? undefined : 'value',
|
|
118
|
+
reason: 'syntax-error',
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.cssSyntaxMatch = cssSyntaxMatch;
|
|
122
|
+
function defToMatcher(lexer, def) {
|
|
123
|
+
const isProp = def.search("<'") === 0;
|
|
124
|
+
const name = def.replace(/^<'?|'?>$/g, '');
|
|
125
|
+
const matcher = isProp ? lexer.properties[name] : lexer.types[name];
|
|
126
|
+
return {
|
|
127
|
+
isProp,
|
|
128
|
+
name,
|
|
129
|
+
matcher,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function eachMimicCases(key, obj) {
|
|
133
|
+
const value = obj[key];
|
|
134
|
+
obj[key] = mimicCases(value);
|
|
135
|
+
}
|
|
136
|
+
function mimicCases(value) {
|
|
137
|
+
return value.replace(/[A-Z]/g, $0 => `mimiccases---${$0}---mimiccases`);
|
|
138
|
+
}
|
|
139
|
+
function deMimicCases(value) {
|
|
140
|
+
return value.replace(/mimiccases---([A-Z])---mimiccases/g, (_, $1) => $1);
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|