File: //home/imagzxcb/public_html/db127a/umask.zip
PK K9�\�h��K K
.npmignorenu �[��� # Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
# Users Environment Variables
.lock-wscript
PK K9�\ w�B5 5 LICENSEnu �[��� The MIT License (MIT)
Copyright (c) 2015 Sam Mikes
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
PK K9�\
�� � ChangeLognu �[��� 2015-01-15 Sam Mikes <smikes@cubane.com>
* index.js: (convert_fromString) accept decimal strings provided they
don't begin with '0'
2015-01-14 Sam Mikes <smikes@cubane.com>
* index.js: initial rev
PK K9�\��f�\ \ README.mdnu �[��� # 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
MITPK K9�\�4�M# # package.jsonnu �[��� {
"_args": [
[
"umask@1.1.0",
"/Users/rebecca/code/npm"
]
],
"_from": "umask@1.1.0",
"_id": "umask@1.1.0",
"_inBundle": false,
"_integrity": "sha1-8pzr8B31F5ErtY/5xOUP3o4zMg0=",
"_location": "/umask",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "umask@1.1.0",
"name": "umask",
"escapedName": "umask",
"rawSpec": "1.1.0",
"saveSpec": null,
"fetchSpec": "1.1.0"
},
"_requiredBy": [
"/",
"/npm-lifecycle"
],
"_resolved": "https://registry.npmjs.org/umask/-/umask-1.1.0.tgz",
"_spec": "1.1.0",
"_where": "/Users/rebecca/code/npm",
"author": {
"name": "Sam Mikes",
"email": "smikes@cubane.com"
},
"bugs": {
"url": "https://github.com/smikes/umask/issues"
},
"description": "convert umask from string <-> number",
"devDependencies": {
"code": "^1.2.1",
"jslint": "^0.7.2",
"lab": "^5.2.0"
},
"homepage": "https://github.com/smikes/umask",
"keywords": [
"umask"
],
"license": "MIT",
"main": "index.js",
"name": "umask",
"repository": {
"type": "git",
"url": "git+https://github.com/smikes/umask.git"
},
"scripts": {
"lint": "jslint --terse --latest *.js test/*.js",
"test": "lab -ct 100"
},
"version": "1.1.0"
}
PK K9�\��TD� � index.jsnu �[��� 'use strict';
var util = require("util");
function toString(val) {
val = val.toString(8);
while (val.length < 4) {
val = "0" + val;
}
return val;
}
var defaultUmask = 18; // 0022;
var defaultUmaskString = toString(defaultUmask);
function validate(data, k, val) {
// must be either an integer or an octal string.
if (typeof val === "number" && !isNaN(val)) {
data[k] = val;
return true;
}
if (typeof val === "string") {
if (val.charAt(0) !== "0") {
return false;
}
data[k] = parseInt(val, 8);
return true;
}
return false;
}
function convert_fromString(val, cb) {
if (typeof val === "string") {
// check for octal string first
if (val.charAt(0) === '0' && /^[0-7]+$/.test(val)) {
val = parseInt(val, 8);
} else if (val.charAt(0) !== '0' && /^[0-9]+$/.test(val)) {
// legacy support for decimal strings
val = parseInt(val, 10);
} else {
return cb(new Error(util.format("Expected octal string, got %j, defaulting to %j",
val, defaultUmaskString)),
defaultUmask);
}
} else if (typeof val !== "number") {
return cb(new Error(util.format("Expected number or octal string, got %j, defaulting to %j",
val, defaultUmaskString)),
defaultUmask);
}
val = Math.floor(val);
if ((val < 0) || (val > 511)) {
return cb(new Error(util.format("Must be in range 0..511 (0000..0777), got %j", val)),
defaultUmask);
}
cb(null, val);
}
function fromString(val, cb) {
// synchronous callback, no zalgo
convert_fromString(val, cb || function (err, result) {
/*jslint unparam:true*/
val = result;
});
return val;
}
exports.toString = toString;
exports.fromString = fromString;
exports.validate = validate;
PK K9�\�h��K K
.npmignorenu �[��� PK K9�\ w�B5 5 � LICENSEnu �[��� PK K9�\
�� � � ChangeLognu �[��� PK K9�\��f�\ \ � README.mdnu �[��� PK K9�\�4�M# # � package.jsonnu �[��� PK K9�\��TD� � � index.jsnu �[��� PK � �