Skip to content

Commit 6e8bb96

Browse files
committed
Use ESM
1 parent 6e71451 commit 6e8bb96

File tree

8 files changed

+65
-73
lines changed

8 files changed

+65
-73
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
*.d.ts
33
*.log
44
*.tgz
5-
.nyc_output/
65
coverage/
76
node_modules/
87
yarn.lock

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage/
2-
*.json
32
*.md

build.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict'
2-
31
// Based on:
42
// <https://github.com/babel/babel/blob/main/packages/babel-helper-validator-identifier/scripts/generate-identifier-regex.js>
53

6-
var fs = require('fs')
7-
var path = require('path')
8-
var regenerate = require('regenerate')
9-
var idStart = require('@unicode/unicode-13.0.0/Binary_Property/ID_Start/code-points.js')
10-
var idCont = require('@unicode/unicode-13.0.0/Binary_Property/ID_Continue/code-points.js')
4+
import fs from 'fs'
5+
import path from 'path'
6+
import regenerate from 'regenerate'
7+
import idStart from '@unicode/unicode-13.0.0/Binary_Property/ID_Start/code-points.js'
8+
import idCont from '@unicode/unicode-13.0.0/Binary_Property/ID_Continue/code-points.js'
119

1210
var start = [36 /* `$` */, 95 /* `_` */].concat(idStart.filter((d) => bmp(d)))
1311
var cont = [0x200c, 0x200d].concat(idCont.filter((d) => bmp(d)))
@@ -19,8 +17,8 @@ fs.writeFileSync(
1917
path.join('regex.js'),
2018
[
2119
'// This module is generated by `build.js`.',
22-
'exports.start = ' + startRe,
23-
'exports.cont = ' + contRe,
20+
'export var start = ' + startRe,
21+
'export var cont = ' + contRe,
2422
''
2523
].join('\n')
2624
)

index.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
'use strict'
2-
3-
exports.start = start
4-
exports.cont = cont
5-
exports.name = name
6-
7-
var id = require('./regex')
1+
import {start as startRe, cont as contRe} from './regex.js'
82

93
/**
104
* Checks if the given character code can start an identifier.
115
*
126
* @param {number} code
137
*/
148
// To do: support astrals.
15-
function start(code) {
16-
return id.start.test(String.fromCharCode(code))
9+
export function start(code) {
10+
return startRe.test(String.fromCharCode(code))
1711
}
1812

1913
/**
@@ -22,17 +16,17 @@ function start(code) {
2216
* @param {number} code
2317
*/
2418
// To do: support astrals.
25-
function cont(code) {
19+
export function cont(code) {
2620
var character = String.fromCharCode(code)
27-
return id.start.test(character) || id.cont.test(character)
21+
return startRe.test(character) || contRe.test(character)
2822
}
2923

3024
/**
3125
* Checks if the given string is a valid identifier name.
3226
*
3327
* @param {string} name
3428
*/
35-
function name(name) {
29+
export function name(name) {
3630
var index = -1
3731

3832
while (++index < name.length) {

package.json

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@
2222
"contributors": [
2323
"Titus Wormer <[email protected]> (https://wooorm.com)"
2424
],
25+
"sideEffects": false,
26+
"type": "module",
27+
"main": "index.js",
28+
"types": "index.d.ts",
2529
"files": [
30+
"index.d.ts",
2631
"index.js",
27-
"regex.js",
28-
"*.d.ts"
32+
"regex.d.ts",
33+
"regex.js"
2934
],
3035
"devDependencies": {
3136
"@types/tape": "^4.0.0",
3237
"@unicode/unicode-13.0.0": "^1.0.0",
38+
"c8": "^7.6.0",
3339
"nyc": "^15.0.0",
3440
"prettier": "^2.0.0",
3541
"regenerate": "^1.0.0",
@@ -42,12 +48,12 @@
4248
"xo": "^0.38.0"
4349
},
4450
"scripts": {
51+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
4552
"generate": "node build",
4653
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
47-
"test-api": "node test",
48-
"test-coverage": "nyc --reporter lcov tape test.js",
49-
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
50-
"test": "npm run generate && npm run format && npm run test-coverage && npm run build",
54+
"test-api": "node test.js",
55+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
56+
"test": "npm run generate && npm run build && npm run format && npm run test-coverage",
5157
"prepack": "npm run build && npm run format"
5258
},
5359
"prettier": {
@@ -60,21 +66,13 @@
6066
},
6167
"xo": {
6268
"prettier": true,
63-
"esnext": false,
6469
"rules": {
70+
"import/no-mutable-exports": "off",
6571
"no-misleading-character-class": "off",
66-
"no-useless-escape": "off",
67-
"unicorn/no-fn-reference-in-iterator": "off",
68-
"unicorn/no-hex-escape": "off",
69-
"unicorn/better-regex": "off"
72+
"no-var": "off",
73+
"prefer-arrow-callback": "off"
7074
}
7175
},
72-
"nyc": {
73-
"check-coverage": true,
74-
"lines": 100,
75-
"functions": 100,
76-
"branches": 100
77-
},
7876
"remarkConfig": {
7977
"plugins": [
8078
"preset-wooorm"

readme.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Check if something can be an identifier name.
99

1010
## Install
1111

12+
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
13+
instead of `require`d.
14+
1215
[npm][]:
1316

1417
```sh
@@ -18,27 +21,30 @@ npm install estree-util-is-identifier-name
1821
## Use
1922

2023
```js
21-
var isIdentifierName = require('estree-util-is-identifier-name')
24+
import {name, start, cont} from 'estree-util-is-identifier-name'
2225

23-
isIdentifierName.name('$something69') // => true
24-
isIdentifierName.name('69') // => false
25-
isIdentifierName.name('var') // => true (this does not handle keywords)
26+
name('$something69') // => true
27+
name('69') // => false
28+
name('var') // => true (this does not handle keywords)
2629

27-
isIdentifierName.start(48) // => false (character code for `0`)
28-
isIdentifierName.cont(48) // => true (character code for `0`)
30+
start(48) // => false (character code for `0`)
31+
cont(48) // => true (character code for `0`)
2932
```
3033

3134
## API
3235

33-
### `isIdentifierName.name(value)`
36+
This package exports the following identifiers: `name`, `start`, and `cont`.
37+
There is no default export.
38+
39+
### `name(value)`
3440

3541
Checks if the given string is a valid identifier name.
3642

37-
### `isIdentifierName.start(code)`
43+
### `start(code)`
3844

3945
Checks if the given character code can start an identifier.
4046

41-
### `isIdentifierName.cont(code)`
47+
### `cont(code)`
4248

4349
Checks if the given character code can continue an identifier.
4450

regex.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)