Skip to content

Use globs and regex tokens to quickly parse multi-line content blocks from text files

License

Notifications You must be signed in to change notification settings

tobiusventures/block-finder

Repository files navigation

Block Finder

Block Finder combines glob-based file scans with regex-based token matches to find, parse, and extract multiline heredoc patterns from text files … and it does it really fast.

Usage

[~] npm i block-finder
// modules
const bf = require('block-finder');

// configure options
const options = {
  cwd: '.',
  glob: '**/*.(js|md)',
  ignore: '**/node_modules',
  start: '/** START **/',
  stop: '/** STOP **/',
};

// promise
bf(options).then(console.log).catch(console.error);

// callback
bf(options, (err, results) => (!!err) ? console.error(err) : console.log(results));

// sync
try {
  console.log(bf({ ...options, mode: 'sync' }));
} catch (err) {
  console.error(err);
}

Options

key type default description
cwd String process.cwd() Current working directory to start searches from
glob String|Array none Glob patterns to be used for file searches
ignore String|Array **/node_modules Glob patterns to ignore in file searches
mode String async Whether to run in sync or async mode (default=async)
start String|RegExp none Starting text block search string pattern
stop String|RegExp none Stopping text block search string pattern

License

MIT License

About

Use globs and regex tokens to quickly parse multi-line content blocks from text files

Resources

License

Stars

Watchers

Forks

Packages

No packages published