html-validate 10.3.1 → 10.4.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/dist/cjs/core.js +49 -16
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/elements.js +40 -2
- package/dist/cjs/elements.js.map +1 -1
- package/dist/cjs/meta-helper.js +5 -1
- package/dist/cjs/meta-helper.js.map +1 -1
- package/dist/cjs/tsdoc-metadata.json +1 -1
- package/dist/esm/core.js +49 -16
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/elements.js +40 -2
- package/dist/esm/elements.js.map +1 -1
- package/dist/esm/meta-helper.js +5 -1
- package/dist/esm/meta-helper.js.map +1 -1
- package/dist/schema/elements.json +2 -2
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/browser.d.ts +23 -1
- package/dist/types/index.d.ts +23 -1
- package/package.json +2 -2
package/dist/esm/meta-helper.js
CHANGED
|
@@ -43,11 +43,15 @@ function allowedIfParentIsPresent(...tags) {
|
|
|
43
43
|
return `requires ${expected} as parent`;
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
+
function hasKeyword(attr, keyword) {
|
|
47
|
+
return attr.toLowerCase().split(/\s+/).includes(keyword);
|
|
48
|
+
}
|
|
46
49
|
const metadataHelper = {
|
|
47
50
|
allowedIfAttributeIsPresent,
|
|
48
51
|
allowedIfAttributeIsAbsent,
|
|
49
52
|
allowedIfAttributeHasValue,
|
|
50
|
-
allowedIfParentIsPresent
|
|
53
|
+
allowedIfParentIsPresent,
|
|
54
|
+
hasKeyword
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
function defineMetadata(metatable) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-helper.js","sources":["../../src/meta/helper.ts","../../src/meta/define-metadata.ts"],"sourcesContent":["import { naturalJoin } from \"../utils/natural-join\";\nimport { type MetaAttributeAllowedCallback } from \"./element\";\nimport { type HtmlElementLike } from \"./html-element-like\";\n\n/**\n * Helpers when writing element metadata.\n *\n * @public\n */\nexport interface MetadataHelper {\n\t/** Returns an error if another attribute is omitted, i.e. it requires another attribute to be present to pass. */\n\tallowedIfAttributeIsPresent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute is present, i.e. it requires another attribute to be omitted to pass. */\n\tallowedIfAttributeIsAbsent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute does not have one of the listed values */\n\tallowedIfAttributeHasValue(\n\t\tthis: void,\n\t\tattr: string,\n\t\tvalue: string[],\n\t\toptions?: { defaultValue?: string | null },\n\t): MetaAttributeAllowedCallback;\n\n\t/**\n\t * Returns an error if the node doesn't have any of the given elements as parent\n\t *\n\t * @since 8.2.0\n\t **/\n\tallowedIfParentIsPresent(this: void, ...tags: string[]): MetaAttributeAllowedCallback;\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsPresent(...attr: string[]) {\n\treturn (node: HtmlElementLike) => {\n\t\tif (attr.some((it) => node.hasAttribute(it))) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(attr.map((it) => `\"${it}\"`));\n\t\treturn `requires ${expected} attribute to be present`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsAbsent(...attr: string[]): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst present = attr.filter((it) => node.hasAttribute(it));\n\t\tif (present.length === 0) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(present.map((it) => `\"${it}\"`));\n\t\treturn `cannot be used at the same time as ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeHasValue(\n\tkey: string,\n\texpectedValue: string[],\n\t{ defaultValue }: { defaultValue?: string | null } = {},\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst attr = node.getAttribute(key);\n\t\tif (attr && typeof attr !== \"string\") {\n\t\t\treturn null;\n\t\t}\n\t\tconst actualValue = attr ?? defaultValue;\n\t\tif (actualValue && expectedValue.includes(actualValue.toLocaleLowerCase())) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(expectedValue.map((it) => `\"${it}\"`));\n\t\treturn `\"${key}\" attribute must be ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfParentIsPresent(\n\tthis: void,\n\t...tags: string[]\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst match = tags.some((it) => node.closest(it));\n\t\tif (match) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(tags.map((it) => `<${it}>`));\n\t\treturn `requires ${expected} as parent`;\n\t};\n}\n\n/**\n * @public\n */\nexport const metadataHelper: MetadataHelper = {\n\tallowedIfAttributeIsPresent,\n\tallowedIfAttributeIsAbsent,\n\tallowedIfAttributeHasValue,\n\tallowedIfParentIsPresent,\n};\n","import { type MetaDataTable } from \"./element\";\n\n/**\n * Helper function to assist IDE with completion and type-checking.\n *\n * @public\n */\nexport function defineMetadata(metatable: MetaDataTable): MetaDataTable {\n\treturn metatable;\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"meta-helper.js","sources":["../../src/meta/helper.ts","../../src/meta/define-metadata.ts"],"sourcesContent":["import { naturalJoin } from \"../utils/natural-join\";\nimport { type MetaAttributeAllowedCallback } from \"./element\";\nimport { type HtmlElementLike } from \"./html-element-like\";\n\n/**\n * Helpers when writing element metadata.\n *\n * @public\n */\nexport interface MetadataHelper {\n\t/** Returns an error if another attribute is omitted, i.e. it requires another attribute to be present to pass. */\n\tallowedIfAttributeIsPresent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute is present, i.e. it requires another attribute to be omitted to pass. */\n\tallowedIfAttributeIsAbsent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute does not have one of the listed values */\n\tallowedIfAttributeHasValue(\n\t\tthis: void,\n\t\tattr: string,\n\t\tvalue: string[],\n\t\toptions?: { defaultValue?: string | null },\n\t): MetaAttributeAllowedCallback;\n\n\t/**\n\t * Returns an error if the node doesn't have any of the given elements as parent\n\t *\n\t * @since 8.2.0\n\t **/\n\tallowedIfParentIsPresent(this: void, ...tags: string[]): MetaAttributeAllowedCallback;\n\n\t/**\n\t * Returns true if an attribute with space-separated tokens includes given\n\t * keyword.\n\t *\n\t * @since 10.4.0\n\t * @param attr - Attribute value.\n\t * @param keyword - Keyword to look for.\n\t */\n\thasKeyword(this: void, attr: string, keyword: string): boolean;\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsPresent(...attr: string[]) {\n\treturn (node: HtmlElementLike) => {\n\t\tif (attr.some((it) => node.hasAttribute(it))) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(attr.map((it) => `\"${it}\"`));\n\t\treturn `requires ${expected} attribute to be present`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsAbsent(...attr: string[]): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst present = attr.filter((it) => node.hasAttribute(it));\n\t\tif (present.length === 0) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(present.map((it) => `\"${it}\"`));\n\t\treturn `cannot be used at the same time as ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeHasValue(\n\tkey: string,\n\texpectedValue: string[],\n\t{ defaultValue }: { defaultValue?: string | null } = {},\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst attr = node.getAttribute(key);\n\t\tif (attr && typeof attr !== \"string\") {\n\t\t\treturn null;\n\t\t}\n\t\tconst actualValue = attr ?? defaultValue;\n\t\tif (actualValue && expectedValue.includes(actualValue.toLocaleLowerCase())) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(expectedValue.map((it) => `\"${it}\"`));\n\t\treturn `\"${key}\" attribute must be ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfParentIsPresent(\n\tthis: void,\n\t...tags: string[]\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst match = tags.some((it) => node.closest(it));\n\t\tif (match) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(tags.map((it) => `<${it}>`));\n\t\treturn `requires ${expected} as parent`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function hasKeyword(attr: string, keyword: string): boolean {\n\treturn attr.toLowerCase().split(/\\s+/).includes(keyword);\n}\n\n/**\n * @public\n */\nexport const metadataHelper: MetadataHelper = {\n\tallowedIfAttributeIsPresent,\n\tallowedIfAttributeIsAbsent,\n\tallowedIfAttributeHasValue,\n\tallowedIfParentIsPresent,\n\thasKeyword,\n};\n","import { type MetaDataTable } from \"./element\";\n\n/**\n * Helper function to assist IDE with completion and type-checking.\n *\n * @public\n */\nexport function defineMetadata(metatable: MetaDataTable): MetaDataTable {\n\treturn metatable;\n}\n"],"names":[],"mappings":";;AA6CO,SAAS,+BAA+B,IAAA,EAAgB;AAC9D,EAAA,OAAO,CAAC,IAAA,KAA0B;AACjC,IAAA,IAAI,IAAA,CAAK,KAAK,CAAC,EAAA,KAAO,KAAK,YAAA,CAAa,EAAE,CAAC,CAAA,EAAG;AAC7C,MAAA,OAAO,IAAA;AAAA,IACR;AACA,IAAA,MAAM,QAAA,GAAW,YAAY,IAAA,CAAK,GAAA,CAAI,CAAC,EAAA,KAAO,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,CAAG,CAAC,CAAA;AACxD,IAAA,OAAO,YAAY,QAAQ,CAAA,wBAAA,CAAA;AAAA,EAC5B,CAAA;AACD;AAKO,SAAS,8BAA8B,IAAA,EAA8C;AAC3F,EAAA,OAAO,CAAC,IAAA,KAA0B;AACjC,IAAA,MAAM,OAAA,GAAU,KAAK,MAAA,CAAO,CAAC,OAAO,IAAA,CAAK,YAAA,C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ACA,IAAA,MAAM,QAAA,GAAW,YAAY,IAAA,CAAK,GAAA,CAAI,CAAC,EAAA,KAAO,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,CAAG,CAAC,CAAA;AACxD,IAAA,OAAO,YAAY,QAAQ,CAAA,UAAA,CAAA;AAAA,EAC5B,CAAA;AACD;AAKO,SAAS,UAAA,CAAW,MAAc,OAAA,EAA0B;AAClE,EAAA,OAAO,KAAK,WAAA,EAAY,CAAE,MAAM,KAAK,CAAA,CAAE,SAAS,OAAO,CAAA;AACxD;AAKO,MAAM,cAAA,GAAiC;AAAA,EAC7C,2BAAA;AAAA,EACA,0BAAA;AAAA,EACA,0BAAA;AAAA,EACA,wBAAA;AAAA,EACA;AACD;;ACrHO,SAAS,eAAe,SAAA,EAAyC;AACvE,EAAA,OAAO,SAAA;AACR;;;;"}
|
|
@@ -316,8 +316,8 @@
|
|
|
316
316
|
"title": "Set to true if this attribute can optionally omit its value"
|
|
317
317
|
},
|
|
318
318
|
"required": {
|
|
319
|
-
"
|
|
320
|
-
"
|
|
319
|
+
"title": "Set to true or a function to evaluate if this attribute is required",
|
|
320
|
+
"oneOf": [{ "type": "boolean" }, { "function": true }]
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
},
|
package/dist/tsdoc-metadata.json
CHANGED
package/dist/types/browser.d.ts
CHANGED
|
@@ -1503,7 +1503,7 @@ export declare interface MetaAttribute {
|
|
|
1503
1503
|
/**
|
|
1504
1504
|
* If set this attribute is required to be present on the element.
|
|
1505
1505
|
*/
|
|
1506
|
-
required?: boolean;
|
|
1506
|
+
required?: boolean | MetaAttributeRequiredCallback;
|
|
1507
1507
|
}
|
|
1508
1508
|
|
|
1509
1509
|
/**
|
|
@@ -1517,6 +1517,19 @@ export declare interface MetaAttribute {
|
|
|
1517
1517
|
*/
|
|
1518
1518
|
export declare type MetaAttributeAllowedCallback = (node: HtmlElementLike, attr: string | DynamicValue | null | undefined) => string | null | undefined;
|
|
1519
1519
|
|
|
1520
|
+
/**
|
|
1521
|
+
* Callback for the `required` property of `MetaAttribute`.
|
|
1522
|
+
*
|
|
1523
|
+
* The return value should be truthy if the attribute is required or falsey if
|
|
1524
|
+
* not. If the return value is a non-empty string it replaces the default
|
|
1525
|
+
* "missing required attribute" error message.
|
|
1526
|
+
*
|
|
1527
|
+
* @public
|
|
1528
|
+
* @since 10.4.0
|
|
1529
|
+
* @param node - The node the attribute belongs to.
|
|
1530
|
+
*/
|
|
1531
|
+
export declare type MetaAttributeRequiredCallback = (node: HtmlElementLike) => string | boolean | null | undefined;
|
|
1532
|
+
|
|
1520
1533
|
/**
|
|
1521
1534
|
* Callback for content category properties of `MetaData`. It takes a node and
|
|
1522
1535
|
* returns whenever the element belongs to the content group or not.
|
|
@@ -1604,6 +1617,15 @@ export declare interface MetadataHelper {
|
|
|
1604
1617
|
* @since 8.2.0
|
|
1605
1618
|
**/
|
|
1606
1619
|
allowedIfParentIsPresent(this: void, ...tags: string[]): MetaAttributeAllowedCallback;
|
|
1620
|
+
/**
|
|
1621
|
+
* Returns true if an attribute with space-separated tokens includes given
|
|
1622
|
+
* keyword.
|
|
1623
|
+
*
|
|
1624
|
+
* @since 10.4.0
|
|
1625
|
+
* @param attr - Attribute value.
|
|
1626
|
+
* @param keyword - Keyword to look for.
|
|
1627
|
+
*/
|
|
1628
|
+
hasKeyword(this: void, attr: string, keyword: string): boolean;
|
|
1607
1629
|
}
|
|
1608
1630
|
|
|
1609
1631
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1743,7 +1743,7 @@ export declare interface MetaAttribute {
|
|
|
1743
1743
|
/**
|
|
1744
1744
|
* If set this attribute is required to be present on the element.
|
|
1745
1745
|
*/
|
|
1746
|
-
required?: boolean;
|
|
1746
|
+
required?: boolean | MetaAttributeRequiredCallback;
|
|
1747
1747
|
}
|
|
1748
1748
|
|
|
1749
1749
|
/**
|
|
@@ -1757,6 +1757,19 @@ export declare interface MetaAttribute {
|
|
|
1757
1757
|
*/
|
|
1758
1758
|
export declare type MetaAttributeAllowedCallback = (node: HtmlElementLike, attr: string | DynamicValue | null | undefined) => string | null | undefined;
|
|
1759
1759
|
|
|
1760
|
+
/**
|
|
1761
|
+
* Callback for the `required` property of `MetaAttribute`.
|
|
1762
|
+
*
|
|
1763
|
+
* The return value should be truthy if the attribute is required or falsey if
|
|
1764
|
+
* not. If the return value is a non-empty string it replaces the default
|
|
1765
|
+
* "missing required attribute" error message.
|
|
1766
|
+
*
|
|
1767
|
+
* @public
|
|
1768
|
+
* @since 10.4.0
|
|
1769
|
+
* @param node - The node the attribute belongs to.
|
|
1770
|
+
*/
|
|
1771
|
+
export declare type MetaAttributeRequiredCallback = (node: HtmlElementLike) => string | boolean | null | undefined;
|
|
1772
|
+
|
|
1760
1773
|
/**
|
|
1761
1774
|
* Callback for content category properties of `MetaData`. It takes a node and
|
|
1762
1775
|
* returns whenever the element belongs to the content group or not.
|
|
@@ -1844,6 +1857,15 @@ export declare interface MetadataHelper {
|
|
|
1844
1857
|
* @since 8.2.0
|
|
1845
1858
|
**/
|
|
1846
1859
|
allowedIfParentIsPresent(this: void, ...tags: string[]): MetaAttributeAllowedCallback;
|
|
1860
|
+
/**
|
|
1861
|
+
* Returns true if an attribute with space-separated tokens includes given
|
|
1862
|
+
* keyword.
|
|
1863
|
+
*
|
|
1864
|
+
* @since 10.4.0
|
|
1865
|
+
* @param attr - Attribute value.
|
|
1866
|
+
* @param keyword - Keyword to look for.
|
|
1867
|
+
*/
|
|
1868
|
+
hasKeyword(this: void, attr: string, keyword: string): boolean;
|
|
1847
1869
|
}
|
|
1848
1870
|
|
|
1849
1871
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-validate",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"description": "Offline HTML5 validator and linter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"jest": "^28.1.3 || ^29.0.3 || ^30.0.0",
|
|
103
103
|
"jest-diff": "^28.1.3 || ^29.0.3 || ^30.0.0",
|
|
104
104
|
"jest-snapshot": "^28.1.3 || ^29.0.3 || ^30.0.0",
|
|
105
|
-
"vitest": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.
|
|
105
|
+
"vitest": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.1"
|
|
106
106
|
},
|
|
107
107
|
"peerDependenciesMeta": {
|
|
108
108
|
"jest": {
|