{"name":"@putout/operator-filesystem","version":"6.0.2","keywords":["putout","putout-operator","operator","filesystem"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/operator-filesystem@6.0.2","homepage":"https://github.com/coderaiser/putout/tree/master/packages/operator-filesystem#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"c498da1818a3b9c661b05a0c86ae1025570786fb","tarball":"http://registry-npm.ywwl.com/@putout/operator-filesystem/download/@putout/operator-filesystem-6.0.2.tgz","fileCount":5,"integrity":"sha512-/wRBi8ymutGbLnibdK6kroZIeHmlumO8/HvaXxmVrV82tz6VZLcMU5Co5b5E+b82IV+nw4RAXLczyFanwqzMlg==","signatures":[{"sig":"MEUCIGb7/MZcMOY6MMEUVTeDywmvY/N9hnt61pU2eKB9H0WoAiEAsMtFL6xneijhWMDtmC+JzSID5lHNtwMfI27gFJ32mDw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18520,"size":4987,"noattachment":false,"key":"/@putout/operator-filesystem/-/@putout/operator-filesystem-6.0.2.tgz"},"main":"lib/filesystem.js","type":"commonjs","engines":{"node":">=18"},"gitHead":"d61d3a5f111425e5ef772847b478bacdc362fe7f","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"10.9.0","description":"🐊Putout operator adds ability to filesystem referenced variables that was not defined","directories":{},"_nodeVersion":"22.13.1","dependencies":{"fullstore":"^3.0.0","try-catch":"^3.0.1","@putout/babel":"^3.0.0","@putout/operate":"^13.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","lerna":"^6.0.1","eslint":"^9.0.0","madrun":"^10.0.0","montag":"^1.2.1","nodemon":"^3.0.1","supertape":"^10.0.0","@putout/test":"^11.0.0","eslint-plugin-n":"^17.0.0","eslint-plugin-putout":"^24.0.0","@putout/engine-parser":"^12.0.0","@putout/operator-json":"^2.0.0"},"peerDependencies":{"putout":">=38"},"_npmOperationalInternal":{"tmp":"tmp/operator-filesystem_6.0.2_1738847807190_0.5470497221314417","host":"s3://npm-registry-packages-npm-production"},"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: DirectoryPath, name: string): DirectoryPath`\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### `readDirectory(directoryPath: DirectoryPath): (FilePath | DirectoryPath)[]`\n\n```js\nconst {operator} = require('putout');\nconst {\n    finedFiles,\n    findFile,\n    readDirectory,\n} = operator;\n\nconst [dirPath] = findFile(ast, '/bin');\n\nreadDirectory(dirPath);\n// returns list of files\n[];\n```\n\n### `createNestedDirectory(path: FilePath|DirectoryPath, name: string): DirectoryPath`\n\n```js\nconst {operator} = require('putout');\nconst {\n    createDirectory,\n    findFile,\n    createNestedDirectory,\n} = operator;\n\nconst newDirectoryPath = createNestedDirectory(ast, '/hello/world');\n```\n\n### `removeEmptyDirectory(DirectoryPath)`\n\n```js\nconst {operator} = require('putout');\nconst {\n    removeEmptyDirectory,\n    createNestedDirectory,\n} = operator;\n\nconst newDirectoryPath = createNestedDirectory(ast, '/hello/world');\n\nremoveEmptyDirectory(newDirectoryPath);\n```\n\n### `readDirectory(directoryPath: DirectoryPath): (FilePath | DirectoryPath)[]`\n\n```js\nconst {operator} = require('putout');\nconst {\n    finedFiles,\n    findFile,\n    readDirectory,\n} = operator;\n\nconst [dirPath] = findFile(ast, '/bin');\n\nreadDirectory(dirPath);\n// returns list of files\n[];\n```\n\n### `findFile(directoryPath: DirectoryPath, name: string | string[], exclude?: string[]): (FilePath | DirectoryPath)[]`\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\nOr `exclude` some files:\n\n```js\nimport {operator} from 'putout';\n\nconst {findFile, getFilename} = operator;\n\nconst coupleFilesWithExcludeArray = findFile(ast, '*.ts', ['*.d.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(path: FilePath | DirectoryPath): 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### `getRootDirectory(path: FilePath | DirectoryPath): DrectoryPath`\n\n```js\nconst {operator} = require('putout');\nconst {\n    findFile,\n    getRootDirectory,\n} = operator;\n\nconst [filePath] = findFile(ast, 'hello');\n\ngetRootDirectory(dirPath);\n```\n\n### `getFilename(path: FilePath | DirectoryPath): 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(path: FilePath | DirectoryPath, directoryPath: DirectoryPath)`\n\n```js\nconst {operator} = require('putout');\nconst {moveFile, copyFile} = operator;\n\ncopyFile(filePath, dirPath);\n```\n\n### `moveFile(path: FilePath | DirectoryPath, directoryPath: DirectoryPath)`\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(path: FilePath | DirectoryPath, 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":1738847807371,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1738847807371,"dist-tags":{"latest":"11.4.0"}}