
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
fuzzystringmatch
Advanced tools
a small library that creates a in-memory index for a fast and fuzzy lookup of search terms
fuzzystringmatch is a small library that creates a in-memory index for a fast and fuzzy lookup of search terms.
Runs in the browser as well as in node.js.
The following country names have been put into the index:
United States of America
United Kingdom of Great Britain
Germany
France
Japan
When searching for the term Unted
, the entries United States of America
and United Kingdom of Great Britain
will be returned.
(see the example section)
npm install fuzzystringmatch
fuzzystringmatch consists of 3 parts that work together:
Each Subject
instance describes one index entry (e.g. one of the country names in the example above).
var mySubject = new require('fuzzystringmatch').Subject('United States of America')
If you want to decorate the Subject
with additional meta data (e.g. an external ranking factory that will be used to sort the list of entries),
a child class of Subject
can be created:
var Subject = require('fuzzystringmatch').Subject
class RankedSubject extends Subject {
constructor(term, rank) {
super(term) //dont forget the parent constructor call
this._rank = rank
}
getRank() {
return this._rank
}
}
var mySubject = new RankedSubject('Germany', 42)
The Digester is the instance that receives all the base data (e.g. the country names from the example above) and build up an index.
The Digester can be supplied with a raw string:
var digester = new require('fuzzystringmatch').Digester()
digester.feed('United States of America')
or can be supplied with an instance of Subject
:
var digester = new require('fuzzystringmatch').Digester()
digester.feed(new Subject('United States of America'))
The Matcher uses the index created by the digester to look up search terms:
var digester = new require('fuzzystringmatch').Digester()
var matcher = new require('fuzzystringmatch').Matcher(digester)
digester.feed('France')
digester.feed('Japan')
console.log(matcher.match('jpan'))
The result of the match
call is a list of ResultEntry
instances.
Each ResultEntry
represents a match regarding the search term and holds a reference to the Subject
from the index.
var fuzzyStringmatch = require('fuzzystringmatch')
var digester = new fuzzyStringmatch.Digester
var matcher = new fuzzyStringmatch.Matcher(digester)
digester.feed('United States of America')
digester.feed(new fuzzyStringmatch.Subject('United Kingdom of Great Britain'))
digester.feed('Germany')
digester.feed('France')
digester.feed('Japan')
matcher
.match('grmany')
.forEach(resultEntry => {
var subject = resultEntry.getSubject()
console.log(`${subject.getTerm()}, Matchscore: ${resultEntry.getMatchRelation()}`)
})
By default the digester and the matcher are configured with a reasonable set of values. If you're running into performance or accuracy issues, there's the possibility to finetune certain aspects by supplying a additional, optional configuration.
var splitter = require('fuzzystringmatch').tools.splitter
var config = {
splitter: {
size: 2, //defines how big the chunks of a string should be
//chosse small for accuracy and big for performance
whitespaces: splitter.WHITESPACES_RESPECT //defines how whitespaces should be treated by the splitter instance
//possible values:
//splitter.WHITESPACES_RESPECT: whitespaces are retained
//splitter.WHITESPACES_SQUASH: whitespaces are treated as non existant
}
}
There is also so the possibility to supply a custom splitter (see the example directory):
var config = {
splitter: {
custom: term => term.split(' ')
}
}
A custom splitter is a simple function that accepts a string and has to return an array of strings.
Creates the Digester instance
Configuration
above), optionalTakes a search term that will be included into the index, can be a raw String or a Subject
instance
Creates the Matcher instance
Configuration
above), optionalMatches a certain search term against the index.
Creates the Subject
instance, takes the term that should be represented by the Subject
Returns the term that is represented
Returns the Subject
the ResultEntry
is in relation with
Returns the relation between the number of matched chunks and the number of searched chunks. Acts as a quality factor for the search result.
FAQs
a small library that creates a in-memory index for a fast and fuzzy lookup of search terms
We found that fuzzystringmatch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.