Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
flashtext2js
Advanced tools
Extract Keywords from sentence or Replace keywords in sentences - flashtext implementation via typescript.
Extract Keywords from sentence or Replace keywords in sentences.
flashtext's implementation via typescript.
read regex-was-taking-5-days-flashtext-does-it-in-15-minutes to learn more.
if you should match over 500 keywords, flashtext will better tha regexp, otherwise you may not need it
npm install flashtext2js
yarn add flashtext2js
then
// FlashText is the Class, flashtext is the instance with default option
import FlashText, { flashtext } from 'flashtextjs';
// if you want to ignore case, use let ft = new FlashText({ignore: true});
// extract keywords from a target string
const target = 'I love Big Apple and Bay Area.'
ft.addKeyWord('Big Apple', 'New York')
ft.addKeyWord('Bay Area')
ft.extractKeywords(target) // output: ['New York', 'Bay Area']
// replace the string via keywords
const target = 'I love Big Apple and New Delhi.'
ft.addKeyWord('New Delhi', 'NCR region');
ft.replaceKeyWords(target) // output: 'I love Big Apple and NCR region.'
add the keyword in trie structure. when the keyword matched in the target string, will return secode param mapped.
mapped default is equal to keyword string.
ft.addKeyWord('New Delhi', 'NCR region');
ft.get('New Delhi'); // output 'NCR region'
ft.extractKeywords('I love Big Apple and Bay Area.') // output: ['NCR region']
as the name
ft.addKeyWordsFromArray(['jack rose'])
the object must like this structure: { 'mapped': [] }
ft.addKeyWordsFromObject({'jack rose': ['jack roses', 'jack ros']});
// means when matched 'jack roses' or 'jack ros', will return 'jack rose'
will remove the keyword in the trie structure
-ft.removeKeyWordsFromArray(keywords: string[])
just forEach(() => removeKeyWord())
will return a keyword-mapped mapper.
ft.addKeyword('abc', 'ABC');
ft.addKeyword('abd', 'ABC');
ft.toMap(); // output {abc: 'ABC', abd: 'ABC'}
will return all the matched keywords in an arry
// extract keywords from a target string
const target = 'I love Big Apple and Bay Area.'
ft.addKeyWord('Big Apple', 'New York')
ft.addKeyWord('Bay Area')
ft.extractKeywords(target) // output: ['New York', 'Bay Area']
will replace the target string with keywords and return it.
// replace the string via keywords
const target = 'I love Big Apple and New Delhi.'
ft.addKeyWord('New Delhi', 'NCR region');
ft.replaceKeyWords(target) // output: 'I love Big Apple and NCR region.'
more api, just go here
FAQs
Extract Keywords from sentence or Replace keywords in sentences - flashtext implementation via typescript.
The npm package flashtext2js receives a total of 22 weekly downloads. As such, flashtext2js popularity was classified as not popular.
We found that flashtext2js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.