33[](https://www.npmjs.com/package/unix-permissions) [](https://github.com/ehmicky/unix-permissions/graphs/contributors) [](https://www.apache.org/licenses/LICENSE-2.0) [](https://codecov.io/gh/ehmicky/unix-permissions) [](https://travis-ci.org/ehmicky/unix-permissions/builds) [](https://www.npmjs.com/package/unix-permissions) [](#) [](https://standardjs.com) [](https://github.com/ehmicky/eslint-config-standard-prettier-fp) [](https://gitter.im/ehmicky-code/unix-permissions)
44
55[ Unix file permissions] ( https://en.wikipedia.org/wiki/File_system_permissions )
6- can take several [ types] ( #types ) . With
7- [ ` chmod ` ] ( https://linux.die.net/man/1/chmod ) they
8- look like either [ ` ug+rw ` ] ( #symbolic ) or [ ` 660 ` ] ( #octal ) , while with
9- [ ` stat ` ] ( https://linux.die.net/man/2/stat ) and
10- [ ` ls ` ] ( https://linux.die.net/man/1/ls ) they look like [ ` drw-rw---- ` ] ( #stat ) .
11- This library enables using any of those [ types] ( #types ) (instead of being
6+ can take many [ shapes] ( #types ) :
7+ [ symbolic] ( #symbolic ) (` ug+rw ` ), [ octal] ( #octal ) (` 660 ` ) or a [ list of characters] ( #stat ) (` drw-rw---- ` ).
8+ This library enables using any of [ these] ( #types ) (instead of being
129limited to a single one) with any [ Node.js] ( #examples-javascript ) or
1310[ CLI command] ( #examples-cli ) .
1411
15- This library also allows you to perform operations on Unix permissions
16- including:
12+ This library can also perform operations on Unix permissions such as:
1713
14+ - [ testing] ( #containpermission-permissions ) ,
15+ [ setting] ( #setpermission-permissions ) and
16+ [ unsetting] ( #notpermission-permissions ) . Using bitwise operations (` | ` ,
17+ ` & ` , ` ^ ` , ` ~ ` ) can be tedious and error-prone otherwise.
1818- [ validating] ( #normalizepermission ) syntax.
1919- [ normalizing] ( #normalizepermission ) . For example ` u+r,u+w ` can be shortened
2020 to ` u+rw ` .
21- - [ testing] ( #containpermission-permissions ) , e.g. "Is this executable by any
22- users?"
23- - [ setting] ( #setpermission-permissions ) and
24- [ unsetting] ( #notpermission-permissions ) . Using bitwise operations (` | ` ,
25- ` & ` , ` ^ ` , ` ~ ` ) can be tedious and error-prone otherwise.
2621- [ inverting] ( #invertpermission ) . For example a
2722 [ ` umask ` ] ( https://linux.die.net/man/2/umask ) of ` 117 ` means new files will be
2823 created with ` 661 ` permissions.
@@ -42,7 +37,8 @@ using those strings.
4237<!-- eslint-disable handle-callback-err, node/prefer-global/process, no-sync -->
4338
4439``` js
45- // Retrieve a file's permission as an object instead of a number
40+ // Retrieve a file's permission as an object like
41+ // `{ user: { write: false, read: true, ... }, ... }` instead of a number
4642convert .object (fs .statSync (' /etc/passwd' ).mode )
4743
4844// Set a file's permission using `symbolic` notation instead of a number
@@ -54,7 +50,9 @@ fs.writeFile('/my/file', content, { mode: convert.number('a=r') })
5450// Disallow executing new files using `umask`
5551process .umask (convert .number (invert (' a-x' )))
5652
57- // Allow your library's users to use any Unix permission type as input
53+ // If your library takes Unix permissions as input, using
54+ // `unix-permissions` under the hood lets your users choose their
55+ // favorite Unix permissions type.
5856myLibrary .method ({ mode: ' a-wx' })
5957myLibrary .method ({ mode: ' 444' })
6058```
@@ -260,12 +258,15 @@ a+r
260258
261259Returns ` permission ` converted to another [ ` type ` ] ( #types ) .
262260
263- Note that [ ` symbolic ` ] ( #symbolic ) and [ ` object ` ] ( #object ) distinguish between
264- leaving permissions as is (omitting them or using ` undefined ` ) and unsetting
265- them (using ` - ` or ` false ` ). [ ` number ` ] ( #number ) and [ ` stat ` ] ( #stat ) do not
261+ Note that [ ` symbolic ` ] ( #symbolic ) and [ ` object ` ] ( #object ) distinguish between:
262+
263+ - leaving permissions as is (omitting them or using ` undefined ` )
264+ - unsetting them (using ` - ` or ` false ` ).
265+
266+ [ ` number ` ] ( #number ) and [ ` stat ` ] ( #stat ) do not
266267make this distinction. If you convert between them, you might lose this
267- information as we assume ` - ` and ` 0 ` in [ ` number ` ] ( #number ) and [ ` stat ` ] ( #stat )
268- mean "unset permissions". However you can use
268+ information as we assume ` 0 ` in [ ` number ` ] ( #number ) and ` - ` in
269+ [ ` stat ` ] ( #stat ) mean "unset permissions". However you can use
269270[ ` positive() ` ] ( #positivepermission ) to overcome this issue.
270271
271272<!-- eslint-disable line-comment-position, no-inline-comments -->
@@ -368,7 +369,7 @@ equal('o+x,o-w', 'o+x', 'o-w') // `false`
368369
369370Returns the result of setting ` permissions ` on ` permission ` .
370371
371- This is useful to avoid error-prone bitwise operations.
372+ This is useful to avoid error-prone bitwise operations ( ` | ` , ` & ` , ` ^ ` , ` ~ ` ) .
372373
373374This can also be used to remove special permissions using
374375` set(permission, 'a-st') ` since some functions like
@@ -427,7 +428,7 @@ invert('1660') // '0117'
427428
428429## ` min(permissions...) `
429430
430- Retrieve the lowest permissions among all argument .
431+ Retrieve the lowest permissions among all arguments .
431432
432433This does not return the lowest argument. Instead it returns a combination
433434of the lowest bits of all arguments.
0 commit comments