@ohos-ports/stdlib-process 0.0.0-stage → 0.4.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +1 -0
  3. package/README.md +220 -2
  4. package/SECURITY.md +5 -0
  5. package/argv/README.md +104 -0
  6. package/argv/docs/repl.txt +22 -0
  7. package/argv/docs/types/index.d.ts +33 -0
  8. package/argv/docs/types/test.ts +28 -0
  9. package/argv/lib/browser.js +28 -0
  10. package/argv/lib/index.js +40 -0
  11. package/argv/lib/main.js +43 -0
  12. package/argv/package.json +70 -0
  13. package/chdir/README.md +124 -0
  14. package/chdir/docs/repl.txt +25 -0
  15. package/chdir/docs/types/index.d.ts +42 -0
  16. package/chdir/docs/types/test.ts +45 -0
  17. package/chdir/lib/index.js +42 -0
  18. package/chdir/lib/main.js +52 -0
  19. package/chdir/lib/polyfill.js +42 -0
  20. package/chdir/package.json +73 -0
  21. package/cwd/README.md +140 -0
  22. package/cwd/bin/cli +60 -0
  23. package/cwd/docs/repl.txt +17 -0
  24. package/cwd/docs/types/index.d.ts +35 -0
  25. package/cwd/docs/types/test.ts +33 -0
  26. package/cwd/docs/usage.txt +8 -0
  27. package/cwd/etc/cli_opts.json +14 -0
  28. package/cwd/lib/index.js +40 -0
  29. package/cwd/lib/main.js +44 -0
  30. package/cwd/lib/polyfill.js +40 -0
  31. package/cwd/package.json +75 -0
  32. package/docs/types/index.d.ts +225 -0
  33. package/env/README.md +104 -0
  34. package/env/docs/repl.txt +12 -0
  35. package/env/docs/types/index.d.ts +32 -0
  36. package/env/docs/types/test.ts +28 -0
  37. package/env/lib/browser.js +28 -0
  38. package/env/lib/index.js +39 -0
  39. package/env/lib/main.js +42 -0
  40. package/env/package.json +72 -0
  41. package/exec-path/README.md +90 -0
  42. package/exec-path/docs/repl.txt +13 -0
  43. package/exec-path/docs/types/index.d.ts +36 -0
  44. package/exec-path/docs/types/test.ts +28 -0
  45. package/exec-path/lib/browser.js +23 -0
  46. package/exec-path/lib/index.js +55 -0
  47. package/exec-path/lib/main.js +46 -0
  48. package/exec-path/package.json +72 -0
  49. package/getegid/README.md +107 -0
  50. package/getegid/docs/repl.txt +20 -0
  51. package/getegid/docs/types/index.d.ts +38 -0
  52. package/getegid/docs/types/test.ts +33 -0
  53. package/getegid/lib/index.js +39 -0
  54. package/getegid/lib/main.js +45 -0
  55. package/getegid/lib/native.js +44 -0
  56. package/getegid/lib/polyfill.js +40 -0
  57. package/getegid/package.json +76 -0
  58. package/geteuid/README.md +111 -0
  59. package/geteuid/docs/repl.txt +20 -0
  60. package/geteuid/docs/types/index.d.ts +38 -0
  61. package/geteuid/docs/types/test.ts +33 -0
  62. package/geteuid/lib/index.js +39 -0
  63. package/geteuid/lib/main.js +45 -0
  64. package/geteuid/lib/native.js +44 -0
  65. package/geteuid/lib/polyfill.js +40 -0
  66. package/geteuid/package.json +76 -0
  67. package/getgid/README.md +107 -0
  68. package/getgid/docs/repl.txt +19 -0
  69. package/getgid/docs/types/index.d.ts +38 -0
  70. package/getgid/docs/types/test.ts +33 -0
  71. package/getgid/lib/index.js +39 -0
  72. package/getgid/lib/main.js +45 -0
  73. package/getgid/lib/native.js +44 -0
  74. package/getgid/lib/polyfill.js +40 -0
  75. package/getgid/package.json +75 -0
  76. package/getuid/README.md +111 -0
  77. package/getuid/docs/repl.txt +19 -0
  78. package/getuid/docs/types/index.d.ts +38 -0
  79. package/getuid/docs/types/test.ts +33 -0
  80. package/getuid/lib/index.js +39 -0
  81. package/getuid/lib/main.js +45 -0
  82. package/getuid/lib/native.js +44 -0
  83. package/getuid/lib/polyfill.js +40 -0
  84. package/getuid/package.json +75 -0
  85. package/lib/index.js +150 -0
  86. package/node-version/README.md +135 -0
  87. package/node-version/bin/cli +60 -0
  88. package/node-version/docs/repl.txt +12 -0
  89. package/node-version/docs/types/index.d.ts +42 -0
  90. package/node-version/docs/types/test.ts +28 -0
  91. package/node-version/docs/usage.txt +8 -0
  92. package/node-version/etc/cli_opts.json +14 -0
  93. package/node-version/lib/browser.js +23 -0
  94. package/node-version/lib/index.js +60 -0
  95. package/node-version/lib/main.js +43 -0
  96. package/node-version/lib/process.js +28 -0
  97. package/node-version/package.json +73 -0
  98. package/package.json +121 -4
  99. package/read-stdin/README.md +152 -0
  100. package/read-stdin/docs/types/index.d.ts +108 -0
  101. package/read-stdin/docs/types/test.ts +73 -0
  102. package/read-stdin/lib/browser.js +66 -0
  103. package/read-stdin/lib/index.js +47 -0
  104. package/read-stdin/lib/main.js +159 -0
  105. package/read-stdin/package.json +67 -0
  106. package/umask/README.md +281 -0
  107. package/umask/bin/cli +84 -0
  108. package/umask/docs/repl.txt +133 -0
  109. package/umask/docs/types/index.d.ts +69 -0
  110. package/umask/docs/types/test.ts +62 -0
  111. package/umask/docs/usage.txt +9 -0
  112. package/umask/etc/cli_opts.json +22 -0
  113. package/umask/lib/browser.js +133 -0
  114. package/umask/lib/from_symbolic.js +218 -0
  115. package/umask/lib/index.js +40 -0
  116. package/umask/lib/main.js +128 -0
  117. package/umask/lib/octal_codes.json +10 -0
  118. package/umask/lib/to_symbolic.js +57 -0
  119. package/umask/package.json +78 -0
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isString = require( '@ohos-ports/stdlib-assert/is-string' ).isPrimitive;
24
+ var isNonNegativeInteger = require( '@ohos-ports/stdlib-assert/is-nonnegative-integer' ).isPrimitive;
25
+ var isBoolean = require( '@ohos-ports/stdlib-assert/is-boolean' ).isPrimitive;
26
+ var isObject = require( '@ohos-ports/stdlib-assert/is-plain-object' );
27
+ var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
28
+ var format = require( '@ohos-ports/stdlib-string/format' );
29
+ var toSymbolic = require( './to_symbolic.js' );
30
+ var fromSymbolic = require( './from_symbolic.js' );
31
+
32
+
33
+ // VARIABLES //
34
+
35
+ var MASK = 0|0; // asm type annotation
36
+
37
+
38
+ // MAIN //
39
+
40
+ /**
41
+ * Get/set the process mask.
42
+ *
43
+ * ## Notes
44
+ *
45
+ * - If provided a mask, the function sets the current mask and returns the previous process mask. Otherwise, the function returns the current process mask.
46
+ * - Browser environments do not support process masks. Hence, this function always returns either `0` or `u=rwx,g=rwx,o=rwx`.
47
+ *
48
+ * @param {(NonNegativeInteger|string)} [mask] - mask
49
+ * @param {Object} [options] - options
50
+ * @param {boolean} [options.symbolic] - boolean indicating whether to return a mask using symbolic notation
51
+ * @throws {TypeError} must provide either a string, nonnegative integer, or an options object
52
+ * @throws {TypeError} must provide valid options
53
+ * @throws {Error} must provide a parseable expression mask
54
+ * @returns {(NonNegativeInteger|string)} process mask
55
+ *
56
+ * @example
57
+ * var mask = umask();
58
+ * // returns 0
59
+ */
60
+ function umask() {
61
+ var options;
62
+ var nargs;
63
+ var mask;
64
+ var opts;
65
+ var arg;
66
+
67
+ nargs = arguments.length;
68
+ if ( nargs === 0 ) {
69
+ return MASK;
70
+ }
71
+ opts = {};
72
+ arg = arguments[ 0 ];
73
+ if ( nargs === 1 ) {
74
+ if ( isString( arg ) ) {
75
+ mask = fromSymbolic( MASK, arg );
76
+ if ( mask instanceof Error ) {
77
+ throw mask;
78
+ }
79
+ return MASK;
80
+ }
81
+ if ( isNonNegativeInteger( arg ) ) {
82
+ // Easy case where we use the built-in function to set the mask and return its return value:
83
+ return MASK;
84
+ }
85
+ if ( isObject( arg ) ) {
86
+ if ( hasOwnProp( arg, 'symbolic' ) ) {
87
+ opts.symbolic = arg.symbolic;
88
+ if ( !isBoolean( opts.symbolic ) ) {
89
+ throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
90
+ }
91
+ }
92
+ mask = MASK;
93
+ if ( opts.symbolic ) {
94
+ mask = toSymbolic( mask );
95
+ }
96
+ return mask;
97
+ }
98
+ throw new TypeError( format( 'invalid argument. Must provide either a string, nonnegative integer, or an options object. Value: `%s`.', arg ) );
99
+ }
100
+ options = arguments[ 1 ];
101
+ if ( !isObject( options ) ) {
102
+ throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
103
+ }
104
+ if ( hasOwnProp( options, 'symbolic' ) ) {
105
+ opts.symbolic = options.symbolic;
106
+ if ( !isBoolean( opts.symbolic ) ) {
107
+ throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
108
+ }
109
+ }
110
+ if ( isString( arg ) ) {
111
+ mask = fromSymbolic( MASK, arg );
112
+ if ( mask instanceof Error ) {
113
+ throw mask;
114
+ }
115
+ } else if ( isNonNegativeInteger( arg ) ) {
116
+ mask = arg;
117
+ } else {
118
+ throw new TypeError( format( 'invalid argument. First argument must be either a string or nonnegative integer. Value: `%s`.', arg ) );
119
+ }
120
+ // Set the mask:
121
+ mask = MASK;
122
+
123
+ // Determine how to format the output value:
124
+ if ( opts.symbolic ) {
125
+ mask = toSymbolic( mask );
126
+ }
127
+ return mask;
128
+ }
129
+
130
+
131
+ // EXPORTS //
132
+
133
+ module.exports = umask;
@@ -0,0 +1,218 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var format = require( '@ohos-ports/stdlib-string/format' );
24
+ var lpad = require( '@ohos-ports/stdlib-string/left-pad' );
25
+
26
+
27
+ // VARIABLES //
28
+
29
+ // Regular expression to parse a mask expression:
30
+ var RE_MASK_EXPRESSION = /^(u{0,1}g{0,1}o{0,1}a{0,1}|)([+\-=])(r{0,1}w{0,1}x{0,1})$/;
31
+
32
+ // Table of permission bit mask offsets:
33
+ var PERMS = {
34
+ 'r': 2, // read
35
+ 'w': 1, // write
36
+ 'x': 0 // execute
37
+ };
38
+
39
+ // Table of class indices in the octal format (e.g., `0o0077`):
40
+ var WHO = {
41
+ 's': 0, // special mode (ignored; see http://man7.org/linux/man-pages/man2/umask.2.html)
42
+ 'u': 1, // user
43
+ 'g': 2, // group
44
+ 'o': 3 // other/non-group
45
+ };
46
+
47
+
48
+ // FUNCTIONS //
49
+
50
+ /**
51
+ * Returns a bit mask.
52
+ *
53
+ * @private
54
+ * @param {NonNegativeInteger} offset - bit offset (right-to-left)
55
+ * @returns {NonNegativeInteger} bit mask
56
+ *
57
+ * @example
58
+ * var y = bitMask( 3 );
59
+ * // returns 8
60
+ */
61
+ function bitMask( offset ) {
62
+ return ( 1 << offset )>>>0; // asm type annotation
63
+ }
64
+
65
+ /**
66
+ * Sets a bit.
67
+ *
68
+ * @private
69
+ * @param {NonNegativeInteger} value - value
70
+ * @param {NonNegativeInteger} offset - bit offset (right-to-left)
71
+ * @returns {NonNegativeInteger} updated value
72
+ *
73
+ * @example
74
+ * var y = setBit( 8, 2 );
75
+ */
76
+ function setBit( value, offset ) {
77
+ return ( value | bitMask( offset ) )>>>0; // asm type annotation
78
+ }
79
+
80
+ /**
81
+ * Clears a bit.
82
+ *
83
+ * @private
84
+ * @param {NonNegativeInteger} value - value
85
+ * @param {NonNegativeInteger} offset - bit offset (right-to-left)
86
+ * @returns {NonNegativeInteger} updated value
87
+ */
88
+ function clearBit( value, offset ) {
89
+ return ( value & ~bitMask( offset ) )>>>0; // asm type annotation
90
+ }
91
+
92
+
93
+ // MAIN //
94
+
95
+ /**
96
+ * Converts a mask expression in symbolic notation to an integer.
97
+ *
98
+ * @private
99
+ * @param {NonNegativeInteger} mask - current mask
100
+ * @param {string} expr - mask expression
101
+ * @returns {(NonNegativeInteger|Error)} integer mask or parse error
102
+ */
103
+ function fromSymbolic( mask, expr ) {
104
+ var digits;
105
+ var parts;
106
+ var perm;
107
+ var who;
108
+ var tmp;
109
+ var idx;
110
+ var op;
111
+ var w;
112
+ var o;
113
+ var i;
114
+ var j;
115
+ var k;
116
+
117
+ // Split the mask into octal digits (e.g., [ '0', '0', '7', '7' ]):
118
+ digits = lpad( mask.toString( 8 ), 4, '0' ).split( '' );
119
+
120
+ // Convert each octal digit to an integer value:
121
+ for ( i = 0; i < digits.length; i++ ) {
122
+ digits[ i ] = parseInt( digits[ i ], 10 );
123
+ }
124
+
125
+ // See if we can easily split the mask into separate mask expressions (e.g., `u+x,g=rw,o=` => [ 'u+x', 'g=rw', 'o=' ] ):
126
+ parts = expr.split( ',' );
127
+
128
+ // For each expression, split into "class", "operator", and "symbols" and update the mask octal digits:
129
+ for ( i = 0; i < parts.length; i++ ) {
130
+ tmp = parts[ i ].match( RE_MASK_EXPRESSION );
131
+ if ( tmp === null ) {
132
+ return new Error( format( 'invalid argument. Unable to parse mask expression. Ensure the expression is properly formatted, only uses the class letters "u", "g", "o", and "a", only uses the operators "+", "-", and "=", and only uses the permission symbols "r", "w", and "x". Value: `%s`.', expr ) );
133
+ }
134
+ // Extract the expression parts:
135
+ who = tmp[ 1 ];
136
+ if ( who === '' ) {
137
+ // If a user class is not specified (e.g., `+x`), "ugo" (user, group, other) is implied...
138
+ who = 'ugo';
139
+ } else {
140
+ // Replace `a` (all) user class letter with "ugo" (user, group, other) equivalent...
141
+ w = '';
142
+ for ( k = 0; k < who.length; k++ ) {
143
+ if ( who[ k ] === 'a' ) {
144
+ w += 'ugo';
145
+ } else {
146
+ w += who[ k ];
147
+ }
148
+ }
149
+ who = w;
150
+ }
151
+ op = tmp[ 2 ];
152
+ perm = tmp[ 3 ];
153
+
154
+ // NOTE: the algorithm below is from the perspective of the mask. If implemented for, say, `chmod`, the "disabling"/"enabling" logic would be reversed. Recall that a "1" in the mask, serves to **disable** a permission setting, not enable.
155
+
156
+ // Disable permissions...
157
+ if ( op === '-' ) {
158
+ if ( perm === '' ) {
159
+ // The `-` operation by itself does not change any bits...
160
+ continue;
161
+ }
162
+ for ( j = 0; j < perm.length; j++ ) {
163
+ o = PERMS[ perm[j] ];
164
+ for ( k = 0; k < who.length; k++ ) {
165
+ idx = WHO[ who[k] ];
166
+ digits[ idx ] = setBit( digits[ idx ], o ); // to disable, we flip on mask bits
167
+ }
168
+ }
169
+ }
170
+ // Enable permissions...
171
+ else if ( op === '+' ) {
172
+ if ( perm === '' ) {
173
+ // The `+` operation by itself does not change any bits...
174
+ continue;
175
+ }
176
+ for ( j = 0; j < perm.length; j++ ) {
177
+ o = PERMS[ perm[j] ];
178
+ for ( k = 0; k < who.length; k++ ) {
179
+ idx = WHO[ who[k] ];
180
+ digits[ idx ] = clearBit( digits[ idx ], o ); // to enable, we clear mask bits
181
+ }
182
+ }
183
+ }
184
+ // Disable all permissions by flipping on all permission mask bits...
185
+ else if ( perm === '' ) { // op === '='
186
+ for ( k = 0; k < who.length; k++ ) {
187
+ idx = WHO[ who[k] ];
188
+ digits[ idx ] = 7;
189
+ }
190
+ }
191
+ // Explicitly set permissions...
192
+ else { // op === '='
193
+ // First, disable all permissions by flipping on all permission mask bits...
194
+ for ( k = 0; k < who.length; k++ ) {
195
+ idx = WHO[ who[k] ];
196
+ digits[ idx ] = 7;
197
+ }
198
+ // Then, explicitly enable permissions by clearing mask bits...
199
+ for ( j = 0; j < perm.length; j++ ) {
200
+ o = PERMS[ perm[j] ];
201
+ for ( k = 0; k < who.length; k++ ) {
202
+ idx = WHO[ who[k] ];
203
+ digits[ idx ] = clearBit( digits[ idx ], o );
204
+ }
205
+ }
206
+ }
207
+ }
208
+ // Convert the digits to an integer value...
209
+ for ( i = 0; i < digits.length; i++ ) {
210
+ digits[ i ] = digits[ i ].toString();
211
+ }
212
+ return parseInt( digits.join( '' ), 8 );
213
+ }
214
+
215
+
216
+ // EXPORTS //
217
+
218
+ module.exports = fromSymbolic;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Get/set the process mask.
23
+ *
24
+ * @module @stdlib/process/umask
25
+ *
26
+ * @example
27
+ * var umask = require( '@ohos-ports/stdlib-process/umask' );
28
+ *
29
+ * var mask = umask();
30
+ * // returns <number>
31
+ */
32
+
33
+ // MODULES //
34
+
35
+ var main = require( './main.js' );
36
+
37
+
38
+ // EXPORTS //
39
+
40
+ module.exports = main;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var proc = require( 'process' );
24
+ var isString = require( '@ohos-ports/stdlib-assert/is-string' ).isPrimitive;
25
+ var isNonNegativeInteger = require( '@ohos-ports/stdlib-assert/is-nonnegative-integer' ).isPrimitive;
26
+ var isBoolean = require( '@ohos-ports/stdlib-assert/is-boolean' ).isPrimitive;
27
+ var isObject = require( '@ohos-ports/stdlib-assert/is-plain-object' );
28
+ var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
29
+ var format = require( '@ohos-ports/stdlib-string/format' );
30
+ var toSymbolic = require( './to_symbolic.js' );
31
+ var fromSymbolic = require( './from_symbolic.js' );
32
+
33
+
34
+ // MAIN //
35
+
36
+ /**
37
+ * Get/set the process mask.
38
+ *
39
+ * ## Notes
40
+ *
41
+ * - If provided a mask, the function sets the current mask and returns the previous process mask. Otherwise, the function returns the current process mask.
42
+ *
43
+ * @param {(NonNegativeInteger|string)} [mask] - mask
44
+ * @param {Object} [options] - options
45
+ * @param {boolean} [options.symbolic] - boolean indicating whether to return a mask using symbolic notation
46
+ * @throws {TypeError} must provide either a string, nonnegative integer, or an options object
47
+ * @throws {TypeError} must provide valid options
48
+ * @throws {Error} must provide a parseable expression mask
49
+ * @returns {(NonNegativeInteger|string)} process mask
50
+ *
51
+ * @example
52
+ * var mask = umask();
53
+ * // returns <number>
54
+ */
55
+ function umask() {
56
+ var options;
57
+ var nargs;
58
+ var mask;
59
+ var opts;
60
+ var arg;
61
+
62
+ nargs = arguments.length;
63
+ if ( nargs === 0 ) {
64
+ return proc.umask();
65
+ }
66
+ opts = {};
67
+ arg = arguments[ 0 ];
68
+ if ( nargs === 1 ) {
69
+ if ( isString( arg ) ) {
70
+ mask = fromSymbolic( proc.umask(), arg );
71
+ if ( mask instanceof Error ) {
72
+ throw mask;
73
+ }
74
+ return proc.umask( mask );
75
+ }
76
+ if ( isNonNegativeInteger( arg ) ) {
77
+ // Easy case where we use the built-in function to set the mask and return its return value:
78
+ return proc.umask( arg );
79
+ }
80
+ if ( isObject( arg ) ) {
81
+ if ( hasOwnProp( arg, 'symbolic' ) ) {
82
+ opts.symbolic = arg.symbolic;
83
+ if ( !isBoolean( opts.symbolic ) ) {
84
+ throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
85
+ }
86
+ }
87
+ mask = proc.umask();
88
+ if ( opts.symbolic ) {
89
+ mask = toSymbolic( mask );
90
+ }
91
+ return mask;
92
+ }
93
+ throw new TypeError( format( 'invalid argument. Must provide either a string, nonnegative integer, or an options object. Value: `%s`.', arg ) );
94
+ }
95
+ options = arguments[ 1 ];
96
+ if ( !isObject( options ) ) {
97
+ throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
98
+ }
99
+ if ( hasOwnProp( options, 'symbolic' ) ) {
100
+ opts.symbolic = options.symbolic;
101
+ if ( !isBoolean( opts.symbolic ) ) {
102
+ throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'symbolic', opts.symbolic ) );
103
+ }
104
+ }
105
+ if ( isString( arg ) ) {
106
+ mask = fromSymbolic( proc.umask(), arg );
107
+ if ( mask instanceof Error ) {
108
+ throw mask;
109
+ }
110
+ } else if ( isNonNegativeInteger( arg ) ) {
111
+ mask = arg;
112
+ } else {
113
+ throw new TypeError( format( 'invalid argument. First argument must be either a string or nonnegative integer. Value: `%s`.', arg ) );
114
+ }
115
+ // Set the mask:
116
+ mask = proc.umask( mask );
117
+
118
+ // Determine how to format the output value:
119
+ if ( opts.symbolic ) {
120
+ mask = toSymbolic( mask );
121
+ }
122
+ return mask;
123
+ }
124
+
125
+
126
+ // EXPORTS //
127
+
128
+ module.exports = umask;
@@ -0,0 +1,10 @@
1
+ {
2
+ "0": "rwx",
3
+ "1": "rw",
4
+ "2": "rx",
5
+ "3": "r",
6
+ "4": "wx",
7
+ "5": "w",
8
+ "6": "x",
9
+ "7": ""
10
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var lpad = require( '@ohos-ports/stdlib-string/left-pad' );
24
+ var OCTAL_CODES = require( './octal_codes.json' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Converts an integer mask to symbolic notation.
31
+ *
32
+ * @private
33
+ * @param {NonNegativeInteger} mask - integer mask
34
+ * @returns {string} mask in symbolic notation
35
+ */
36
+ function toSymbolic( mask ) {
37
+ var out;
38
+
39
+ // Convert the mask to a four-digit octal string representation (e.g., 0077):
40
+ mask = mask.toString( 8 );
41
+ mask = lpad( mask, 4, '0' );
42
+
43
+ // For each digit, get the permissions: (NOTE: we skip the special modes digit, as only the file permission bits of the mask are used; see http://man7.org/linux/man-pages/man2/umask.2.html)
44
+ out = '';
45
+ out += 'u='+OCTAL_CODES[ mask[1] ];
46
+ out += ',';
47
+ out += 'g='+OCTAL_CODES[ mask[2] ];
48
+ out += ',';
49
+ out += 'o='+OCTAL_CODES[ mask[3] ];
50
+
51
+ return out;
52
+ }
53
+
54
+
55
+ // EXPORTS //
56
+
57
+ module.exports = toSymbolic;
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@stdlib/process/umask",
3
+ "version": "0.0.0",
4
+ "description": "Get/set the process mask.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "bin": {
17
+ "umask": "./bin/cli"
18
+ },
19
+ "main": "./lib",
20
+ "browser": {
21
+ "./lib": "./lib/browser.js",
22
+ "process": "process/"
23
+ },
24
+ "directories": {
25
+ "benchmark": "./benchmark",
26
+ "doc": "./docs",
27
+ "example": "./examples",
28
+ "lib": "./lib",
29
+ "scripts": "./scripts",
30
+ "test": "./test"
31
+ },
32
+ "types": "./docs/types",
33
+ "scripts": {},
34
+ "homepage": "https://github.com/stdlib-js/stdlib",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git://github.com/stdlib-js/stdlib.git"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/stdlib-js/stdlib/issues"
41
+ },
42
+ "dependencies": {},
43
+ "devDependencies": {},
44
+ "engines": {
45
+ "node": ">=0.10.0",
46
+ "npm": ">2.7.0"
47
+ },
48
+ "os": [
49
+ "aix",
50
+ "darwin",
51
+ "freebsd",
52
+ "linux",
53
+ "macos",
54
+ "openbsd",
55
+ "sunos",
56
+ "win32",
57
+ "windows",
58
+ "openharmony"
59
+ ],
60
+ "keywords": [
61
+ "stdlib",
62
+ "stdutils",
63
+ "stdutil",
64
+ "utilities",
65
+ "utility",
66
+ "utils",
67
+ "util",
68
+ "process",
69
+ "umask",
70
+ "permissions",
71
+ "mask",
72
+ "security",
73
+ "chmod",
74
+ "restrictions",
75
+ "filesystem",
76
+ "fs"
77
+ ]
78
+ }