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

find-by-words

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-by-words - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

17

find-by-words.js

@@ -13,3 +13,12 @@ /*

})('findByWords', this, function (name, context) {
var findByWords = function(a, word) {
var _isEqual = function(word1, word2, caseSensitive) {
if (caseSensitive) {
return word1.toLowerCase() == word2.toLowerCase();
}
return word1 == word2;
};
var findByWords = function(a, word, caseSensitive) {
var size = word.length;

@@ -25,3 +34,3 @@ var first = 0;

if (wordPart == word) {
if (_isEqual(wordPart, word, caseSensitive)) {
found = true;

@@ -31,7 +40,7 @@ output.push(a[middle]);

while (a[--_middle] && a[_middle].slice(0, size) == word) {
while (a[--_middle] && _isEqual(a[_middle].slice(0, size), word, caseSensitive)) {
output.push(a[_middle]);
}
while (a[++middle] && a[middle].slice(0, size) == word) {
while (a[++middle] && _isEqual(a[middle].slice(0, size), word, caseSensitive)) {
output.push(a[middle]);

@@ -38,0 +47,0 @@ }

@@ -5,3 +5,3 @@ {

"repository": "evandrolg/find-by-words",
"version": "1.0.2",
"version": "1.0.3",
"main": "search-by-words.js",

@@ -8,0 +8,0 @@ "keywords": [

@@ -12,7 +12,12 @@ # find-by-words

## Parameters
* **wordsList** <code>Array</code>
* **word** <code>String</code>
* **caseSensitive** <code>Boolean</code> (<code>false</code> by default)
## How to use?
```js
findByWords(['python', 'ruby', 'java', 'javascript', 'lua'], 'java');
findByWords(['python', 'ruby', 'java', 'javascript', 'lua'], 'Java', true);
// output: ['java', 'javascript']
```

@@ -6,4 +6,4 @@ var assert = require('assert');

var verifyOutput = function(list, word, expected) {
var output = findByWords(list, word);
var verifyOutput = function(list, word, expected, caseSensitive) {
var output = findByWords(list, word, caseSensitive);
assert(expected.every((v, i) => v == output[i]));

@@ -20,2 +20,17 @@ };

});
it('should return an array with two items using case sensitive comparation', function() {
verifyOutput(['python', 'ruby', 'Java', 'JavaScript', 'lua'],
'java', ['Java', 'JavaScript'], true);
});
it('should return an empty array with because caseSenstive parameter is undefined', function() {
verifyOutput(['python', 'ruby', 'Java', 'JavaScript', 'lua'],
'java', []);
});
it('should return an empty array with because caseSenstive parameter is false', function() {
verifyOutput(['python', 'ruby', 'Java', 'JavaScript', 'lua'],
'java', [], false);
});
});
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