File Pluck

raw JSON →
0.6.5 verified Fri May 01 auth: no javascript

A Node.js library for extracting text snippets from files or strings using customizable delimiters. Version 0.6.5 is the latest stable release. The library returns snippets as strings or can break them into key/value pairs with optional JSON output. It uses a Promise-based API and supports glob patterns for file matching. Unlike simple grep or regex solutions, file-pluck provides built-in objectification and JSON serialization, making it suitable for documentation generation and structured data extraction from annotated code or markup.

error TypeError: filePluck.pluckFile is not a function
cause Calling pluckFile as a static method instead of an instance method.
fix
const p = filePluck(); then p.pluckFile('file.txt')
error ReferenceError: require is not defined
cause Attempting to use require in an ES module environment.
fix
Use dynamic import or configure your project for CommonJS.
error Cannot find module 'file-pluck'
cause Package not installed or missing from node_modules.
fix
Run: npm install file-pluck
gotcha filePluck() must be called to create an instance; methods like pluckFile and objectify are not static.
fix Use const p = filePluck(); then call p.pluckFile() or p.objectify()
breaking The API no longer returns a promise directly from require; you must instantiate.
fix Update code to call filePluck() before using methods.
deprecated Some users expect ES module import; package only provides CommonJS.
fix Use require() or set up bundler to handle CJS.
gotcha Glob patterns are supported but not documented; may cause unexpected matching.
fix Test glob patterns carefully; use simple file paths when possible.
npm install file-pluck
yarn add file-pluck
pnpm add file-pluck

Demonstrates basic usage: creating an instance with default options, plucking snippets from a file, and logging results.

const filePluck = require('file-pluck');

// Create an instance with default delimiters (opening: '/***', closing: '***/')
const p = filePluck();

// Pluck snippets from a file
p.pluckFile('example.txt')
  .then(snippets => {
    console.log('Snippets:', snippets);
    // Output: ['pluck this text', 'pluck this text too']
  })
  .catch(err => {
    console.error('Error:', err);
  });