Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fs-utils

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-utils - npm Package Compare versions

Comparing version 0.6.5 to 0.7.0

274

index.js

@@ -80,3 +80,6 @@ /*!

var fp = path.join.apply(path, arguments);
return fs.existsSync(fp);
try {
return fs.existsSync(fp);
} catch (err) {}
return false;
};

@@ -92,4 +95,4 @@

exports.isEmpty = function(fp) {
if (!exists(fp)) {
exports.isEmptyFile = function(fp) {
if (exists(fp) === false) {
return false;

@@ -102,2 +105,18 @@ }

/**
* Return `true` if the file exists and is empty.
*
* @param {String} `filepath`
* @return {Boolean}
* @api public
*/
exports.isEmptyDir = function(fp) {
if (exists(fp) === false) {
return false;
}
var files = fs.readdirSync(fp);
return files.length > 0;
};
/**
* Return `true` if the filepath is a directory.

@@ -111,3 +130,3 @@ *

exports.isDir = function(filepath) {
if (!fs.existsSync(filepath)) {
if (!exists(filepath)) {
return false;

@@ -127,3 +146,3 @@ }

var isFile = exports.isFile = function(filepath) {
if (!fs.existsSync(filepath)) {
if (!exists(filepath)) {
return false;

@@ -189,11 +208,11 @@ }

var readFile = exports.readFile = function(filepath, options, cb) {
if (!cb) {
if (typeof options === 'function') {
cb = options;
options = {};
} else {
cb = function () {};
}
if (typeof options === 'function') {
cb = options;
options = {};
}
if (typeof cb !== 'function') {
throw new TypeError('readfile expects callback to be a function');
}
var opts = utils.extend({normalize: true, encoding: 'utf8'}, options);

@@ -212,19 +231,18 @@

/**
* Read a file synchronously and parse contents as JSON.
* marks.
* Read a YAML file asynchronously and parse its contents as JSON.
*
* @param {String} `filepath`
* @return {Object}
* @return {Object} `options`
* @return {Function} `cb` Callback function
* @api public
*/
exports.readJSONSync = function(filepath, options) {
return JSON.parse(exports.readFileSync(filepath, options));
exports.readYAML = function(filepath, options, cb) {
return utils.readYaml.apply(utils.readYaml, arguments);
};
/**
* Read JSON file asynchronously and parse content as JSON
* Read a YAML file synchronously and parse its contents as JSON
*
* @param {String} `filepath`
* @param {Function} `callback`
* @return {Object}

@@ -234,16 +252,11 @@ * @api public

exports.readJSON = function(filepath, cb) {
utils.async.waterfall([
function (next) {
readFile(filepath, next);
}, function (contents, next) {
next(null, JSON.parse(contents));
}
], cb);
exports.readYAMLSync = function(filepath, options) {
return utils.readYaml.sync.apply(utils.readYaml, arguments);
};
/**
* Read a YAML file synchronously and parse its content as JSON
* Read JSON file asynchronously and parse contents as JSON
*
* @param {String} `filepath`
* @param {Function} `callback`
* @return {Object}

@@ -253,8 +266,13 @@ * @api public

exports.readYAMLSync = function(filepath) {
return utils.YAML.load(exports.readFileSync(filepath));
exports.readJSON = function(filepath, cb) {
exports.readFile(filepath, function(err, contents) {
if (err) return cb(err);
cb(null, JSON.parse(contents.toString()));
});
};
/**
* Read a YAML file synchronously and parse its content as JSON
* Read a file synchronously and parse contents as JSON.
* marks.
*

@@ -266,30 +284,13 @@ * @param {String} `filepath`

exports.readYAML = function(filepath, options, cb) {
if (!cb) {
if (typeof options === 'function') {
cb = options;
options = {};
} else {
cb = function () {};
}
}
var opts = utils.extend({normalize: true, encoding: 'utf8'}, options);
fs.readFile(filepath, opts.encoding, function (err, content) {
if (err) return cb(err);
if (opts.normalize && opts.encoding === 'utf8') {
content = exports.normalize(content);
}
cb(null, utils.YAML.load(content));
});
exports.readJSONSync = function(filepath, options) {
return JSON.parse(exports.readFileSync(filepath, options));
};
/**
* Read JSON or utils.YAML. Determins the reader automatically
* Read JSON or YAML utils.async. Determins the reader automatically
* based on file extension.
*
* @param {String} `filepath`
* @param {String} `options`
* @param {Object} `options`
* @param {Function} `callback`
* @return {String}

@@ -299,29 +300,12 @@ * @api public

exports.readDataSync = function(filepath, options) {
var opts = options || {};
var ext = opts.lang || opts.parse || path.extname(filepath);
var reader = exports.readJSONSync;
if (ext[0] === '.') {
ext = ext.slice(1);
}
switch (ext) {
case 'json':
reader = exports.readJSONSync;
break;
case 'yml':
case 'yaml':
reader = exports.readYAMLSync;
break;
}
return reader(filepath, opts);
exports.readData = function(filepath, options, cb) {
return utils.readData.data.apply(utils.readData, arguments);
};
/**
* Read JSON or YAML utils.async. Determins the reader automatically
* Read JSON or utils.YAML. Determins the reader automatically
* based on file extension.
*
* @param {String} `filepath`
* @param {String} `options`
* @param {Object} `options`
* @return {String}

@@ -331,25 +315,4 @@ * @api public

exports.readData = function(filepath, options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
var opts = utils.extend({}, options);
var ext = opts.parse || path.extname(filepath);
var reader = exports.readJSON;
if (ext[0] === '.') {
ext = ext.slice(1);
}
switch (ext) {
case 'json':
reader = exports.readJSON;
break;
case 'yml':
case 'yaml':
reader = exports.readYAML;
break;
}
reader(filepath, cb);
exports.readDataSync = function(filepath, options) {
return utils.readData.data.sync.apply(utils.readData, arguments);
};

@@ -365,8 +328,9 @@

var mkdir = exports.mkdir = function(dest, cb) {
var destpath = path.dirname(dest);
fs.exists(destpath, function (exist) {
var dir = path.dirname(dest);
fs.exists(dir, function (exist) {
if (exist) {
fs.mkdir(dest, cb);
} else {
mkdir(destpath, function () {
mkdir(dir, function (err) {
if (err) return cb(err);
fs.mkdir(dest, cb);

@@ -387,5 +351,5 @@ });

mode = mode || parseInt('0777', 8) & (~process.umask());
if (!fs.existsSync(dirpath)) {
if (!exists(dirpath)) {
var parentDir = path.dirname(dirpath);
if (fs.existsSync(parentDir)) {
if (exists(parentDir)) {
fs.mkdirSync(dirpath, mode);

@@ -409,16 +373,3 @@ } else {

exports.writeFile = function(dest, content, cb) {
var destpath = path.dirname(dest);
fs.exists(destpath, function (exists) {
if (exists) {
fs.writeFile(dest, content, cb);
} else {
mkdir(destpath, function (err) {
if (err) {
cb(err);
} else {
fs.writeFile(dest, content, cb);
}
});
}
});
utils.writeFile.apply(utils.writeFile, arguments);
};

@@ -437,9 +388,3 @@

exports.writeFileSync = function(dest, str, options) {
var opts = utils.extend({enc: 'utf8'}, options);
var dir = path.dirname(dest);
if (!exists(dir)) {
mkdirSync(dir);
}
fs.writeFileSync(dest, str, opts.enc);
utils.writeFile.sync.apply(utils.writeFile, arguments);
};

@@ -458,5 +403,3 @@

exports.writeJSONSync = function(dest, str, options) {
var opts = utils.extend({indent: 2}, options);
str = JSON.stringify(str, null, opts.indent);
exports.writeFileSync(dest, str);
utils.writeJson.sync.apply(utils.writeJson, arguments);
};

@@ -475,9 +418,3 @@

exports.writeJSON = function(dest, str, options, cb) {
if (typeof options === 'function') {
cb = options; options = {};
}
var indent = options && options.indent || 2;
var json = JSON.stringify(str, null, indent);
exports.writeFile(dest, json, cb);
utils.writeJson.apply(utils.writeJson, arguments);
};

@@ -496,5 +433,3 @@

exports.writeYAMLSync = function(dest, str, options) {
var indent = options && options.indent || 2;
var json = utils.YAML.dump(str, null, indent);
exports.writeFileSync(dest, json);
utils.writeYaml.sync.apply(utils.writeYaml, arguments);
};

@@ -512,10 +447,4 @@

exports.writeYAML = function(dest, str, options, cb) {
if (typeof options === 'function') {
cb = options; options = {};
}
var opts = utils.extend({indent: 2}, options);
str = utils.YAML.dump(str, null, opts.indent);
exports.writeFile(dest, str, cb);
exports.writeYAML = function(dest, data, options, cb) {
utils.writeYaml.apply(utils.writeYaml, arguments);
};

@@ -538,21 +467,4 @@

exports.writeDataSync = function(dest, str, options) {
var defaults = {ext: exports.ext(dest), indent: 2};
var opts = utils.extend({}, defaults, options);
var writer = exports.writeJSONSync;
if (opts.ext[0] === '.') {
opts.ext = opts.ext.slice(1);
}
switch (opts.ext) {
case 'json':
writer = exports.writeJSONSync;
break;
case 'yml':
case 'yaml':
writer = exports.writeYAMLSync;
break;
}
return writer(dest, str, opts);
exports.writeDataSync = function(dest, data, options) {
utils.writeData.sync.apply(utils.writeData, arguments);
};

@@ -566,34 +478,14 @@

* ```js
* writeDataSync('foo.yml', {foo: "bar"});
* writeData('foo.yml', {foo: "bar"});
* ```
*
* @param {String} `dest`
* @param {String} `str`
* @param {String} `data`
* @param {Options} `options`
* @param {Function} `cb` Callback function
* @api public
*/
exports.writeData = function(dest, str, options, cb) {
if (typeof options === 'function') {
cb = options; options = {};
}
var defaults = {ext: exports.ext(dest), indent: 2};
var opts = utils.extend({}, defaults, options);
var writer = exports.writeJSON;
var ext = opts.ext;
if (ext[0] === '.') {
ext = ext.slice(1);
}
switch (opts.ext) {
case 'json':
writer = exports.writeJSON;
break;
case 'yml':
case 'yaml':
writer = exports.writeYAML;
break;
}
writer(dest, str, options, cb);
exports.writeData = function(dest, data, options, cb) {
utils.writeData.apply(utils.writeData, arguments);
};

@@ -654,3 +546,3 @@

* @param {String} `patterns` Glob patterns to use.
* @param {String} `options` Options for matched.
* @param {Object} `options` Options for matched.
* @param {Function} `cb`

@@ -692,3 +584,3 @@ * @api public

utils.async.each(files, function (filepath, next) {
if (opts.cwd) {
if (opts.cwd && !exports.isAbsolute(filepath)) {
filepath = path.resolve(opts.cwd, filepath);

@@ -706,3 +598,3 @@ }

* @param {String} `patterns` Glob patterns to use.
* @param {String} `options` Options for matched.
* @param {Object} `options` Options for matched.
* @param {Function} `cb`

@@ -709,0 +601,0 @@ * @api private

{
"name": "fs-utils",
"description": "fs extras and utilities to extend the node.js file system module. Used in Assemble and many other projects.",
"version": "0.6.5",
"version": "0.7.0",
"homepage": "https://github.com/assemble/fs-utils",

@@ -28,13 +28,19 @@ "author": "Jon Schlinkert (https://github.com/assemble)",

"graceful-fs": "^4.1.2",
"is-absolute": "^0.2.2",
"is-absolute": "^0.2.3",
"js-yaml": "^3.4.3",
"kind-of": "^2.0.1",
"kind-of": "^3.0.0",
"lazy-cache": "^0.2.4",
"matched": "^0.3.2",
"normalize-path": "^0.3.0",
"relative": "^0.1.6"
"normalize-path": "^2.0.1",
"read-data": "^0.3.0",
"read-yaml": "^1.0.0",
"relative": "^3.0.2",
"write": "^0.2.1",
"write-data": "^0.1.0",
"write-json": "^0.2.2",
"write-yaml": "^0.2.2"
},
"devDependencies": {
"mocha": "^2.3.3",
"should": "^4.0.4"
"mocha": "*",
"should": "*"
},

@@ -55,6 +61,8 @@ "keywords": [

"related": {
"description": "",
"list": [
"micromatch",
"is-glob"
"write-data",
"write-json",
"read-data",
"read-yaml",
"write-yaml"
]

@@ -61,0 +69,0 @@ }

@@ -51,3 +51,3 @@ # fs-utils [![NPM version](https://badge.fury.io/js/fs-utils.svg)](http://badge.fury.io/js/fs-utils)

### [.isEmpty](index.js#L91)
### [.isEmptyFile](index.js#L94)

@@ -61,4 +61,13 @@ Return `true` if the file exists and is empty.

### [.isDir](index.js#L107)
### [.isEmptyDir](index.js#L110)
Return `true` if the file exists and is empty.
**Params**
* `filepath` **{String}**
* `returns` **{Boolean}**
### [.isDir](index.js#L126)
Return `true` if the filepath is a directory.

@@ -71,3 +80,3 @@

### [.isLink](index.js#L138)
### [.isLink](index.js#L157)

@@ -81,3 +90,3 @@ True if the filepath is a symbolic link.

### [.glob](index.js#L152)
### [.glob](index.js#L171)

@@ -92,3 +101,3 @@ Glob files using [matched]. Or glob files synchronously

### [.readFileSync](index.js#L163)
### [.readFileSync](index.js#L182)

@@ -103,3 +112,3 @@ Read a file synchronously. Also strips any byte order

### [readFile](index.js#L183)
### [readFile](index.js#L202)

@@ -116,6 +125,5 @@ Read a file asynchronously.

### [.readJSONSync](index.js#L214)
### [.readYAML](index.js#L233)
Read a file synchronously and parse contents as JSON.
marks.
Read a YAML file asynchronously and parse its contents as JSON.

@@ -125,7 +133,8 @@ **Params**

* `filepath` **{String}**
* `returns` **{Object}**
* `returns` **{Object}** `options`
* `returns` **{Function}** `cb`: Callback function
### [.readJSON](index.js#L227)
### [.readYAMLSync](index.js#L245)
Read JSON file asynchronously and parse content as JSON
Read a YAML file synchronously and parse its contents as JSON

@@ -135,8 +144,7 @@ **Params**

* `filepath` **{String}**
* `callback` **{Function}**
* `returns` **{Object}**
### [.readYAMLSync](index.js#L245)
### [.readJSON](index.js#L258)
Read a YAML file synchronously and parse its content as JSON
Read JSON file asynchronously and parse contents as JSON

@@ -146,7 +154,9 @@ **Params**

* `filepath` **{String}**
* `callback` **{Function}**
* `returns` **{Object}**
### [.readYAML](index.js#L257)
### [.readJSONSync](index.js#L275)
Read a YAML file synchronously and parse its content as JSON
Read a file synchronously and parse contents as JSON.
marks.

@@ -158,5 +168,5 @@ **Params**

### [.readDataSync](index.js#L289)
### [.readData](index.js#L290)
Read JSON or utils.YAML. Determins the reader automatically
Read JSON or YAML utils.async. Determins the reader automatically
based on file extension.

@@ -167,8 +177,9 @@

* `filepath` **{String}**
* `options` **{String}**
* `options` **{Object}**
* `callback` **{Function}**
* `returns` **{String}**
### [.readData](index.js#L320)
### [.readDataSync](index.js#L304)
Read JSON or YAML utils.async. Determins the reader automatically
Read JSON or utils.YAML. Determins the reader automatically
based on file extension.

@@ -179,6 +190,6 @@

* `filepath` **{String}**
* `options` **{String}**
* `options` **{Object}**
* `returns` **{String}**
### [.writeFile](index.js#L394)
### [.writeFile](index.js#L358)

@@ -193,3 +204,3 @@ Asynchronously write a file to disk.

### [.writeFileSync](index.js#L421)
### [.writeFileSync](index.js#L372)

@@ -205,3 +216,3 @@ Synchronously write files to disk, creating any

### [.writeJSONSync](index.js#L441)
### [.writeJSONSync](index.js#L386)

@@ -217,3 +228,3 @@ Synchronously write JSON to disk, creating any

### [.writeJSON](index.js#L457)
### [.writeJSON](index.js#L400)

@@ -229,3 +240,3 @@ Asynchronously write files to disk, creating any

### [.writeYAMLSync](index.js#L477)
### [.writeYAMLSync](index.js#L414)

@@ -241,3 +252,3 @@ Synchronously write YAML to disk, creating any

### [.writeYAML](index.js#L493)
### [.writeYAML](index.js#L428)

@@ -253,3 +264,3 @@ Aynchronously write YAML to disk, creating any

### [.writeDataSync](index.js#L518)
### [.writeDataSync](index.js#L447)

@@ -270,3 +281,3 @@ Synchronously write JSON or YAML to disk, creating any intermediary directories if they don't exist. Data type is determined by the `dest` file extension.

### [.writeData](index.js#L554)
### [.writeData](index.js#L467)

@@ -278,4 +289,5 @@ Asynchronously write JSON or YAML to disk, creating any intermediary directories if they don't exist. Data type is determined by the `dest` file extension.

* `dest` **{String}**
* `str` **{String}**
* `data` **{String}**
* `options` **{Options}**
* `cb` **{Function}**: Callback function

@@ -285,6 +297,6 @@ **Example**

```js
writeDataSync('foo.yml', {foo: "bar"});
writeData('foo.yml', {foo: "bar"});
```
### [.copyFileSync](index.js#L587)
### [.copyFileSync](index.js#L479)

@@ -298,3 +310,3 @@ Copy files synchronously;

### [.rmdir](index.js#L600)
### [.rmdir](index.js#L492)

@@ -309,3 +321,3 @@ Asynchronously remove dirs and child dirs that exist.

### [.del](index.js#L637)
### [.del](index.js#L529)

@@ -318,6 +330,6 @@ Delete folders and files recursively. Pass a callback

* `patterns` **{String}**: Glob patterns to use.
* `options` **{String}**: Options for matched.
* `options` **{Object}**: Options for matched.
* `cb` **{Function}**
### [.ext](index.js#L705)
### [.ext](index.js#L597)

@@ -331,3 +343,3 @@ Return the file extension.

### [.dirname](index.js#L717)
### [.dirname](index.js#L609)

@@ -341,3 +353,3 @@ Directory path excluding filename.

### [.last](index.js#L743)
### [.last](index.js#L635)

@@ -352,3 +364,3 @@ The last `n` segments of a filepath. If a number

### [.first](index.js#L758)
### [.first](index.js#L650)

@@ -363,3 +375,3 @@ The first `n` segments of a filepath. If a number

### [.lastChar](index.js#L777)
### [.lastChar](index.js#L669)

@@ -380,3 +392,3 @@ Returns the last character in `filepath`

### [.addSlash](index.js#L804)
### [.addSlash](index.js#L696)

@@ -393,3 +405,3 @@ Add a trailing slash to the filepath.

### [.normalizePath](index.js#L819)
### [.normalizePath](index.js#L711)

@@ -403,3 +415,3 @@ Normalize a filepath and remove trailing slashes.

### [.relative](index.js#L845)
### [.relative](index.js#L737)

@@ -413,3 +425,3 @@ Resolve the relative path from `a` to `b.

### [.isAbsolute](index.js#L857)
### [.isAbsolute](index.js#L749)

@@ -423,3 +435,3 @@ Return `true` if the path is absolute.

### [.equivalent](index.js#L871)
### [.equivalent](index.js#L763)

@@ -435,3 +447,3 @@ Return `true` if path `a` is the same as path `b.

### [.doesPathContain](index.js#L886)
### [.doesPathContain](index.js#L778)

@@ -447,3 +459,3 @@ True if descendant path(s) contained within ancestor path. Note: does not test if paths actually exist.

### [.isPathCwd](index.js#L915)
### [.isPathCwd](index.js#L807)

@@ -459,3 +471,3 @@ True if a filepath is the CWD.

### [.isPathInCwd](index.js#L932)
### [.isPathInCwd](index.js#L824)

@@ -471,4 +483,7 @@ True if a filepath is contained within the CWD.

* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern.… [more](https://www.npmjs.com/package/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob)
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://www.npmjs.com/package/micromatch) | [homepage](https://github.com/jonschlinkert/micromatch)
* [read-data](https://www.npmjs.com/package/read-data): Read JSON or YAML files. | [homepage](https://github.com/jonschlinkert/read-data)
* [read-yaml](https://www.npmjs.com/package/read-yaml): Very thin wrapper around js-yaml for directly reading in YAML files. | [homepage](https://github.com/jonschlinkert/read-yaml)
* [write-data](https://www.npmjs.com/package/write-data): Write a YAML or JSON file to disk. Automatically detects the format to write based… [more](https://www.npmjs.com/package/write-data) | [homepage](https://github.com/jonschlinkert/write-data)
* [write-json](https://www.npmjs.com/package/write-json): Write a JSON file to disk, also creates intermediate directories in the destination path if… [more](https://www.npmjs.com/package/write-json) | [homepage](https://github.com/jonschlinkert/write-json)
* [write-yaml](https://www.npmjs.com/package/write-yaml): Write YAML. Converts JSON to YAML writes it to the specified file. | [homepage](https://github.com/jonschlinkert/write-yaml)

@@ -501,2 +516,2 @@ ## Running tests

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 04, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 17, 2015._

@@ -33,4 +33,10 @@ 'use strict';

require('normalize-path', 'normalize');
require('write', 'writeFile');
require('kind-of', 'typeOf');
require('matched', 'glob');
require('read-data');
require('read-yaml');
require('write-json');
require('write-yaml');
require('write-data');
require('relative');

@@ -45,2 +51,13 @@

/**
* Utils
*/
utils.tryStat = function(fp) {
try {
return fs.statSync(fp);
} catch (err) {}
return null;
};
/**
* Expose `utils` modules

@@ -47,0 +64,0 @@ */

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc