find-text
Fast, minimal, and easy to use tool for finding text across multiple files
Last updated 2 years ago by denniscual .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install find-text 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.1                                ...           latest (2 years ago)

2 Versions

  • 1.1.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 6
Last Month 10
Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |