{"id":22010593,"url":"https://github.com/airkro/fs-chain","last_synced_at":"2026-02-27T23:16:40.869Z","repository":{"id":37989898,"uuid":"177511534","full_name":"Airkro/fs-chain","owner":"Airkro","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-05T22:53:56.000Z","size":1340,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-05T23:34:42.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/Airkro.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,"zenodo":null}},"created_at":"2019-03-25T04:00:36.000Z","updated_at":"2025-04-27T22:50:32.000Z","dependencies_parsed_at":"2023-09-24T21:46:13.832Z","dependency_job_id":"a10fbb72-7262-4bc0-bc7a-effb17dffde5","html_url":"https://github.com/Airkro/fs-chain","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/Airkro%2Ffs-chain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Airkro%2Ffs-chain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Airkro%2Ffs-chain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Airkro%2Ffs-chain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Airkro","download_url":"https://codeload.github.com/Airkro/fs-chain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596293,"owners_count":21773842,"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":[],"created_at":"2024-11-30T02:13:38.266Z","updated_at":"2026-02-27T23:16:40.865Z","avatar_url":"https://github.com/Airkro.png","language":"JavaScript","readme":"# fs-chain\n\nA file I/O tool chain.\n\n[![npm][npm-badge]][npm-url]\n[![github][github-badge]][github-url]\n![node][node-badge]\n\n[npm-url]: https://www.npmjs.com/package/fs-chain\n[npm-badge]: https://img.shields.io/npm/v/fs-chain.svg?style=flat-square\u0026logo=npm\n[github-url]: https://github.com/airkro/fs-chain\n[github-badge]: https://img.shields.io/npm/l/fs-chain.svg?style=flat-square\u0026colorB=blue\u0026logo=github\n[node-badge]: https://img.shields.io/node/v/fs-chain.svg?style=flat-square\u0026colorB=green\u0026logo=node.js\n\n## Installation\n\n```bash\nnpm install fs-chain --save-dev\n```\n\n## Usage\n\n```mjs\nimport { Chain } from 'fs-chain';\n\n// Create file\nnew Chain().modify(() =\u003e 'text:sample').output('./filename.txt');\n\n// Copy file\nnew Chain().source('./old-file.txt').output('./new-file.txt');\n\n// Edit file\nnew Chain()\n  .source('./filename.txt')\n  .modify((data) =\u003e data.trim())\n  .output();\n\n// Create JSON file\nnew Chain()\n  .modify(() =\u003e ({ key: 'value' }))\n  .encode()\n  .output('./data.json');\n\n// Copy JSON file\nnew Chain()\n  .source('./old-data.json')\n  .decode()\n  .modify((data) =\u003e data.key)\n  .encode()\n  .output('./new-data.json');\n\n// Pretty JSON output\nnew Chain()\n  .modify(() =\u003e ({ key: 'value' }))\n  .config({ pretty: true })\n  .encode()\n  .output('./pretty.json');\n\n// Resolve module path (~ prefix)\nnew Chain().source('~/some-module');\n\n// Error handling with onFail\nnew Chain()\n  .modify(() =\u003e 'data')\n  .modify(() =\u003e {\n    throw new Error('error');\n  })\n  .onFail((data) =\u003e {\n    // data is the last successful value: 'data'\n    console.log('Failed but recovered:', data);\n  });\n\n// Logging\nnew Chain()\n  .logger('testing 1') // ✔ testing 1\n  .modify(() =\u003e {\n    throw new Error('fail');\n  })\n  .logger('testing 2'); // ✘ testing 2\n\n// Custom root directory\nnew Chain(process.cwd()).source('./');\n\n// Root from import.meta.url\nnew Chain(import.meta.url).source('../');\n\n// Promise-like chaining\nawait new Chain()\n  .source('./data.json')\n  .decode()\n  .then((data) =\u003e {\n    console.log('Loaded:', data);\n\n    return data;\n  });\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairkro%2Ffs-chain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fairkro%2Ffs-chain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairkro%2Ffs-chain/lists"}