Socket
Socket
Sign inDemoInstall

hoek

Package Overview
Dependencies
Maintainers
2
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 0.5.0 to 0.6.0

45

lib/index.js

@@ -496,2 +496,45 @@ // Load modules

});
};
};
/*
var event = {
ets: 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.ets);
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);
};

2

package.json
{
"name": "hoek",
"description": "General purpose node utilities",
"version": "0.5.0",
"version": "0.6.0",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",

@@ -6,0 +6,0 @@ "contributors":[

@@ -29,3 +29,3 @@ <a href="https://github.com/walmartlabs/blammo"><img src="https://raw.github.com/walmartlabs/blammo/master/images/from.png" align="right" /></a>

* [Escaping Characters](#escaped "Escaping Characters")
* [escapeHTML](#escapeHTMLstring "escapeHTML")
* [escapeHtml](#escapeHtmlstring "escapeHtml")
* [escapeHeaderAttribute](#escapeHeaderAttributeattribute "escapeHeaderAttribute")

@@ -38,2 +38,6 @@ * [escapeRegex](#escapeRegexstring "escapeRegex")

* [callStack](#callStackslice "callStack")
* [toss](#tosscondition "toss")
* [Load files](#load-files "Load Files")
* [loadPackage](#loadPackagedir "loadpackage")
* [loadDirModules](#loadDirModulespath-excludefiles-target "loaddirmodules")

@@ -106,6 +110,6 @@

newTarget = Hoek.merge(target, source2); // results in {a: null, b: 2, c: 5}
newTarget = Hoek.merge(target, source2, false); // results in {a: 1, b:2, c: 5}
newTarget = Hoek.merge(target, source2, false); // results in {a: null, b:2, c: 5}
newTarget = Hoek.merge(target, source) // results in [1, 2, 3, 4, 5]
newTarget = Hoek.merge(target, source, true, false) // results in [4, 5]
newTarget = Hoek.merge(targetArray, sourceArray) // results in [1, 2, 3, 4, 5]
newTarget = Hoek.merge(targetArray, sourceArray, true, false) // results in [4, 5]

@@ -252,10 +256,11 @@

target.a() // returns 'a!'
target.c() // returns 'c!'
target.b() // returns undefined
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(obj, from, to)

@@ -275,3 +280,3 @@ Rename a key of an object

A Timer object
A Timer object. Initializing a new timer object sets the ts to the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.

@@ -286,5 +291,152 @@ ```javascript

console.log("Time is now: " + timerObj.ts)
console.log("Elapsed time from initialization: " + timerObj.elapsed)
console.log("Elapsed time from initialization: " + timerObj.elapsed() + 'milliseconds')
```
# Binary Encoding/Decoding
### base64urlEncode(value)
Encodes value in Base64 or URL encoding
### base64urlDecode(value)
Decodes data in Base64 or URL encoding.
# Escaping Characters
Hoek provides convenient methods for escaping html characters. The escaped characters are as followed:
```javascript
internals.htmlEscaped = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'`': '&#x60;'
};
```
### escapeHtml(string)
```javascript
var string = '<html> hey </html>';
var escapedString = Hoek.escapeHtml(string); // returns &lt;html&gt; hey &lt;/html&gt;
```
### escapeHeaderAttribute(attribute)
Escape attribute value for use in HTTP header
```javascript
var a = Hoek.escapeHeaderAttribute('I said "go w\\o me"'); //returns I said \"go w\\o me\"
```
### escapeRegex(string)
Escape string for Regex construction
```javascript
var a = Hoek.escapeRegex('4^f$s.4*5+-_?%=#!:@|~\\/`"(>)[<]d{}s,'); // returns 4\^f\$s\.4\*5\+\-_\?%\=#\!\:@\|~\\\/`"\(>\)\[<\]d\{\}s\,
```
# Errors
### assert(message)
```javascript
var a = 1, b =2;
Hoek.assert(a === b, 'a should equal b'); // ABORT: a should equal b
```
### abort(message)
First checks if process.env.NODE_ENV === 'test', and if so, throws error message. Otherwise,
displays most recent stack and then exits process.
### displayStack(slice)
Displays the trace stack
```javascript
var stack = Hoek.displayStack();
console.log(stack) // returns something like:
[ 'null (/Users/user/Desktop/hoek/test.js:4:18)',
'Module._compile (module.js:449:26)',
'Module._extensions..js (module.js:467:10)',
'Module.load (module.js:356:32)',
'Module._load (module.js:312:12)',
'Module.runMain (module.js:492:10)',
'startup.processNextTick.process._tickCallback (node.js:244:9)' ]
```
### callStack(slice)
Returns a trace stack array.
```javascript
var stack = Hoek.callStack();
console.log(stack) // returns something like:
[ [ '/Users/user/Desktop/hoek/test.js', 4, 18, null, false ],
[ 'module.js', 449, 26, 'Module._compile', false ],
[ 'module.js', 467, 10, 'Module._extensions..js', false ],
[ 'module.js', 356, 32, 'Module.load', false ],
[ 'module.js', 312, 12, 'Module._load', false ],
[ 'module.js', 492, 10, 'Module.runMain', false ],
[ 'node.js',
244,
9,
'startup.processNextTick.process._tickCallback',
false ] ]
```
### toss(condition)
toss(condition /*, [message], callback */)
Return an error as first argument of a callback
# Load Files
### loadPackage(dir)
Load and parse package.json process root or given directory
```javascript
var pack = Hoek.loadPackage(); // pack.name === 'hoek'
```
### loadDirModules(path, excludeFiles, target)
Loads modules from a given path; option to exclude files (array).

@@ -682,3 +682,44 @@ // Load modules

});
describe('#printEvent', function () {
it('outputs event as string', function (done) {
var event = {
ets: (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 = {
ets: (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);
});
});
});
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