{"id":15835247,"url":"https://github.com/kaelzhang/fs-chmod","last_synced_at":"2025-04-01T12:29:43.184Z","repository":{"id":57242171,"uuid":"191866148","full_name":"kaelzhang/fs-chmod","owner":"kaelzhang","description":"A drop-in replacement of `fs.chmod` with `+x` support.","archived":false,"fork":false,"pushed_at":"2019-06-14T14:52:40.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T13:16:16.195Z","etag":null,"topics":["chmod"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-14T02:53:02.000Z","updated_at":"2021-06-09T15:19:38.000Z","dependencies_parsed_at":"2022-09-04T21:21:51.846Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/fs-chmod","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffs-chmod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffs-chmod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffs-chmod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffs-chmod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/fs-chmod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246639166,"owners_count":20809955,"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":["chmod"],"created_at":"2024-10-05T14:21:41.592Z","updated_at":"2025-04-01T12:29:43.163Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/fs-chmod.svg?branch=master)](https://travis-ci.org/kaelzhang/fs-chmod)\n[![Coverage](https://codecov.io/gh/kaelzhang/fs-chmod/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/fs-chmod)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/fs-chmod?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/fs-chmod)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/fs-chmod.svg)](http://badge.fury.io/js/fs-chmod)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/fs-chmod.svg)](https://www.npmjs.org/package/fs-chmod)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/fs-chmod.svg)](https://david-dm.org/kaelzhang/fs-chmod)\n--\u003e\n\n# fs-chmod\n\nA drop-in replacement of [`fs.chmod`][chmod] with `+x` support.\n\n- supports **finer-grained [symbolic modes]**, such as `+x`, `ug+rw`, and etc.\n- supports **mode object** to make the mode better described.\n\n## Install\n\n```sh\n$ npm i fs-chmod\n```\n\n## Usage\n\n```js\nconst {\n  chmod,\n  chmodSync,\n  parse\n} = require('fs-chmod')\n\nchmod('/path/to/file.js', '+x').then(() =\u003e {\n  console.log('done')\n})\n\nchmodSync.sync('/path/to/file.js', 'a+x')\n```\n\n### chmod(path, mode): Promise\n### chmod(path, mode, callback): void\n### chmodSync(path, mode): void\n\n- **path** `string | Buffer | URL` the same as vanilla [`fs.chmod`][chmod]\n- **mode** `integer | Mode | string`\n- **callback** `Function(error?)`\n\nChanges the permissions of a file.\n\n### parse(str): Mode\n\n- **str** `string` Symbolic notation string of file system permissions\n\nParses the symbolic notation string, such as `+x`, `ug+rwx` into an object of the interface `Mode`(see below)\n\n```js\nconst mode = parse('u+x')\n\nconsole.log(mode.owner.execute)  // true\nconsole.log(mode.owner.read)     // false\nconsole.log(mode.group)         // undefined\n```\n\n## mode\n\n### mode `integer`\n\nThe same as the the second parameter of vanilla [`fs.chmod`][chmod].\n\n**PAY ATTENTION** that `mode` should be an **octal** number.\n\n```js\nchmodSync('/path/to/file', 0o777)  // ✅ Correct~\nchmodSync('/path/to/file', 777)    // ❌ WRONG!\n```\n\n### mode `object\u003cMode\u003e`\n\n```ts\ninterface Permission {\n  read?: boolean\n  write?: boolean\n  execute?: boolean\n}\n\ninterface Mode {\n  owner?: Permission\n  group?: Permission\n  others?: Permission\n  setuid?: boolean\n  setgid?: boolean\n  sticky?: boolean\n}\n```\n\nFor details, see [symbolic modes]\n\n\n```sh\n# bash\nchmod ug+rst /path/to/file\n```\n\nis equivalent to\n\n```js\nchmodSync('path/to/file', 'ug+rst')\n\n// or\nchmodSync('path/to/file', {\n  owner: {\n    read: true\n  },\n  group: {\n    read: true\n  },\n  setuid: true,\n  setgid: true,\n  sticky: true\n})\n```\n\n### mode `string`\n\n```\n[references][operator][modes]\n```\n\n- Supported references: `u`, `g`, `o`, `a`\n- Supported operators: `+`, `=`, `-`\n- Supported modes:\n  - `r`, `w`, `x`\n  \u003c!-- - `X`: special execute --\u003e\n  - `s`: setuid/setgid\n  - `t`: sticky\n\n## License\n\n[MIT](LICENSE)\n\n[chmod]: https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_chmod_path_mode_callback\n[symbolic modes]: https://en.wikipedia.org/wiki/Chmod#Symbolic_modes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Ffs-chmod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Ffs-chmod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Ffs-chmod/lists"}