|
| 1 | +- [chmod (function)](#chmod-function) |
1 | 2 | - [ChmodPermissionsWho (type)](#chmodpermissionswho-type) |
2 | 3 | - [ChmodPermissionsWhat (type)](#chmodpermissionswhat-type) |
3 | | -- [chmod (function)](#chmod-function) |
| 4 | + |
| 5 | +# chmod (function) |
| 6 | + |
| 7 | +Set the permission bits for the specified file. |
| 8 | + |
| 9 | +- `@param` _permissions_ — The permission bits to set. This can be a number, a string |
| 10 | + containing an octal number, or an object. |
| 11 | +- `@param` _path_ — The path to the file. |
| 12 | + |
| 13 | +Provides the same functionality as the unix binary of the same name. |
| 14 | + |
| 15 | +The `permissions` argument can be either: |
| 16 | + |
| 17 | +- a number (best expressed using octal, eg `0o655`) |
| 18 | +- a string (which will be interpreted as an octal number, eg `'777'`) |
| 19 | +- or an object (see below). |
| 20 | + |
| 21 | +> NOTE: At this time there are no "add"/"remove" semantics; the existing |
| 22 | +> permissions will be completely overwritten with your specified permissions. |
| 23 | +> This will be changed later as this is not intuitive. |
| 24 | +
|
| 25 | +When permissions is an object, each of the object's own properties' keys must |
| 26 | +be one of these strings: |
| 27 | + |
| 28 | +- `"user"` |
| 29 | +- `"group"` |
| 30 | +- `"others"` |
| 31 | +- `"all"` (meaning "user", "group", and "others") |
| 32 | +- `"u"` (alias for "user") |
| 33 | +- `"g"` (alias for "group") |
| 34 | +- `"o"` (alias for "others") |
| 35 | +- `"a"` (alias for "all") |
| 36 | +- `"ug"` ("user" plus "group") |
| 37 | +- `"go"` ("group" plus "others") |
| 38 | +- `"uo"` ("user" plus "others") |
| 39 | + |
| 40 | +and their values must be one of these strings: |
| 41 | + |
| 42 | +- `"read"` (permission to read the contents of the file) |
| 43 | +- `"write"` (permission to write to the file's contents) |
| 44 | +- `"execute"` (permission to run the file as an executable) |
| 45 | +- `"readwrite"` (both "read" and "write") |
| 46 | +- `"none"` (no permissions) |
| 47 | +- `"full"` ("read", "write", and "execute") |
| 48 | +- `"r"` (alias for "read") |
| 49 | +- `"w"` (alias for "write") |
| 50 | +- `"x"` (alias for "execute") |
| 51 | +- `"rw"` (alias for "readwrite") |
| 52 | +- `"rx"` ("read" and "execute") |
| 53 | +- `"wx"` ("write" and "execute") |
| 54 | +- `"rwx"` (alias for "full") |
| 55 | + |
| 56 | +Some example objects: |
| 57 | + |
| 58 | +```ts |
| 59 | +chmod({ user: "readwrite", group: "read", others: "none" }); |
| 60 | +chmod({ ug: "rw", o: "w" }); |
| 61 | +chmod({ all: "full" }); |
| 62 | +``` |
| 63 | + |
| 64 | +```ts |
| 65 | +declare function chmod( |
| 66 | + permissions: |
| 67 | + | number |
| 68 | + | string |
| 69 | + | Record<ChmodPermissionsWho, ChmodPermissionsWhat>, |
| 70 | + path: string | Path |
| 71 | +): void; |
| 72 | +``` |
4 | 73 |
|
5 | 74 | # ChmodPermissionsWho (type) |
6 | 75 |
|
@@ -41,20 +110,3 @@ declare type ChmodPermissionsWhat = |
41 | 110 | | "wx" |
42 | 111 | | "rwx"; |
43 | 112 | ``` |
44 | | - |
45 | | -# chmod (function) |
46 | | - |
47 | | -Set the permission bits for the specified file. |
48 | | - |
49 | | -- `@param` _permissions_ — The permission bits to set. This can be a number, a string containing an octal number, or an object. |
50 | | -- `@param` _path_ — The path to the file. |
51 | | - |
52 | | -```ts |
53 | | -declare function chmod( |
54 | | - permissions: |
55 | | - | number |
56 | | - | string |
57 | | - | Record<ChmodPermissionsWho, ChmodPermissionsWhat>, |
58 | | - path: string | Path |
59 | | -): void; |
60 | | -``` |
|
0 commit comments