New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

search-in-file

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

search-in-file

Includes utility methods and command to search text within file(s).

  • 3.4.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
355
decreased by-80.41%
Maintainers
1
Weekly downloads
 
Created
Source

Search In File

NPM

Package quality

Includes utility methods and command to search text within file(s).

Installation

npm install --save search-in-file

Available Utility Methods

1. fileSearch(paths, textToSearch, options)

Search a text within files

Parameters:

  • paths: Absolute path files to search.
  • textToSearch: Text to search in files.
  • options: Various options for file search.

Return value: A promise with a list of files in which text is present.

2. getFilesFromDir(dirPath, recursive, omitEmpty)

Get a list of files from a directory

Parameters:

  • dirPath: Path of the directory to get files from.
  • recursive: Get files recursively from directory.
  • omitEmpty: A flag to omit empty files from result.

Return value: A list of files present in the given directory.

3. search(data, textToSearch, options)

Check if the text is present in given data

Parameters:

  • data: Data to search from.
  • textToSearch: Text to search.
  • options: Various options for search.

Return value: true, if text is present in given data. Else false

Available Options

  • recursive: Searches recursively in all sub-directories and files. Default false
  • words: Searches for the exact word. Default false
  • ignoreCase: Case in-sensitive search. Default false
  • isRegex: Searches for the regular expression. Default false
  • ignoreDir: Ignore the specified directories/path while searching. Default []
  • fileMask: Only search in files with given extension. Default null
  • searchResults: Type of search results to get. lineNo to get line with line number that contains given search text. Default filePaths

Usage As command line tool

To use this as a command line tool install this package globally using -g command.

Now, run command

search-in-file <text-to-search>

For example,

search-in-file hello

This will search for text "hello" in all the files from a directory where the command is run.

search-in-file hello world will search for text having either "hello" or "world". To search for hello world, use search-in-file "hello world". I.e. to search for text having more than one word, enclose the text in quotes.

There are the following flags available with this commands:

-p <path>, --path <path> : Path(s) of file/directory to search. Default: Current working directory

-w, --word : Search for exact word?

-i, --ignore-case : Ignore case while searching?

--reg : Consider "text-to-search" as regex?

-r, --recursive : Search recursively in sub-directories of a directory

-e <exclude-dir>, --exclude-dir <exclude-dir> : Directory/file(s) to exclude while searching

-f <file-mask>, --file-mask <file-mask> : Search in files with specific extension. Example: ".txt", ".js"

-s <type>, --search-results <type> : Type of search result. "filePaths"/"lineNo". Default: filePaths

Examples

search-in-file hello -p some-file-path

will search for text having hello in the specified file.

search-in-file hello -p some-dir-path

will search for text having hello in all the files in specified directory.

search-in-file hello -p some-dir-path -r

will search for text having hello in all the files in all subdirectories of the specified directory.

search-in-file hello -p some-dir-path -p some-other-dir-path

will search for text having hello in all the files in both the directories.

search-in-file hello -p some-dir-path -e dir-to-exclude

will search for text having hello in all the files in specified directory except the dir-to-exclude directory.

search-in-file hello -p some-dir-path -w

will search for the exact word hello.

search-in-file hello -p some-dir-path -w -i -f .txt

will search for the exact word hello (ignoring case) in all the with extension ".txt" in the specified directory

search-in-file hello -p some-dir-path -w -s lineNo

will search for the exact word hello and output the files along with the line number where the text is found.

Keywords

FAQs

Package last updated on 21 Jan 2024

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