Last active
March 11, 2022 19:25
-
-
Save rotty3000/537e9218ad4792258ad0711fab8b5f56 to your computer and use it in GitHub Desktop.
Validate Web Component Custom Element name with bash and grep
This file contains hidden or 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
#!/bin/bash | |
# Derived from https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name | |
PCENCHAR=[-.0-9_a-z\\xB7\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x{037D}\\x{037F}-\\x{1FFF}\\x{200C}-\\x{200D}\\x{203F}-\\x{2040}\\x{2070}-\\x{218F}\\x{2C00}-\\x{2F2F}\\x{3001}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}] | |
CUSTOM_ELEMENT_NAME_REGEX=^[a-z]${PCENCHAR}*-${PCENCHAR}*$ | |
if ! (echo "$1" | grep -q -P $CUSTOM_ELEMENT_NAME_REGEX); then | |
echo "invalid custom element name '$1'" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I find it strange that
a-
,a--
, etc, are supported.