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

estree-util-is-identifier-name

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

estree-util-is-identifier-name - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

3

index.d.ts

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

export {cont, name, start} from './lib/index.js'
export type Options = import('./lib/index.js').Options;
export { cont, name, start } from "./lib/index.js";

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

/**
* @typedef {import('./lib/index.js').Options} Options
*/
export {cont, name, start} from './lib/index.js'
/**
* Checks if the given character code can start an identifier.
* Checks if the given code point can start an identifier.
*
* @param {number} code
* Character code to check.
* @param {number | undefined} code
* Code point to check.
* @returns {boolean}
* Whether `code` can start an identifier.
*/
export function start(code: number): boolean
export function start(code: number | undefined): boolean;
/**
* Checks if the given character code can continue an identifier.
* Checks if the given code point can continue an identifier.
*
* @param {number} code
* Character code to check.
* @param {number | undefined} code
* Code point to check.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {boolean}
* Whether `code` can continue an identifier.
*/
export function cont(code: number): boolean
export function cont(code: number | undefined, options?: Options | null | undefined): boolean;
/**

@@ -24,5 +26,16 @@ * Checks if the given value is a valid identifier name.

* Identifier to check.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {boolean}
* Whether `name` can be an identifier.
*/
export function name(name: string): boolean
export function name(name: string, options?: Options | null | undefined): boolean;
/**
* Configuration.
*/
export type Options = {
/**
* Support JSX identifiers (default: `false`).
*/
jsx?: boolean | null | undefined;
};

@@ -1,28 +0,45 @@

import {start as startRe, cont as contRe} from './regex.js'
/**
* @typedef Options
* Configuration.
* @property {boolean | null | undefined} [jsx=false]
* Support JSX identifiers (default: `false`).
*/
const startRe = /[$_\p{ID_Start}]/u
const contRe = /[$_\u{200C}\u{200D}\p{ID_Continue}]/u
const contReJsx = /[-$_\u{200C}\u{200D}\p{ID_Continue}]/u
const nameRe = /^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u
const nameReJsx = /^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u
/** @type {Options} */
const emptyOptions = {}
/**
* Checks if the given character code can start an identifier.
* Checks if the given code point can start an identifier.
*
* @param {number} code
* Character code to check.
* @param {number | undefined} code
* Code point to check.
* @returns {boolean}
* Whether `code` can start an identifier.
*/
// To do: support astrals.
// Note: `undefined` is supported so you can pass the result from `''.codePointAt`.
export function start(code) {
return startRe.test(String.fromCharCode(code))
return code ? startRe.test(String.fromCodePoint(code)) : false
}
/**
* Checks if the given character code can continue an identifier.
* Checks if the given code point can continue an identifier.
*
* @param {number} code
* Character code to check.
* @param {number | undefined} code
* Code point to check.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {boolean}
* Whether `code` can continue an identifier.
*/
// To do: support astrals.
export function cont(code) {
const character = String.fromCharCode(code)
return startRe.test(character) || contRe.test(character)
// Note: `undefined` is supported so you can pass the result from `''.codePointAt`.
export function cont(code, options) {
const settings = options || emptyOptions
const re = settings.jsx ? contReJsx : contRe
return code ? re.test(String.fromCodePoint(code)) : false
}

@@ -35,14 +52,11 @@

* Identifier to check.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {boolean}
* Whether `name` can be an identifier.
*/
export function name(name) {
let index = -1
while (++index < name.length) {
if (!(index ? cont : start)(name.charCodeAt(index))) return false
}
// `false` if `name` is empty.
return index > 0
export function name(name, options) {
const settings = options || emptyOptions
const re = settings.jsx ? nameReJsx : nameRe
return re.test(name)
}
{
"name": "estree-util-is-identifier-name",
"version": "2.1.0",
"version": "3.0.0",
"description": "Check if something can be an ecmascript (javascript) identifier name",

@@ -27,4 +27,3 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [

@@ -36,41 +35,30 @@ "lib/",

"devDependencies": {
"@types/node": "^18.0.0",
"@types/regenerate": "^1.0.0",
"@unicode/unicode-15.0.0": "^1.0.0",
"c8": "^7.6.0",
"prettier": "^2.0.0",
"regenerate": "^1.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"xo": "^0.55.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"generate": "node --conditions development build.js",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"xo": {
"prettier": true,
"rules": {
"no-misleading-character-class": "off",
"unicorn/prefer-code-point": "off"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]

@@ -81,4 +69,8 @@ },

"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true
}
}

@@ -20,5 +20,6 @@ # estree-util-is-identifier-name

* [API](#api)
* [`cont(code)`](#contcode)
* [`name(name)`](#namename)
* [`cont(code[, options])`](#contcode-options)
* [`name(name[, options])`](#namename-options)
* [`start(code)`](#startcode)
* [Options](#options)
* [Types](#types)

@@ -43,3 +44,3 @@ * [Compatibility](#compatibility)

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

@@ -53,3 +54,3 @@ ```sh

```js
import * as isIdentifierName from 'https://esm.sh/estree-util-is-identifier-name@2'
import {cont, name, start} from 'https://esm.sh/estree-util-is-identifier-name@3'
```

@@ -61,3 +62,3 @@

<script type="module">
import * as isIdentifierName from 'https://esm.sh/estree-util-is-identifier-name@2?bundle'
import {cont, name, start} from 'https://esm.sh/estree-util-is-identifier-name@3?bundle'
</script>

@@ -75,4 +76,4 @@ ```

start(48) // => false (character code for `0`)
cont(48) // => true (character code for `0`)
start(48) // => false (code point for `'0'`)
cont(48) // => true (code point for `'0'`)
```

@@ -82,9 +83,10 @@

This package exports the identifiers [`cont`][cont], [`name`][name], and
[`start`][start].
This package exports the identifiers [`cont`][api-cont],
[`name`][api-name], and
[`start`][api-start].
There is no default export.
### `cont(code)`
### `cont(code[, options])`
Checks if the given character code can continue an identifier.
Checks if the given code point can continue an identifier.

@@ -94,3 +96,5 @@ ###### Parameters

* `code` (`number`)
— character code to check
— code point to check
* `options` ([`Options`][api-options], optional)
— configuration

@@ -101,3 +105,3 @@ ###### Returns

### `name(name)`
### `name(name[, options])`

@@ -110,2 +114,4 @@ Checks if the given value is a valid identifier name.

— identifier to check
* `options` ([`Options`][api-options], optional)
— configuration

@@ -118,3 +124,3 @@ ###### Returns

Checks if the given character code can start an identifier.
Checks if the given code point can start an identifier.

@@ -124,3 +130,3 @@ ###### Parameters

* `code` (`number`)
— character code to check
— code point to check

@@ -131,14 +137,26 @@ ###### Returns

### Options
Configuration (TypeScript type).
###### Fields
* `jsx` (`boolean`, default: `false`)
— support JSX identifiers.
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
It exports the additional type [`Options`][api-options].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`estree-util-is-identifier-name@^3`, compatible with Node.js 16.
## Related

@@ -177,5 +195,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/estree-util-is-identifier-name.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=estree-util-is-identifier-name
[size]: https://bundlephobia.com/result?p=estree-util-is-identifier-name
[size]: https://bundlejs.com/?q=estree-util-is-identifier-name

@@ -214,6 +232,8 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[cont]: #contcode
[api-cont]: #contcode-options
[name]: #namename
[api-name]: #namename-options
[start]: #startcode
[api-start]: #startcode
[api-options]: #options
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