5.0/51
@vue-reactivity/fs
npm i @vue-reactivity/fs

@vue-reactivity/fs

Reactive filesystem powered by @vue/reactivity

by vue-reactivity

0.1.1 (see all)License:MITTypeScript:Built-In
npm i @vue-reactivity/fs
Readme

Reactive filesystem powered by @vue/reactivity

npm npm bundle size

Install

npm i @vue-reactivity/fs

Usage

Work only in Node.js

Async usage

import { useFile } from '@vue-reactivity/fs'

const fileRef = await useFile('messages.txt').waitForReady()

console.log(fileRef.value) // output file content

fileRef.value += 'Hello World' // append to file

fileRef.value = 'Good Morning' // write to file

Callback usage

import { useFile } from '@vue-reactivity/fs'

useFile('messages.txt')
  .waitForReady()
  .then(fileRef => {
    console.log(fileRef.value) // output file content
  })

Watch for file changes (via chokidar)

const fileRef = useFile('messages.txt', { watchFileChanges: true })

useJson

import { useJSON } from '@vue-reactivity/fs'

const data = useJSON('data.json', { initialValue: { foo: 'bar' }})

console.log(data.value) // { foo: 'bar' }

data.value = { bar: 'foo' } // write to json file

Custom serializer

import YAML from 'js-yaml'
import { useFileWithSerializer } from '@vue-reactivity/fs'

export function useYAML<T>(path: string, options: JSONSerializerOptions<T> = {}) {
  return useFileWithSerializer<T>(
    path,
    {
      ...options,
      serialize: v => YAML.safeDump(v)
      deserialize: v => YAML.safeLoad(v),
    },
  )
}

License

MIT

Downloads/wk

29

GitHub Stars

37

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
0.1.1
latest
2yrs ago
No alternatives found
No tutorials found
Add a tutorial