• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-Sep-2020-

test/H03-May-2022-

.npmignoreH A D26-Oct-1985587 2921

ChangeLogH A D26-Oct-1985208 105

LICENSEH A D26-Oct-19851.1 KiB2317

README.mdH A D26-Oct-19851.8 KiB7851

package.jsonH A D20-Sep-20201.3 KiB6160

README.md

1# umask
2
3Convert umask from string <-> number.
4
5## Installation & Use
6
7```
8$ npm install -S umask
9
10var umask = require('umask');
11
12console.log(umask.toString(18));        // 0022
13
14console.log(umask.fromString('0777'))   // 511
15```
16
17## API
18
19### `toString( val )`
20
21Converts `val` to a 0-padded octal string.  `val` is assumed to be a
22Number in the correct range (0..511)
23
24### `fromString( val, [cb] )`
25
26Converts `val` to a Number that can be used as a umask.  `val` can
27be of the following forms:
28
29  * String containing octal number (leading 0)
30  * String containing decimal number
31  * Number
32
33In all cases above, the value obtained is then converted to an integer and
34checked against the legal `umask` range 0..511
35
36`fromString` can be used as a simple converter, with no error feedback, by
37omitting the optional callback argument `cb`:
38
39```
40   var mask = umask.fromString(val);
41
42   // mask is now the umask descibed by val or
43   // the default, 0022 (18 dec)
44```
45
46The callback arguments are `(err, val)` where `err` is either `null` or an
47Error object and `val` is either the converted umask or the default umask, `0022`.
48
49```
50   umask.fromString(val, function (err, val) {
51       if (err) {
52          console.error("invalid umask: " + err.message)
53       }
54
55       /* do something with val */
56   });
57```
58
59The callback, if provided, is always called **synchronously**.
60
61### `validate( data, k, val )`
62
63This is a validation function of the form expected by `nopt`.  If
64`val` is a valid umask, the function returns true and sets `data[k]`.
65If `val` is not a valid umask, the function returns false.
66
67The `validate` function is stricter than `fromString`: it only accepts
68Number or octal String values, and the String value must begin with `0`.
69The `validate` function does **not** accept Strings containing decimal
70numbers.
71
72# Maintainer
73
74Sam Mikes <smikes@cubane.com>
75
76# License
77
78MIT