{"name":"mem-fs-editor","version":"12.0.3","author":{"name":"Simon Boudrias"},"license":"MIT","_id":"mem-fs-editor@12.0.3","maintainers":[{"name":"sboudrias","email":"admin@simonboudrias.com"},{"name":"mshima","email":"marceloshima@gmail.com"}],"homepage":"https://github.com/SBoudrias/mem-fs-editor#readme","bugs":{"url":"https://github.com/SBoudrias/mem-fs-editor/issues"},"dist":{"shasum":"6c73144630442609f03cfb02aeaaba38891d0f79","tarball":"http://registry-npm.ywwl.com/mem-fs-editor/download/mem-fs-editor-12.0.3.tgz","fileCount":46,"integrity":"sha512-RVfJmfthkI/2b8Woy0r1HXAq/vKbnIyvfn7y7JdKO9sngIwYKARvqf/XrdOr2eokn+shQi7TLwXHB0ZyMTnjog==","signatures":[{"sig":"MEQCIHIbm9H4wecluNy5dU1YUPMvqzFpjofAwIxRagbPTZkOAiAShXXgVPvuEYDi1rQ4pWGdc9yW4AwURX3FJ0yh3rvtWQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":53699,"size":13291,"noattachment":false,"key":"/mem-fs-editor/-/mem-fs-editor-12.0.3.tgz"},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=20.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./state":{"types":"./dist/state.d.ts","default":"./dist/state.js"},"./transform":{"types":"./dist/transform.d.ts","default":"./dist/transform.js"}},"gitHead":"6979fb007fa5ef21d63a676f7c6195dedaee7d10","scripts":{"fix":"eslint . --fix","test":"vitest --run","build":"tsc -p tsconfig.build.json","prepare":"npm run build","pretest":"eslint ."},"_npmUser":{"name":"mshima","email":"marceloshima@gmail.com"},"repository":{"url":"git+https://github.com/SBoudrias/mem-fs-editor.git","type":"git"},"_npmVersion":"11.11.0","description":"File edition helpers working on top of mem-fs","directories":{},"_nodeVersion":"22.22.0","dependencies":{"ejs":"^4.0.1","debug":"^4.4.3","vinyl":"^3.0.1","commondir":"^1.0.1","minimatch":"^10.2.4","@types/ejs":"^3.1.5","multimatch":"^8.0.0","tinyglobby":"^0.2.15","deep-extend":"^0.6.0","isbinaryfile":"5.0.7","normalize-path":"^3.0.0","textextensions":"^6.11.0","@types/picomatch":"^4.0.2","binaryextensions":"^6.11.0"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^10.0.2","vitest":"^4.0.18","globals":"^17.3.0","prettier":"^3.8.1","@eslint/js":"^10.0.1","typescript":"^5.9.3","@types/debug":"^4.1.12","escape-regexp":"0.0.1","@eslint/eslintrc":"^3.3.4","@types/commondir":"^1.0.2","eslint-config-xo":"0.46.0","typescript-eslint":"^8.56.1","@types/deep-extend":"^0.6.2","@vitest/coverage-v8":"^4.0.18","@types/escape-regexp":"^0.0.3","@types/normalize-path":"^3.0.2","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.5","@typescript-eslint/parser":"^8.56.1","prettier-plugin-packagejson":"^3.0.0","@typescript-eslint/eslint-plugin":"^8.56.1"},"peerDependencies":{"mem-fs":"^4.0.0","@types/node":">=20"},"acceptDependencies":{"isbinaryfile":"^6.0.0"},"peerDependenciesMeta":{"@types/node":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/mem-fs-editor_12.0.3_1772639384678_0.30385024606513733","host":"s3://npm-registry-packages-npm-production"},"readme":"# mem-fs-editor\n\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, data[, options])`\n\nAppend the new `contents` to the existing `filepath` content and parse the new contents as an [ejs](http://ejs.co/) template where `data` 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- `options.transformOptions`. Options passed to the EJS renderer when processing the template, similar to `copyTpl`.\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])`\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.fileTransform` function that transforms both the destination path and file contents. The function receives a single object parameter with the following properties:\n\n- `destinationPath`: The resolved destination file path (string)\n- `sourcePath`: The source file path (string)\n- `contents`: The file contents as a `Buffer`\n- `data`: Optional data passed via `options.transformData`\n- `options`: Optional options passed via `options.transformOptions`\n\nThe function should return an object `{ path, contents }` where:\n\n- `path`: The transformed destination path (string)\n- `contents`: The transformed file contents (string | Buffer)\n\nExample:\n\n```js\nfs.copy('source.txt', 'dest.txt', {\n  fileTransform({ destinationPath, sourcePath, contents, data, options }) {\n    const newPath = destinationPath.replace('.txt', '.md');\n    const newContents = contents.toString().toUpperCase();\n    return { path: newPath, contents: newContents };\n  },\n});\n```\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\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])`\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`. The `fileTransform` function can also return a `Promise<{ path: string; contents: string | Buffer }>` for async transformations.\n\nSee [copy() documentation for more details](#copyfrom-to-options).\n\n### `#copyTpl(from, to, data[, options])`\n\nCopy the `from` file and, if it is not a binary file, parse its content as an [ejs](http://ejs.co/) template where `data` is the template context (the variable names available inside the template).\n\n`options.transformOptions` replaced the old `tplOptions` parameter and is passed as ejs options. `mem-fs-editor` automatically setup the filename option so you can easily use partials.\n\nYou can also optionally pass a `options` object (see [copy() documentation for more details](#copyfrom-to-options)).\n\nTemplates syntax looks like this:\n\n```\n<%= value %>\n<%- include('partial.ejs', { name: 'Simon' }) %>\n```\n\nDir syntax looks like this:\n\n```\n/some/path/dir<%= value %>/...\n```\n\nRefer to the [ejs documentation](http://ejs.co/) for more details.\n\n### `#copyTplAsync(from, to, data[, options])`\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](#copytplfrom-to-data-options)).\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","publish_time":1772639384825,"_cnpm_publish_time":1772639384825,"dist-tags":{"latest":"12.1.0"}}