is-word-character
Advanced tools
Comparing version 1.0.4 to 2.0.0
24
index.js
@@ -1,14 +0,14 @@ | ||
'use strict' | ||
module.exports = wordCharacter | ||
var fromCode = String.fromCharCode | ||
var re = /\w/ | ||
// Check if the given character code, or the character code at the first | ||
// character, is a word character. | ||
function wordCharacter(character) { | ||
return re.test( | ||
typeof character === 'number' ? fromCode(character) : character.charAt(0) | ||
/** | ||
* Check if the given character code, or the character code at the first | ||
* character, is a word character. | ||
* | ||
* @param {string|number} character | ||
* @returns {boolean} Whether `character` is a word character. | ||
*/ | ||
export function isWordCharacter(character) { | ||
return /\w/.test( | ||
typeof character === 'number' | ||
? String.fromCharCode(character) | ||
: character.charAt(0) | ||
) | ||
} |
{ | ||
"name": "is-word-character", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "Check if a character is a word character", | ||
@@ -23,24 +23,29 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.25.0" | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.6.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.38.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s isWordCharacter -o is-word-character.js", | ||
"build-mangle": "browserify . -s isWordCharacter -p tinyify -o is-word-character.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" | ||
"prepublishOnly": "npm run build && npm run format", | ||
"prebuild": "rimraf \"*.d.ts\"", | ||
"build": "tsc", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"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 build && npm run format && npm run test-coverage" | ||
}, | ||
@@ -57,13 +62,7 @@ "prettier": { | ||
"prettier": true, | ||
"esnext": false, | ||
"ignores": [ | ||
"is-word-character.js" | ||
] | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"remarkConfig": { | ||
@@ -70,0 +69,0 @@ "plugins": [ |
@@ -12,2 +12,5 @@ # is-word-character | ||
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed | ||
instead of `require`d. | ||
[npm][]: | ||
@@ -22,10 +25,10 @@ | ||
```js | ||
var wordCharacter = require('is-word-character') | ||
import {isWordCharacter} from 'is-word-character' | ||
wordCharacter('a') // => true | ||
wordCharacter('Z') // => true | ||
wordCharacter('0') // => true | ||
wordCharacter('_') // => true | ||
wordCharacter(' ') // => false | ||
wordCharacter('💩') // => false | ||
isWordCharacter('a') // => true | ||
isWordCharacter('Z') // => true | ||
isWordCharacter('0') // => true | ||
isWordCharacter('_') // => true | ||
isWordCharacter(' ') // => false | ||
isWordCharacter('💩') // => false | ||
``` | ||
@@ -35,4 +38,7 @@ | ||
### `wordCharacter(character|code)` | ||
This package exports the following identifiers: `isWordCharacter`. | ||
There is no default export. | ||
### `isWordCharacter(character|code)` | ||
Check whether the given character code (`number`), or the character code at the | ||
@@ -55,5 +61,5 @@ first position (`string`), is a word character. | ||
[build-badge]: https://img.shields.io/travis/wooorm/is-word-character.svg | ||
[build-badge]: https://github.com/wooorm/is-word-character/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/wooorm/is-word-character | ||
[build]: https://github.com/wooorm/is-word-character/actions | ||
@@ -60,0 +66,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/is-word-character.svg |
5610
5
22
79
Yes
9