Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

validate-element-name

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-element-name - npm Package Compare versions

Comparing version 2.1.1 to 3.0.0

39

cli.js
#!/usr/bin/env node
'use strict';
var logSymbols = require('log-symbols');
var meow = require('meow');
var validate = require('./');
import logSymbols from 'log-symbols';
import meow from 'meow';
import validate from './index.js';
var cli = meow([
'Usage',
' $ validate-element-name <element-name>',
'',
'Example',
' $ validate-element-name s-slider',
' ' + logSymbols.success + ' Valid element name.'
]);
const cli = meow(`
Usage
$ validate-element-name <element-name>
Example
$ validate-element-name s-slider
${logSymbols.success} Valid element name
`, {
importMeta: import.meta
});
if (cli.input.length === 0) {

@@ -21,13 +22,13 @@ console.error('Specify an element name');

var res = validate(cli.input[0]);
const result = validate(cli.input[0]);
if (res.isValid) {
if (res.message) {
console.log(logSymbols.success + ' Valid element name, but...');
console.log(logSymbols.warning + ' ' + res.message);
if (result.isValid) {
if (result.message) {
console.log(`${logSymbols.success} Valid element name, but…`);
console.log(`${logSymbols.warning} ${result.message}`);
} else {
console.log(logSymbols.success + ' Valid element name.');
console.log(`${logSymbols.success} Valid element name.`);
}
} else {
console.error(logSymbols.error + ' ' + res.message);
console.error(`${logSymbols.error} ${result.message}`);
}

@@ -1,6 +0,5 @@

'use strict';
var isPotentialCustomElementName = require('is-potential-custom-element-name');
import isPotentialCustomElementName from 'is-potential-custom-element-name';
// https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name
var reservedNames = [
const reservedNames = new Set([
'annotation-xml',

@@ -14,3 +13,3 @@ 'color-profile',

'missing-glyph'
];
]);

@@ -26,3 +25,3 @@ function hasError(name) {

if (name.indexOf('-') === -1) {
if (!name.includes('-')) {
return 'Custom element names must contain a hyphen. Example: unicorn-cake';

@@ -44,3 +43,3 @@ }

if (reservedNames.indexOf(name) !== -1) {
if (reservedNames.has(name)) {
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';

@@ -71,11 +70,11 @@ }

if (/-$/.test(name)) {
if (name.endsWith('-')) {
return 'Custom element names should not end with a hyphen.';
}
if (/[\.]/.test(name)) {
if (/\./.test(name)) {
return 'Custom element names should not contain a dot character as it would need to be escaped in a CSS selector.';
}
if (/[^\x20-\x7E]/.test(name)) {
if (/[^\u0020-\u007E]/.test(name)) {
return 'Custom element names should not contain non-ASCII characters.';

@@ -88,3 +87,3 @@ }

if (/[^a-z0-9]{2}/i.test(name)) {
if (/[^a-z\d]{2}/i.test(name)) {
return 'Custom element names should not contain consecutive non-alpha characters.';

@@ -94,9 +93,9 @@ }

module.exports = function (name) {
var errMsg = hasError(name);
export default function validateElementName(name) {
const errorMessage = hasError(name);
return {
isValid: !errMsg,
message: errMsg || hasWarning(name)
isValid: !errorMessage,
message: errorMessage || hasWarning(name)
};
};
}
{
"name": "validate-element-name",
"version": "2.1.1",
"description": "Validate the name of a custom element",
"license": "MIT",
"repository": "sindresorhus/validate-element-name",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bin": "cli.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"cli.js"
],
"keywords": [
"cli-app",
"cli",
"validate",
"validator",
"check",
"custom",
"element",
"elements",
"elem",
"el",
"html",
"tag",
"name",
"wc",
"web",
"components"
],
"dependencies": {
"is-potential-custom-element-name": "^1.0.0",
"log-symbols": "^1.0.0",
"meow": "^3.7.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "validate-element-name",
"version": "3.0.0",
"description": "Validate the name of a custom element",
"license": "MIT",
"repository": "sindresorhus/validate-element-name",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com/"
},
"type": "module",
"exports": "./index.js",
"bin": "./cli.js",
"engines": {
"node": ">=12.20"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"cli.js"
],
"keywords": [
"cli-app",
"cli",
"validate",
"validator",
"check",
"custom",
"element",
"elements",
"html",
"tag",
"name",
"wc",
"web",
"components"
],
"dependencies": {
"is-potential-custom-element-name": "^1.0.1",
"log-symbols": "^5.0.0",
"meow": "^10.0.1"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.40.2"
}
}

@@ -1,2 +0,2 @@

# validate-element-name [![Build Status](https://travis-ci.org/sindresorhus/validate-element-name.svg?branch=master)](https://travis-ci.org/sindresorhus/validate-element-name)
# validate-element-name

@@ -9,14 +9,12 @@ > Validate the name of a [custom element](http://www.html5rocks.com/en/tutorials/webcomponents/customelements/)

## Install
```
$ npm install --save validate-element-name
$ npm install validate-element-name
```
## Usage
```js
const validate = require('validate-element-name');
import validateElementName from 'validate-element-name';

@@ -29,3 +27,2 @@ validate('unicorn');

## CLI

@@ -47,6 +44,1 @@

```
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc