Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vue-reactivity/fs
Reactive filesystem powered by @vue/reactivity
https://github.com/vue-reactivity/fs
fs reactive-fs vue-reactivity vue3
Last synced: 2 days ago
JSON representation
Reactive filesystem powered by @vue/reactivity
- Host: GitHub
- URL: https://github.com/vue-reactivity/fs
- Owner: vue-reactivity
- License: mit
- Created: 2020-09-19T05:30:27.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-14T02:46:46.000Z (about 4 years ago)
- Last Synced: 2024-11-06T10:03:45.683Z (8 days ago)
- Topics: fs, reactive-fs, vue-reactivity, vue3
- Language: TypeScript
- Homepage:
- Size: 50.8 KB
- Stars: 55
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Reactive filesystem powered by@vue/reactivity
## Install
npm i @vue-reactivity/fs### Usage
> Work only in Node.js
#### Async usage
```ts
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
```ts
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`](https://github.com/paulmillr/chokidar))
```ts
const fileRef = useFile('messages.txt', { watchFileChanges: true })
```#### `useJson`
```ts
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
```ts
import YAML from 'js-yaml'
import { useFileWithSerializer } from '@vue-reactivity/fs'export function useYAML(path: string, options: JSONSerializerOptions = {}) {
return useFileWithSerializer(
path,
{
...options,
serialize: v => YAML.safeDump(v)
deserialize: v => YAML.safeLoad(v),
},
)
}
```## License
MIT