fs-utils

fs extras and utilities to extend the node.js file system module. Used in Assemble and many other projects.

fs-utils

fs extras and utilities to extend the node.js file system module. Used in Assemble and many other projects.

Install with npm:

npm i fs-utils --save-dev
npm test
var fs = require('fs-utils');

.stripCR

  • str {String}
  • returns: {String}

Strip carriage returns from a string.

.stripBOM

Strip byte order marks from a string.

  • str {String}
  • returns: {String}

See BOM

.slashify

  • str {String}
  • stripTrailing {Boolean}: False by default.
  • returns: {String}

Normalize all slashes to forward slashes.

.isEmpty

  • filepath {String}
  • returns: {Boolean}

Return true if the file exists and is empty.

.isDir

  • filepath {String}
  • returns: {Boolean}

Return true if the filepath is a directory.

.isLink

  • filepath {String}
  • returns: {Boolean}

True if the filepath is a symbolic link.

.glob

  • patterns {String|Array}
  • returns: {options}

Glob files using globby. Or glob files synchronously with glob.sync.

.readFileSync

  • filepath {String}
  • returns: {String}

Read a file synchronously. Also strips any byte order marks.

readFile

  • filepath {String}
  • options {Object}
  • normalize {Boolean}: Strip carriage returns and BOM.
  • encoding {String}: Default is utf8
  • callback {Function}

Read a file asynchronously.

.readJSONSync

  • filepath {String}
  • returns: {Object}

Read a file synchronously and parse contents as JSON. marks.

.readJSON

  • filepath {String}
  • callback {Function}
  • returns: {Object}

Read JSON file asynchronously and parse content as JSON

.readYAMLSync

  • filepath {String}
  • returns: {Object}

Read a YAML file synchronously and parse its content as JSON

.readYAML

  • filepath {String}
  • returns: {Object}

Read a YAML file synchronously and parse its content as JSON

.readDataSync

  • filepath {String}
  • options {String}
  • returns: {String}

Read JSON or YAML. Determins the reader automatically based on file extension.

.readData

  • filepath {String}
  • options {String}
  • returns: {String}

Read JSON or YAML async. Determins the reader automatically based on file extension.

.writeFile

  • dest {String}
  • content {String}
  • callback {Function}

Asynchronously write a file to disk.

.writeFileSync

  • dest {String}
  • str {String}
  • options {Options}

Synchronously write files to disk, creating any intermediary directories if they don't exist.

.writeJSONSync

  • dest {String}
  • str {String}
  • options {Options}

Synchronously write JSON to disk, creating any intermediary directories if they don't exist.

.writeJSON

  • dest {String}
  • str {String}
  • options {Options}

Asynchronously write files to disk, creating any intermediary directories if they don't exist.

.writeYAMLSync

  • dest {String}
  • str {String}
  • options {Options}

Synchronously write YAML to disk, creating any intermediary directories if they don't exist.

.writeYAML

  • dest {String}
  • str {String}
  • options {Options}

Aynchronously write YAML to disk, creating any intermediary directories if they don't exist.

.writeDataSync

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"});

.writeData

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"});

.copyFileSync

  • src {String}
  • dest {String}

Copy files synchronously;

.rmdir

  • dir {String}
  • {Function}: `cb
  • returns: {Function}

Asynchronously remove dirs and child dirs that exist.

.del

  • patterns {String}: Glob patterns to use.
  • options {String}: Options for globby.
  • cb {Function}

Delete folders and files recursively. Pass a callback as the last argument to use async.

.ext

  • filepath {String}
  • returns: {String}

Return the file extension.

.dirname

  • filepath {String}
  • returns: {String}

Directory path excluding filename.

.last

  • filepath {String}
  • returns: {String}

The last n segments of a filepath. If a number isn't passed for n, the last segment is returned.

.first

  • filepath {String}
  • returns: {String}

The first n segments of a filepath. If a number isn't passed for n, the first segment is returned.

.lastChar

Returns the last character in filepath

  • filepath {String}
  • returns: {String}
lastChar('foo/bar/baz/');
//=> '/'

.addSlash

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.

.normalizePath

  • filepath {String}
  • returns: {String}

Normalize a filepath and remove trailing slashes.

.relative

  • filepath {String}
  • returns: {String}

Resolve the relative path from a to `b.

.isAbsolute

  • {[type]}: filepath
  • returns: {Boolean}

Return true if the path is absolute.

.equivalent

  • filepath {String}
  • a {String}
  • b {String}
  • returns: {Boolean}

Return true if path a is the same as path `b.

.doesPathContain

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].

.isPathCwd

True if a filepath is the CWD.

  • filepath {String}
  • returns: {Boolean}

Sourced from [Grunt].

.isPathInCwd

  • filepath {String}
  • returns: {Boolean}

True if a filepath is contained within the CWD.

Jon Schlinkert

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on October 24, 2014.