0.6.0 • Published 4 years ago
@ihcmikmai/file-scan v0.6.0
file-scan - utility to scan text files
Table of Contents
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