From 0b7940b6e9f3bc87529c8e8e03ab5e9754add261 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Tue, 21 Jun 2016 20:39:44 +0200 Subject: [PATCH] Match the updated specification https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name See https://github.com/w3c/webcomponents/issues/239 for background. --- index.js | 9 +++++---- package.json | 4 ++-- test.js | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index cee766c..2c9ba50 100644 --- a/index.js +++ b/index.js @@ -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', @@ -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'; } } diff --git a/package.json b/package.json index d46b4c6..e2bf873 100644 --- a/package.json +++ b/package.json @@ -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": "*" diff --git a/test.js b/test.js index 794b58f..5d1014d 100644 --- a/test.js +++ b/test.js @@ -35,7 +35,7 @@ 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); @@ -43,4 +43,5 @@ it('should return true for `isValid` with warnings for not recommended names', f assert(validate('uni-corné').message); assert(validate('xml-unicorn').isValid); assert(validate('xml-unicorn').message); + assert(validate('foo-💩').message); });