{"name":"mem-fs-editor","version":"11.1.2","author":{"name":"Simon Boudrias"},"license":"MIT","_id":"mem-fs-editor@11.1.2","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":"9ee84ee8889c6a9b8c1ccedc736e0f01f4558090","tarball":"http://registry-npm.ywwl.com/mem-fs-editor/download/mem-fs-editor-11.1.2.tgz","fileCount":46,"integrity":"sha512-yUVFK96XhGv31iWZ3G60pGNIuXuZTUsWz0GQzv9ffjYFf1oXs0PcD3LFZHzRDImH+Da21x/C4csEjN0W5ygdQA==","signatures":[{"sig":"MEQCIGalmCejcnlAl6D/Hi5hyMk+VxkfpTJYK+oDSVhKujyFAiBQvL25vmogxFg5/l9olOcHdM+tFbQE4r4eGKXqn/sCnQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":46035,"size":11949,"noattachment":false,"key":"/mem-fs-editor/-/mem-fs-editor-11.1.2.tgz"},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.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":"31c0f9dabba71ded3edabf189b7219de2b756b63","scripts":{"fix":"eslint . --fix","test":"vitest --run","build":"tsc","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":"10.8.2","description":"File edition helpers working on top of mem-fs","directories":{},"_nodeVersion":"18.20.4","dependencies":{"ejs":"^3.1.10","vinyl":"^3.0.0","globby":"^14.0.2","commondir":"^1.0.1","minimatch":"^9.0.3","@types/ejs":"^3.1.4","multimatch":"^7.0.0","@types/node":">=18","deep-extend":"^0.6.0","isbinaryfile":"5.0.2","normalize-path":"^3.0.0","textextensions":"^6.11.0","binaryextensions":"^6.11.0"},"_hasShrinkwrap":false,"devDependencies":{"sinon":"^19.0.2","eslint":"^8.51.0","vitest":"^2.0.5","prettier":"^3.0.3","coveralls":"^3.1.1","typescript":"^5.2.2","escape-regexp":"0.0.1","eslint-config-xo":"^0.43.1","@vitest/coverage-v8":"^2.0.5","eslint-config-prettier":"^9.0.0","eslint-plugin-prettier":"^5.0.1","@typescript-eslint/parser":"^7.18.0","prettier-plugin-packagejson":"^2.4.6","@typescript-eslint/eslint-plugin":"^7.18.0"},"peerDependencies":{"mem-fs":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mem-fs-editor_11.1.2_1728731038366_0.47091360095080925","host":"s3://npm-registry-packages"},"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":1728731038589,"_cnpm_publish_time":1728731038589,"dist-tags":{"latest":"12.1.0"}}