3 Convert umask from string <-> number.
10 var umask = require('umask');
12 console.log(umask.toString(18)); // 0022
14 console.log(umask.fromString('0777')) // 511
21 Converts `val` to a 0-padded octal string. `val` is assumed to be a
22 Number in the correct range (0..511)
24 ### `fromString( val, [cb] )`
26 Converts `val` to a Number that can be used as a umask. `val` can
27 be of the following forms:
29 * String containing octal number (leading 0)
30 * String containing decimal number
33 In all cases above, the value obtained is then converted to an integer and
34 checked against the legal `umask` range 0..511
36 `fromString` can be used as a simple converter, with no error feedback, by
37 omitting the optional callback argument `cb`:
40 var mask = umask.fromString(val);
42 // mask is now the umask descibed by val or
43 // the default, 0022 (18 dec)
46 The callback arguments are `(err, val)` where `err` is either `null` or an
47 Error object and `val` is either the converted umask or the default umask, `0022`.
50 umask.fromString(val, function (err, val) {
52 console.error("invalid umask: " + err.message)
55 /* do something with val */
59 The callback, if provided, is always called **synchronously**.
61 ### `validate( data, k, val )`
63 This 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]`.
65 If `val` is not a valid umask, the function returns false.
67 The `validate` function is stricter than `fromString`: it only accepts
68 Number or octal String values, and the String value must begin with `0`.
69 The `validate` function does **not** accept Strings containing decimal
74 Sam Mikes <smikes@cubane.com>