Socket
Socket
Sign inDemoInstall

hoek

Package Overview
Dependencies
Maintainers
3
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hoek - npm Package Compare versions

Comparing version 1.5.2 to 2.0.0

test/modules/ignore.txt

18

lib/escape.js

@@ -117,11 +117,11 @@ // Declare internals

if ((i >= 97 && i <= 122) || // a-z
(i >= 65 && i <= 90) || // A-Z
(i >= 48 && i <= 57) || // 0-9
i === 32 || // space
i === 46 || // .
i === 44 || // ,
i === 45 || // -
i === 58 || // :
i === 95) { // _
if ((i >= 97) || // a-z
(i >= 65 && i <= 90) || // A-Z
(i >= 48 && i <= 57) || // 0-9
i === 32 || // space
i === 46 || // .
i === 44 || // ,
i === 45 || // -
i === 58 || // :
i === 95) { // _

@@ -128,0 +128,0 @@ safe[i] = null;

@@ -213,16 +213,2 @@ // Load modules

// Find which keys are present
exports.matchKeys = function (obj, keys) {
var matched = [];
for (var i = 0, il = keys.length; i < il; ++i) {
if (obj.hasOwnProperty(keys[i])) {
matched.push(keys[i]);
}
}
return matched;
};
// Flatten array

@@ -247,12 +233,2 @@

// Remove keys
exports.removeKeys = function (object, keys) {
for (var i = 0, il = keys.length; i < il; i++) {
delete object[keys[i]];
}
};
// Convert an object key chain string ('a.b.c') to reference (object[a][b][c])

@@ -272,3 +248,3 @@

!ref.hasOwnProperty(path[i]) ||
(typeof ref !== 'object' && (options.functions === false || typeof ref !== 'function'))) {
(typeof ref !== 'object' && options.functions === false)) { // Only object and function can have properties

@@ -288,36 +264,2 @@ exports.assert(!options.strict || i + 1 === il, 'Missing segment', path[i], 'in reach path ', chain);

// Inherits a selected set of methods from an object, wrapping functions in asynchronous syntax and catching errors
exports.inheritAsync = function (self, obj, keys) {
keys = keys || null;
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
if (keys instanceof Array &&
keys.indexOf(i) < 0) {
continue;
}
self.prototype[i] = (function (fn) {
return function (next) {
var result = null;
try {
result = fn();
}
catch (err) {
return next(err);
}
return next(null, result);
};
})(obj[i]);
}
}
};
exports.formatStack = function (stack) {

@@ -415,37 +357,2 @@

exports.loadDirModules = function (path, excludeFiles, target) { // target(filename, name, capName)
var exclude = {};
for (var i = 0, il = excludeFiles.length; i < il; ++i) {
exclude[excludeFiles[i] + '.js'] = true;
}
var files = Fs.readdirSync(path);
for (i = 0, il = files.length; i < il; ++i) {
var filename = files[i];
if (/\.js$/.test(filename) &&
!exclude[filename]) {
var name = filename.substr(0, filename.lastIndexOf('.'));
var capName = name.charAt(0).toUpperCase() + name.substr(1).toLowerCase();
if (typeof target !== 'function') {
target[capName] = require(path + '/' + name);
}
else {
target(path + '/' + name, name, capName);
}
}
}
};
exports.rename = function (obj, from, to) {
exports.assert(obj.hasOwnProperty(from), 'Invalid property', from);
obj[to] = obj[from];
delete obj[from];
};
exports.Timer = function () {

@@ -496,19 +403,2 @@

// Load and parse package.json process root or given directory
exports.loadPackage = function (dir) {
var result = {};
var filepath = Path.normalize((dir || process.env.PWD || process.cwd()) + '/package.json');
if (Fs.existsSync(filepath)) {
try {
result = JSON.parse(Fs.readFileSync(filepath));
}
catch (e) { }
}
return result;
};
// Escape string for Regex construction

@@ -523,19 +413,2 @@

// Return an error as first argument of a callback
exports.toss = function (condition /*, [message], next */) {
var message = (arguments.length === 3 ? arguments[1] : '');
var next = (arguments.length === 3 ? arguments[2] : arguments[1]);
var err = (message instanceof Error ? message : (message ? new Error(message) : (condition instanceof Error ? condition : new Error())));
if (condition instanceof Error ||
!condition) {
return next(err);
}
};
// Base64url (RFC 4648) encode

@@ -594,45 +467,2 @@

/*
var event = {
timestamp: now.getTime(),
tags: ['tag'],
data: { some: 'data' }
};
*/
exports.consoleFunc = console.log;
exports.printEvent = function (event) {
var pad = function (value) {
return (value < 10 ? '0' : '') + value;
};
var now = new Date(event.timestamp);
var timestring = (now.getYear() - 100).toString() +
pad(now.getMonth() + 1) +
pad(now.getDate()) +
'/' +
pad(now.getHours()) +
pad(now.getMinutes()) +
pad(now.getSeconds()) +
'.' +
now.getMilliseconds();
var data = event.data;
if (typeof event.data !== 'string') {
try {
data = JSON.stringify(event.data);
}
catch (e) {
data = 'JSON Error: ' + e.message;
}
}
var output = timestring + ', ' + event.tags[0] + ', ' + data;
exports.consoleFunc(output);
};
exports.nextTick = function (callback) {

@@ -651,21 +481,2 @@

exports.readStream = function (stream, callback) {
var result = '';
stream.on('readable', function () {
var read = stream.read();
if (read) {
result += read.toString();
}
});
stream.once('end', function () {
callback(result);
});
};
exports.once = function (method) {

@@ -692,2 +503,26 @@

exports.isAbsolutePath = function (path, platform) {
if (!path) {
return false;
}
if (Path.isAbsolute) { // node >= 0.11
return Path.isAbsolute(path);
}
platform = platform || process.platform;
// Unix
if (platform !== 'win32') {
return path[0] === '/';
}
// Windows
return !!path.match(/^(?:[a-zA-Z]:[\\\/])|(?:[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/])/); // C:\ or \\something\something
};
exports.ignore = function () { };

@@ -694,0 +529,0 @@

{
"name": "hoek",
"description": "General purpose node utilities",
"version": "1.5.2",
"version": "2.0.0",
"repository": "git://github.com/spumko/hoek",

@@ -16,3 +16,3 @@ "main": "index",

"devDependencies": {
"lab": "1.x.x"
"lab": "3.x.x"
},

@@ -19,0 +19,0 @@ "scripts": {

@@ -18,8 +18,5 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a>

* [intersect](#intersectarray1-array2 "intersect")
* [matchKeys](#matchkeysobj-keys "matchKeys")
* [flatten](#flattenarray-target "flatten")
* [removeKeys](#removekeysobject-keys "removeKeys")
* [reach](#reachobj-chain-options "reach")
* [inheritAsync](#inheritasyncself-obj-keys "inheritAsync")
* [rename](#renameobj-from-to "rename")
* [Timer](#timer "Timer")

@@ -39,8 +36,5 @@ * [Bench](#bench "Bench")

* [callStack](#callstackslice "callStack")
* [toss](#tosscondition "toss")
* [Load files](#load-files "Load Files")
* [loadPackage](#loadpackagedir "loadpackage")
* [loadDirModules](#loaddirmodulespath-excludefiles-target "loaddirmodules")
* [Streams](#streams "Streams")
* [readStream](#readstream "readStream")

@@ -171,14 +165,2 @@

### matchKeys(obj, keys)
Find which keys are present
```javascript
var obj = {a: 1, b: 2, c: 3};
var keys = ["a", "e"];
Hoek.matchKeys(obj, keys) // returns ["a"]
```
### flatten(array, target)

@@ -196,16 +178,2 @@

### removeKeys(object, keys)
Remove keys
```javascript
var object = {a: 1, b: 2, c: 3, d: 4};
var keys = ["a", "b"];
Hoek.removeKeys(object, keys) // object is now {c: 3, d: 4}
```
### reach(obj, chain, [options])

@@ -223,47 +191,2 @@

### inheritAsync(self, obj, keys)
Inherits a selected set of methods from an object, wrapping functions in asynchronous syntax and catching errors
```javascript
var targetFunc = function () { };
var proto = {
a: function () {
return 'a!';
},
b: function () {
return 'b!';
},
c: function () {
throw new Error('c!');
}
};
var keys = ['a', 'c'];
Hoek.inheritAsync(targetFunc, proto, ['a', 'c']);
var target = new targetFunc();
target.a(function(err, result){console.log(result)} // returns 'a!'
target.c(function(err, result){console.log(result)} // returns undefined
target.b(function(err, result){console.log(result)} // gives error: Object [object Object] has no method 'b'
```
### rename(obj, from, to)
Rename a key of an object
```javascript
var obj = {a : 1, b : 2};
Hoek.rename(obj, "a", "c"); // obj is now {c : 1, b : 2}
```
# Timer

@@ -396,9 +319,2 @@

### toss(condition)
toss(condition /*, [message], callback */)
Return an error as first argument of a callback
# Load Files

@@ -419,15 +335,1 @@

# Streams
### readStream
Read an entire stream buffer into a string
```javascript
readStream(inputStream, function (outputString) {
...
});
```

@@ -83,2 +83,9 @@ // Load modules

});
it('encodes {} characters', function (done) {
var encoded = Hoek.escapeHtml('{}');
expect(encoded).to.equal('&#x7b;&#x7d;');
done();
});
});

@@ -85,0 +92,0 @@ });

@@ -395,2 +395,11 @@ // Load modules

});
it('overrides Buffer', function (done) {
var a = { x: new Buffer('abc') };
var b = Hoek.merge({ x: {} }, a);
expect(a.x.toString()).to.equal('abc');
done();
});
});

@@ -411,2 +420,11 @@

it('throws when target is null', function (done) {
expect(function () {
Hoek.applyToDefaults(null, {});
}).to.throw('Invalid defaults value: must be an object');
done();
});
it('should return null if options is false', function (done) {

@@ -486,8 +504,6 @@

var keys = [{ x: 1 }, { x: 2 }, { x: 3 }];
var keys = [{ x: 1 }, { x: 2 }, { x: 3 }, { y: 4 }];
var subkey = 'x';
var a = Hoek.mapToObject(keys, subkey);
for (var i in keys) {
expect(a[keys[i][subkey]]).to.equal(true);
}
expect(a).to.deep.equal({ 1: true, 2: true, 3: true });
done();

@@ -543,18 +559,2 @@ });

describe('#matchKeys', function () {
it('should match the existing object keys', function (done) {
var obj = {
a: 1,
b: 2,
c: 3,
d: null
};
expect(Hoek.matchKeys(obj, ['b', 'c', 'd', 'e'])).to.deep.equal(['b', 'c', 'd']);
done();
});
});
describe('#flatten', function () {

@@ -571,22 +571,2 @@

describe('#removeKeys', function () {
var objWithHiddenKeys = {
location: {
name: 'San Bruno'
},
company: {
name: '@WalmartLabs'
}
};
it('should delete params with definition\'s hide set to true', function (done) {
var a = Hoek.removeKeys(objWithHiddenKeys, ['location']);
expect(objWithHiddenKeys.location).to.not.exist;
expect(objWithHiddenKeys.company).to.exist;
done();
});
});
describe('#reach', function () {

@@ -631,3 +611,3 @@

it('returns undefined on missing member', function (done) {
it('returns undefined on missing object member', function (done) {

@@ -638,2 +618,8 @@ expect(Hoek.reach(obj, 'a.b.c.d.x')).to.equal(undefined);

it('returns undefined on missing function member', function (done) {
expect(Hoek.reach(obj, 'i.y', { functions: true })).to.equal(undefined);
done();
});
it('throws on missing member in strict mode', function (done) {

@@ -684,46 +670,2 @@

describe('#inheritAsync', function () {
it('should inherit selected methods and wrap in async call', function (done) {
var proto = {
a: function () {
return 'a!';
},
b: function () {
return 'b!';
},
c: function () {
throw new Error('c!');
}
};
var targetFunc = function () { };
targetFunc.prototype.c = function () {
return 'oops';
};
Hoek.inheritAsync(targetFunc, proto, ['a', 'c']);
var target = new targetFunc();
expect(typeof target.a).to.equal('function');
expect(typeof target.c).to.equal('function');
expect(target.b).to.not.exist;
target.a(function (err, result) {
expect(err).to.not.exist;
expect(result).to.equal('a!');
target.c(function (err, result) {
expect(result).to.not.exist;
expect(err.message).to.equal('c!');
done();
});
});
});
});
describe('#callStack', function () {

@@ -806,3 +748,2 @@

it('should respect hideStack argument', function (done) {

@@ -833,2 +774,30 @@

it('throws in test mode', function (done) {
var env = process.env.NODE_ENV;
process.env.NODE_ENV = 'test';
expect(function () {
Hoek.abort('my error message', true);
}).to.throw('my error message');
process.env.NODE_ENV = env;
done();
});
it('throws in test mode with default message', function (done) {
var env = process.env.NODE_ENV;
process.env.NODE_ENV = 'test';
expect(function () {
Hoek.abort('', true);
}).to.throw('Unknown error');
process.env.NODE_ENV = env;
done();
});
it('should default to showing stack', function (done) {

@@ -918,53 +887,2 @@

describe('#loadDirModules', function () {
it('should load modules from directory', function (done) {
var target = {};
Hoek.loadDirModules(__dirname + '/modules', ['test2'], target);
expect(target.Test1.x).to.equal(1);
expect(target.Test2).to.not.exist;
expect(target.Test3.z).to.equal(3);
done();
});
it('should list modules from directory into function', function (done) {
var target = {};
Hoek.loadDirModules(__dirname + '/modules', ['test2'], function (path, name, capName) {
target[name] = capName;
});
expect(target.test1).to.equal('Test1');
expect(target.test2).to.not.exist;
expect(target.test3).to.equal('Test3');
done();
});
});
describe('#rename', function () {
it('should rename object key', function (done) {
var a = { b: 'c' };
Hoek.rename(a, 'b', 'x');
expect(a.b).to.not.exist;
expect(a.x).to.equal('c');
done();
});
it('should throw and invalid key in object error', function (done) {
var fn = function () {
var obj = {a:1, b:2};
Hoek.rename(obj, 'd', 'a');
};
expect(fn).to.throw('Invalid property d');
done();
});
});
describe('Timer', function () {

@@ -996,12 +914,2 @@

describe('#loadPackage', function () {
it('should load itself', function (done) {
var pack = Hoek.loadPackage();
expect(pack.name).to.equal('hoek');
done();
});
});
describe('#escapeRegex', function () {

@@ -1017,58 +925,2 @@

describe('#toss', function () {
it('should call callback with new error', function (done) {
var callback = function (err) {
expect(err).to.exist;
expect(err.message).to.equal('bug');
done();
};
Hoek.toss(true, 'feature', callback);
Hoek.toss(false, 'bug', callback);
});
it('should call callback with new error and no message', function (done) {
Hoek.toss(false, function (err) {
expect(err).to.exist;
expect(err.message).to.equal('');
done();
});
});
it('should call callback with error condition', function (done) {
Hoek.toss(new Error('boom'), function (err) {
expect(err).to.exist;
expect(err.message).to.equal('boom');
done();
});
});
it('should call callback with new error using message with error condition', function (done) {
Hoek.toss(new Error('ka'), 'boom', function (err) {
expect(err).to.exist;
expect(err.message).to.equal('boom');
done();
});
});
it('should call callback with new error using passed error with error condition', function (done) {
Hoek.toss(new Error('ka'), new Error('boom'), function (err) {
expect(err).to.exist;
expect(err.message).to.equal('boom');
done();
});
});
});
describe('Base64Url', function () {

@@ -1092,2 +944,9 @@

});
it('should base64 URL-safe a hex string', function (done) {
var buffer = new Buffer(str, 'binary');
expect(Hoek.base64urlEncode(buffer.toString('hex'), 'hex')).to.equal(base64str);
done();
});
});

@@ -1103,2 +962,8 @@

it('should un-base64 URL-safe a string into hex', function (done) {
expect(Hoek.base64urlDecode(base64str, 'hex')).to.equal(new Buffer(str, 'binary').toString('hex'));
done();
});
it('should un-base64 URL-safe a string and return a buffer', function (done) {

@@ -1189,43 +1054,2 @@

describe('#printEvent', function () {
it('outputs event as string', function (done) {
var event = {
timestamp: (new Date(2013, 1, 1, 6, 30, 45, 123)).getTime(),
tags: ['a', 'b', 'c'],
data: { some: 'data' }
};
Hoek.consoleFunc = function (string) {
Hoek.consoleFunc = console.log;
expect(string).to.equal('130201/063045.123, a, {"some":"data"}');
done();
};
Hoek.printEvent(event);
});
it('outputs JSON error', function (done) {
var event = {
timestamp: (new Date(2013, 1, 1, 6, 30, 45, 123)).getTime(),
tags: ['a', 'b', 'c'],
data: { some: 'data' }
};
event.data.a = event.data;
Hoek.consoleFunc = function (string) {
Hoek.consoleFunc = console.log;
expect(string).to.equal('130201/063045.123, a, JSON Error: Converting circular structure to JSON');
done();
};
Hoek.printEvent(event);
});
});
describe('#nextTick', function () {

@@ -1259,30 +1083,2 @@

describe('#readStream', function () {
it('reads a stream and provides output to callback', function (done) {
var readable = new Stream.Readable();
readable._read = function () {
this.push('hello');
this.push(' ');
readable._read = function () {
this.push('world');
this.push(null);
return false;
};
return true;
};
Hoek.readStream(readable, function (result) {
expect(result).to.equal('hello world');
done();
});
});
});
describe('#once', function () {

@@ -1319,2 +1115,57 @@

describe('#isAbsoltePath', function () {
it('identifies if path is absolute on Unix without node support', { parallel: false }, function (done) {
var orig = Path.isAbsolute;
Path.isAbsolute = undefined;
expect(Hoek.isAbsolutePath('')).to.equal(false);
expect(Hoek.isAbsolutePath('a')).to.equal(false);
expect(Hoek.isAbsolutePath('./a')).to.equal(false);
expect(Hoek.isAbsolutePath('/a')).to.equal(true);
expect(Hoek.isAbsolutePath('/')).to.equal(true);
Path.isAbsolute = orig;
done();
});
it('identifies if path is absolute with fake node support', { parallel: false }, function (done) {
var orig = Path.isAbsolute;
Path.isAbsolute = function (path) { return path[0] === '/'; };
expect(Hoek.isAbsolutePath('', 'linux')).to.equal(false);
expect(Hoek.isAbsolutePath('a', 'linux')).to.equal(false);
expect(Hoek.isAbsolutePath('./a', 'linux')).to.equal(false);
expect(Hoek.isAbsolutePath('/a', 'linux')).to.equal(true);
expect(Hoek.isAbsolutePath('/', 'linux')).to.equal(true);
Path.isAbsolute = orig;
done();
});
it('identifies if path is absolute on Windows without node support', { parallel: false }, function (done) {
var orig = Path.isAbsolute;
Path.isAbsolute = undefined;
expect(Hoek.isAbsolutePath('//server/file', 'win32')).to.equal(true);
expect(Hoek.isAbsolutePath('//server/file', 'win32')).to.equal(true);
expect(Hoek.isAbsolutePath('\\\\server\\file', 'win32')).to.equal(true);
expect(Hoek.isAbsolutePath('C:/Users/', 'win32')).to.equal(true);
expect(Hoek.isAbsolutePath('C:\\Users\\', 'win32')).to.equal(true);
expect(Hoek.isAbsolutePath('C:cwd/another', 'win32')).to.equal(false);
expect(Hoek.isAbsolutePath('C:cwd\\another', 'win32')).to.equal(false);
expect(Hoek.isAbsolutePath('directory/directory', 'win32')).to.equal(false);
expect(Hoek.isAbsolutePath('directory\\directory', 'win32')).to.equal(false);
Path.isAbsolute = orig;
done();
});
});
describe('#ignore', function () {

@@ -1321,0 +1172,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc