read-resolved-file-sync

1.0.1 • Public • Published

read-resolved-file-sync

Deceive your linter by hiding both sync function calls.

API

resolveAndRead(remoteRequire, spec[, encoding])

The module exports this function.

remoteRequire should be your module's require, or true if for some reason you want to resolve relative to this module instead of yours.

spec is whatever name you want resolved.

encoding will be passed to fs.readFileSync(), unless it is omitted or undefined, in which case 'UTF-8' will be passed.

resolveAndRead(remoteRequire)

Return a function with arguments (spec[, encoding]) that acts as above but remembers remoteRequire.

Usage

from test/test.js:

var resolveAndRead = require('read-resolved-file-sync')(require),
  origIndent = resolveAndRead('../package.json'),
  parsedMeta = require('../package.json'),
  fragments  = resolveAndRead.frag('./frags.json')
  eq = require('assert').deepStrictEqual;
 
eq(JSON.parse(origIndent), parsedMeta);
eq(fragments('foo'), '21,   43, 65,\n    87, 9.000\n\n');
eq(fragments('bar'), '  [true, false],\n\nnull');

License

ISC

Package Sidebar

Install

npm i read-resolved-file-sync

Weekly Downloads

2

Version

1.0.1

License

ISC

Last publish

Collaborators

  • mk-pmb