urlfs

1.1.0 • Public • Published

URL Filesystem

Use the webserver as a faux filesystem using localStorage

API

const urlfs = {
  storage: localStorage // storage object to use
  stackd: [] // directory stack used by `pushd` and `popd`
  pwd: "./" // current working directory

  absUrl(path = this.pwd) // resolve `path` relative to `pwd`
  dirname(path) // directory name of `path`
  basename(path) // base filename of `path`
  cd(path) // change current directory
  pushd(path) // push `pwd` to `stackd` and change current directory to `path`
  popd() // pop path from `stackd` and change current directory to it

  ls(path) // return array of entries in `path`

  delete(path) // delete file or entire directory
  copy(path, dest) // copy `path` to `dest`

  readText(path) // return file contents as string
  writeText(path, data) // write text to file
  addListenerToPath(path, listener) // register `listener` as a function to be called on every change to `path` or its descendants
  removeListenerFromPath(path, listener) // remove `listener` from `path` 

  readJson(path) // parse file contents as JSON and return its value if valid, otherwise behave as `readText`
  writeJson(path, data) // write stringified data to file
  editJson(path, timeout = 0) // like `readJson`, but returned value will be saved automatically to the same file after timeout.
}

Package Sidebar

Install

npm i urlfs

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

8.56 kB

Total Files

4

Last publish

Collaborators

  • poeticandroid