Skip to content

Commit fec5d33

Browse files
committed
Fork the project as a library for programmatic usage only
* Rename the package to unix-permissions-lib * Expose ES, CJS and UMD exports, TypeScript types remain included * Remove the command-line interface together with the documentation and tests * Add VS Code settings
1 parent ba53b16 commit fec5d33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5265
-5459
lines changed

.all-contributorsrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"projectName": "unix-permissions",
2+
"projectName": "unix-permissions-lib",
33
"projectOwner": "ehmicky",
44
"repoType": "github",
55
"repoHost": "https://github.com",
@@ -21,6 +21,13 @@
2121
"ideas",
2222
"doc"
2323
]
24+
},
25+
{
26+
"login": "prantlf",
27+
"name": "Ferdinand Prantl",
28+
"contributions": [
29+
"build"
30+
]
2431
}
2532
],
2633
"contributorsPerLine": 7,

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ body:
4747
description: |
4848
Enter the following command in a terminal and copy/paste its output:
4949
```bash
50-
npx envinfo --system --binaries --browsers --npmPackages unix-permissions
50+
npx envinfo --system --binaries --browsers --npmPackages unix-permissions-lib
5151
```
5252
validations:
5353
required: true

.github/ISSUE_TEMPLATE/bug_types.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ body:
3333
description: |
3434
Enter the following command in a terminal and copy/paste its output:
3535
```bash
36-
npx envinfo --system --binaries --browsers --npmPackages unix-permissions typescript --npmGlobalPackages typescript
36+
npx envinfo --system --binaries --browsers --npmPackages unix-permissions-lib typescript --npmGlobalPackages typescript
3737
```
3838
validations:
3939
required: true

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"files.exclude": {
3+
"**/.git": true,
4+
"**/.DS_Store": true,
5+
"**/Thumbs.db": true,
6+
".eslintcache": true,
7+
"build": true,
8+
"dist": true
9+
}
10+
}

README.md

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
<img alt="unix-permissions logo" src="https://raw.githubusercontent.com/ehmicky/design/main/unix-permissions/unix-permissions.png" width="500"/>
44
</picture>
55

