extractwords
Advanced tools
Comparing version 1.0.1 to 1.1.0
27
index.js
@@ -1,3 +0,24 @@ | ||
module.exports = (str) => { | ||
return str.match(/[a-zA-Z]+('[a-zA-Z]+)?/g) || []; | ||
} | ||
const defaults = { | ||
lowercase: false, | ||
punctuation: false | ||
}; | ||
module.exports = (str, options = {}) => { | ||
options = { | ||
...defaults, | ||
...options | ||
}; | ||
let words; | ||
if (options.punctuation) { | ||
words = str.match(/\S*[a-zA-Z]+\S*('\S*[a-zA-Z]+\S*)?/g) || []; | ||
} else { | ||
words = str.match(/[a-zA-Z]+('[a-zA-Z]+)?/g) || []; | ||
} | ||
if (options.lowercase) { | ||
words = words.map(str => str.toLowerCase()); | ||
} | ||
return words; | ||
}; |
{ | ||
"name": "extractwords", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Extract the words from a string", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "node test.js && xo index.js" | ||
}, | ||
"author": "Faraz", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
"license": "MIT", | ||
"repository": "f-a-r-a-z/extractwords", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/f-a-r-a-z/extractwords.git" | ||
}, | ||
"files": [ | ||
@@ -27,3 +30,6 @@ "index.js" | ||
"parse" | ||
] | ||
], | ||
"devDependencies": { | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -17,5 +17,14 @@ # extractwords [![Build Status](https://api.travis-ci.com/f-a-r-a-z/extractwords.svg?branch=master)](https://travis-ci.com/f-a-r-a-z/extractwords) | ||
extractwords('Good morning, how are you?'); | ||
//=> ['Good', 'morning', 'how', 'are', 'you'] | ||
extractwords('Good Morning, how are you?'); | ||
//=> ['Good', 'Morning', 'how', 'are', 'you'] | ||
extractwords('Good morning, how are you?', {lowercase: true}); | ||
//=> ['good', 'morning', 'how', 'are', 'you'] | ||
extractwords('Good Morning, how are you?', {punctuation: true}); | ||
//=> ['Good', 'Morning,', 'how', 'are', 'you?'] | ||
extractwords('Great work ... son.', {punctuation: true}); | ||
//=> ['Great', 'work', 'son.'] | ||
extractwords("He didn't pay for his meal m'aam"); | ||
@@ -27,4 +36,3 @@ //=> ['He', "didn't", 'pay', 'for', 'his', 'meal', "m'aam"] | ||
extractwords(''); | ||
//=> [] | ||
``` | ||
@@ -35,3 +43,3 @@ | ||
### extractwords(str) | ||
### extractwords(str, [options]) | ||
@@ -42,2 +50,21 @@ #### str | ||
Text containing words to be extracted | ||
Text containing words to be extracted. | ||
#### options | ||
Type: `object` | ||
##### lowercase | ||
Type: `boolean`<br> | ||
Default: `false` | ||
If `true`, all words returned are lowercased. | ||
##### punctuation | ||
Type: `boolean`<br> | ||
Default: `false` | ||
If `true`, all punctuation next to words are retained. | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
3376
20
67
0
0
1