summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/node_modules/umask/README.md
blob: 80009ae709b2c5cc9a7468a63ed0fe9b701bfd60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# umask

Convert umask from string <-> number.

## Installation & Use

```
$ npm install -S umask

var umask = require('umask');

console.log(umask.toString(18));        // 0022

console.log(umask.fromString('0777'))   // 511
```

## API

### `toString( val )`

Converts `val` to a 0-padded octal string.  `val` is assumed to be a
Number in the correct range (0..511)

### `fromString( val, [cb] )`

Converts `val` to a Number that can be used as a umask.  `val` can
be of the following forms:

  * String containing octal number (leading 0)
  * String containing decimal number
  * Number

In all cases above, the value obtained is then converted to an integer and
checked against the legal `umask` range 0..511

`fromString` can be used as a simple converter, with no error feedback, by
omitting the optional callback argument `cb`:

```
   var mask = umask.fromString(val);

   // mask is now the umask descibed by val or
   // the default, 0022 (18 dec)
```

The callback arguments are `(err, val)` where `err` is either `null` or an
Error object and `val` is either the converted umask or the default umask, `0022`.

```
   umask.fromString(val, function (err, val) {
       if (err) {
          console.error("invalid umask: " + err.message)
       }

       /* do something with val */
   });
```

The callback, if provided, is always called **synchronously**.

### `validate( data, k, val )`

This is a validation function of the form expected by `nopt`.  If
`val` is a valid umask, the function returns true and sets `data[k]`.
If `val` is not a valid umask, the function returns false.

The `validate` function is stricter than `fromString`: it only accepts
Number or octal String values, and the String value must begin with `0`.
The `validate` function does **not** accept Strings containing decimal
numbers.

# Maintainer

Sam Mikes <smikes@cubane.com>

# License

MIT