Skip to content

mk-pmb/read-resolved-file-sync-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Deceive your linter by hiding both sync function calls.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published