Skip to content

Commit

Permalink
Match the updated specification
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Jun 21, 2016
1 parent a96bdfa commit 0b7940b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var ncname = require('ncname');
var isPotentialCustomElementName = require('is-potential-custom-element-name');

// https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name
var reservedNames = [
'annotation-xml',
'color-profile',
Expand Down Expand Up @@ -33,13 +34,13 @@ function hasError(name) {
return 'Custom element names must not start with a hyphen.';
}

// http://www.w3.org/TR/custom-elements/#concepts
if (!ncname.test(name)) {
// https://html.spec.whatwg.org/multipage/scripting.html#prod-potentialcustomelementname
if (!isPotentialCustomElementName(name)) {
return 'Invalid element name.';
}

if (reservedNames.indexOf(name) !== -1) {
return 'The supplied element name is reserved and can\'t be used.\nSee: http://www.w3.org/TR/custom-elements/#concepts';
return 'The supplied element name is reserved and can\'t be used.\nSee: https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name';
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"components"
],
"dependencies": {
"is-potential-custom-element-name": "^1.0.0",
"log-symbols": "^1.0.0",
"meow": "^3.3.0",
"ncname": "^1.0.0"
"meow": "^3.3.0"
},
"devDependencies": {
"mocha": "*"
Expand Down
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ it('should return true for `isValid` with warnings for not recommended names', f
assert(validate('uni--corn').message);
assert(validate('uni-----corn').message);
assert(validate('uni-co___rn').message);
assert(validate('øl-unicorn').isValid);
assert(!validate('øl-unicorn').isValid);
assert(validate('øl-unicorn').message);
assert(validate('uni-co.rn').isValid);
assert(validate('uni-co.rn').message);
assert(validate('uni-corné').isValid);
assert(validate('uni-corné').message);
assert(validate('xml-unicorn').isValid);
assert(validate('xml-unicorn').message);
assert(validate('foo-💩').message);
});

0 comments on commit 0b7940b

Please sign in to comment.