@markuplint/types 3.0.0-dev.25 → 3.0.0-dev.38

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.
Files changed (61) hide show
  1. package/package.json +2 -2
  2. package/gen/specific-schema.json +0 -98
  3. package/gen/types.ts +0 -66
  4. package/src/check-multi-types.ts +0 -35
  5. package/src/check.spec.ts +0 -83
  6. package/src/check.ts +0 -48
  7. package/src/css-syntax.spec.ts +0 -167
  8. package/src/css-syntax.ts +0 -188
  9. package/src/debug.ts +0 -3
  10. package/src/defs.ts +0 -811
  11. package/src/enum.ts +0 -25
  12. package/src/get-candidate.ts +0 -24
  13. package/src/index.ts +0 -3
  14. package/src/keyword-type.ts +0 -64
  15. package/src/list.spec.ts +0 -133
  16. package/src/list.ts +0 -34
  17. package/src/match-result.ts +0 -49
  18. package/src/number.ts +0 -46
  19. package/src/primitive/index.spec.ts +0 -65
  20. package/src/primitive/index.ts +0 -7
  21. package/src/primitive/is-float.ts +0 -8
  22. package/src/primitive/is-int.ts +0 -8
  23. package/src/primitive/is-non-zero-uint.ts +0 -8
  24. package/src/primitive/is-quantity.ts +0 -38
  25. package/src/primitive/is-uint.ts +0 -15
  26. package/src/primitive/range.ts +0 -14
  27. package/src/primitive/split-unit.ts +0 -20
  28. package/src/rfc/is-bcp-47.spec.ts +0 -23
  29. package/src/rfc/is-bcp-47.ts +0 -13
  30. package/src/token/index.ts +0 -2
  31. package/src/token/token-collection.spec.ts +0 -147
  32. package/src/token/token-collection.ts +0 -444
  33. package/src/token/token.ts +0 -144
  34. package/src/types.schema.ts +0 -1113
  35. package/src/types.ts +0 -118
  36. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  37. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  38. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  39. package/src/whatwg/check-autocomplete.ts +0 -380
  40. package/src/whatwg/check-datetime/date-string.ts +0 -44
  41. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  42. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  43. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  44. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  45. package/src/whatwg/check-datetime/index.ts +0 -36
  46. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  47. package/src/whatwg/check-datetime/month-string.ts +0 -31
  48. package/src/whatwg/check-datetime/time-string.ts +0 -49
  49. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  50. package/src/whatwg/check-datetime/week-string.ts +0 -41
  51. package/src/whatwg/check-datetime/year-string.ts +0 -26
  52. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  53. package/src/whatwg/check-mime-type.spec.ts +0 -59
  54. package/src/whatwg/check-mime-type.ts +0 -46
  55. package/src/whatwg/is-abs-url.spec.ts +0 -8
  56. package/src/whatwg/is-abs-url.ts +0 -31
  57. package/src/whatwg/is-browser-context-name.ts +0 -16
  58. package/src/whatwg/is-custom-element-name.ts +0 -76
  59. package/src/whatwg/is-itemprop-name.ts +0 -17
  60. package/tsconfig.test.json +0 -3
  61. package/tsconfig.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/types",
3
- "version": "3.0.0-dev.25+a27e39aa",
3
+ "version": "3.0.0-dev.38+b959e06f",
4
4
  "description": "Type declaration and value checker",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -31,5 +31,5 @@
31
31
  "@types/debug": "^4.1.7",
32
32
  "@types/whatwg-mimetype": "2"
33
33
  },
34
- "gitHead": "a27e39aa4362bce572d1893df2f1571705b62df1"
34
+ "gitHead": "b959e06f4838b3e6798c990427e22422efe8e699"
35
35
  }
