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

boundary-match

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boundary-match

Regex string match and replace that honors boundaries for targets prepended and/or appended with non-word characters.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

boundary-match NPM version Build Status Dependency Status Coverage percentage

Regex string match and replace that honors boundaries for targets prepended and/or appended with non-word characters.

Installation

$ npm install --save boundary-match

Usage

const boundaryMatch = require('boundary-match');

boundaryMatch('(HotDog)', '(hotdog)', 'i');
// => [ '(HotDog)', index: 0, input: '(HotDog)' ]

// Q. But Why?
// A. Because, these fail to work as expected:

'(HotDog)'.match(/\b\(hotdog\)\b/i);
// => null
'(HotDog)'.match(new RegExp('\\b\\(hotdog\\)\\b', 'i'));
// => null

// When matching isn't enough... `replace`
let matched = boundaryMatch('Gimme a (HotDog)', '(HOTDOG)', 'i');
boundaryMatch.replace(matched, 'Chili Dog!');
// => Gimme a Chili Dog!

API

boundaryMatch(string, target[, flags])

If the target is found in the string, it returns an Array containing the entire matched target as the first element; an index property for the start of the match; and an input property that contains the entire string. If there were no matches, null is returned.

  • string
    • Required : String the string to be searched.
  • target
  • flags
    • Optional : String can have any combination of the following values:
      • i : ignore case

boundaryMatch.replace(match, target)

Returns a String that replaces the found match results with target

  • match
    • Required : Array the result of previously calling boundaryMatch
  • target
    • Required : String the string that replaces the found match

TODO

  • [] Implement other native RegExp flags: g,u, m, y

FYI

License

ISC © Buster Collings

Keywords

FAQs

Package last updated on 12 Apr 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc