Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extractwords

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extractwords - npm Package Compare versions

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;
};

16

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc