Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Read file and eval it. Uses any-eval.
Like require
, but asynchronous and doesn't use the module cache.
Important: internally file-eval
will resolve passed relative paths with path.resolve()
, not require.resolve()
.
In addition to JSON
and CommonJS
supports JSON5 data format.
$ npm install --save file-eval
const fileEval = require('file-eval');
fileEval('./path/to/file.js')
.then(console.log)
.catch(console.error);
Type: String
.
The filename or file descriptor.
The file-eval
determinate format by extension. If filename ends with .js
, its contents will be evaluating with vm.
If filename ends with .json
extention, its contents will be parsing with JSON.parse
. If filename ends with .json5
extention, its contents will be parsing with json5.
By default expected JS-expression or CommonJS module contents.
Type: Object
, string
.
Options or encoding.
Type: string
.
Default: utf-8
.
The file encoding.
Type: string
.
Default: r
.
The flag mode.
Type: Object
.
The object to provide into execute method.
If context
is specified, then module contents will be evaluating with vm.runInNewContext
.
If context
is not specified, then module contents will be evaluating with vm.runInThisContext
.
With context you can provide some like-a-global variables into file-eval
.
const fileEval = require('file-eval');
const secretKey = '^___^';
// The file has the contents "module.exports = secretKey;"
fileEval('./path/to/file.js', {
context: { secretKey }
});
// ➜ '^___^'
Synchronous version of fileEval.
Method signature is same.
Supports CommonJS, JSON and JSON5 formats.
See examples with evaluating files with different formats.
Evaluates CommonJS
files with .js
extention.
const fileEval = require('file-eval');
// export data with `module.exports` or `exports`
fileEval('./path/to/file.js');
Evaluates JSON
files with .json
extention.
const fileEval = require('file-eval');
fileEval('./path/to/file.json');
Evaluates JSON5
files with .json5
extention.
JSON5 is not an official successor to JSON, and JSON5 content may not work with existing JSON parsers. For this reason, JSON5 files use a new
.json5
extension.
const fileEval = require('file-eval');
fileEval('./path/to/file.json5');
MIT © Andrew Abramov
FAQs
Read file and eval it
The npm package file-eval receives a total of 44 weekly downloads. As such, file-eval popularity was classified as not popular.
We found that file-eval demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.