Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match the updated specification #8

Merged
merged 1 commit into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});