Skip to content

Latest commit

 

History

History
181 lines (147 loc) · 3.9 KB

File metadata and controls

181 lines (147 loc) · 3.9 KB

chmod (Chmod)

Set the permission bits for the specified file.

Provides the same functionality as the unix binary of the same name.

const chmod: Chmod;

Chmod (interface)

The interface for the global function chmod, which has two call signatures.

interface Chmod {
  (permissions: number | string, path: string | Path): void;
  <Operation extends Chmod.Operation>(
    operation: Operation,
    permissions: Partial<Record<Chmod.Who, Chmod.Permission>>,
    path: string | Path,
  ): void;
}

Chmod(...) (call signature)

Set the permission bits for the specified file.

Provides the same functionality as the unix binary of the same name.

  • @param permissions — The permission bits to set. This can be a number, or a string containing an octal number.
  • @param path — The path to the file.
(permissions: number | string, path: string | Path): void;

Chmod(...) (call signature)

Apply a change to the permission bits for the specified file.

Provides the same functionality as the unix binary of the same name.

  • @param operation — What to do to the bits; can be "add", "set", or "remove".
  • @param permissions — An object describing the changes (see below).
  • @param path — The path to the file.

Each of the permissions object's own property keys must be one of these strings:

  • "user"
  • "group"
  • "others"
  • "all" (meaning "user", "group", and "others")
  • "u" (alias for "user")
  • "g" (alias for "group")
  • "o" (alias for "others")
  • "a" (alias for "all")
  • "ug" ("user" plus "group")
  • "go" ("group" plus "others")
  • "uo" ("user" plus "others")

and their values must be one of these strings:

  • "read" (permission to read the contents of the file)
  • "write" (permission to write to the file's contents)
  • "execute" (permission to run the file as an executable)
  • "readwrite" (both "read" and "write")
  • "none" (no permissions)
  • "full" ("read", "write", and "execute")
  • "r" (alias for "read")
  • "w" (alias for "write")
  • "x" (alias for "execute")
  • "rw" (alias for "readwrite")
  • "rx" ("read" and "execute")
  • "wx" ("write" and "execute")
  • "rwx" (alias for "full")

Some example objects:

{ user: "readwrite", group: "read", others: "none" }
{ ug: "rw", o: "w" }
{ all: "full" }
<Operation extends Chmod.Operation>(operation: Operation, permissions: Partial<Record<Chmod.Who, Chmod.Permission>>, path: string | Path): void;

Chmod (namespace)

declare namespace Chmod {
  export type Who =
    | "user"
    | "group"
    | "others"
    | "all"
    | "u"
    | "g"
    | "o"
    | "a"
    | "ug"
    | "go"
    | "uo";
  export type Operation = "add" | "set" | "remove";
  export type Permission =
    | "read"
    | "write"
    | "execute"
    | "readwrite"
    | "none"
    | "full"
    | "r"
    | "w"
    | "x"
    | "rw"
    | "rx"
    | "wx"
    | "rwx";
}

Chmod.Who (exported type)

A string representing who a permission applies to.

type Who =
  | "user"
  | "group"
  | "others"
  | "all"
  | "u"
  | "g"
  | "o"
  | "a"
  | "ug"
  | "go"
  | "uo";

Chmod.Operation (exported type)

A string representing how the permissions should be changed.

type Operation = "add" | "set" | "remove";

Chmod.Permission (exported type)

A string representing the access level for the given permission.

type Permission =
  | "read"
  | "write"
  | "execute"
  | "readwrite"
  | "none"
  | "full"
  | "r"
  | "w"
  | "x"
  | "rw"
  | "rx"
  | "wx"
  | "rwx";