Skip to content

Commit a3b6017

Browse files
committed
Refactor to move implementation to lib/
1 parent 478484c commit a3b6017

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const startRe = regenerate().add(start).toRegExp()
2020
const contRe = regenerate().add(cont).remove(start).toRegExp()
2121

2222
fs.writeFileSync(
23-
path.join('regex.js'),
23+
path.join('lib', 'regex.js'),
2424
[
2525
'// This module is generated by `build.js`.',
2626
'export const start = ' + startRe,

index.js

+1-38
Original file line numberDiff line numberDiff line change
@@ -1,38 +1 @@
1-
import {start as startRe, cont as contRe} from './regex.js'
2-
3-
/**
4-
* Checks if the given character code can start an identifier.
5-
*
6-
* @param {number} code
7-
*/
8-
// To do: support astrals.
9-
export function start(code) {
10-
return startRe.test(String.fromCharCode(code))
11-
}
12-
13-
/**
14-
* Checks if the given character code can continue an identifier.
15-
*
16-
* @param {number} code
17-
*/
18-
// To do: support astrals.
19-
export function cont(code) {
20-
const character = String.fromCharCode(code)
21-
return startRe.test(character) || contRe.test(character)
22-
}
23-
24-
/**
25-
* Checks if the given string is a valid identifier name.
26-
*
27-
* @param {string} name
28-
*/
29-
export function name(name) {
30-
let index = -1
31-
32-
while (++index < name.length) {
33-
if (!(index ? cont : start)(name.charCodeAt(index))) return false
34-
}
35-
36-
// `false` if `name` is empty.
37-
return index > 0
38-
}
1+
export {cont, name, start} from './lib/index.js'

lib/index.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {start as startRe, cont as contRe} from './regex.js'
2+
3+
/**
4+
* Checks if the given character code can start an identifier.
5+
*
6+
* @param {number} code
7+
*/
8+
// To do: support astrals.
9+
export function start(code) {
10+
return startRe.test(String.fromCharCode(code))
11+
}
12+
13+
/**
14+
* Checks if the given character code can continue an identifier.
15+
*
16+
* @param {number} code
17+
*/
18+
// To do: support astrals.
19+
export function cont(code) {
20+
const character = String.fromCharCode(code)
21+
return startRe.test(character) || contRe.test(character)
22+
}
23+
24+
/**
25+
* Checks if the given string is a valid identifier name.
26+
*
27+
* @param {string} name
28+
*/
29+
export function name(name) {
30+
let index = -1
31+
32+
while (++index < name.length) {
33+
if (!(index ? cont : start)(name.charCodeAt(index))) return false
34+
}
35+
36+
// `false` if `name` is empty.
37+
return index > 0
38+
}

regex.js renamed to lib/regex.js

File renamed without changes.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
"main": "index.js",
2828
"types": "index.d.ts",
2929
"files": [
30+
"lib/",
3031
"index.d.ts",
31-
"index.js",
32-
"regex.d.ts",
33-
"regex.js"
32+
"index.js"
3433
],
3534
"devDependencies": {
3635
"@types/regenerate": "^1.0.0",

0 commit comments

Comments
 (0)