graceful-fs / fs-extra wrapper with goodies
npm install @valtech-commerce/fs> graceful-fs / fs-extra wrapper with goodies
``sh`
$ npm install @valtech-commerce/fs
`js
import { fsAsync, fsSync } from "@valtech-commerce/fs";
fsSync.move("/path1/path2/path3", "/path4");
fsAsync.chmodPattern("/path1/path2/*/.js", 0o775).then(() => {
console.log("Yeah!");
});
`
> fs is graceful-fs
> fse is fs-extra
for matching glob pattern file/dir.#### pattern
Required
Type: String
glob pattern.
#### mode
Required
Type: Number
File mode.
#### options
Type: Object
glob options.
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.
$3
Maps fse.copy
$3
Maps fs.promises.copyFile
$3
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.
$3
Maps fse.emptyDir
$3
Maps fse.ensureDir
$3
Maps fse.ensureFile
$3
Maps fse.ensureLink
$3
Maps fse.ensureSymlink
$3
Maps fs.promises.lchmod
$3
Maps fs.promises.lchown
$3
Maps fs.promises.link
$3
Maps fs.promises.lstat
$3
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)
$3
Maps fs.promises.mkdir
$3
Maps fse.mkdirp
$3
Maps fse.mkdirs
$3
Maps fs.promises.mkdtemp
$3
Maps fse.move
$3
Maps fs.promises.open
$3
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.
$3
Maps fse.outputFile
$3
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.
$3
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.
$3
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.
$3
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.
$3
Maps fse.pathExists
$3
Reads and decompresses file using gzip.
Promise returns an String#### file
Required
Type:
String
Path of file to read.
$3
Maps fs.promises.readdir
$3
Maps fs.promises.readFile
$3
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.
$3
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.
$3
Maps fs.promises.readlink
$3
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.
$3
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)
$3
Maps fs.promises.realpath
$3
Maps fse.remove
$3
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
$3
Uses rimraf to delete files and directories via a globbing pattern
#### pattern
Required
Type:
String
Globbing pattern
$3
Maps fs.promises.rename
$3
Maps fs.promises.rmdir
$3
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
$3
Maps fs.promises.stat
$3
Maps fs.promises.symlink
$3
Maps fs.promises.truncate
$3
Maps fs.promises.unlink
$3
Maps fs.promises.utimes
$3
Compresses and writes content to file using gzip.#### file
Required
Type:
String
Path of file to write.#### content
Required
Type:
String
Content to write.
$3
Maps fs.promises.writeFile
$3
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.
$3
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.
$3
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.
$3
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
$3
Maps fs.accessSync
$3
Maps fs.appendFileSync
$3
Maps fs.chmodSync
$3
Maps fs.chownSync
$3
Maps fs.closeSync
$3
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.
$3
Maps fse.copySync
$3
Maps fs.copyFileSync
$3
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.
$3
Maps fse.emptyDirSync
$3
Maps fse.ensureDirSync
$3
Maps fse.ensureFileSync
$3
Maps fse.ensureLinkSync
$3
Maps fse.ensureSymlinkSync
$3
Maps fs.existsSync
$3
Almost the same as fss.exists, except that it also validates the case-sensitivity of the path.
$3
Maps fs.fchmodSync
$3
Maps fs.fchownSync
$3
Maps fs.fdatasyncSync
$3
Maps fs.fstatSync
$3
Maps fs.fsyncSync
$3
Maps fs.ftruncateSync
$3
Maps fs.futimesSync
$3
Maps fs.lchmodSync
$3
Maps fs.lchownSync
$3
Maps fs.linkSync
$3
Maps fs.lstatSync
$3
Maps fs.mkdirSync
$3
Maps fse.mkdirpSync
$3
Maps fse.mkdirsSync
$3
Maps fs.mkdtempSync
$3
Maps fse.moveSync
$3
Maps fs.openSync
$3
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.
$3
Maps fse.outputFileSync
$3
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.
$3
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.
$3
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.
$3
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.
$3
Maps fse.pathExistsSync
$3
Maps fs.readSync
$3
Reads and decompresses file using gzip.
Return String#### file
Required
Type:
String
Path of file to read.
$3
Maps fs.readdirSync
$3
Maps fs.readFileSync
$3
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.
$3
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.
$3
Maps fs.readlinkSync
$3
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.
$3
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)
$3
Maps fs.realpathSync
$3
Maps fs.realpathSync.native
$3
Maps fse.removeSync
$3
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
$3
Uses rimraf to delete files and directories via a globbing pattern
#### pattern
Required
Type:
String
Globbing pattern
$3
Maps fs.renameSync
$3
Maps fs.rmdirSync
$3
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
$3
Maps fs.statSync
$3
Maps fs.symlinkSync
$3
Maps fs.truncateSync
$3
Maps fs.unlinkSync
$3
Maps fs.utimesSync
$3
Maps fs.writeSync
$3
Compresses and writes content to file using gzip.#### file
Required
Type:
String
Path of file to write.#### content
Required
Type:
String
Content to write.
$3
Maps fs.writeFileSync
$3
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.
$3
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.
$3
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.
$3
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`[npm-badge]: https://img.shields.io/npm/v/@valtech-commerce/fs?style=flat-square
[npmsio-badge]: https://img.shields.io/npms-io/final-score/@valtech-commerce/fs?style=flat-square
[librariesio-badge]: https://img.shields.io/librariesio/sourcerank/npm/@valtech-commerce/fs?style=flat-square
[tests-badge]: https://img.shields.io/github/actions/workflow/status/valtech-commerce/fs/tests.yaml?style=flat-square&branch=main
[license-badge]: https://img.shields.io/badge/license-MIT-green?style=flat-square
[npm-url]: https://www.npmjs.com/package/@valtech-commerce/fs
[npmsio-url]: https://npms.io/search?q=%40valtech-commerce%2Ffs
[librariesio-url]: https://libraries.io/npm/@valtech-commerce%2Ffs
[tests-url]: https://github.com/valtech-commerce/fs/actions/workflows/tests.yaml?query=branch%3Amain
[license-url]: https://opensource.org/licenses/MIT