Filesystem utilities.
Your OS's filesystem isn't the most powerful database, it's one of the more familiar and human-friendly ones out there.
This package exports:
$
helper function, which concatenates paths.File
and Directory
classes, which you can use to
specify whether you expect a file or a directory at a given path.JSONFile
, YAMLFile
etc. subclasses for automatically
loading data in a given format.fs
, fs/promises
, as well as mkdirp
and rimraf
.import $, { Directory, TextFile, JSONFile } from '@hackbg/file'
const root = $(process.cwd())
// Access files through a directory
const dir = root.in('data').as(Directory).make()
dir.at('file.txt').as(TextFile).save('my data')
dir.at('file.json').as(JSONFile).save({my:'data'})
console.log(dir.list())
// Or directly
console.log(new JSONFile(root, 'data', 'file.json').load())
console.log(root.in('data').at('file.txt').as(TextFile).load())
Made with #%&! @ Hack.bg
Generated using TypeDoc