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

string-search

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

string-search

Node module for searching multi-line string using regex

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
decreased by-20.4%
Maintainers
1
Weekly downloads
 
Created
Source

NPM version Build Status Dependency Status Coverage Status

Node module that carries out regex search on given multi-line string and returns match information.

Features

string-search finds and returns match information for each match.

  • Accepts a multi-line string and regular expression in string format.
  • Searches the given string with provided regular expression.
  • Returns a promise that eventually resolves to an array. The array contains match objects each having following attributes -
    • line - line number(s) that the matched result was found on.
    • term - the search term.
    • text - the entire line(s) that the matched result was found in.

Getting Started

Install with NPM - npm install --save string-search

Usage

var stringSearcher = require('string-search');

stringSearcher.find('This is the string to search text in', 'string')
  .then(function(resultArr) {
    //resultArr => [ {line: 1, text: 'This is the string to search text in'} ]
  });

API

stringSearcher.find(targetString, regex)

NameTypeArgumentDescription
targetStringstring<required>target string to be searched. Can be multi-line(can contain line breaks).
regexstring<required>a string in regular expression format to search.

Returns promise that resolves to an array of objects containing following attributes -

NameTypeDescription
lineintegerline number that the matched result was found on.
termstringThe search term
textstringthe entire line(s) that the matched result was found in.

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

Notes

Heavily inspired by lineder. I needed file reading part separated from text searching part so that a file can be read only once and multiple searches can be carried out on it. I also used promise to return results instead of a callback.

License

Copyright © 2015 Omkar Patil

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 09 Nov 2015

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