diff --git a/.gitignore b/.gitignore index bd5f5ee..735f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store *.log -.nyc_output/ coverage/ node_modules/ -is-hexadecimal.js -is-hexadecimal.min.js yarn.lock diff --git a/.prettierignore b/.prettierignore index 6ef8749..cebe81f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,2 @@ coverage/ -is-hexadecimal.js -is-hexadecimal.min.js -*.json *.md diff --git a/index.js b/index.js index 567c9d1..6c960a2 100644 --- a/index.js +++ b/index.js @@ -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 ( diff --git a/package.json b/package.json index b857f0c..7eb758e 100644 --- a/package.json +++ b/package.json @@ -20,27 +20,25 @@ "contributors": [ "Titus Wormer (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, @@ -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": [ diff --git a/readme.md b/readme.md index c2b80bc..8c9929d 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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 diff --git a/test.js b/test.js index 316d473..ed076cd 100644 --- a/test.js +++ b/test.js @@ -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() })