{"id":21414872,"url":"https://github.com/magic/fs","last_synced_at":"2025-03-16T18:42:05.660Z","repository":{"id":46817260,"uuid":"225253983","full_name":"magic/fs","owner":"magic","description":"node fs promises + additional functions","archived":false,"fork":false,"pushed_at":"2023-10-07T18:40:41.000Z","size":1053,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T18:07:53.693Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://magic.github.io/fs","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2019-12-02T00:42:33.000Z","updated_at":"2022-01-05T01:20:22.000Z","dependencies_parsed_at":"2024-06-21T03:41:45.771Z","dependency_job_id":"558f7239-1c41-42fb-9ee4-0420e4387cac","html_url":"https://github.com/magic/fs","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ffs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ffs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ffs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ffs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magic","download_url":"https://codeload.github.com/magic/fs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243911273,"owners_count":20367651,"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-11-22T18:34:16.682Z","updated_at":"2025-03-16T18:42:05.637Z","avatar_url":"https://github.com/magic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @magic/fs\n\nexports all fs.promises + exists + mkdirp + rmrf + getFiles + getDirs functions.\n\n[![NPM version][npm-image]][npm-url]\n[![Linux Build Status][travis-image]][travis-url]\n[![Windows Build Status][appveyor-image]][appveyor-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n\n[html-docs](https://magic.github.io/fs)\n\n### installation\n\nbe in a nodejs project\n\n```bash\nnpm install @magic/fs\n```\n\n### import\n\n```javascript\nimport fs from '@magic/fs'\n\nconst run = async () =\u003e {\n  await fs.mkdirp('./test_235235/dir/to/create')\n  console.log('dir created')\n  await fs.rmrf('./test_235235')\n  console.log('dir deleted, even though it had contents.')\n}\nrun()\n```\n\n### promises\n\npromises from fs:\n\n```\naccess\ncopyFile\nopen\nopendir\nrename\ntruncate\nrmdir\nmkdir\nreaddir\nreadlink\nsymlink\nlstat\nstat\nlink\nunlink\nchmod\nlchmod\nlchown\nchown\nutimes\nrealpath\nmkdtemp\nwriteFile\nappendFile\nreadFile\nexists\nreadDir\nreadfile\nrmDir\n```\n\n### export overloads:\n\n```javascript\nrmdir, rmDir\nreadfile, readFile\nreaddir, readDir\n```\n\n### Additional functions:\n\n#### mkdirp\n\nsame as mkdir -p on unix\n\n```javascript\nawait fs.mkdirp('./path/to/dir')\n```\n\n#### rmrf\n\nsame as rm -rf on unix.\n\n**will not work outside process.cwd()**\n\n```javascript\nawait fs.rmrf('./path/to/dir')\n```\n\n#### exists\n\nsame as fs.exists, but promisified and ready for esmodules.\n\n#### getDirectories\n\nget a list of directories in a directory,\nrecursively.\n\n```javascript\nimport fs from '@magic/fs'\n\nconst run = async () =\u003e {\n  // first level directories\n  const directories = await fs.getDirectories(process.cwd(), false)\n  console.log(directories)\n\n  // first level again\n  const dirs = await fs.getDirectories(process.cwd(), { depth: false })\n\n  // recursive run\n  const deepDirectories = await fs.getDirectories(process.cwd())\n  console.log(deepDirectories)\n\n  // recursive run with specified depth\n  const deepDirectoriesDepth2 = await fs.getDirectories(process.cwd(), { depth: 2 })\n  console.log(deepDirectoriesDepth2)\n\n  // use /some/dir as root instead of process.cwd()\n  const deepDirWithRoot = await fs.getDirectories(process.cwd(), { depth: true, root: '/some/dir' })\n  console.log(deepDirWithRoot)\n}\nrun()\n```\n\n#### getFiles\n\nget a list of files in a directory,\nrecursively.\n\n```javascript\nimport fs from '@magic/fs'\n\nconst run = async () =\u003e {\n  // first level directories\n  const files = await fs.getFiles(process.cwd())\n  console.log(files)\n\n  // recursive run\n  const deepFiles = await fs.getFiles(process.cwd(), { depth: true })\n  console.log(deepFiles)\n\n  // recursive run with specified depth,\n  const deepFilesDepth2 = await fs.getFiles(process.cwd(), { depth: 2 })\n  console.log(deepFilesDepth2)\n}\nrun()\n```\n\n#### getFileType\n\nget the file type of a file,\nbased on extension,\nand defaulting to \"txt\"\n\n```javascript\nimport fs from '@magic/fs'\n\nconst fileType = fs.getFileType('html.html')\nconsole.log(fileType, fileType === 'html')\n\nconst nonFileType = fs.getFileType()\nconsole.log(nonFileType, nonFileType === 'txt')\n```\n\n### changelog\n\n#### 0.0.1\n\nfirst release\n\n#### 0.0.2\n\n- bump required node version\n- update dependencies\n\n#### 0.0.3\n\nbetter error messages\n\n#### 0.0.4\n\nrmrf returns true if directory does not exist.\n\n#### 0.0.5\n\nuse @magic/mime-types to export contentTypes\n\n#### 0.0.6\n\nbump required node version to 14.2.0\n\n#### 0.0.7\n\nrmrf: add dryRun option\n\n#### 0.0.8\n\nupdate dependencies\n\n#### 0.0.9\n\n- remove unused imports from getDirectories\n- getDirectories and getFiles now accept a number as second argument.\n\n```\n// if a number is given instead of true/false, then this is the depth of recursion.\ngetFiles(directory, 2) // two levels down\n```\n\n#### 0.0.10\n\n- bump required node version to 14.15.4\n- update dependencies\n\n##### 0.0.11\n\nupdate dependencies (@magic/mime-types)\n\n##### 0.0.12\n\nexport all functions from native fs\n\n##### 0.0.13\n\n- getDirectories, getFiles: default root to process.cwd() if first argument is an array and root is not passed\n- update dependencies\n\n##### 0.0.14\n\nupdate dependencies (@magic/mime-types)\n\n##### 0.0.15\n\nupdate @magic/types to avoid circular dependency\n\n##### 0.0.16\n\nadd deprecation warning for calls to fs.getDirectories, fs.getFilePath and fs.getFiles that do not use an options object\n\n##### 0.0.17\n\nupdate dependencies\n\n##### 0.0.18\n\nupdate mime-types\n\n##### 0.0.19\n\nupdate dependencies\n\n##### 0.0.20\n\nupdate dependencies\n\n##### 0.0.21\n\n- add missing @magic/fs dependency\n- update dependencies\n\n##### 0.0.22\n\nupdate dependencies\n\n##### 0.0.23\n\nupdate dependencies\n\n##### 0.0.24\n\ngetFiles: allow files to be filtered by extension, using the .extension key of the second parameter\n\n##### 0.0.25\n\nupdate dependencies\n\n##### 0.0.26\n\nupdate dependencies\n\n##### 0.0.27\n\nupdate dependencies\n\n##### 0.0.28\n\nupdate dependencies\n\n##### 0.0.29\n\n- update dependencies\n- getFiles and getDirectories now accept maxDepth and minDepth config args\n\n##### 0.0.30\n\n- update dependencies\n- remove deprecated getFiles and getDirectories api\n- add minDepth option\n\n##### 0.0.31 - unreleased\n\n...\n\n[npm-image]: https://img.shields.io/npm/v/@magic/fs.svg\n[npm-url]: https://www.npmjs.com/package/@magic/fs\n[travis-image]: https://img.shields.io/travis/com/magic/fs.svg?branch=master\n[travis-url]: https://travis-ci.com/magic/fs\n[appveyor-image]: https://img.shields.io/appveyor/ci/magic/fs/master.svg\n[appveyor-url]: https://ci.appveyor.com/project/magic/fs/branch/master\n[coveralls-image]: https://coveralls.io/repos/github/magic/fs/badge.svg\n[coveralls-url]: https://coveralls.io/github/magic/fs\n[greenkeeper-image]: https://badges.greenkeeper.io/magic/fs.svg\n[greenkeeper-url]: https://badges.greenkeeper.io/magic/fs.svg\n[snyk-image]: https://snyk.io/test/github/magic/fs/badge.svg\n[snyk-url]: https://snyk.io/test/github/magic/fs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagic%2Ffs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagic%2Ffs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagic%2Ffs/lists"}