validate-element-name
Advanced tools
Comparing version 0.1.0 to 0.1.1
14
index.js
'use strict'; | ||
var ncname = require('ncname'); | ||
@@ -23,2 +24,15 @@ var reservedNames = [ | ||
if (/^\d/i.test(name)) { | ||
throw new Error('Custom element names must not start with a digit'); | ||
} | ||
if (/^-/i.test(name)) { | ||
throw new Error('Custom element names must not start with a hyphen'); | ||
} | ||
// http://www.w3.org/TR/custom-elements/#concepts | ||
if (!ncname.test(name.replace(/-/g, ''))) { | ||
throw new Error('Invalid element name.'); | ||
} | ||
if (reservedNames.indexOf(name) !== -1) { | ||
@@ -25,0 +39,0 @@ throw new Error('The supplied element name is reserved and can\'t be used. See: http://www.w3.org/TR/custom-elements/#concepts'); |
{ | ||
"name": "validate-element-name", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Validate the name of a custom element", | ||
@@ -37,2 +37,5 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"ncname": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -39,0 +42,0 @@ "mocha": "*" |
@@ -5,3 +5,5 @@ # validate-element-name [![Build Status](https://travis-ci.org/sindresorhus/validate-element-name.svg?branch=master)](https://travis-ci.org/sindresorhus/validate-element-name) | ||
Custom element names should start with `a-z` and contain `a-z` and at least one `-` with optionally `0-9`. | ||
## Install | ||
@@ -8,0 +10,0 @@ |
2553
34
34
1
+ Addedncname@^0.1.0
+ Addedncname@0.1.2(transitive)
+ Addedxml-char-classes@0.1.0(transitive)