-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added helper and rules for validating a string is an html5 tag name.
- Loading branch information
Showing
10 changed files
with
992 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2019 - 2024 Toreda, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
/** | ||
* @category Validators – Html5 | ||
*/ | ||
export type Html5Tag = | ||
| 'area' | ||
| 'article' | ||
| 'aside' | ||
| 'audio' | ||
| 'b' | ||
| 'base' | ||
| 'basefront' | ||
| 'bdi' | ||
| 'bdo' | ||
| 'blockquote' | ||
| 'body' | ||
| 'br' | ||
| 'button' | ||
| 'canvas' | ||
| 'caption' | ||
| 'cite' | ||
| 'code' | ||
| 'col' | ||
| 'colgroup' | ||
| 'data' | ||
| 'del' | ||
| 'details' | ||
| 'dfn' | ||
| 'dialog' | ||
| 'dir' | ||
| 'div' | ||
| 'dl' | ||
| 'dt' | ||
| 'em' | ||
| 'embed' | ||
| 'fieldset' | ||
| 'figcaption' | ||
| 'figure' | ||
| 'font' | ||
| 'footer' | ||
| 'form' | ||
| 'frame' | ||
| 'frameset' | ||
| 'h1' | ||
| 'h2' | ||
| 'h3' | ||
| 'h4' | ||
| 'h5' | ||
| 'h6' | ||
| 'head' | ||
| 'header' | ||
| 'hgroup' | ||
| 'hr' | ||
| 'html' | ||
| 'i' | ||
| 'iframe' | ||
| 'img' | ||
| 'input' | ||
| 'ins' | ||
| 'kbd' | ||
| 'keygen' | ||
| 'label' | ||
| 'legend' | ||
| 'li' | ||
| 'link' | ||
| 'main' | ||
| 'map' | ||
| 'mark' | ||
| 'menu' | ||
| 'menuitem' | ||
| 'meta' | ||
| 'meter' | ||
| 'nav' | ||
| 'noframes' | ||
| 'noscript' | ||
| 'object' | ||
| 'ol' | ||
| 'optgroup' | ||
| 'option' | ||
| 'output' | ||
| 'p' | ||
| 'param' | ||
| 'picture' | ||
| 'pre' | ||
| 'progress' | ||
| 'q' | ||
| 'rp' | ||
| 'rt' | ||
| 'ruby' | ||
| 's' | ||
| 'samp' | ||
| 'script' | ||
| 'section' | ||
| 'select' | ||
| 'small' | ||
| 'source' | ||
| 'span' | ||
| 'strike' | ||
| 'strong' | ||
| 'style' | ||
| 'sub' | ||
| 'summary' | ||
| 'sup' | ||
| 'svg' | ||
| 'table' | ||
| 'tbody' | ||
| 'td' | ||
| 'template' | ||
| 'textarea' | ||
| 'tfoot' | ||
| 'th' | ||
| 'thead' | ||
| 'time' | ||
| 'title' | ||
| 'tr' | ||
| 'track' | ||
| 'tt' | ||
| 'u' | ||
| 'ul' | ||
| 'var' | ||
| 'video' | ||
| 'wbr' | ||
| string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import {type Html5Tag} from './tag'; | ||
|
||
export const html5Tags: Set<Html5Tag> = new Set<Html5Tag>([ | ||
'area', | ||
'article', | ||
'aside', | ||
'audio', | ||
'b', | ||
'base', | ||
'basefront', | ||
'bdi', | ||
'bdo', | ||
'blockquote', | ||
'body', | ||
'br', | ||
'button', | ||
'canvas', | ||
'caption', | ||
'cite', | ||
'code', | ||
'col', | ||
'colgroup', | ||
'data', | ||
'del', | ||
'details', | ||
'dfn', | ||
'dialog', | ||
'dir', | ||
'div', | ||
'dl', | ||
'dt', | ||
'em', | ||
'embed', | ||
'fieldset', | ||
'figcaption', | ||
'figure', | ||
'font', | ||
'footer', | ||
'form', | ||
'frame', | ||
'frameset', | ||
'h1', | ||
'h2', | ||
'h3', | ||
'h4', | ||
'h5', | ||
'h6', | ||
'head', | ||
'header', | ||
'hgroup', | ||
'hr', | ||
'html', | ||
'i', | ||
'iframe', | ||
'img', | ||
'input', | ||
'ins', | ||
'kbd', | ||
'keygen', | ||
'label', | ||
'legend', | ||
'li', | ||
'link', | ||
'main', | ||
'map', | ||
'mark', | ||
'menu', | ||
'menuitem', | ||
'meta', | ||
'meter', | ||
'nav', | ||
'noframes', | ||
'noscript', | ||
'object', | ||
'ol', | ||
'optgroup', | ||
'option', | ||
'output', | ||
'p', | ||
'param', | ||
'picture', | ||
'pre', | ||
'progress', | ||
'q', | ||
'rp', | ||
'rt', | ||
'ruby', | ||
's', | ||
'samp', | ||
'script', | ||
'section', | ||
'select', | ||
'small', | ||
'source', | ||
'span', | ||
'strike', | ||
'strong', | ||
'style', | ||
'sub', | ||
'summary', | ||
'sup', | ||
'svg', | ||
'table', | ||
'tbody', | ||
'td', | ||
'template', | ||
'textarea', | ||
'tfoot', | ||
'th', | ||
'thead', | ||
'time', | ||
'title', | ||
'tr', | ||
'track', | ||
'tt', | ||
'u', | ||
'ul', | ||
'var', | ||
'video', | ||
'wbr' | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2019 - 2024 Toreda, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
import {type Html5Tag} from '../../html5/tag'; | ||
import {html5Tags} from '../../html5/tags'; | ||
|
||
/** | ||
* Determine if value is a strict boolean type. Does not return true for | ||
* otherwise truthy non-boolean values. | ||
* @param value | ||
* @returns | ||
* | ||
* @category Validators – Html5 | ||
*/ | ||
export function isHtml5Tag(value: unknown): value is Html5Tag { | ||
if (typeof value !== 'string') { | ||
return false; | ||
} | ||
|
||
const lower = value.toLocaleLowerCase().trim(); | ||
return html5Tags.has(lower); | ||
} |
Oops, something went wrong.