6-
[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/unix-permissions)
7-
[![Browsers](https://img.shields.io/badge/-Browsers-808080?logo=firefox&colorA=404040)](https://unpkg.com/unix-permissions?module)
6+
[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/unix-permissions-lib)
7+
[![Browsers](https://img.shields.io/badge/-Browsers-808080?logo=firefox&colorA=404040)](https://unpkg.com/unix-permissions-lib?module)
88
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts)
9-
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/unix-permissions)
10-
[![Minified size](https://img.shields.io/bundlephobia/minzip/unix-permissions?label&colorA=404040&colorB=808080&logo=webpack)](https://bundlephobia.com/package/unix-permissions)
11-
[![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon&colorA=404040&logoColor=9590F9)](https://fosstodon.org/@ehmicky)
12-
[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky)
9+
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/prantlf/unix-permissions)
10+
[![Minified size](https://img.shields.io/bundlephobia/minzip/unix-permissions-lib?label&colorA=404040&colorB=808080&logo=webpack)](https://bundlephobia.com/package/unix-permissions-lib)
1311

14-
Swiss Army knife for Unix permissions.
12+
Swiss Army knife for Unix permissions - a library for programmatic usage only.
13+
14+
This is a fork to be used as a library which offers ES, CJS and UMD module formats as exports. If you need only the ES export or want to use the command line tool, use the [original project](https://github.com/ehmicky/unix-permissions).
1515

1616
[Unix file permissions](https://en.wikipedia.org/wiki/File_system_permissions)
1717
can take many [shapes](#permission-types): [symbolic](docs/types.md#symbolic)
1818
(`ug+rw`), [octal](docs/types.md#octal) (`660`) or a
1919
[list of characters](docs/types.md#stat) (`drw-rw----`). This library enables
2020
using any of [these](#permission-types) (instead of being limited to a single
21-
one) with any [Node.js](#examples-javascript) or [CLI command](#examples-cli).
21+
one) with any [Node.js](#examples-javascript).
2222

2323
This library can also perform operations on Unix permissions such as:
2424

@@ -44,12 +44,10 @@ using those strings.
4444

4545
# Examples
4646

47-
In JavaScript:
48-
4947
<!-- eslint-disable n/no-sync -->
5048

5149
```js
52-
import { convert } from 'unix-permissions'
50+
import { convert } from 'unix-permissions-lib'
5351

5452
// Retrieve a file's permission as an object like
5553
// `{ user: { write: false, read: true, ... }, ... }` instead of a number
@@ -65,33 +63,24 @@ fs.writeFile('/my/file', content, { mode: convert.number('a=r') })
6563
process.umask(convert.number(invert('a-x')))
6664

6765
// If your library takes Unix permissions as input, using
68-
// `unix-permissions` under the hood lets your users choose their
66+
// `unix-permissions-lib` under the hood lets your users choose their
6967
// favorite Unix permissions type.
7068
myLibrary.method({ mode: 'a-wx' })
7169
myLibrary.method({ mode: '444' })
7270
```
7371

74-
On the command line:
75-
76-
```bash
77-
$ stat -c "%a" /etc/passwd
78-
644
79-
80-
$ unix-permissions convert.symbolic "$(stat -c "%a" /etc/passwd)"
81-
u=rw,go=r
82-
```
83-
8472
# Demo
8573

8674
You can try this library:
8775

88-
- either directly [in your browser](https://repl.it/@ehmicky/unix-permissions).
76+
- either directly
77+
[in your browser](https://repl.it/@prantlf/unix-permissions-lib).
8978
- or by executing the [`examples` files](examples/README.md) in a terminal.
9079

9180
# Install
9281

9382
```bash
94-
npm install unix-permissions
83+
npm install unix-permissions-lib
9584
```
9685

9786
This package works in both Node.js >=14.18.0 and
@@ -106,7 +95,7 @@ not CommonJS.
10695
# Usage (JavaScript)
10796

10897
```js
109-
import { convert } from 'unix-permissions'
98+
import { convert } from 'unix-permissions-lib'
11099

111100
// `permission` will be set to `rw-rw----`
112101
const permission = convert.stat('660')
@@ -115,16 +104,6 @@ const permission = convert.stat('660')
115104
Several methods other than `convert` are available but they mostly follow the
116105
same pattern. Permission strings are passed as input and returned as output.
117106

118-
# Usage (CLI)
119-
120-
```bash
121-
$ unix-permissions convert.stat 660
122-
rw-rw----
123-
```
124-
125-
The same methods as in JavaScript are available. Exit code will be `1` if an
126-
error occurred, e.g. if the permission syntax is invalid.
127-
128107
# Permission types
129108

130109
You can use any of the following permission types as input. You can also

docs/API.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# API
22

3-
The following methods are available both in
4-
[JavaScript](../README.md#usage-javascript) and on the
5-
[command line](../README.md#usage-cli).
3+
The following methods are available in
4+
[JavaScript](../README.md#usage-javascript).
65

76
You can try all the examples below:
87

9-
- either directly [in your browser](https://repl.it/@ehmicky/unix-permissions).
8+
- either directly
9+
[in your browser](https://repl.it/@prantlf/unix-permissions-lib).
1010
- or by executing the [`examples` files](../examples/README.md) in a terminal.
1111

1212
All methods (except [`type()`](#typepermission)) throw an exception if the
@@ -30,7 +30,7 @@ mean "unset permissions". However you can use
3030
[`positive()`](#positivepermission) to overcome this issue.
3131

3232
```js
33-
import { convert } from 'unix-permissions'
33+
import { convert } from 'unix-permissions-lib'
3434

3535
console.log(convert.symbolic('111')) // 'a=x'
3636
console.log(positive(convert.symbolic('111'))) // 'a+x'
@@ -49,7 +49,7 @@ try {
4949
Returns the `permission`'s [`type`](types.md) or `'invalid'`.
5050

5151
```js
52-
import { type } from 'unix-permissions'
52+
import { type } from 'unix-permissions-lib'
5353

5454
console.log(type('1')) // 'octal'
5555
console.log(type(1)) // 'number'
@@ -64,7 +64,7 @@ Normalizes a `permission` to its canonical shape.
6464
Throws an exception if `permission` is invalid.
6565

6666
```js
67-
import { normalize } from 'unix-permissions'
67+
import { normalize } from 'unix-permissions-lib'
6868

6969
console.log(normalize('1')) // '0001'
7070
console.log(normalize('g+x,o+x')) // 'go+x'
@@ -86,7 +86,7 @@ Removes all negative permissions. See
8686
explanation.
8787

8888
```js
89-
import { positive, invert } from 'unix-permissions'
89+
import { positive, invert } from 'unix-permissions-lib'
9090

9191
console.log(positive('o+x,o-rw')) // 'o+x'
9292
console.log(positive('o=x')) // 'o+x'
@@ -99,10 +99,10 @@ console.log(invert(positive('660'))) // '-0660'
9999

100100
Tests whether `permission` includes `permissions`.
101101

102-
Returns `true` or `false` or (on the CLI) use the exit code `0` or `1`.
102+
Returns `true` or `false`.
103103

104104
```js
105-
import { contain } from 'unix-permissions'
105+
import { contain } from 'unix-permissions-lib'
106106

107107
console.log(contain('--x--x--x', 'a=x')) // `true`
108108
console.log(contain('--x--x--x', 'a+x')) // `true`
@@ -120,10 +120,10 @@ console.log(contain('o+x,o-w', 'o+x', 'o-w')) // `true`
120120

121121
Tests whether `permission` equals exactly `permissions`.
122122

123-
Returns `true` or `false` or (on the CLI) use the exit code `0` or `1`.
123+
Returns `true` or `false`.
124124

125125
```js
126-
import { equal } from 'unix-permissions'
126+
import { equal } from 'unix-permissions-lib'
127127

128128
console.log(equal('--x--x--x', 'a=x')) // `true`
129129
console.log(equal('--x--x--x', 'a+x')) // `false`
@@ -148,7 +148,7 @@ This can also be used to remove special permissions using
148148
[`umask`](https://linux.die.net/man/2/umask) do not allow them.
149149

150150
```js
151-
import { set } from 'unix-permissions'
151+
import { set } from 'unix-permissions-lib'
152152

153153
console.log(set('---------', 'a+x')) // '--x--x--x'
154154
console.log(set('---------', 'a+x', 'a+r')) // 'r-xr-xr-x'
@@ -165,7 +165,7 @@ This can be used in combination with `set()` to unset `permissions` instead of
165165
setting them.
166166

167167
```js
168-
import { not, set } from 'unix-permissions'
168+
import { not, set } from 'unix-permissions-lib'
169169

170170
console.log(not('u+xs')) // 'u-xs'
171171
console.log(not('u-xs')) // 'u+xs'
@@ -187,7 +187,7 @@ For example a [`umask`](https://linux.die.net/man/2/umask) of `117` means new
187187
files will be created with `661` permissions.
188188

189189
```js
190-
import { invert } from 'unix-permissions'
190+
import { invert } from 'unix-permissions-lib'
191191

192192
console.log(invert('u+xs')) // 'u-x'
193193
console.log(invert('u-xs')) // 'u+x'
@@ -209,7 +209,7 @@ This can be useful if you are looking for the lowest permission of a several
209209
files, e.g. during a directory recursion.
210210

211211
```js
212-
import { min } from 'unix-permissions'
212+
import { min } from 'unix-permissions-lib'
213213

214214
console.log(min('404', '440', '402')) // '0400'
215215
```
@@ -219,7 +219,7 @@ console.log(min('404', '440', '402')) // '0400'
219219
Inverse of [`min()`](#minpermissions).
220220

221221
```js
222-
import { max } from 'unix-permissions'
222+
import { max } from 'unix-permissions-lib'
223223

224224
console.log(max('404', '440', '402')) // '0446'
225225
```

docs/types.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ them.
66

77
You can try all the examples below:
88

9-
- either directly [in your browser](https://repl.it/@ehmicky/unix-permissions).
9+
- either directly
10+
[in your browser](https://repl.it/@prantlf/unix-permissions-lib).
1011
- or by executing the [`examples` files](../examples/README.md) in a terminal.
1112

1213
## octal
@@ -28,7 +29,7 @@ An operator can be prepended:
2829
- `-`: unset specified permissions
2930

3031
```js
31-
import { convert } from 'unix-permissions'
32+
import { convert } from 'unix-permissions-lib'
3233

3334
console.log(convert.stat('720')) // 'rwx-w----'
3435
console.log(convert.stat('7000')) // '--S--S--T'
@@ -49,12 +50,10 @@ It is the same as `octal` except:
4950

5051
- as a decimal number.
5152
- no operator can be used.
52-
- it can be used as input in [JavaScript](../README.md#usage-javascript) but not
53-
on the [command line](../README.md#usage-cli), where all numbers should be in
54-
[`octal`](#octal) form instead.
53+
- it can be used as input in [JavaScript](../README.md#usage-javascript).
5554

5655
```js
57-
import { convert } from 'unix-permissions'
56+
import { convert } from 'unix-permissions-lib'
5857

5958
console.log(convert.stat(0)) // '---------'
6059
console.log(convert.stat(1)) // '--------x'
@@ -76,7 +75,7 @@ Optionally a first character can be specified to indicate the file type (e.g.
7675
`d` for directories).
7776

7877
```js
79-
import { convert } from 'unix-permissions'
78+
import { convert } from 'unix-permissions-lib'
8079

8180
console.log(convert.octal('--------x')) // '0001'
8281
console.log(convert.octal('--x--x--x')) // '0111'
@@ -105,7 +104,7 @@ Several groups can be specified using a comma-separated list like `g+x,o+r`.
105104
User classes can be concatenated like `go+x`.
106105

107106
```js
108-
import { convert } from 'unix-permissions'
107+
import { convert } from 'unix-permissions-lib'
109108

110109
console.log(convert.octal('o+wx')) // '+0003'
111110
console.log(convert.octal('o=wx')) // '0003'
@@ -137,7 +136,7 @@ The values can be `true`, `false` or `undefined`. `undefined` leaves permissions
137136
as is while `false` unsets them.
138137

139138
```js
140-
import { convert } from 'unix-permissions'
139+
import { convert } from 'unix-permissions-lib'
141140

142141
console.log(convert.symbolic({ others: { read: true, execute: true } }))
143142
// 'o+rx'
@@ -159,9 +158,3 @@ console.log(
159158
)
160159
// 'ug+s,o+t'
161160
```
162-
163-
On the command line:
164-
165-
```bash
166-
unix-permissions convert.symbolic '{ "all": { "read": true } }' # a+r
167-
```

0 commit comments

Comments
 (0)