Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 11, 2021
1 parent e8bf9cd commit ac2216e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 55 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
is-hexadecimal.js
is-hexadecimal.min.js
yarn.lock
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
coverage/
is-hexadecimal.js
is-hexadecimal.min.js
*.json
*.md
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'

module.exports = hexadecimal

// Check if the given character code, or the character code at the first
// character, is hexadecimal.
function hexadecimal(character) {
export function isHexadecimal(character) {
var code = typeof character === 'string' ? character.charCodeAt(0) : character

return (
Expand Down
30 changes: 11 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,25 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
"devDependencies": {
"browserify": "^17.0.0",
"nyc": "^15.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s isHexadecimal -o is-hexadecimal.js",
"build-mangle": "browserify . -s isHexadecimal -p tinyify -o is-hexadecimal.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -52,16 +50,10 @@
},
"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"is-hexadecimal.js"
]
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
20 changes: 13 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Check if a character is hexadecimal.

## Install

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.

[npm][]:

```sh
Expand All @@ -18,20 +21,23 @@ npm install is-hexadecimal
## Use

```js
var hexadecimal = require('is-hexadecimal')
import {isHexadecimal} from 'is-hexadecimal'

hexadecimal('a') // => true
hexadecimal('0') // => true
hexadecimal('G') // => false
hexadecimal('💩') // => false
isHexadecimal('a') // => true
isHexadecimal('0') // => true
isHexadecimal('G') // => false
isHexadecimal('💩') // => false
```

## API

### `hexadecimal(character|code)`
This package exports the following identifiers: `isHexadecimal`.
There is no default export.

### `isHexadecimal(character|code)`

Check whether the given character code (`number`), or the character code at the
first position (`string`), is hexadecimal.
first position (`string`), is isHexadecimal.

## Related

Expand Down
34 changes: 16 additions & 18 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
'use strict'
import test from 'tape'
import {isHexadecimal} from './index.js'

var test = require('tape')
var hexadecimal = require('.')

test('hexadecimal(character)', function (t) {
t.ok(hexadecimal('a'))
t.ok(hexadecimal('F'))
t.ok(hexadecimal('0'))
t.ok(hexadecimal('a'.charCodeAt(0)))
t.notOk(hexadecimal('G'))
t.notOk(hexadecimal('a'.charCodeAt(0) - 1))
t.notOk(hexadecimal('f'.charCodeAt(0) + 1))
t.notOk(hexadecimal('A'.charCodeAt(0) - 1))
t.notOk(hexadecimal('F'.charCodeAt(0) + 1))
t.notOk(hexadecimal('0'.charCodeAt(0) - 1))
t.notOk(hexadecimal('9'.charCodeAt(0) + 1))
t.notOk(hexadecimal('g'.charCodeAt(0)))
t.notOk(hexadecimal('💩'))
test('isHexadecimal(character)', function (t) {
t.ok(isHexadecimal('a'))
t.ok(isHexadecimal('F'))
t.ok(isHexadecimal('0'))
t.ok(isHexadecimal('a'.charCodeAt(0)))
t.notOk(isHexadecimal('G'))
t.notOk(isHexadecimal('a'.charCodeAt(0) - 1))
t.notOk(isHexadecimal('f'.charCodeAt(0) + 1))
t.notOk(isHexadecimal('A'.charCodeAt(0) - 1))
t.notOk(isHexadecimal('F'.charCodeAt(0) + 1))
t.notOk(isHexadecimal('0'.charCodeAt(0) - 1))
t.notOk(isHexadecimal('9'.charCodeAt(0) + 1))
t.notOk(isHexadecimal('g'.charCodeAt(0)))
t.notOk(isHexadecimal('💩'))

t.end()
})

0 comments on commit ac2216e

Please sign in to comment.