@ihcmikmai/file-scan

scan text files for patterns


Keywords
files, scan, glob, regex
License
MIT
Install
npm install @ihcmikmai/file-scan@0.6.0

Documentation

CircleCI

file-scan - utility to scan text files

Table of Contents

  1. Install
  2. Examples
  3. Test
  4. Logs

Install

# npm
npm install --save-dev @ihcmikmai/file-scan
# yarn
yarn add @ihcmikmai/file-scan --dev

Examples

$ file-scan -h
Usage: index [options]

Options:
  -V, --version          output the version number
  -p, --pattern <regex>  regex pattern
  -h, --help             display help for command

Scan all files in 2 level directories, ignoring node_modules directory

$ file-scan ./*[!node_modules]**/** --pattern secret
  • if your regex include \ escape them with \\ :
 --pattern "secret-\d+"
 # should be
 --pattern "secret-\\d+"
import { match, scanFiles } from '@ihcmikmai/file-scan';
// scanning via glob pattern
const results = await scan(/my-regex/, "./**/*.json");
// scanning via file list
const results = await scanFiles(/my-regex/, ["./file1.json", "./file2.json"])

Use file-scan as pre-commit hook

configure precommit, this example use husky:

  "husky": {
    "hooks": {
      "pre-commit": "file-scan -p apikey-1234567890 ./**/**"
    }
  }

Tests

Run tests

yarn test

Run tests with verbose logs

yarn test:verbose

Logs

FILE_SCAN_DEBUG=* file-scan