{"id":22767099,"url":"https://github.com/judehunter/reactivefile","last_synced_at":"2025-04-15T00:36:07.275Z","repository":{"id":39608732,"uuid":"281846798","full_name":"judehunter/reactivefile","owner":"judehunter","description":"Parse and reactively auto-save JSON, TOML, YAML and any other data file with ease.","archived":false,"fork":false,"pushed_at":"2023-01-06T12:13:36.000Z","size":1073,"stargazers_count":11,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T12:38:28.350Z","etag":null,"topics":["data","data-structures","file","filesystem","javascript","reactive","reactive-programming","typescript","typescript-definitions"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/judehunter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-23T04:04:53.000Z","updated_at":"2024-09-25T19:20:37.000Z","dependencies_parsed_at":"2023-02-06T01:32:14.505Z","dependency_job_id":null,"html_url":"https://github.com/judehunter/reactivefile","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/judehunter%2Freactivefile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/judehunter%2Freactivefile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/judehunter%2Freactivefile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/judehunter%2Freactivefile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/judehunter","download_url":"https://codeload.github.com/judehunter/reactivefile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986186,"owners_count":21194022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","data-structures","file","filesystem","javascript","reactive","reactive-programming","typescript","typescript-definitions"],"created_at":"2024-12-11T13:16:58.269Z","updated_at":"2025-04-15T00:36:07.257Z","avatar_url":"https://github.com/judehunter.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n    \u003cimg alt=\"reactivefile logo\" src=\"https://i.imgur.com/80tlZOU.png\" width=\"150px\"/\u003e\n\t\u003cbr\u003e\n    ReactiveFile\u003cbr\u003e\n    \u003ca href=\"https://www.npmjs.com/package/reactivefile\"\u003e\u003cimg alt=\"npm-badge\" src=\"https://img.shields.io/npm/v/reactivefile.svg?colorB=32CD32\" height=\"20\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://bundlephobia.com/result?p=reactivefile\"\u003e\u003cimg src='https://img.shields.io/bundlephobia/minzip/reactivefile.svg'/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/judehunter/reactivefile/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"license-badge\" height=\"20\"\u003e\u003c/a\u003e\n\u003c/h1\u003e\n\u003ch4 align=\"center\"\u003e\n    A lightweight library for creating a reactive ⚡️ binding between a JS object and a file.\u003cbr\u003e\n    \u003cbr\u003e\n\u003c/h4\u003e\n\n## Description\nReactiveFile is a library which handles parsing a data file and then auto-saving it reactively whenever you change the object.\n\nMost popular filetypes (`JSON`, `TOML`, `YAML`, `XML`) are handled automatically. The API provides a set of tools that let you easily implement parsers and serializers for other languages.\n\nThe reactivity of a ReactiveFile object is deep by default.\n\nCurrently only supports `Node.js` (browser implementation is on the way)\n\n----\nA simple example of a `JSON` file with a counter:\n```jsonc\n// data.json\n{\"counter\": 0}\n```\nYou can create a reactive binding with a few lines of code:\n```ts\nimport * as ReactiveFile from 'reactivefile'\n\nconst data = await ReactiveFile.load('data.json')\ndata.$.counter++\n```\nThe counter in `data.json` now has a value of 1.\n\n## Setup\nJust run:\n```bash\nyarn add reactivefile\n```\nor:\n```bash\nnpm install reactivefile\n```\n\n## Usage\n### Import the package\n```ts\nimport * as ReactiveFile from 'reactivefile'\n// or\nconst ReactiveFile = require('reactivefile')\n```\n### Create a reactive binding\n```ts\nconst data = await ReactiveFile.load('data.json', options)\n// use .loadSync(...) for synchronous loading instead\n```\nYou can also create a `ReactiveFile` from an existing object and set a destination file\n```ts\nconst data = ReactiveFile.from(response, {saveTo: 'destination.toml'})\n```\n### Alter your data\n```ts\ndata.$.lastAccess = new Date()\n// data.$ is an alias for data.val\n```\nAdding new keys to your objects requires you to refresh your object's reactivity\n```ts\ndata.$.newKey = 100\ndata.react()\ndata.$.newKey = 200\n```\n### Create parsing and serializing functions for any data type and file extension\nThe implementation of the built-in `toml` type:\n```ts\nReactiveFile.registerType('toml', str =\u003e toml.parse(str), obj =\u003e toml.stringify(obj))\n```\nYou can also copy these functions from one type to another\n```ts\nReactiveFile.assignType('yaml', 'yml')\n// creates a yaml type with the same parser and serializer as yml\n```\nThese types are also the file extensions — files with the `json` extension will be automatically handled by the `json` parser. You can override this behaviour by specifying the data type.\n```ts\nconst data = await ReactiveFile.load('data.json', {type: 'toml'})\n// reads toml from the data.json file (and saves in toml as well)\n```\n----\n### Options\n#### encoding\nThe encoding of the file. One of: `'ascii', 'base64', 'binary', 'hex', 'latin1', 'ucs-2', 'ucs2', 'utf-8', 'utf16le', 'utf8'`.\n#### type\nThe type/language of the file. Defaults to the file's extension.\n#### saveTo\nThe destination file path. If set, saves your data to another file instead. Otherwise overwrites the original file.\n#### reactive\nTurns on/off the reactive binding. The object can be then saved with `.save()` or `.saveSync()` instead. Defaults to `true`.\n#### deep\nTurns on/off deep reactivity. Defaults to `true`.\n#### asyncSave\nTurns on/off asynchronous saving (instead of synchronous). Defaults to `true`.\n\n----\n### License\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjudehunter%2Freactivefile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjudehunter%2Freactivefile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjudehunter%2Freactivefile/lists"}