{"id":24617739,"url":"https://github.com/jacoblincool/file-mapping","last_synced_at":"2025-05-07T05:41:29.705Z","repository":{"id":38327781,"uuid":"500577790","full_name":"JacobLinCool/file-mapping","owner":"JacobLinCool","description":"A library that maps JSON file and in-memory data, and using lazy-writing strategy to reduce disk I/O.","archived":false,"fork":false,"pushed_at":"2024-12-26T00:41:09.000Z","size":210,"stargazers_count":1,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-26T01:23:24.113Z","etag":null,"topics":["file","javascript","json","mapping","typescript"],"latest_commit_sha":null,"homepage":"https://jacoblincool.github.io/file-mapping/","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/JacobLinCool.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-06T20:05:44.000Z","updated_at":"2022-10-15T10:55:21.000Z","dependencies_parsed_at":"2023-01-21T22:45:49.818Z","dependency_job_id":"adea39c6-a41e-4948-8be7-45f88ebc46d0","html_url":"https://github.com/JacobLinCool/file-mapping","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.10526315789473684","last_synced_commit":"dd3b5d9a5fc2ea7ce0d63375208fca3509f4aa4f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Ffile-mapping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Ffile-mapping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Ffile-mapping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Ffile-mapping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JacobLinCool","download_url":"https://codeload.github.com/JacobLinCool/file-mapping/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235519909,"owners_count":19003201,"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":["file","javascript","json","mapping","typescript"],"created_at":"2025-01-24T23:40:23.194Z","updated_at":"2025-01-24T23:40:23.724Z","avatar_url":"https://github.com/JacobLinCool.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# File Mapping\n\n[![NPM](https://img.shields.io/npm/v/file-mapping.svg?style=flat)](https://www.npmjs.com/package/file-mapping)\n\nA library that maps JSON file and in-memory data, and using lazy-writing strategy to reduce disk I/O.\n\n## Usage\n\n### Simple Usage\n\n```ts\nimport { mapping } from \"file-mapping\";\n\nconst data = mapping(\"./data.json\", {});\n\ndata.name = \"Jacob\";\ndata.age = 19;\n\n// Then, the file should be written automatically and only once.\n```\n\n### Nested Data\n\n```ts\nimport { mapping } from \"file-mapping\";\n\nconst data = mapping(\"./data.json\", {});\n\ndata.collection = {};\ndata.collection.document = {};\ndata.collection.document.something = \"something\";\n// Nested data are also supported.\n```\n\n### Listen to file write\n\n```ts\nimport { mapping } from \"file-mapping\";\n\nconst data = mapping(\"./data.json\", {}, (data, changes) =\u003e {\n    console.log(`write ${changes} changes into disk`, data);\n});\n\nfor (let i = 0; i \u003c 1000; i++) {\n    data[`key-${i}`] = `value-${i}`;\n}\n```\n\n### Event Emitter style\n\n`Mapping` also count the number of write operations internally, and you can use `.data`, `.file`, `.written` to get the informations.\n\n```ts\nimport { Mapping } from \"file-mapping\";\n\nconst mapping = new Mapping(\"./data.json\", {});\nconst data = mapping.data;\n\nmapping.on(\"write\", (data, changes) =\u003e {\n    console.log(`write ${changes} changes into disk`, data);\n});\n\nfor (let i = 0; i \u003c 1000; i++) {\n    data[`key-${i}`] = `value-${i}`;\n}\n```\n\n## Links\n\n- NPM Package: \u003chttps://www.npmjs.com/package/file-mapping\u003e\n- Documentation: \u003chttps://jacoblincool.github.io/file-mapping/\u003e\n- GitHub Repository: \u003chttps://github.com/JacobLinCool/file-mapping/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Ffile-mapping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacoblincool%2Ffile-mapping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Ffile-mapping/lists"}