find-text

1.1.1 • Public • Published

find-text

Fast, minimal, and easy to use tool for finding text across multiple files. It is tiny (3.78kb bundle size, including dependecies).

NPM Build Status JavaScript Style Guide

Install

npm install find-text

Usage

The module exposes two API's findText and findTextInFiles.

findText

import { findText } from './index'
 
/**
 * findText :: (String, String) => Promise
 *
 * Find the text on the given file.
 */
findText('TODO', '/Users/user/Desktop/sample/src/users.js')
  .then((results) => {
    console.log(results) // See below the shape of result output
  })
  .catch((err) => {
    // Error object
    console.log(err)
  })

The result contains the fileName, matches, and count of matches in the file.

const result = {
  fileName: 'src/users.js', // current working directory path is omitted
  matches: [{
    text: '// TODO: Add update user API', // line in found text
    lineNumber: 5
  }],
  count: 1
}

findTextInFiles

import { findTextInFiles } from './index'
 
/**
 * findTextInFiles :: (String, String) => Promise
 *
 * Find the text in the files which are resided at the given directory. 
 */
findTextInFiles('TODO', 'src/users.js')
  .then((results) => {
    console.log(results) // See below the shape of results output
  })
  .catch((err) => {
    // Error object
    console.log(err)
  })

The results is an array of object (the output returned by findText)

const results = [
  {
    fileName: 'src/users.js', 
    matches: [{
      text: '// TODO: Add update user API',
      lineNumber: 5
    }],
    count: 1
  }
]

API

findText :: (String, String) => Promise

Find the text on the given file. When the text is not found in the given file, it returns empty object.

Promise is rejected when passing path which is not exist.

text

Type: string

The string you want to search for.

path

Type: string

The path you want to search in.

findTextInFiles :: (String, String) => Promise

Find the text in the files which are resided at the given directory. It recursively reads the nested files which match for the pattern.

It returns empty array when passing not found text or no files are matched for the given pattern.

text

Type: string

The string you want to search for.

pattern

Type: string|string[]

Pattern to be matched. It supports negated pattern. For more information about pattern, check micromatch

Changelog

This project adheres to Semantic Versioning. Every release, along with the migration instructions, is documented on the Github Releases page.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i find-text

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

12.3 kB

Total Files

4

Last publish

Collaborators

  • denniscual