{"id":13457764,"url":"https://github.com/SBoudrias/mem-fs-editor","last_synced_at":"2025-03-24T14:32:15.672Z","repository":{"id":22013073,"uuid":"25338697","full_name":"SBoudrias/mem-fs-editor","owner":"SBoudrias","description":"File edition helpers working on top of mem-fs (https://github.com/SBoudrias/mem-fs)","archived":false,"fork":false,"pushed_at":"2024-05-19T13:27:03.000Z","size":1663,"stargazers_count":410,"open_issues_count":15,"forks_count":49,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-23T02:03:35.370Z","etag":null,"topics":[],"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/SBoudrias.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-MIT","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},"funding":{"github":"sboudrias"}},"created_at":"2014-10-17T04:43:46.000Z","updated_at":"2024-06-17T17:29:29.580Z","dependencies_parsed_at":"2024-04-19T23:25:56.718Z","dependency_job_id":"6f73304b-301c-43e9-9b2f-41f182d2081f","html_url":"https://github.com/SBoudrias/mem-fs-editor","commit_stats":{"total_commits":244,"total_committers":31,"mean_commits":7.870967741935484,"dds":0.569672131147541,"last_synced_commit":"6a5f9c268deb592fa1e7f8a82eb82f34e7b7d86e"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBoudrias%2Fmem-fs-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBoudrias%2Fmem-fs-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBoudrias%2Fmem-fs-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBoudrias%2Fmem-fs-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SBoudrias","download_url":"https://codeload.github.com/SBoudrias/mem-fs-editor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245061398,"owners_count":20554563,"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-07-31T09:00:36.029Z","updated_at":"2025-03-24T14:32:15.655Z","avatar_url":"https://github.com/SBoudrias.png","language":"TypeScript","funding_links":["https://github.com/sponsors/sboudrias"],"categories":["JavaScript","Uncategorized","TypeScript"],"sub_categories":["Uncategorized"],"readme":"# mem-fs-editor\n\n[![Node.js CI](https://github.com/SBoudrias/mem-fs-editor/workflows/Node.js%20CI/badge.svg)](https://github.com/SBoudrias/mem-fs-editor/actions?query=workflow%3A%22Node.js+CI%22)\n[![NPM version](https://badge.fury.io/js/mem-fs-editor.svg)](http://badge.fury.io/js/mem-fs-editor)\n[![Coverage Status](https://codecov.io/gh/SBoudrias/mem-fs-editor/branch/master/graph/badge.svg)](https://codecov.io/gh/SBoudrias/mem-fs-editor)\n\nFile edition helpers working on top of [mem-fs](https://github.com/SBoudrias/mem-fs)\n\n## Usage\n\n```js\nimport { create as createMemFs } from 'mem-fs';\nimport { create as createEditor } from 'mem-fs-editor';\n\nconst store = createMemFs();\nconst fs = createEditor(store);\n\nfs.write('somefile.js', 'var a = 1;');\nawait fs.commit();\n```\n\n### `#read(filepath, [options])`\n\nRead a file and return its contents as a string.\n\nYou can alternatively get the raw contents buffer if you pass `options.raw = true`.\n\nBy default, calling `read()` on a file path that does not exist throws error. You can, however, pass `options.defaults = 'your default content'` to get a default content you pass in, if you prefer to not deal with try/catch.\n\n### `#readJSON(filepath, [defaults])`\n\nRead a file and parse its contents as JSON.\n\n`readJSON()` internally calls `read()` but will not throw an error if the file path you pass in does not exist. If you pass in an optional `defaults`, the `defaults` content will be returned in case of the target file is missing, instead of `undefined`. (Error would still be thrown if `JSON.parse` failed to parse your target file.)\n\n### `#write(filepath, contents)`\n\nReplace the content of a file (existing or new) with a string or a buffer.\n\n### `#writeJSON(filepath, contents[, replacer [, space]])`\n\nReplace the content of a file (existing or new) with an object that is to be converted by calling `JSON.stringify()`.\n\n`contents` should usually be a JSON object, but it can technically be anything that is acceptable by [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).\n\nOptionally pass `replacer` and `space` as the last two arguments, as defined by [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). `spacer` is used to format the output string (prettify).\n\nDefault value for `space` is `2`, when not specified.\n\n### `#append(filepath, contents, [options])`\n\nAppend the new contents to the current file contents.\n\n- `options.trimEnd` (default `true`). Trim trailing whitespace of the current file contents.\n- `options.separator` (default `os.EOL`). Separator to insert between current and new contents.\n- `options.create` (default `false`). Create the file if doesn't exists.\n\n### `#appendTpl(filepath, contents, context[, templateOptions[, [options]])`\n\nAppend the new `contents` to the exsting `filepath` content and parse the new contents as an [ejs](http://ejs.co/) template where `context` is the template context (the variable names available inside the template).\n\n- `options.trimEnd` (default `true`). Trim trailing whitespace of the current file contents.\n- `options.separator` (default `os.EOL`). Separator to insert between current and new contents.\n\n### `#extendJSON(filepath, contents[, replacer [, space]])`\n\nExtend the content of an existing JSON file with the partial objects provided as argument.\n\nOptionally take the same JSON formatting arguments than `#writeJSON()`.\n\n### `#delete(filepath, [options])`\n\nDelete a file or a directory.\n\n`filePath` can also be a `glob`. If `filePath` is glob, you can optionally pass in an `options.globOptions` object to change its pattern matching behavior. The full list of options are being described [here](https://github.com/mrmlnc/fast-glob#options-1). The `sync` flag is forced to be `true` in `globOptions`.\n\n### `#copy(from, to, [options], context[, templateOptions ])`\n\nCopy file(s) from the `from` path to the `to` path.\nWhen passing array, you should pass `options.fromBasePath` to be used to calculate the `to` relative path. The common directory will be detected and used as `fromBasePath` otherwise.\n\nOptionally, pass an `options.process` function (`process(contents)`) returning a string or a buffer who'll become the new file content. The process function will take a single contents argument who is the copied file contents as a `Buffer`.\n\n`options.ignoreNoMatch` can be used to silence the error thrown if no files match the `from` pattern.\n`options.append` can be used to append `from` contents to `to` instead of copying, when the file is already loaded in mem-fs (safe for regeneration).\n\n`from` can be a glob pattern that'll be match against the file system. If that's the case, then `to` must be an output directory. For a globified `from`, you can optionally pass in an `options.globOptions` object to change its pattern matching behavior. The full list of options are being described [here](https://github.com/mrmlnc/fast-glob#options-1). The `nodir` flag is forced to be `true` in `globOptions` to ensure a vinyl object representing each matching directory is marked as `deleted` in the `mem-fs` store.\n\nOptionally, when `from` is a glob pattern, pass an `options.processDestinationPath` function (`processDestinationPath(destinationFile)`) returning a string who'll become the new file name.\n\n`options.noGlob` can be used to by bypass glob matching entirely. In that case, `from` will directly match file paths against the file system.\n\n### `#copyAsync(from, to, [options], context[, templateOptions ])`\n\nAsync version of `copy`.\n\n`copy` loads `from` to memory and copy its contents to `to`.\n`copyAsync` copies directly from the disk to `to`, falling back to `copy` behavior if the file doesn't exists on disk.\n\nSame parameters of `copy` (see [copy() documentation for more details](#copyfrom-to-options-context-templateoptions-)).\n\n### `#copyTpl(from, to, context[, templateOptions [, copyOptions]])`\n\nCopy the `from` file and, if it is not a binary file, parse its content as an [ejs](http://ejs.co/) template where `context` is the template context (the variable names available inside the template).\n\nYou can optionally pass a `templateOptions` object. `mem-fs-editor` automatically setup the filename option so you can easily use partials.\n\nYou can also optionally pass a `copyOptions` object (see [copy() documentation for more details](#copyfrom-to-options-context-templateoptions-)).\n\nTemplates syntax looks like this:\n\n```\n\u003c%= value %\u003e\n\u003c%- include('partial.ejs', { name: 'Simon' }) %\u003e\n```\n\nDir syntax looks like this:\n\n```\n/some/path/dir\u003c%= value %\u003e/...\n```\n\nRefer to the [ejs documentation](http://ejs.co/) for more details.\n\n### `#copyTplAsync(from, to, [options], context[, templateOptions ])`\n\nAsync version of `copyTpl` that uses `copyAsync` instead of `copy`.\n\nCan be used for best performance. Reduces overheads.\n\nSame parameters of `copyTpl` (see [copyTpl() documentation for more details](#copyfrom-to-options-context-templateoptions-)).\n\n### `#move(from, to, [options])`\n\nMove/rename a file from the `from` path to the `to` path.\n\n`#move` internally uses `#copy` and `#delete`, so `from` can be a glob pattern, and you can provide `options.globOptions` with it.\n\n### `#exists(filepath)`\n\nReturns `true` if a file exists. Returns `false` if the file is not found or deleted.\n\n### `#commit([options,] [...transforms])`\n\nPass stored files through a pipeline and persist every changes made to files in the mem-fs store to disk.\n\nIf provided, `options` is the pipeline options.\nBy default only modified files are passed through the pipeline.\nPass a custom filter `options.filter` to customize files passed through the pipeline.\nIf provided, `...transforms` is a vararg of TransformStream to be applied on a stream of vinyl files (like gulp plugins).\n`commitTransform` is appended to `transforms` and persists modified files to disk, non modified files are passed through.\n\nreturns promise that is resolved once the pipeline is finished.\n\n### `#dump([cwd,] [filter])`\n\nDump files to compare expected result.\nProvide a `cwd` for relative path. Allows to omit temporary path.\nProvide a `filter` function or a pattern to focus on specific files.\n`dump` returns only modified (committed or not) files when no filter or a pattern is provided.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSBoudrias%2Fmem-fs-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSBoudrias%2Fmem-fs-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSBoudrias%2Fmem-fs-editor/lists"}