fs-utils
fs extras and utilities to extend the node.js file system module. Used in Assemble and many other projects.
Install
Install with npm:
npm i fs-utils --save-dev
Run tests
npm test
Usage
var fs = require('fs-utils');
API
str
{String}returns
: {String}
Strip carriage returns from a string.
Strip byte order marks from a string.
str
{String}returns
: {String}
See BOM
str
{String}returns
: {String}
Normalize all slashes to forward slashes.
filepath
{String}returns
: {Boolean}
Return true
if the file exists and is empty.
filepath
{String}returns
: {Boolean}
Return true
if the filepath is a directory.
filepath
{String}returns
: {Boolean}
True if the filepath is a symbolic link.
patterns
{String|Array}returns
: {options}
Glob files using globby. Or glob files synchronously
with glob.sync
.
filepath
{String}returns
: {String}
Read a file synchronously. Also strips any byte order
marks.
filepath
{String}options
{Object}normalize
{Boolean}: Strip carriage returns and BOM.encoding
{String}: Default is utf8
callback
{Function}
Read a file asynchronously.
filepath
{String}returns
: {Object}
Read a file synchronously and parse contents as JSON.
marks.
filepath
{String}callback
{Function}returns
: {Object}
Read JSON file asynchronously and parse content as JSON
filepath
{String}returns
: {Object}
Read a YAML file synchronously and parse its content as JSON
filepath
{String}returns
: {Object}
Read a YAML file synchronously and parse its content as JSON
filepath
{String}options
{String}returns
: {String}
Read JSON or YAML. Determins the reader automatically
based on file extension.
filepath
{String}options
{String}returns
: {String}
Read JSON or YAML async. Determins the reader automatically
based on file extension.
Write
dest
{String}str
{String}options
{Options}
Synchronously write files to disk, creating any
intermediary directories if they don't exist.
dest
{String}str
{String}options
{Options}
Synchronously write JSON to disk, creating any
intermediary directories if they don't exist.
dest
{String}str
{String}options
{Options}
Asynchronously write files to disk, creating any
intermediary directories if they don't exist.
dest
{String}str
{String}options
{Options}
Synchronously write YAML to disk, creating any
intermediary directories if they don't exist.
dest
{String}str
{String}options
{Options}
Aynchronously write YAML to disk, creating any
intermediary directories if they don't exist.
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.
dest
{String}str
{String}options
{Options}
writeDataSync('foo.yml', {foo: "bar"});
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}options
{Options}
writeDataSync('foo.yml', {foo: "bar"});
src
{String}dest
{String}
Copy files synchronously;
dir
{String}- {Function}: `cb
returns
: {Function}
Asynchronously remove dirs and child dirs that exist.
filepath
{String}returns
: {String}
Return the file extension.
filepath
{String}returns
: {String}
Directory path excluding filename.
filepath
{String}returns
: {String}
The last n
segments of a filepath. If a number
isn't passed for n
, the last segment is returned.
filepath
{String}returns
: {String}
The first n
segments of a filepath. If a number
isn't passed for n
, the first segment is returned.
Returns the last character in filepath
filepath
{String}returns
: {String}
lastChar('foo/bar/baz/');
//=> '/'
Add a trailing slash to the filepath.
filepath
{String}returns
: {String}
Note, this does not consult the file system
to check if the filepath is file or a directory.
filepath
{String}returns
: {String}
Normalize a filepath and remove trailing slashes.
filepath
{String}returns
: {String}
Resolve the relative path from a
to `b.
- {[type]}: filepath
returns
: {Boolean}
Return true
if the path is absolute.
filepath
{String}a
{String}b
{String}returns
: {Boolean}
Return true
if path a
is the same as path `b.
True if descendant path(s) contained within ancestor path. Note: does not test if paths actually exist.
ancestor
{String}: The starting path.returns
: {Boolean}
Sourced from [Grunt].
True if a filepath is the CWD.
filepath
{String}returns
: {Boolean}
Sourced from [Grunt].
filepath
{String}returns
: {Boolean}
True if a filepath is contained within the CWD.
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on October 06, 2014.