Socket
Socket
Sign inDemoInstall

word-detect.js

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    word-detect.js

A (super) small library for intelligently detecting words in strings.


Version published
Weekly downloads
1
Maintainers
1
Install size
4.08 kB
Created
Weekly downloads
 

Readme

Source

word-detect.js

A (super) small library for intelligently detecting words in strings.

NOTE: none of these functions are case sensitive. Also, this library currently only works in English.

Install with:

npm i word-detect.js

How To Use

word-detect has three main functions:

  • includesWord()
  • includesAllWords()
  • includesAnyWords()

includesWord()

includesWord() searches for a word inside of a string. If the word is inside of another word (e.g. Rat inside of Crate), it will be ignored. The function takes in 2 parameters; The string, and the word to be searched for.

const wordDetect = require('word-detect.js');

// This will return true:
wordDetect.includesWord('Hello World!', "hello");

// Even though 'hell' is inside 'hello', this will still return false:
wordDetect.includesWord('Hello World!', "hell");

includesAllWords()

includesAllWords searches for an array of words inside of a string. If the words are inside of other words (e.g. Ten inside of Tent), it will be ignored. The function takes in 2 parameters; the string, and an array of words to be searched for.


const wordDetect = require('word-detect.js');

// This will return true:
wordDetect.includesAllWords('Gavin waited for the train', ['gavin', 'waited']);

// This will return false, because the string only contains one of the words:
wordDetect.includesAllWords('Gavin waited for the train', ['wait', 'the']);

includesAnyWords()

includesAnyWords() searches for any of the words in an array, inside of a string. If the words are inside of other words (e.g. Owl inside of Bowl), it will be ignored. The function takes in 2 parameters; the string, and an array of words to be searched for.


const wordDetect = require('word-detect.js');

// This will return true:
wordDetect.includesAnyWords('Where do you live?', ['how', 'do', 'you']);

// This will return false:
wordDetect.includesAnyWords('Where do you live?', ['what', 'your', 'name']);

Keywords

FAQs

Last updated on 22 Aug 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc