Skip to content

Commit 0b7940b

Browse files
committed
1 parent a96bdfa commit 0b7940b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
2-
var ncname = require('ncname');
2+
var isPotentialCustomElementName = require('is-potential-custom-element-name');
33

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

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

4142
if (reservedNames.indexOf(name) !== -1) {
42-
return 'The supplied element name is reserved and can\'t be used.\nSee: http://www.w3.org/TR/custom-elements/#concepts';
43+
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';
4344
}
4445
}
4546

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
"components"
4242
],
4343
"dependencies": {
44+
"is-potential-custom-element-name": "^1.0.0",
4445
"log-symbols": "^1.0.0",
45-
"meow": "^3.3.0",
46-
"ncname": "^1.0.0"
46+
"meow": "^3.3.0"
4747
},
4848
"devDependencies": {
4949
"mocha": "*"

test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ it('should return true for `isValid` with warnings for not recommended names', f
3535
assert(validate('uni--corn').message);
3636
assert(validate('uni-----corn').message);
3737
assert(validate('uni-co___rn').message);
38-
assert(validate('øl-unicorn').isValid);
38+
assert(!validate('øl-unicorn').isValid);
3939
assert(validate('øl-unicorn').message);
4040
assert(validate('uni-co.rn').isValid);
4141
assert(validate('uni-co.rn').message);
4242
assert(validate('uni-corné').isValid);
4343
assert(validate('uni-corné').message);
4444
assert(validate('xml-unicorn').isValid);
4545
assert(validate('xml-unicorn').message);
46+
assert(validate('foo-💩').message);
4647
});

0 commit comments

Comments
 (0)