@markuplint/types
Advanced tools
Comparing version 4.0.0-alpha.4 to 4.0.0-alpha.5
@@ -91,8 +91,10 @@ import { checkMultiTypes } from './check-multi-types.js'; | ||
is: value => { | ||
// NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] | ||
const nameStartChar = /[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]/u; | ||
// NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] | ||
const nameCharTail = /-|[\d.\u00B7]|[\u0300-\u036F\u203F\u2040]/; | ||
// Name ::= NameStartChar (NameChar)* | ||
const name = new RegExp(`(?:${nameStartChar.source})(?:${nameCharTail})*`, 'u'); | ||
/** | ||
* NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] | ||
* NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] | ||
* Name ::= NameStartChar (NameChar)* | ||
*/ | ||
const name = | ||
// eslint-disable-next-line no-misleading-character-class | ||
/[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}][\d.\u00B7\u0300-\u036F\u203F\u2040-]*/u; | ||
return name.test(value) ? matched() : unmatched(value, 'unexpected-token'); | ||
@@ -99,0 +101,0 @@ }, |
export class Token { | ||
static getCol(value, offset) { | ||
const lines = value.slice(0, offset).split(/\n/g); | ||
const lines = value.slice(0, offset).split(/\n/); | ||
return (lines.at(-1) ?? '').length + 1; | ||
} | ||
static getLine(value, offset) { | ||
return value.slice(0, offset).split(/\n/g).length; | ||
return value.slice(0, offset).split(/\n/).length; | ||
} | ||
@@ -9,0 +9,0 @@ static getType(value, separators) { |
@@ -5,4 +5,11 @@ import type { FormattedPrimitiveTypeCreator } from '../types.js'; | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name | ||
* > PotentialCustomElementName ::= | ||
* > [a-z] (PCENChar)* '-' (PCENChar)* | ||
* > PCENChar ::= | ||
* > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | | ||
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] | ||
* > This uses the EBNF notation from the XML specification. [XML] | ||
* | ||
* > They start with an ASCII lower alpha, ensuring that the HTML parser will treat them as tags instead of as text. | ||
* | ||
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production | ||
@@ -19,6 +26,4 @@ * > - name must not be any of the following: | ||
* | ||
* ASCII-case-insensitively. | ||
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name | ||
*/ | ||
export declare const isCustomElementName: FormattedPrimitiveTypeCreator; |
/** | ||
* PotentialCustomElementName | ||
* PCENChar | ||
* | ||
* > PCENChar ::= | ||
* > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | | ||
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] | ||
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname | ||
* | ||
*/ | ||
const onlyPCENChar = | ||
// eslint-disable-next-line no-misleading-character-class | ||
/^[-.\d_a-z\u00B7\u00C0-\u00D6[\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C\u200D\u203F\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u; | ||
/** | ||
* valid name of custom element | ||
* | ||
* > PotentialCustomElementName ::= | ||
@@ -13,31 +23,4 @@ * > [a-z] (PCENChar)* '-' (PCENChar)* | ||
* | ||
* ASCII-case-insensitively. | ||
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser. | ||
*/ | ||
const rePCENChar = [ | ||
'\\-', | ||
'\\.', | ||
'[0-9]', | ||
'_', | ||
'[a-z]', | ||
'\u00B7', | ||
'[\u00C0-\u00D6]', | ||
'[\u00D8-\u00F6]', | ||
'[\u00F8-\u037D]', | ||
'[\u037F-\u1FFF]', | ||
'[\u200C-\u200D]', | ||
'[\u203F-\u2040]', | ||
'[\u2070-\u218F]', | ||
'[\u2C00-\u2FEF]', | ||
'[\u3001-\uD7FF]', | ||
'[\uF900-\uFDCF]', | ||
'[\uFDF0-\uFFFD]', | ||
'[\uD800-\uDBFF][\uDC00-\uDFFF]', | ||
].join('|'); | ||
const rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i'); | ||
/** | ||
* valid name of custom element | ||
* > They start with an ASCII lower alpha, ensuring that the HTML parser will treat them as tags instead of as text. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name | ||
* | ||
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production | ||
@@ -54,5 +37,3 @@ * > - name must not be any of the following: | ||
* | ||
* ASCII-case-insensitively. | ||
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name | ||
*/ | ||
@@ -73,4 +54,11 @@ export const isCustomElementName = () => { | ||
} | ||
return rePCEN.test(tagName); | ||
// First char must be ASCII lowercase alpha. | ||
if (!/^[a-z]/.test(tagName)) { | ||
return false; | ||
} | ||
if (!tagName.includes('-')) { | ||
return false; | ||
} | ||
return onlyPCENChar.test(tagName); | ||
}; | ||
}; |
{ | ||
"name": "@markuplint/types", | ||
"version": "4.0.0-alpha.4", | ||
"version": "4.0.0-alpha.5", | ||
"description": "Type declaration and value checker", | ||
@@ -38,3 +38,3 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
}, | ||
"gitHead": "991b3aef77fde42c79343ee8c807257a35c589d7" | ||
"gitHead": "0c3e4690662edf1765bcc4b6411ec5507c1e2ea3" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
224927
37
5680