@@ -1,98 +0,0 @@
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
- "patternProperties": {
70
- ".*": {
71
- "type": "array",
72
- "minItems": 1,
73
- "uniqueItems": true,
74
- "items": { "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 DELETED
@@ -1,66 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
1
- import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
-
3
- import { log } from './debug';
4
- import { matched } from './match-result';
5
-
6
- export function checkMultiTypes(value: string, checks: CustomSyntaxCheck[]) {
7
- let unmatched: UnmatchedResult | undefined;
8
-
9
- for (const check of checks) {
10
- const res = check(value);
11
- if (res.matched) {
12
- return res;
13
- }
14
-
15
- // @ts-ignore
16
- res._fn = check.name;
17
-
18
- // @ts-ignore
19
- log('%s(%d) vs %s(%d)', unmatched?._fn, unmatched?.passCount, res._fn, res.passCount);
20
- const passedA = unmatched?.passCount || 0;
21
- const passedB = res.passCount || 0;
22
- const offsetA = unmatched?.offset || 0;
23
- const offsetB = res.offset;
24
-
25
- if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
26
- unmatched = res;
27
- }
28
- }
29
-
30
- const result = unmatched || matched();
31
-
32
- log('%d checks result: %O', checks.length, result);
33
-
34
- return result;
35
- }
package/src/check.spec.ts DELETED
@@ -1,83 +0,0 @@
1
- import { check } from './check';
2
-
3
- test('Any', () => {
4
- expect(check('', 'Any').matched).toBe(true);
5
- expect(check(' ', 'Any').matched).toBe(true);
6
- expect(check('a', 'Any').matched).toBe(true);
7
- });
8
-
9
- test('NoEmptyAny', () => {
10
- expect(check('', 'NoEmptyAny').matched).toBe(false);
11
- expect(check(' ', 'NoEmptyAny').matched).toBe(true);
12
- expect(check('a', 'NoEmptyAny').matched).toBe(true);
13
- });
14
-
15
- test('OneLineAny', () => {
16
- expect(check('', 'OneLineAny').matched).toBe(true);
17
- expect(check(' ', 'OneLineAny').matched).toBe(true);
18
- expect(check('a', 'OneLineAny').matched).toBe(true);
19
- expect(check('a ', 'OneLineAny').matched).toBe(true);
20
- expect(check('a b', 'OneLineAny').matched).toBe(true);
21
- expect(check('a\n', 'OneLineAny').matched).toBe(false);
22
- expect(check('a\nb', 'OneLineAny').matched).toBe(false);
23
- expect(check('a\r\nb', 'OneLineAny').matched).toBe(false);
24
- expect(check('a\rb', 'OneLineAny').matched).toBe(false);
25
- });
26
-
27
- test('Pattern', () => {
28
- expect(check('.*', 'Pattern').matched).toBe(true);
29
- expect(check('[a-z]+', 'Pattern').matched).toBe(true);
30
- expect(check(']//[()?!+*', 'Pattern').matched).toBe(false);
31
- });
32
-
33
- test('BCP47', () => {
34
- expect(check('en', 'BCP47').matched).toBe(true);
35
- expect(check('en-US', 'BCP47').matched).toBe(true);
36
- expect(check('ja', 'BCP47').matched).toBe(true);
37
- expect(check(' ja ', 'BCP47').matched).toBe(false);
38
- expect(check('', 'BCP47').matched).toBe(false);
39
- expect(check('zh/cn', 'BCP47').matched).toBe(false);
40
- });
41
-
42
- test('Srcset', () => {
43
- expect(check('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
44
- expect(check('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
45
- expect(check('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
46
- expect(check('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
47
- });
48
-
49
- test('IconSize', () => {
50
- expect(check('any', 'IconSize').matched).toBe(true);
51
- expect(check('Any', 'IconSize').matched).toBe(true);
52
- expect(check('10x10', 'IconSize').matched).toBe(true);
53
- expect(check('1x1', 'IconSize').matched).toBe(true);
54
- expect(check('1x0', 'IconSize').matched).toBe(false);
55
- expect(check('0x1', 'IconSize').matched).toBe(false);
56
- expect(check('0x0', 'IconSize').matched).toBe(false);
57
- expect(check('', 'IconSize').matched).toBe(false);
58
- expect(check(' ', 'IconSize').matched).toBe(false);
59
- expect(check('1', 'IconSize').matched).toBe(false);
60
- expect(check('1x', 'IconSize').matched).toBe(false);
61
- expect(check('x1', 'IconSize').matched).toBe(false);
62
- });
63
-
64
- test('Number', () => {
65
- expect(check('10', { type: 'integer', gt: 0 }).matched).toBe(true);
66
- expect(check('0', { type: 'integer', gt: 0 }).matched).toBe(false);
67
- expect(check('0', { type: 'integer', gte: 0 }).matched).toBe(true);
68
- expect(check('9', { type: 'integer', lt: 10 }).matched).toBe(true);
69
- expect(check('10', { type: 'integer', lt: 10 }).matched).toBe(false);
70
- });
71
-
72
- test('Non-exist types', () => {
73
- // @ts-ignore
74
- expect(check('abc', 'String').matched).toBe(true);
75
- // @ts-ignore
76
- expect(check('abc', 'FooBar').matched).toBe(true);
77
- // @ts-ignore
78
- expect(check('abc', ' ').matched).toBe(true);
79
- // @ts-ignore
80
- expect(check('abc', '\n').matched).toBe(true);
81
- // @ts-ignore
82
- expect(check('abc', '').matched).toBe(true);
83
- });
package/src/check.ts DELETED
@@ -1,48 +0,0 @@
1
- import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
2
-
3
- import { log } from './debug';
4
- import { checkEnum } from './enum';
5
- import { checkKeywordType } from './keyword-type';
6
- import { checkList } from './list';
7
- import { checkNumber } from './number';
8
-
9
- export function check(value: string, type: Type, ref?: string, cache = true): Result {
10
- if (isKeyword(type)) {
11
- log('Check keyword: %s', type);
12
- return checkKeywordType(value, type, cache);
13
- }
14
- if (isList(type)) {
15
- log('Check list: %O', type);
16
- return checkList(value, type, ref, cache);
17
- }
18
- if (isEnum(type)) {
19
- log('Check enum: %O', type);
20
- return checkEnum(value, type, ref);
21
- }
22
- log('Check number: %O', type);
23
- return checkNumber(value, type, ref);
24
- }
25
-
26
- export function isKeyword(type: Type): type is KeywordDefinedType {
27
- return typeof type === 'string';
28
- }
29
-
30
- export function isList(type: Type): type is List {
31
- return typeof type !== 'string' && 'token' in type;
32
- }
33
-
34
- export function isEnum(type: Type): type is Enum {
35
- return typeof type !== 'string' && 'enum' in type;
36
- }
37
-
38
- export function isNumber(type: Type): type is Number {
39
- return typeof type !== 'string' && 'enum' in type;
40
- }
41
-
42
- export function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax {
43
- return typeof type === 'string' || 'syntax' in type;
44
- }
45
-
46
- export function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax {
47
- return !isCSSSyntax(type);
48
- }
@@ -1,167 +0,0 @@
1
- import type { CustomCssSyntax } from './types';
2
-
3
- import { cssSyntaxMatch } from './css-syntax';
4
-
5
- test('CSS Standard', () => {
6
- expect(cssSyntaxMatch('10px', '<length>').matched).toBe(true);
7
- expect(cssSyntaxMatch('one-pixel', '<length>').matched).toBe(false);
8
- expect(cssSyntaxMatch('(prefers-color-scheme: dark)', '<media-query-list>').matched).toBe(true);
9
- });
10
-
11
- test('Extends', () => {
12
- const sourceSizeList: CustomCssSyntax = {
13
- ref: 'https://html.spec.whatwg.org/multipage/images.html#sizes-attributes',
14
- syntax: {
15
- apply: '<source-size-list>',
16
- def: {
17
- 'source-size-list': '[ <source-size># , ]? <source-size-value>',
18
- 'source-size': '<media-condition> <source-size-value>',
19
- 'source-size-value': '<length>',
20
- },
21
- },
22
- };
23
- expect(cssSyntaxMatch('50vw', sourceSizeList).matched).toBe(true);
24
- expect(cssSyntaxMatch('(max-width: 600px) 200px, 50vw', sourceSizeList).matched).toBe(true);
25
- expect(cssSyntaxMatch('print 300vw', sourceSizeList).matched).toBe(false);
26
- expect(cssSyntaxMatch('(max-width: 600px) 200px', sourceSizeList).matched).toBe(false);
27
- expect(
28
- cssSyntaxMatch('(max-width: 600px) 200px', {
29
- ...sourceSizeList,
30
- syntax: {
31
- ...sourceSizeList.syntax,
32
- apply: '<source-size>',
33
- },
34
- }).matched,
35
- ).toBe(true);
36
-
37
- const keyTimes: CustomCssSyntax = {
38
- ref: 'https://svgwg.org/specs/animations/#KeyTimesAttribute',
39
- syntax: {
40
- apply: '<key-times>',
41
- def: {
42
- 'key-times': '<number> [; <number>]* [;]?',
43
- },
44
- },
45
- };
46
- expect(cssSyntaxMatch('20; 20; 30', keyTimes).matched).toBe(true);
47
- expect(cssSyntaxMatch('20; 20; 30;', keyTimes).matched).toBe(true);
48
- expect(cssSyntaxMatch('20; 20; abc;', keyTimes).matched).toBe(false);
49
- expect(cssSyntaxMatch('20; 20; ;', keyTimes).matched).toBe(false);
50
-
51
- const SVGViewBox: CustomCssSyntax = {
52
- ref: 'https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute',
53
- syntax: {
54
- apply: '<view-box>',
55
- def: {
56
- 'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
57
- 'min-x': '<number>',
58
- 'min-y': '<number>',
59
- width: '<number>',
60
- height: '<number>',
61
- },
62
- },
63
- };
64
- expect(cssSyntaxMatch('0 0 30 10', SVGViewBox).matched).toBe(true);
65
- expect(cssSyntaxMatch('0 0, 30, 10', SVGViewBox).matched).toBe(true);
66
- expect(cssSyntaxMatch('0 0, 30', SVGViewBox).matched).toBe(false);
67
-
68
- const percentageList: CustomCssSyntax = {
69
- ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage',
70
- syntax: {
71
- apply: '<percentage-list>',
72
- def: {
73
- 'percentage-list': '[ <number> [,]? ]* <number>',
74
- },
75
- },
76
- };
77
- expect(cssSyntaxMatch('0 0 30 10', percentageList).matched).toBe(true);
78
- expect(cssSyntaxMatch('0, 0, 30 10', percentageList).matched).toBe(true);
79
- expect(cssSyntaxMatch('0', percentageList).matched).toBe(true);
80
- expect(cssSyntaxMatch('', percentageList).matched).toBe(false);
81
-
82
- const custom: CustomCssSyntax = {
83
- ref: 'n/a',
84
- syntax: {
85
- apply: '<custom>',
86
- def: {
87
- custom: '0 | 1 | .',
88
- },
89
- },
90
- };
91
- expect(cssSyntaxMatch('0', custom).matched).toBe(true);
92
- expect(cssSyntaxMatch('1', custom).matched).toBe(true);
93
- expect(cssSyntaxMatch('.', custom).matched).toBe(true);
94
- expect(cssSyntaxMatch('2', custom).matched).toBe(false);
95
- expect(cssSyntaxMatch(':', custom).matched).toBe(false);
96
- });
97
-
98
- test('custom-type-checking', () => {
99
- const custom: CustomCssSyntax = {
100
- ref: 'n/a',
101
- caseSensitive: true,
102
- syntax: {
103
- apply: '<custom>',
104
- def: {
105
- custom: '<custom-type>',
106
- 'custom-type': token => {
107
- if (!token) {
108
- return 0;
109
- }
110
- return token.value === '1' ? 1 : 0;
111
- },
112
- },
113
- },
114
- };
115
- expect(cssSyntaxMatch('1', custom).matched).toBe(true);
116
- expect(cssSyntaxMatch('0', custom).matched).toBe(false);
117
- });
118
-
119
- test('case-sensitive', () => {
120
- const custom: CustomCssSyntax = {
121
- ref: 'n/a',
122
- caseSensitive: true,
123
- syntax: {
124
- apply: '<custom>',
125
- def: {
126
- custom: 'CaSeS [a | B | aBc]',
127
- },
128
- },
129
- };
130
- expect(cssSyntaxMatch('CaSeS a', custom).matched).toBe(true);
131
- expect(cssSyntaxMatch('CaSeS B', custom).matched).toBe(true);
132
- expect(cssSyntaxMatch('CaSeS aBc', custom).matched).toBe(true);
133
- expect(cssSyntaxMatch('CaSeS A', custom)).toStrictEqual({
134
- column: 7,
135
- line: 1,
136
- matched: false,
137
- length: 1,
138
- offset: 6,
139
- partName: 'value',
140
- raw: 'A',
141
- reason: 'syntax-error',
142
- ref: 'n/a',
143
- expects: [
144
- {
145
- type: 'syntax',
146
- value: 'CaSeS [ a | B | aBc ]',
147
- },
148
- ],
149
- });
150
- expect(cssSyntaxMatch('CaSeS abc', custom)).toStrictEqual({
151
- column: 7,
152
- line: 1,
153
- matched: false,
154
- length: 3,
155
- offset: 6,
156
- partName: 'value',
157
- raw: 'abc',
158
- reason: 'syntax-error',
159
- ref: 'n/a',
160
- expects: [
161
- {
162
- type: 'syntax',
163
- value: 'CaSeS [ a | B | aBc ]',
164
- },
165
- ],
166
- });
167
- });