@valtech-commerce/fs
v1.7.0
Published
graceful-fs / fs-extra wrapper with goodies
Downloads
621
Readme
fs wrappers
graceful-fs / fs-extra wrapper with goodies
Install
$ npm install @valtech-commerce/fs
Usage
import { fsAsync, fsSync } from "@valtech-commerce/fs";
fsSync.move("/path1/path2/path3", "/path4");
fsAsync.chmodPattern("/path1/path2/**/*.js", 0o775).then(() => {
console.log("Yeah!");
});
Async - API
fs
is graceful-fs
fse
is fs-extra
access
Maps fs.promises.access
appendFile
chmod
Maps fs.promises.chmod
chmodPattern(pattern, mode [, options])
Applies fs.chmod
for matching glob
pattern file/dir.
pattern
Required
Type: String
glob pattern.
mode
Required
Type: Number
File mode.
options
Type: Object
glob options.
chown
Maps fs.promises.chown
compressFile(source [, destination])
Compresses file using gzip
Promise
returns destination
source
Required
Type: String
Path of file to compress.
destination
Type: String
Default: Same as source with a .gz
added at the end
Path of file when compressed.
copy
Maps fse.copy
copyFile
Maps fs.promises.copyFile
decompressFile(source [, destination])
Decompresses file using gzip
Promise
returns destination
source
Required
Type: String
Path of file to decompress.
destination
Type: String
Default: Same as source with the .gz
removed at the end
Path of file when decompressed.
emptyDir
Maps fse.emptyDir
ensureDir
Maps fse.ensureDir
ensureFile
Maps fse.ensureFile
ensureLink
Maps fse.ensureLink
ensureSymlink
Maps fse.ensureSymlink
lchmod
Maps fs.promises.lchmod
lchown
Maps fs.promises.lchown
link
Maps fs.promises.link
lstat
Maps fs.promises.lstat
mergeFiles(sources, destination)
Merge multiple files into a single file
sources
Required
Type: Array
of String
Path of files to merge.
destination
Required
Type: String
Path of merged file. (If it ends with .gz
it will be compressed using gzip)
mkdir
Maps fs.promises.mkdir
mkdirp
Maps fse.mkdirp
mkdirs
Maps fse.mkdirs
mkdtemp
Maps fs.promises.mkdtemp
move
Maps fse.move
open
Maps fs.promises.open
outputCompressed(file, content)
Almost the same as writeCompressed, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write.
content
Required
Type: String
Content to write.
outputFile
Maps fse.outputFile
outputJson(file, object [, options])
Almost the same as writeJson, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON.stringify replacer.
options.space
Type: String
or Number
JSON.stringify space.
outputJson5(file, object [, options])
Almost the same as writeJson5, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON5.stringify replacer.
options.space
Type: String
or Number
JSON5.stringify replacer.
outputXml(file, object [, options])
Almost the same as writeXml, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options
Type: Object
xml2js.Builder().buildObject options.
outputYaml(file, object)
Almost the same as writeYaml, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
pathExists
Maps fse.pathExists
readCompressed(file)
Reads and decompresses file using gzip.
Promise
returns an String
file
Required
Type: String
Path of file to read.
readdir
Maps fs.promises.readdir
readFile
Maps fs.promises.readFile
readJson(file [, reviver])
Reads a JSON file and then parses it into an object.
Promise
returns an Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
reviver
Type: Function
JSON.parse reviver.
readJson5(file [, reviver])
Reads a JSON5 file and then parses it into an object.
Promise
returns an Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
reviver
Type: Function
JSON5.parse reviver.
readlink
Maps fs.promises.readlink
readXml(file [, options])
Reads a XML file and then parses it into an object.
Promise
returns an Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
options
Type: Object
xml2js.parseString options.
readYaml(file)
Reads a YAML file and then parses it into an object.
Promise
returns an Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
realpath
Maps fs.promises.realpath
remove
Maps fse.remove
removeEmptyDir(root)
Uses delete-empty to recursively delete all empty folders in a directory and child directories
Promise
returns an Array
of deleted directories
root
Required
Type: String
Path of root directory to scan
removePattern(pattern)
Uses rimraf to delete files and directories via a globbing pattern
pattern
Required
Type: String
Globbing pattern
rename
Maps fs.promises.rename
rmdir
Maps fs.promises.rmdir
scandir(root, type, [options])
Uses klaw to scan directory for files or directories.
Return Array
of files / directories
root
Required
Type: String
Path of directory to scan.
type
Required
Type: String
Scan for file
or dir
options.recursive
Type: Boolean
Scan in subdirectories
Default: false
options.fullPath
Type: String
Return full absolute path instead of relative path from scanned directory
Default: false
options.pattern
Type: String
Filter results with minimatch pattern
Default: '**'
options.keepJunk
Type: Boolean
Keep junk files (also filters out .gitkeep
)
Default: false
stat
Maps fs.promises.stat
symlink
Maps fs.promises.symlink
truncate
Maps fs.promises.truncate
unlink
Maps fs.promises.unlink
utimes
Maps fs.promises.utimes
writeCompressed(file, content)
Compresses and writes content to file using gzip.
file
Required
Type: String
Path of file to write.
content
Required
Type: String
Content to write.
writeFile
writeJson(file, content [, options])
Writes an object to a JSON file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON.stringify replacer.
options.space
Type: String
or Number
JSON.stringify space.
writeJson5(file, content [, options])
Writes an object to a JSON5 file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON5.stringify replacer.
options.space
Type: String
or Number
JSON5.stringify replacer.
writeXml(file, content [, options])
Writes an object to a XML file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options
Type: Object
xml2js.Builder().buildObject options.
writeYaml(file, object)
Writes an object to a YAML file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
Sync - API
fs
is graceful-fs
fse
is fs-extra
access
Maps fs.accessSync
appendFile
Maps fs.appendFileSync
chmod
Maps fs.chmodSync
chown
Maps fs.chownSync
close
Maps fs.closeSync
compressFile(source [, destination])
Compresses file using gzip
Return String
destination
source
Required
Type: String
Path of file to compress.
destination
Type: String
Default: Same as source with a .gz
added at the end
Path of file when compressed.
copy
Maps fse.copySync
copyFile
Maps fs.copyFileSync
decompressFile(source [, destination])
Decompresses file using gzip
Return String
destination
source
Required
Type: String
Path of file to decompress.
destination
Type: String
Default: Same as source with the .gz
removed at the end
Path of file when decompressed.
emptyDir
Maps fse.emptyDirSync
ensureDir
Maps fse.ensureDirSync
ensureFile
Maps fse.ensureFileSync
ensureLink
Maps fse.ensureLinkSync
ensureSymlink
exists
Maps fs.existsSync
existsCase(path)
Almost the same as fss.exists
, except that it also validates the case-sensitivity of the path.
fchmod
Maps fs.fchmodSync
fchown
Maps fs.fchownSync
fdatasync
Maps fs.fdatasyncSync
fstat
Maps fs.fstatSync
fsync
Maps fs.fsyncSync
ftruncate
Maps fs.ftruncateSync
futimes
Maps fs.futimesSync
lchmod
Maps fs.lchmodSync
lchown
Maps fs.lchownSync
link
Maps fs.linkSync
lstat
Maps fs.lstatSync
mkdir
Maps fs.mkdirSync
mkdirp
Maps fse.mkdirpSync
mkdirs
Maps fse.mkdirsSync
mkdtemp
Maps fs.mkdtempSync
move
Maps fse.moveSync
open
Maps fs.openSync
outputCompressed(file, content)
Almost the same as writeCompressed, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write.
content
Required
Type: String
Content to write.
outputFile
Maps fse.outputFileSync
outputJson(file, object [, options])
Almost the same as writeJson, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON.stringify replacer.
options.space
Type: String
or Number
JSON.stringify space.
outputJson5(file, object [, options])
Almost the same as writeJson5, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON5.stringify replacer.
options.space
Type: String
or Number
JSON5.stringify space.
outputXml(file, object [, options])
Almost the same as writeXml, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options
Type: Object
xml2js.Builder().buildObject options.
outputYaml(file, object)
Almost the same as writeYaml, except that if the directory does not exist, it's created.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
pathExists
Maps fse.pathExistsSync
read
Maps fs.readSync
readCompressed(file)
Reads and decompresses file using gzip.
Return String
file
Required
Type: String
Path of file to read.
readdir
Maps fs.readdirSync
readFile
Maps fs.readFileSync
readJson(file [, reviver])
Reads a JSON file and then parses it into an object.
Return Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
reviver
Type: Function
JSON.parse reviver.
readJson5(file [, reviver])
Reads a JSON5 file and then parses it into an object.
Return Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
reviver
Type: Function
JSON5.parse reviver.
readlink
Maps fs.readlinkSync
readXml(file [, options])
Reads a XML file and then parses it into an object.
Return Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
options
Type: Object
xml2jsParser.parseStringSync options.
readYaml(file)
Reads a YAML file and then parses it into an object.
Return Object
file
Required
Type: String
Path of file to read. (If it ends with .gz
it will be decompressed using gzip)
realpath
Maps fs.realpathSync
realpath.native
remove
Maps fse.removeSync
removeEmptyDir(root)
Uses delete-empty to recursively delete all empty folders in a directory and child directories
Return Array
of deleted directories
root
Required
Type: String
Path of root directory to scan
removePattern(pattern)
Uses rimraf to delete files and directories via a globbing pattern
pattern
Required
Type: String
Globbing pattern
rename
Maps fs.renameSync
rmdir
Maps fs.rmdirSync
scandir(root, type, [options])
Uses klaw-sync to scan directory for files or directories.
Return Array
of files / directories
root
Required
Type: String
Path of directory to scan.
type
Required
Type: String
Scan for file
or dir
options.recursive
Type: Boolean
Scan in subdirectories
Default: false
options.fullPath
Type: String
Return full absolute path instead of relative path from scanned directory
Default: false
options.pattern
Type: String
Filter results with minimatch pattern
Default: '**'
options.keepJunk
Type: Boolean
Keep junk files (also filters out .gitkeep
)
Default: false
stat
Maps fs.statSync
symlink
Maps fs.symlinkSync
truncate
Maps fs.truncateSync
unlink
Maps fs.unlinkSync
utimes
Maps fs.utimesSync
write
Maps fs.writeSync
writeCompressed(file, content)
Compresses and writes content to file using gzip.
file
Required
Type: String
Path of file to write.
content
Required
Type: String
Content to write.
writeFile
Maps fs.writeFileSync
writeJson(file, content [, options])
Writes an object to a JSON file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON.stringify replacer.
options.space
Type: String
or Number
JSON.stringify space.
writeJson5(file, content [, options])
Writes an object to a JSON5 file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options.replacer
Type: Function
JSON5.stringify replacer.
options.space
Type: String
or Number
JSON5.stringify space.
writeXml(file, content [, options])
Writes an object to a XML file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.
options
Type: Object
xml2js.Builder().buildObject options.
writeYaml(file, object)
Writes an object to a YAML file.
file
Required
Type: String
Path of file to write. (If it ends with .gz
it will be compressed using gzip)
object
Required
Type: Object
Object to write.