{
  "name": "hoek",
  "description": "General purpose node utilities",
  "version": "0.7.6",
  "author": {
    "name": "Eran Hammer",
    "email": "eran@hueniverse.com",
    "url": "http://hueniverse.com"
  },
  "contributors": [
    {
      "name": "Van Nguyen",
      "email": "the.gol.effect@gmail.com"
    }
  ],
  "repository": {
    "type": "git",
    "url": "git://github.com/spumko/hoek"
  },
  "main": "index",
  "keywords": [
    "utilities"
  ],
  "engines": {
    "node": "0.8.x"
  },
  "dependencies": {},
  "devDependencies": {
    "lab": "0.0.x",
    "complexity-report": "0.x.x"
  },
  "scripts": {
    "test": "make test-cov"
  },
  "licenses": [
    {
      "type": "BSD",
      "url": "http://github.com/spumko/hoek/raw/master/LICENSE"
    }
  ],
  "readme": "<a href=\"https://github.com/spumko\"><img src=\"https://raw.github.com/spumko/spumko/master/images/from.png\" align=\"right\" /></a>\n![hoek Logo](https://raw.github.com/spumko/hoek/master/images/hoek.png)\n\nGeneral purpose node utilities\n\n[![Build Status](https://secure.travis-ci.org/spumko/hoek.png)](http://travis-ci.org/spumko/hoek)\n\n# Table of Contents\n\n* [Introduction](#introduction \"Introduction\")\n* [Object](#object \"Object\")\n  * [clone](#cloneobj \"clone\")\n  * [merge](#mergetarget-source-isnulloverride-ismergearrays \"merge\")\n  * [applyToDefaults](#applytodefaultsdefaults-options \"applyToDefaults\")\n  * [unique](#uniquearray-key \"unique\")\n  * [mapToObject](#maptoobjectarray-key \"mapToObject\")\n  * [intersect](#intersectarray1-array2 \"intersect\")\n  * [matchKeys](#matchkeysobj-keys \"matchKeys\")\n  * [flatten](#flattenarray-target \"flatten\")\n  * [removeKeys](#removekeysobject-keys \"removeKeys\")\n  * [reach](#reachobj-chain \"reach\")\n  * [inheritAsync](#inheritasyncself-obj-keys \"inheritAsync\")\n  * [rename](#renameobj-from-to \"rename\")\n* [Timer](#timer \"Timer\")\n* [Binary Encoding/Decoding](#binary \"Binary Encoding/Decoding\")\n  * [base64urlEncode](#binary64urlEncodevalue \"binary64urlEncode\")\n  * [base64urlDecode](#binary64urlDecodevalue \"binary64urlDecode\")\n* [Escaping Characters](#escaped \"Escaping Characters\")\n  * [escapeHtml](#escapeHtmlstring \"escapeHtml\")\n  * [escapeHeaderAttribute](#escapeHeaderAttributeattribute \"escapeHeaderAttribute\")\n  * [escapeRegex](#escapeRegexstring \"escapeRegex\")\n* [Errors](#errors \"Errors\")\n  * [assert](#assertmessage \"assert\")\n  * [abort](#abortmessage \"abort\")\n  * [displayStack](#displayStackslice \"displayStack\")\n  * [callStack](#callStackslice \"callStack\")\n  * [toss](#tosscondition \"toss\")\n* [Load files](#load-files \"Load Files\")\n  * [loadPackage](#loadPackagedir \"loadpackage\")\n  * [loadDirModules](#loadDirModulespath-excludefiles-target \"loaddirmodules\")\n\n\n\n# Introduction\n\nThe *Hoek* general purpose node utilities library is used to aid in a variety of manners. It comes with useful methods for Ararys (clone, merge, applyToDefaults), Objects (removeKeys, copy), Asserting and more. \n\nFor example, to use Hoek to set configuration with default options:\n```javascript\nvar Hoek = require('hoek');\n\nvar default = {url : \"www.github.com\", port : \"8000\", debug : true}\n\nvar config = Hoek.applyToDefaults(default, {port : \"3000\", admin : true});\n\n// In this case, config would be { url: 'www.github.com', port: '3000', debug: true, admin: true }\n```\n\nUnder each of the sections (such as Array), there are subsections which correspond to Hoek methods. Each subsection will explain how to use the corresponding method. In each js excerpt below, the var Hoek = require('hoek') is omitted for brevity.\n\n## Object\n\nHoek provides several helpful methods for objects and arrays.\n\n### clone(obj)\n\nThis method is used to clone an object or an array. A *deep copy* is made (duplicates everything, including values that are objects). \n\n```javascript\n\nvar nestedObj = {\n        w: /^something$/ig,\n        x: {\n            a: [1, 2, 3],\n            b: 123456,\n            c: new Date()\n        },\n        y: 'y',\n        z: new Date()\n    };\n\nvar copy = Hoek.clone(nestedObj);\n\ncopy.x.b = 100;\n\nconsole.log(copy.y)        // results in 'y'\nconsole.log(nestedObj.x.b) // results in 123456\nconsole.log(copy.x.b)      // results in 100\n```\n\n### merge(target, source, isNullOverride, isMergeArrays)\nisNullOverride, isMergeArrays default to true\n\nMerge all the properties of source into target, source wins in conflic, and by default null and undefined from source are applied\n\n\n```javascript\n\nvar target = {a: 1, b : 2}\nvar source = {a: 0, c: 5}\nvar source2 = {a: null, c: 5}\n\nvar targetArray = [1, 2, 3];\nvar sourceArray = [4, 5];\n\nvar newTarget = Hoek.merge(target, source);     // results in {a: 0, b: 2, c: 5}\nnewTarget = Hoek.merge(target, source2);        // results in {a: null, b: 2, c: 5}\nnewTarget = Hoek.merge(target, source2, false); // results in {a: null, b:2, c: 5}\n\nnewTarget = Hoek.merge(targetArray, sourceArray)              // results in [1, 2, 3, 4, 5]\nnewTarget = Hoek.merge(targetArray, sourceArray, true, false) // results in [4, 5]\n\n\n\n\n```\n\n### applyToDefaults(defaults, options)\n\nApply options to a copy of the defaults\n\n```javascript\n\nvar defaults = {host: \"localhost\", port: 8000};\nvar options = {port: 8080};\n\nvar config = Hoek.applyToDefaults(defaults, options); // results in {host: \"localhost\", port: 8080};\n\n\n```\n\n### unique(array, key)\n\nRemove duplicate items from Array\n\n```javascript\n\nvar array = [1, 2, 2, 3, 3, 4, 5, 6];\n\nvar newArray = Hoek.unique(array); // results in [1,2,3,4,5,6];\n\narray = [{id: 1}, {id: 1}, {id: 2}];\n\nnewArray = Hoek.unique(array, \"id\") // results in [{id: 1}, {id: 2}]\n\n```\n\n### mapToObject(array, key)\n\nConvert an Array into an Object\n\n```javascript\n\nvar array = [1,2,3];\nvar newObject = Hoek.mapToObject(array); // results in [{\"1\": true}, {\"2\": true}, {\"3\": true}]\n\narray = [{id: 1}, {id: 2}];\nnewObject = Hoek.mapToObject(array, \"id\") // results in [{\"id\": 1}, {\"id\": 2}]\n\n```\n### intersect(array1, array2)\n\nFind the common unique items in two arrays\n\n```javascript\n\nvar array1 = [1, 2, 3];\nvar array2 = [1, 4, 5];\n\nvar newArray = Hoek.intersect(array1, array2) // results in [1]\n\n```\n\n### matchKeys(obj, keys) \n\nFind which keys are present\n\n```javascript\n\nvar obj = {a: 1, b: 2, c: 3};\nvar keys = [\"a\", \"e\"];\n\nHoek.matchKeys(obj, keys) // returns [\"a\"]\n\n```\n\n### flatten(array, target)\n\nFlatten an array\n\n```javascript\n\nvar array = [1, 2, 3];\nvar target = [4, 5]; \n\nvar flattenedArray = Hoek.flatten(array, target) // results in [4, 5, 1, 2, 3];\n\n```\n\n### removeKeys(object, keys)\n\nRemove keys\n\n```javascript\n\nvar object = {a: 1, b: 2, c: 3, d: 4};\n\nvar keys = [\"a\", \"b\"];\n\nHoek.removeKeys(object, keys) // object is now {c: 3, d: 4}\n\n```\n\n### reach(obj, chain)\n\nConverts an object key chain string to reference\n\n```javascript\n\nvar chain = 'a.b.c';\nvar obj = {a : {b : { c : 1}}};\n\nHoek.reach(obj, chain) // returns 1\n\n```\n\n### inheritAsync(self, obj, keys) \n\nInherits a selected set of methods from an object, wrapping functions in asynchronous syntax and catching errors\n\n```javascript\n\nvar targetFunc = function () { };\n\nvar proto = {\n                a: function () {\n                    return 'a!';\n                },\n                b: function () {\n                    return 'b!';\n                },\n                c: function () {\n                    throw new Error('c!');\n                }\n            };\n\nvar keys = ['a', 'c'];\n\nHoek.inheritAsync(targetFunc, proto, ['a', 'c']);\n\nvar target = new targetFunc();\n\ntarget.a(function(err, result){console.log(result)}         // returns 'a!'       \n\ntarget.c(function(err, result){console.log(result)}         // returns undefined\n\ntarget.b(function(err, result){console.log(result)}         // gives error: Object [object Object] has no method 'b'\n\n```\n\n### rename(obj, from, to)\n\nRename a key of an object\n\n```javascript\n\nvar obj = {a : 1, b : 2};\n\nHoek.rename(obj, \"a\", \"c\");     // obj is now {c : 1, b : 2}\n\n```\n\n\n# Timer\n\nA Timer object. Initializing a new timer object sets the ts to the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.\n\n```javascript\n\n\nexample : \n\n\nvar timerObj = new Hoek.Timer();\nconsole.log(\"Time is now: \" + timerObj.ts)\nconsole.log(\"Elapsed time from initialization: \" + timerObj.elapsed() + 'milliseconds')\n\n```\n\n# Binary Encoding/Decoding\n\n### base64urlEncode(value)\n\nEncodes value in Base64 or URL encoding\n\n### base64urlDecode(value)\n\nDecodes data in Base64 or URL encoding.\n# Escaping Characters\n\nHoek provides convenient methods for escaping html characters. The escaped characters are as followed:\n\n```javascript\n\ninternals.htmlEscaped = {\n    '&': '&amp;',\n    '<': '&lt;',\n    '>': '&gt;',\n    '\"': '&quot;',\n    \"'\": '&#x27;',\n    '`': '&#x60;'\n};\n\n```\n\n### escapeHtml(string)\n\n```javascript\n\nvar string = '<html> hey </html>';\nvar escapedString = Hoek.escapeHtml(string); // returns &lt;html&gt; hey &lt;/html&gt;\n\n```\n\n### escapeHeaderAttribute(attribute)\n\nEscape attribute value for use in HTTP header\n\n```javascript\n\nvar a = Hoek.escapeHeaderAttribute('I said \"go w\\\\o me\"');  //returns I said \\\"go w\\\\o me\\\"\n\n\n```\n\n\n### escapeRegex(string)\n\nEscape string for Regex construction\n\n```javascript\n\nvar a = Hoek.escapeRegex('4^f$s.4*5+-_?%=#!:@|~\\\\/`\"(>)[<]d{}s,');  // returns 4\\^f\\$s\\.4\\*5\\+\\-_\\?%\\=#\\!\\:@\\|~\\\\\\/`\"\\(>\\)\\[<\\]d\\{\\}s\\,\n\n\n\n```\n\n# Errors\n\n### assert(message)\n\n```javascript\n\nvar a = 1, b =2;\n\nHoek.assert(a === b, 'a should equal b');  // ABORT: a should equal b\n\n```\n\n### abort(message)\n\nFirst checks if process.env.NODE_ENV === 'test', and if so, throws error message. Otherwise,\ndisplays most recent stack and then exits process.\n\n\n\n### displayStack(slice)\n\nDisplays the trace stack\n\n```javascript\n\nvar stack = Hoek.displayStack();\nconsole.log(stack) // returns something like:\n\n[ 'null (/Users/user/Desktop/hoek/test.js:4:18)',\n  'Module._compile (module.js:449:26)',\n  'Module._extensions..js (module.js:467:10)',\n  'Module.load (module.js:356:32)',\n  'Module._load (module.js:312:12)',\n  'Module.runMain (module.js:492:10)',\n  'startup.processNextTick.process._tickCallback (node.js:244:9)' ]\n\n```\n\n### callStack(slice)\n\nReturns a trace stack array.\n\n```javascript\n\nvar stack = Hoek.callStack();\nconsole.log(stack)  // returns something like:\n\n[ [ '/Users/user/Desktop/hoek/test.js', 4, 18, null, false ],\n  [ 'module.js', 449, 26, 'Module._compile', false ],\n  [ 'module.js', 467, 10, 'Module._extensions..js', false ],\n  [ 'module.js', 356, 32, 'Module.load', false ],\n  [ 'module.js', 312, 12, 'Module._load', false ],\n  [ 'module.js', 492, 10, 'Module.runMain', false ],\n  [ 'node.js',\n    244,\n    9,\n    'startup.processNextTick.process._tickCallback',\n    false ] ]\n\n\n```\n\n### toss(condition)\n\ntoss(condition /*, [message], callback */)\n\nReturn an error as first argument of a callback\n\n\n# Load Files\n\n### loadPackage(dir)\n\nLoad and parse package.json process root or given directory\n\n```javascript\n\nvar pack = Hoek.loadPackage();  // pack.name === 'hoek'\n\n```\n\n### loadDirModules(path, excludeFiles, target) \n\nLoads modules from a given path; option to exclude files (array).\n\n\n\n\n",
  "readmeFilename": "README.md",
  "_id": "hoek@0.7.6",
  "dist": {
    "shasum": "30c553c4bbfd8f78015fb48a8d643b966490cb32"
  },
  "_from": "hoek@0.7.x",
  "_resolved": "https://registry.npmjs.org/hoek/-/hoek-0.7.6.tgz"
}
