fso
fso - FileSystemObject is a objective fs interface like Pathname(ruby)
Last updated 7 months ago by narazaka .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fso 
SYNC missed versions from official npm registry.

fso - FileSystemObject

npm npm license npm download total npm download by month dependencies Status devDependencies Status

Travis Build Status AppVeyor Build Status codecov.io Code Climate Codacy Badge Greenkeeper badge

fso - FileSystemObject is a objective fs interface like Pathname(ruby).

Installation

npm install fso

Usage

node.js:

var fso = require('fso').default;
var FileSystemObject = require('fso').FileSystemObject;

ES2015:

import fso, {FileSystemObject} from 'fso';

API

API Documents (with type annotations)

objective methods

constructor

var abc = new FileSystemObject("a", "b", "c");
abc.toString() === "a/b/c"

new / join

dir = fso.new('dir');
a = dir.new('a.txt');
a.writeFileSync('aaaaaa');

parent

dir = fso.new('dir');
p = dir.parent();
dir = p.new('dir');

children, childrenSync

dir = fso.new('dir');
files = dir.childrenSync();

childrenAll, childrenAllSync

dir = fso.new('dir');
files = dir.childrenAllSync();

filteredChildren, filteredChildrenSync, filteredChildrenAll, filteredChildrenAllSync

excepts = ["ignore_file", "path/to/ignore_directory"];
entries = target.filteredChildrenAllSync(excepts);
// Sync
excepts = (entry) => entry.isDirectorySync();
files = target.filteredChildrenAllSync(excepts); // childrenSync() minus directories
// Promise form condition also OK when Promise form call
excepts = (entry) => entry.isDirectory();
files = await target.filteredChildrenAll(excepts);
// callback form also OK when callback form call
excepts = (entry, callback) =>
  entry.isDirectory(
    (error, isDirectory) => callback(error, isDirectory)
  );
target.filteredChildrenAll(excepts, (error, files) => console.log(files.toString()));

path

path / toString

fooPath = fso.new('foo').path;
fooPath = fso.new('foo').toString();

'fs' API

Supports all the node.js 'fs' APIs that needs no first path argument.

method(...args, callback), methodSync(...args) and promise = method(...args)

one file args

fs.truncateSync('/path/to/file', 0);
// is
file = fso.new('/path/to/file');
file.truncateSync(0);

two file args

fs.rename('/path/to/file', 'newfile', callback);
// is
file = fso.new('/path/to/file');
file.remane('newfile', callback);

fd args

fd = fs.openSync('/path/to/file');
fs.ftruncateSync(fd, 0);
fs.close(fd);
// is
file = fso.new('/path/to/file');
file.openSync();
file.ftruncateSync(0);
file.close();

convenient additional

mkdirAll

fso.new('long/deep/path/to').mkdirAll().then(...);

mkdirp (= mkdirAll)

mkpath (= mkdirAll)

readdirAll

dir.readdirAllSync()
// results
['a.txt', 'aa', 'aa/a.txt', 'aa/b', 'aa/b/c.txt']

rmAll

await dir.rmAll('junk');

rmtree (= rmAll)

mergeDirectory

target.mergeDirectory(source);

copy:

target.rmAllSync();
target.mergeDirectorySync(source);

filteredMergeDirectory

excepts = ["ignore_file", "path/to/ignore_directory"];
target.filteredMergeDirectorySync(source, excepts);
excepts = (entry) => entry.path === "ignore_file" || entry.path === "path/to/ignore_directory";
target.filteredMergeDirectorySync(source, excepts);

isChildOf

dir.new("foo/bar").isChildOf(dir)

isParentOf

dir.isParentOf(dir.new("foo/bar"))

path methods

(property) delimiter

fso.delimiter; // ":" or ";"

(property) sep

fso.sep; // "/" or "\\"

(static) format

var entry = FileSystemObject.format({...});

parse

var parsedObject = fso.new("a").parse();

normalize

fso.new("a").normalize(); // same as fso.new("a")

basename

fso.new("a/b/c").basename(); // same as new FileSystemObject("c")

dirname

same as parent()

extname

fso.new("a/b/c.txt").extname(); // ".txt"

isAbsolute

fso.new("a/b/c.txt").isAbsolute() === true

relative

fso.new("a/b/c").relative(fso.new("a/d")); // same as new FileSystemObject("../d")
fso.new("/a/b/c").relative("/a/d"); // same as new FileSystemObject("../d")

resolve

fso.new("a/b/c").resolve("/") // same as new FileSystemObject("/a/b/c")

License

This is released under MIT License.

Current Tags

  • 2.6.3                                ...           latest (7 months ago)

42 Versions

  • 2.6.3                                ...           7 months ago
  • 2.6.2                                ...           8 months ago
  • 2.6.1                                ...           8 months ago
  • 2.6.0                                ...           8 months ago
  • 2.5.15                                ...           9 months ago
  • 2.5.14                                ...           10 months ago
  • 2.5.13                                ...           a year ago
  • 2.5.12                                ...           a year ago
  • 2.5.11                                ...           a year ago
  • 2.5.10                                ...           a year ago
  • 2.5.9                                ...           a year ago
  • 2.5.8                                ...           a year ago
  • 2.5.7                                ...           2 years ago
  • 2.5.6                                ...           2 years ago
  • 2.5.5                                ...           2 years ago
  • 2.5.3                                ...           2 years ago
  • 2.5.2                                ...           2 years ago
  • 2.5.1                                ...           2 years ago
  • 2.5.0                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.3.1                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.4                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (11)

Copyright 2014 - 2016 © taobao.org |