{"name":"@putout/operator-filesystem","version":"3.8.1","type":"commonjs","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"🐊Putout operator adds ability to filesystem referenced variables that was not defined","homepage":"https://github.com/coderaiser/putout/tree/master/packages/operator-filesystem#readme","main":"lib/filesystem.js","release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git://github.com/coderaiser/putout.git"},"scripts":{"test":"madrun test","watch:test":"madrun watch:test","lint":"madrun lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","fix:lint":"madrun fix:lint","coverage":"madrun coverage","report":"madrun report"},"dependencies":{"@putout/babel":"^2.0.0","@putout/operate":"^12.0.0","fullstore":"^3.0.0","try-catch":"^3.0.1"},"keywords":["putout","putout-operator","operator","filesystem"],"devDependencies":{"@putout/engine-parser":"^10.0.2","@putout/operator-json":"^2.0.0","@putout/test":"^8.0.0","c8":"^9.0.0","eslint":"^9.0.0-alpha.0","eslint-plugin-n":"^17.0.0-0","eslint-plugin-putout":"^22.0.0","lerna":"^6.0.1","madrun":"^10.0.0","montag":"^1.2.1","nodemon":"^3.0.1","supertape":"^9.0.0"},"peerDependencies":{"putout":">=34"},"license":"MIT","engines":{"node":">=18"},"publishConfig":{"access":"public"},"gitHead":"b57cb2bfd52e1651f62bbbde7e424f9819239eb1","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_id":"@putout/operator-filesystem@3.8.1","_nodeVersion":"20.10.0","_npmVersion":"9.6.6","dist":{"integrity":"sha512-z+YYNxLwf062rDeY4YMNmgo7vGCHDh7E0WEcHJzlji8jX6oi2zYLqoHnCV4/sSlCiumj002LvHG8RPtu8dam2A==","shasum":"d14a9ac76a583f276a2c1f8673395b5d2a4f8feb","tarball":"http://registry-npm.ywwl.com/@putout/operator-filesystem/download/@putout/operator-filesystem-3.8.1.tgz","fileCount":5,"unpackedSize":17237,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBcL/mm8OF8+wYsOzwJQ1lUgJJRCP5ltzwuNYWl2WUn6AiBTaLp4he3km5J5uP5IEU8OBLzsNiMbqMRL6k7Z/NlCbQ=="}],"size":4695,"noattachment":false,"key":"/@putout/operator-filesystem/-/@putout/operator-filesystem-3.8.1.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/operator-filesystem_3.8.1_1705400508641_0.7153579652614144"},"_hasShrinkwrap":false,"readme":"# @putout/operator-filesystem [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/operator-filesystem.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/operator-filesystem \"npm\"\n\n🐊[**Putout**](https://github.com/coderaiser/putout) operator adds ability to lint filesystem.\n\n## Install\n\n```\nnpm i putout @putout/operator-filesystem\n```\n\n## API\n\n### `createFile(directoryPath: DirectoryPath, name: string, content?: string): FilePath`\n\n```js\nconst {operator} = require('putout');\nconst {findFile, createFile} = operator;\n\nconst [dirPath] = findFile(ast, 'hello');\nconst filePath = createFile(dirPath, 'world.txt', 'hello world');\n```\n\n### `createDirectory(directoryPath: FilePath, name: string): FilePath`\n\n```js\nconst {operator} = require('putout');\nconst {\n    createDirectory,\n    findFile,\n} = operator;\n\nconst [dirPath] = findFile(ast, 'hello');\n\nconst newDirectoryPath = createDirectory(dirPath, 'world');\n```\n\n### `findFile(filePath: Path|FilePath, name: string | string[]): FilePath[]`\n\n```js\nconst {operator} = require('putout');\nconst {finedFiles, findFile} = operator;\n\nconst [filePath] = findFile(ast, 'hello');\n```\n\nYou can also pass array of file masks:\n\n```js\nimport {operator} from 'putout';\n\nconst {findFile} = operator;\nconst coupleFiles = findFile(ast, ['*.js', '*.ts']);\n```\n\nAnd even search for a directory:\n\n```js\nimport {operator} from 'putout';\n\nconst {findFile} = operator;\nconst coupleFiles = findFile(ast, ['/home/coderaiser', '/home/coderaiser/putout']);\n```\n\n### `getParentDirectory(filePath: FilePath): FilePath|null`\n\n```js\nconst {operator} = require('putout');\nconst {\n    createDirectory,\n    findFile,\n    getParentDirectory,\n} = operator;\n\nconst [dirPath] = findFile(ast, 'hello');\n\nconst newDirectoryPath = createDirectory(dirPath, 'world');\n\ndirPath === getParentDirectory(newDirectoryPath);\n// returns\ntrue;\n```\n\n### `getFilename(path: FilePath): string`\n\n```js\nconst {operator} = require('putout');\nconst {getFilename} = operator;\n\nconst name = getFilename(filePath);\n```\n\n### `getFileType(path: FilePath): string`\n\n```js\nconst {operator} = require('putout');\nconst {getFilename, getFileType} = operator;\n\ngetFileType(filePath);\n// returns\n'file';\n```\n\n### `getFileContent(path: FilePath): [is: boolean, content: string]`\n\nGet `content` property if it exists, use [`readFileContent`](#read-file-content) to read file from **Filesystem**.\n\n```js\nconst {operator} = require('putout');\nconst {getFileContent} = operator;\n\ngetFileContent(filePath);\n// returns\n[true, 'hello world'];\n```\n\n### `removeFile(filePath: Path)`\n\n```js\nconst {operator} = require('putout');\nconst {removeFile} = operator;\n\nremoveFile(filePath);\n```\n\n### `copyFile(filePath: FilePath, dirPath: FilePath)`\n\n```js\nconst {operator} = require('putout');\nconst {moveFile, copyFile} = operator;\n\ncopyFile(filePath, dirPath);\n```\n\n### `moveFile(filePath: FilePath, dirPath: FilePath)`\n\n```js\nconst {operator} = require('putout');\nconst {moveFile} = operator;\n\nmoveFile(filePath, dirPath);\n```\n\n### `readFileContent(filePath: FilePath): string`\n\n```js\nconst {operator} = require('putout');\nconst {readFileContent} = operator;\n\nreadFileContent(filePath);\n// returns\n'hello';\n```\n\n### `writeFileContent(filePath: FilePath, content: string)`\n\n```js\nconst {operator} = require('putout');\nconst {\n    writeFileContent,\n    readFileContent,\n} = operator;\n\nwriteFileContent(filePath, 'hello');\nreadFileContent(filePath);\n// returns\n'hello';\n```\n\n### `renameFile(filePath: FilePath, name: string)`\n\n```js\nconst {operator} = require('putout');\nconst {renameFile, findFile} = operator;\n\nconst [filePath] = findFile(path, 'README.md');\n\nrenameFile(filePath, 'readme.md');\n```\n\nthis is the same as:\n\n```\nrenameFile(filePath, '/any/path/here/readme.md');\n```\n\nSince `basename` is used.\n\n> The `path.basename()` method returns the last portion of a path, similar to the Unix basename command. Trailing directory separators are ignored.\n>\n> (c) [nodejs.org](https://nodejs.org/api/path.html#pathbasenamepath-suffix)\n\nTo move file use [`moveFile()`](#movefilefilepath-filepath-dirpath-filepath).\n\n## Example\n\n```js\nconst montag = require('montag');\nconst {\n    parse,\n    print,\n    operator,\n} = require('putout');\n\nconst {renameFile, findFile} = operator;\n\nconst ast = parse(montag`\n    putout_processor_filesystem({\n        \"type\": \"directory\",\n        \"filename\": \"/hello\",\n        \"files\": []\n    });\n`);\n\nconst [filePath] = findFile(ast, 'hello');\n\nrenameFile(filePath, 'world');\n\nprint(ast);\n// returns\n`\nputout_processor_filesystem({\n    \"type\": \"directory\",\n    \"filename\": \"/hello\",\n    \"files\": []\n});\n`;\n```\n\n## License\n\nMIT\n","publish_time":1705400508787,"_cnpm_publish_time":1705400508787,"dist-tags":{"latest":"11.4.0"}}