module-definition
Advanced tools
Comparing version 3.1.0 to 3.2.0
12
index.js
@@ -79,10 +79,11 @@ 'use strict'; | ||
* @param {String} file | ||
* @param {Object} options | ||
* @return {String} | ||
*/ | ||
function sync(file) { | ||
function sync(file, options) { | ||
if (!file) { | ||
throw new Error('filename missing'); | ||
} | ||
const data = fs.readFileSync(file, 'utf8'); | ||
var fileSystem = options ? (options.fileSystem || fs) : fs; | ||
const data = fileSystem.readFileSync(file, 'utf8'); | ||
return fromSource(data.toString()); | ||
@@ -97,3 +98,3 @@ } | ||
*/ | ||
module.exports = function(filepath, cb) { | ||
module.exports = function(filepath, cb, options) { | ||
if (!filepath) { | ||
@@ -108,4 +109,5 @@ throw new Error('filename missing'); | ||
const opts = {encoding: 'utf8'}; | ||
var fileSystem = options ? (options.fileSystem || fs) : fs; | ||
fs.readFile(filepath, opts, function(err, data) { | ||
fileSystem.readFile(filepath, opts, function(err, data) { | ||
if (err) { | ||
@@ -112,0 +114,0 @@ return cb(err); |
{ | ||
"name": "module-definition", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Determines if a file is using a CommonJS or AMD module definition", | ||
@@ -29,4 +29,6 @@ "main": "index.js", | ||
"jscs-preset-mrjoelkemp": "~2.0.0", | ||
"mocha": "^5.2.0" | ||
"mocha": "^5.2.0", | ||
"unionfs": "^3.0.2", | ||
"memfs": "^2.14.1" | ||
} | ||
} |
@@ -36,3 +36,18 @@ # module-definition [![npm](http://img.shields.io/npm/v/module-definition.svg)](https://npmjs.org/package/module-definition) [![npm](http://img.shields.io/npm/dm/module-definition.svg)](https://npmjs.org/package/module-definition) | ||
When specifying a filename, using the sync or async api, you can also provide an `options` object with an alternative `fs` implementation used to read the source file with. | ||
```javascript | ||
var myFs = GetFs(); | ||
var options = {fileSystem: myFs} | ||
// Async | ||
getModuleType('myscript.js', function (err, type) { | ||
console.log(type); | ||
}, options); | ||
// Sync | ||
var type = getModuleType.sync('myscript.js', options); | ||
``` | ||
Via shell command (requires a global install: `npm install -g module-definition`) | ||
@@ -39,0 +54,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5242
110
56
5