1.0.1 • Published 7 years ago

read-resolved-file-sync v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

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