{"_id":"vs-util","_rev":"49-59773f781632bcefc36d59443fea4e1e","name":"vs-util","description":"Utilities commonly used in my projects","dist-tags":{"latest":"0.0.23"},"versions":{"0.0.1":{"name":"vs-util","version":"0.0.1","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.1","dist":{"shasum":"ee1310efdeda85e7ca17fa729063c41954404b5e","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.1.tgz","integrity":"sha512-p9krvgi1B3GXnV43oIPFTKZK4nc9RReYPAx+foPHJUW9HnY6lHHUL7lnedfmIsrdOa+m9D1BIVtH7H/fVJ33Fw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHtLapuGfLhUTEVsNZszBLOwmaXHiMxdPMxzhAG7f/mVAiEAnmdhPJPNYZJBr7pDplt6COZQuKA/D/1DkCUvBzq4LrE="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.2":{"name":"vs-util","version":"0.0.2","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.2","dist":{"shasum":"0030e2671676925c786ae574e2942e7c252537eb","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.2.tgz","integrity":"sha512-vsjYMo9l0h0sJnAbHQd8eXtQd2sT0hWhrJLeT42Cutoo89bc93JE01j7qcx1cWgUFZTc+ArpK6Bz/SrRgNN7+g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCq8nRpkyJgepnZjXcvwMyB0diNJFQIw/86fNDXv9Lv2wIgahiCtmH5Q1nAuWlSUknZKFITYCFcnSqYXbveqNpc2a0="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.3":{"name":"vs-util","version":"0.0.3","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.3","dist":{"shasum":"f5d95778c863272d551c2d6707304f2ed71bc6f5","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.3.tgz","integrity":"sha512-92AqqygdT9mJ7vngcs5ATXCyFGmTQpSeBwjakdsV6S/LQKBeNPLgD38yafnE6nNo53nrpC08lcfI+b8jX0WqDg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCwgkIZbuMMIv1bbWlvD4DWoy2LpptOVMvjDvzIB513ygIgR+VqCsmi04nxw/8Sij5AsKia/UkDwEgUQO3QRHS4ACg="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.4":{"name":"vs-util","version":"0.0.4","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.4","dist":{"shasum":"67c74c16ac8dad374a3aca974ca8657566c177b0","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.4.tgz","integrity":"sha512-NsMb4wBIfK3qeG3bYgrG7DixLEdgxn3Q6UFakXE8JDe3dnnX+zI+dC557tLd405QlG9O5guv6TzJkbgWpcYa9Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDJDLz/GqSv84creUgTZNLIW4JwxJkZE9uBFDOzLBFTCwIgR94yMkpuXRevVpwgda9dY+vrm9HUWl2F+o5iXXbpQDU="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.5":{"name":"vs-util","version":"0.0.5","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.5","dist":{"shasum":"83d61000baeb1201700625104d5009e2742cf548","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.5.tgz","integrity":"sha512-myvQjn8I2W52Q48/V6FXTZ/HRSDIvf4KjSIyxwaYeAcHQTTw+NVenrdocsOMzBSXiU2UZddShHX+H8GwqwtOvw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC3dJEaKtjgOzDegFDzAQ2q2kZH5GNKzAhyp3bY1b7muwIhAOc77ZyDh1SsNXqRWxL6d0X7IZD06aRGZT1ou6C5QJSA"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.6":{"name":"vs-util","version":"0.0.6","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.6","dist":{"shasum":"6cd585551c2df63d774847cbec298c462ba1dd25","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.6.tgz","integrity":"sha512-epzN2na8GF8cUTTCTdERgR0Vv+HC0ZnGlGBW8xMqgmrN0RuBYyxtWf4vCzG5fmXhIRMDYbX6Eap4nlCDttpSUw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+zAvONy1z8qztjTYQH7/h5OuuqyOc5WPvo+r0vdQKcwIgUbubCqDXZiqkFK6+gjcFW7mP273W/zXukGIVJ7DjH/I="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.7":{"name":"vs-util","version":"0.0.7","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.7","dist":{"shasum":"74035e3cee01ea50216ab9f12da98b026e532c66","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.7.tgz","integrity":"sha512-EbC9Zb1QBQ16HFXkbDGzrGSiUUz0/tcXJiMe8W2RhWE0Xh69EAD9UPcReRFGnZWcM7YnaNUx8+6wJGvusz7VvQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCSmcpBT/gNQC7CRO4UOpJOPcIb7xh+yGBJ0A/kIr5r9wIhAJy+jFRSOGGl7bhaVq1voa65rUvkDCQhJKQ57Evn1I7d"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.8":{"name":"vs-util","version":"0.0.8","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.8","dist":{"shasum":"18eeb4d263ca5b17fa1c81e53fd1b8f1cac31eb7","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.8.tgz","integrity":"sha512-XAiLmEklvo71Ap+cGxF4PO/pMFJkyR4yhoOawUeF+V/3zajOoLSIUFte13NMGz9/LwwsjPbV1+ze4SyCUMa1vw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCVVlkOnBEwwhGiLr3+ZrTZ8Z/0mkiVZyZriSVCXlF9jwIgY3UKjVXbThSQn0MABcXbAExCTp8bch1Nq1or4TKIuMM="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.9":{"name":"vs-util","version":"0.0.9","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.9","dist":{"shasum":"d6df4410a5b4d1037cd7f38efe35961e7d170aec","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.9.tgz","integrity":"sha512-tl2tEs100RODKSI9oWx56j2gfDec6Riz4hCow9gF1wYhaYU5srZnq2apsTdwCvcflfIOxqRDYeTOb07tzUZB6A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDAzuNw7OOus9srh0/iPLTluQEA2HnPPQOHFN8RofH8cQIhAOegZG84cZai2HiDbbHW9IbL/u9LrKQA8tpkIFxBm+uu"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.10":{"name":"vs-util","version":"0.0.10","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.10","dist":{"shasum":"19ab07f8ff2a3d2f2c5b0e24fd5558ea76058d5d","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.10.tgz","integrity":"sha512-AQbmHMi2Yb8r09Ch3Llikrfb1RXybMH+VWWEkjvC3apyhQ8ODTgbwFdIfBEGS4T76BWjhKnz/HbvGynT6PvgNw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZGfl6XiD5taqUmWy8vQSd5UOes6kfHFHTfrSnjx5DTgIgMoai6rsHYxiitm8eRSP2trBBKRRNdDkNuCZpG7+BzbY="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.11":{"name":"vs-util","version":"0.0.11","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.11","dist":{"shasum":"11eada75ace758089a35356ca27abfa0658d8eff","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.11.tgz","integrity":"sha512-McaXJZ1eOGZZkJrWUNVMhmalJEihtzBdSDmZ34BNGuqSPRK/pF/u2oI/8a6foLN5E4Fv//mww/c5UxdDOVxPmw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD3pUMoYGsOqjS58SuuuElhl2vfBGIXY8VfaiRwkevwOQIhAM2R7adqT4AzYeBBSlrtLIziPQHUWMa1xzIxXTCOM0c9"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.12":{"name":"vs-util","version":"0.0.12","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.http.get(host, port, path, data, callback);\nutil.http.post(host, port, path, data, callback);\nutil.http.put(host, port, path, data, callback);\nutil.http.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.12","dist":{"shasum":"0e5e59c171fba82fc02d9059189a5eb8ef312e72","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.12.tgz","integrity":"sha512-gzjoWsA6rQWGTBQDLiaOIdmoSSvhX5oECCyKpmCr523mGfmarmMtGRrXCPP6D99IMWFe/gbcoCHn9tceAWKD9w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB4avF/NVskw1CeSlButg03PTWdUyQ18sYOwWPM6Bd6UAiAn1vA75qEOLH3Qn9PE714/iA5yiU7RKiDtPBYYQhkwzQ=="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.13":{"name":"vs-util","version":"0.0.13","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.http.get(host, port, path, data, callback);\nutil.http.post(host, port, path, data, callback);\nutil.http.put(host, port, path, data, callback);\nutil.http.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.13","dist":{"shasum":"b39f21c1601e2fa27acd2df31e5d98a01a4dfd23","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.13.tgz","integrity":"sha512-8wbFcMhXwzerutlOG8lzuP3inSYRfVgR1Or45DZOGou9t7AalMbT3GnRJ3w29e4d0vUz4955feEyvWZ91K6Lnw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0LZ7eDoDopK3ZLFrOLFoEMgAI24BfrpMfvuUWurdWmAIhAKyXsGcjKydvSMlhMwdphUYOn4K1Rt2g0NB2iG0Fk9QF"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.14":{"name":"vs-util","version":"0.0.14","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.14","dist":{"shasum":"189749233d2c36871d1510abd61504fe3ca98529","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.14.tgz","integrity":"sha512-+vUSSNAQ0vMeHGBcJ85xnkB4vp1ZK2Swq4D0h9pmqP65lVfvl4WO5fZVKXptE2NmHO4wlHbGc88V0n+7gKdTUA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIQDDNv6+8Jrb/Qm+JQq3KnogEULtLEWIaClMu4gKllfVLQIfE2c7T09xZQ8VCxKQ3NlDFKzhv5IBHstE/+/vL9PTbg=="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.15":{"name":"vs-util","version":"0.0.15","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.15","dist":{"shasum":"4b678df53d3bab70733241a4de714df1ae9fb16f","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.15.tgz","integrity":"sha512-OEss8LjN4kziicu9QwdJTqbqabgNDk9tDNBD2WBZ7eAIhEk5uRs9yKF6jngiTw5yctTy6L67D1uXW4BhuCHc4w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDBoWZX+y1yOUgWXpq7k+uD2Suvtziw7ohbK1eOOKdLTAIhALmJ/c4CuGhK8VdoI1OgbI1eEBclVwAFaNK8r7ueHPie"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.16":{"name":"vs-util","version":"0.0.16","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.16","dist":{"shasum":"a62df3ee4869ed0e2ca7ad3c88e9cf93da9c08bb","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.16.tgz","integrity":"sha512-Whbk9EdWNcMZ5btaPe3hcJVBTu6AGOKb2szGIjNvoZnkv08qC7OJilW7KoCv19KA0jSN27crkXdJhMtTht1nRQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGslnwAcS4amzcGmPYZ1jTePie5Y2H/8Ng0HJYyZPMK2AiEA4aPGS3MOCHl6jZGKaYc7ANLxpbgR4lhM3wdA8Y1nR/o="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.17":{"name":"vs-util","version":"0.0.17","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.17","dist":{"shasum":"27761b317df8ae6469b49493bff6ba6d3905d169","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.17.tgz","integrity":"sha512-FhfBWKlFSbbu5AOJ0ZB8QdkeGZ/HhQkfREVcNRrjrVHUSqCn9fAyYR7ZCeIxTlvtvqkgMUm6hR6DfCJwD9XNJA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDcJLL0ih/4HQjtWmA7xer1GOEjG7hgwIJQ/lMlY0eZYQIhAP5DonYsnOlcmbYITuUKHCl71Kzga3gGlktIWMg2lrWL"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.18":{"name":"vs-util","version":"0.0.18","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.18","dist":{"shasum":"622b9818a3b4d0143290a237d1120c5d3492bb86","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.18.tgz","integrity":"sha512-02oYx3LpLwBCI0L8ZvTzsw39isr27NnmcgCXH12lX0q6gg8ollTcvPrDN3yKJ8yGStUGRcN+h7YCQGbtTwmPEw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHGm3sywicDMAUmYqIFL+asUapsMqorSdrlkJUCRjTNQAiAUXwN7Y6dwbP55JbuQKr9HOThcqmPtj6Gg64LQ79/QkQ=="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.19":{"name":"vs-util","version":"0.0.19","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.19","dist":{"shasum":"1e306526666db62e6dafb5bb81588ab3e14a6355","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.19.tgz","integrity":"sha512-HT3R/72az3z8fJpi+97XmH/lyB1kV/8Dn5lEjl96pphyHETPqc5WWKWgXi9mjei3NGuekboqY2p9jRFu8lxgOg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD/jserDas8W+sNO19MmjRaj7SMkbbNA87emC+euOsBeQIgdkQNDJ+1MT7HgCNJbPUZ2fjmjTCdvN9KnZdrajHcooI="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.20":{"name":"vs-util","version":"0.0.20","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.20","dist":{"shasum":"7a4889eaab59bc90975b80762ed556e2a9304537","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.20.tgz","integrity":"sha512-zV7J8V6zLmphBeG3XI3KwksRlrDgJIaqyJO2OqZzbF6XvGXLYRO+GR76vE56XIECyUa+uTLCdMcV4yrlBinxkg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDCq7reccR2TkGZhkY8K7eTZo6xq9NCla1aOTyG0qSzDAiB8oIGbNJ2y6YCnEYRWG4zZLfsxOqPcEwOzSm59cKJh7w=="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.21":{"name":"vs-util","version":"0.0.21","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.21","dist":{"shasum":"65b322c838c012cf36ff19e5466297d7f738332e","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.21.tgz","integrity":"sha512-uorC50qmfjh/fmvatrLMWOj/CSvMB444L4r1pgg+DXWUFL3sxXptCmN/KOPtm2tPAtDgp+F1MHNKGXH+BDW4rw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDPJJOHgz4OgohPaSHNbvmRcK7BVA1LP0WmVanfqDJ/zwIhAK26rncN14t+uW3cUqy3vamZZQ5S8sDLSysO1VJGWbBx"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.22":{"name":"vs-util","version":"0.0.22","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.22","dist":{"shasum":"77e81436238728ca07f1213ff14b2a5d903c8293","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.22.tgz","integrity":"sha512-Wph6sw5I5tfHBLRW8IvIn4oWazkzMAdCP9CIfnJSyIm9Gcxegloo6WlnpNyd7X1T0ldBYL3zWCh9UXTC/Rqj9g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDQNRNqOzQEuw9M7VV9KhdP8EInFzNrk/VfrKp2P3VASAIgd77t+9lKb40wO3qEQ8XsrTaLr3CZpGfelAJo4YZMtG0="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]},"0.0.23":{"name":"vs-util","version":"0.0.23","description":"Utilities commonly used in my projects","main":"vs-util.js","scripts":{"test":"node vs-util.js test","start":"node vs-util.js"},"dependencies":{},"engines":{"node":"*"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"},"keywords":["util","utility"],"author":{"name":"Vladimir Darmin"},"license":"MIT","readmeFilename":"README.md","readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = util.http.GET, type = util.http.FORM,\nvar host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.http.request(method, host, port, path, data, type, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.http.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.http.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\nwith their corresponding data types *FORM*, *JSON*, *HTML*, and *TEXT*\n\n```javascript\nutil.http.get(host, port, path, data, callback);\n\nutil.http.post(host, port, path, data, callback);\nutil.http.post.form(host, port, path, data, callback);\nutil.http.post.json(host, port, path, data, callback);\nutil.http.post.html(host, port, path, data, callback);\nutil.http.post.text(host, port, path, data, callback);\n\nutil.http.put(host, port, path, data, callback);\nutil.http.put.form(host, port, path, data, callback);\nutil.http.put.json(host, port, path, data, callback);\nutil.http.put.html(host, port, path, data, callback);\nutil.http.put.text(host, port, path, data, callback);\n\nutil.http.del(host, port, path, data, callback);\nutil.http.del.form(host, port, path, data, callback);\nutil.http.del.json(host, port, path, data, callback);\nutil.http.del.html(host, port, path, data, callback);\nutil.http.del.text(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n#### Define ####\n\nAdd routes to express server instance\n\n```javascript\nvar action = function action ( request, response, callback ) {\n  callback(null, \"Taking Action!\");\n}\n\nvar ping = function ping ( request, response, callback ) {\n  callback(null, new Date().getTime());\n}\n\n\nvar routes = [\n  { method: 'get', path: '/action', middleware: [ ], execute: action },\n  { method: 'get', path: '/ping',   middleware: [ ], execute: ping   }\n];\n\n\nvar express = require('express');\nvar server = exporess();\n\nutil.server.define(server, routes);\n\nserver.listen(8080);\n```\n\n#### Respond ####\n\nSend response in an appropriate format\n\n```javascript\nvar express = require('express');\nvar server = exporess();\n\nserver.get('/action', function ( request, response ) {\n  var error = null, value = 'this is html';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.html', function ( request, response ) {\n  var error = null, value = 'this is html again';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.json', function ( request, response ) {\n  var error = null, value = 'this is json';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.get('/action.txt', function ( request, response ) {\n  var error = null, value = 'this is plain text';\n  \n  util.server.respond(request, response, error, value);\n});\n\nserver.listen(8080);\n```\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLogging\n-------\n\nThe output to the console, generated by the module, can be turned on or off\n\n```javascript\nvar mongo = require('vs-util');\n\nmongo.log.on();    // turn logging on\nmongo.log.off();   // turn logging off\n\nmongo.log(true);   // turn logging on\nmongo.log(false);  // turn logging off\n```\n\n\nLicense\n-------\n\nMIT\n","_id":"vs-util@0.0.23","dist":{"shasum":"7c9002d5715796ed11992cb752636c0d0a748169","tarball":"https://registry.npmjs.org/vs-util/-/vs-util-0.0.23.tgz","integrity":"sha512-9+HaSroF4irBsws7HLo46srXBF4V/KPTJG+oGY0EQJ7rrmB+N9K7vLRoZrQoetsj53XuMj9b+eu9r4TJVIrFuA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDL4ojXXehhcCG63VUhc6i6HyMvYzBnPcY/fBtuy9SSdAiEA3E/RO+CQ6WP5ebpZcl9boQHXw0gOJ9YEoBA3Y7E3DT0="}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"d_vova","email":"vladimir.darmin@gmail.com"},"maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}]}},"readme":"vs-util\n=======\n\nUtilities commonly used in my projects\n\n\nInstallation\n------------\n\n```\nnpm install vs-util\n```\n\n\nQuick Start\n-----------\n\n```javascript\nvar util = require('vs-util');\n```\n\n\nHTTP\n----\n\nWorking with http requests and data sent over the wire\n\n```javascript\nvar util = require('vs-util');\n\nvar json = { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n\nconsole.log(json);\n\n// json { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Request ####\n\nSend HTTP request\n\n```javascript\nvar method = 'GET', host = 'www.google.com', port = 80, path = '/';\nvar data = json, callback = function callback ( error, value ) {\n  console.log(error || value);\n}\n\nutil.request(method, host, port, path, data, callback);\n```\n\n\n#### Encode ####\n\nConvert JSON object into format used by HTTP Request\n\n```javascript\nvar encoded = util.encode(json);\n\nconsole.log(encoded);\n\n// encoded { a: '\"b\"', c: '{\"d\":\"e\",\"f\":\"h\"}', i: '[\"j\",\"k\",\"l\"]' }\n```\n\n\n#### Decode ####\n\nConvert encoded object back into JSON format\n\n```javascript\nvar decoded = util.decode(encoded);\n\nconsole.log(decoded);\n\n// decoded { a: 'b', c: { d: 'e', f: 'h' }, i: [ 'j', 'k', 'l' ] }\n```\n\n\n#### Shortcuts ####\n\n*GET*, *POST*, *PUT*, and *DELETE* have corresponding shortcuts\n\n```javascript\nutil.request.get(host, port, path, data, callback);\nutil.request.post(host, port, path, data, callback);\nutil.request.put(host, port, path, data, callback);\nutil.request.del(host, port, path, data, callback);\n```\n\n\nAuth\n----\n\nWorking with authentication and authorization\n\n#### Create ####\n\nCreate salted hash for a given password that is already salted and ready to be saved\n(this method uses *SHA256*, and 32 bytes of salt)\n\n```javascript\nvar password = 'my secret password';\nvar salthash = util.auth.create(password);\n\nconsole.log(password);\nconsole.log(salthash);\n\n// my secret password\n// f26883bbc9c5667c06858279b5572fecaffe58a51cbf56dce5442d018fc948655cf91b67b6b11ef4d5ce5f63bed8a0de95a37d0d470a6b716a35ad91a1e93446\n```\n\n\n#### Verify ####\n\nWhen time comes and verification is required, simply call verify\n\n```javascript\nvar drowssap = 'drowsapp terces ym';\n\nvar correct = util.auth.verify(password, salthash);\nvar incorrect = util.auth.verify(drowssap, salthash);\n\nconsole.log(correct);   // true\nconsole.log(incorrect); // false\n```\n\n\n#### Encode ####\n\nSometimes it is important to ensure security of other saved data\n(this method uses *AES256*)\n\n```javascript\nvar text = 'this is secret data that should be encoded and decoded';\n\nvar encoded = util.auth.encode(text, password, salthash);\n\nconsole.log(encoded);\n\n// encoded dc0159af5121e192b06fd38b35200a61d78cf50cbc68922fa3cf4ea45d82598d3aaff9ec68cd37988942a4834e2e3467519be89f92a2acf98ddb48f50e65b554\n```\n\n#### Decode ####\n\nWhen time comes and decoding is required, simply call decode\n\n```javascript\nvar decoded = util.auth.decode(encoded, password, salthash);\n\nconsole.log(decoded);\n\n// this is secret data that should be encoded and decoded\n```\n\n\nServer\n------\n\n\nPresent\n-------\n\nFormat JSON structure into a tree-like string representation\n\n```javascript\nvar json = {\n  ENV: 'DEV',\n  NAME: 'vs-util presentation test',\n  PORT: 8080,\n  STUN: { host: 'stun.l.google.com', port: 19302 },\n  MONGO: 'mongodb://localhost/vs-util',\n  DB: {\n    logs: {\n      dropSync: false, batchSize: 10000,\n      create: { capped: true, size: 123456789, autoIndexId: true },\n      indexes: [ [ { id: 1 } ], [ { timestamp: 1 } ] ]\n    }\n  },\n  SERVICES_MONGO: 'mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789',\n  SERVICES_DB: {\n    services: { dropSync: false, batchSize: 10000 },\n    snapshots: { dropSync: false, batchSize: 10000 }\n  },\n  SERVICES_REFRESH: 500,\n  SERVICES_TIMEOUT: 500,\n  SERVICES_DISCOVER: 60000,\n  SERVICES_HEARTBEAT: 100,\n  SERVICES_SNAPSHOT: 1000,\n  LOG: { debug: -1, normal: 0, warning: 2, error: 3 }\n}\n\n\nvar title = 'CONFIG', depth = 4, prefix = '// ';\nvar formatted = util.present(title, json, depth, prefix);\n\nconsole.log(formatted);\n```\n\nFor console output there is a shortcut\n\n```javascript\nutil.present.log(title, json, depth, prefix);\n```\n\nThe output in both cases is going to look like:\n\n```\n// * config\n// |-- ENV                => \"DEV\"\n// |-- NAME               => \"vs-util presentation test\"\n// |-- PORT               => 8080\n// |-- STUN\n// | |-- host               => \"stun.l.google.com\"\n// | `-- port               => 19302\n// |-- MONGO              => \"mongodb://localhost/vs-util\"\n// |-- DB\n// | `-- logs\n// |   |-- dropSync           => false\n// |   |-- batchSize          => 10000\n// |   |-- create\n// |   | |-- capped             => true\n// |   | |-- size               => 123456789\n// |   | `-- autoIndexId        => true\n// |   `-- indexes\n// |     |-- 0                  => [{\"id\":1}]\n// |     `-- 1                  => [{\"timestamp\":1}]\n// |-- SERVICES_MONGO     => \"mongodb://heroku:1234567890abcdef1234567890abcdef@dharma.mongohq.com:10074/app12346789\"\n// |-- SERVICES_DB\n// | |-- services\n// | | |-- dropSync           => false\n// | | `-- batchSize          => 10000\n// | `-- snapshots\n// |   |-- dropSync           => false\n// |   `-- batchSize          => 10000\n// |-- SERVICES_REFRESH   => 500\n// |-- SERVICES_TIMEOUT   => 500\n// |-- SERVICES_DISCOVER  => 60000\n// |-- SERVICES_HEARTBEAT => 100\n// |-- SERVICES_SNAPSHOT  => 1000\n// `-- LOG\n//   |-- debug              => -1\n//   |-- normal             => 0\n//   |-- warning            => 2\n//   `-- error              => 3\n```\n\n\nGenerate\n--------\n\nRandom buffer of given length\n\n```javascript\nvar buffer = util.generate(8);\n\nconsole.log(buffer);\n\n// buffer <Buffer 41 6b 9e 2a 79 30 ba 67>\n```\n\n\n#### Hex ####\n\nGenerate random bytes of given length in hex\n\n```javascript\nvar hex = util.generate.hex(8);\n\nconsole.log(hex);\n\n// hex 5f7dafd337bb870b\n```\n\n#### ID ####\n\nGenerate random unique id (16 bytes long)\n\n```javascript\nvar id = util.generate.id();\n\nconsole.log(id);\n\n// id 42741578f9f17000bd7dc0bcc7a360ae\n```\n\n\nLicense\n-------\n\nMIT\n","maintainers":[{"name":"d_vova","email":"vladimir.darmin@gmail.com"}],"time":{"modified":"2022-06-28T18:41:12.257Z","created":"2013-09-26T00:06:16.284Z","0.0.1":"2013-09-26T00:06:21.622Z","0.0.2":"2013-09-26T20:41:12.034Z","0.0.3":"2013-09-26T23:52:56.273Z","0.0.4":"2013-09-27T17:19:43.128Z","0.0.5":"2013-09-27T17:35:30.904Z","0.0.6":"2013-09-27T20:24:07.547Z","0.0.7":"2013-09-27T20:39:36.598Z","0.0.8":"2013-09-27T21:08:12.850Z","0.0.9":"2013-09-27T21:11:41.516Z","0.0.10":"2013-09-27T21:20:44.865Z","0.0.11":"2013-09-27T23:03:42.373Z","0.0.12":"2013-09-27T23:13:15.697Z","0.0.13":"2013-09-28T01:06:23.415Z","0.0.14":"2013-09-28T03:51:08.650Z","0.0.15":"2013-09-28T06:33:14.555Z","0.0.16":"2013-09-28T07:29:19.768Z","0.0.17":"2013-09-29T03:24:36.634Z","0.0.18":"2013-09-29T06:42:31.831Z","0.0.19":"2013-09-29T07:02:32.194Z","0.0.20":"2013-09-30T06:30:36.565Z","0.0.21":"2013-09-30T06:34:47.011Z","0.0.22":"2013-09-30T07:17:05.100Z","0.0.23":"2013-09-30T17:38:48.588Z"},"author":{"name":"Vladimir Darmin"},"repository":{"type":"git","url":"git://github.com/d-vova/vs-util.git"}}