0.1.5 • Published 11 years ago
sak v0.1.5
Swiss Army Knife (SAK)
Version 0.1.5
Swiss Army Knife for Node.js. Use this module for developing you application. Once you're done grap the individual modules for production.
Created by Thomas de Zeeuw, thomasdezeeuw@gmail.com (https://thomasdezeeuw.nl/).
Released under a MIT license.
Exports
Clone
Function
Clone an object.
Example
var clone = require('sak').clone
, obj1 = {a: 'a'}
, obj2 = clone(obj1);
console.log('obj2', obj2); // obj2 {a: 'a'}
console.log(obj1 == obj2); // falseParams
| Name | Description | Type |
|---|---|---|
| obj | An object or any variable that needs to be cloned. | Object |
Return
| Description | Type |
|---|---|
| A clone of the original object. | Object |
Merge
Function
Merge an object with other object(s).
Example
var merge = require('sak').merge
, obj1 = {a: 'a'}
, obj2 = {b: 'b'};
var obj = merge(obj1, obj2);
console.log('obj', obj) // Obj {a: 'a', b: 'b'}Params
| Name | Description | Type |
|---|---|---|
| obj | Objects that need to be merged, overwrites from right to left. | Object |
Return
| Description | Type |
|---|---|
| A single merged object. | Object |
isObject
Function
Test if an variable is an object.
Example
var obj1 = {a: 'a'}
, obj2 = 'not an object';
var test1 = isObject(obj1)
, test2 = isObject(obj2);
console.log('test1', test1) // test1 true
console.log('test2', test2) // test2 falseParams
| Name | Description | Type |
|---|---|---|
| obj | Variable that might be an object | Object |
Return
| Description | Type |
|---|---|
| Whether or not it's an object. | Boolean |
IsFunction
Function
Test if an variable is a function.
Example
var obj1 = function () {}
, obj2 = 'not a function';
var test1 = isFunction(obj1)
, test2 = isFunction(obj2);
console.log('test1', test1) // test1 true
console.log('test2', test2) // test2 falseParams
| Name | Description | Type |
|---|---|---|
| fn | Variable that might be a function. | Object |
Return
| Description | Type |
|---|---|
| Whether or not it's a function. | Boolean |
firstToUpper
Function, public.
Capitalize the first letter of a string.
Example
var string = 'my string'
, upperString = firstToUpper(string);
console.log('upperString', upperString) // upperString My stringParams
| Name | Type |
|---|---|
| str | String |
Return
| Description | Type |
|---|---|
| Same string starting with a capital character. | String |
forkArguments
encode
Function
Encode arguments to pass when forking a process.
Example
// Master process
var options = {port: 8000, env: 'production'}
, encoded = encode(options)
, child = cp.fork('./my-child-script.js', encoded);Params
| Name | Description | Type |
|---|---|---|
| data | The data to pass to the forked process. |
Return
| Description | Type |
|---|---|
| An array with encoded data, ready to be passed to the forking function. | Array |
decode
Function
Decode arguments that are passed to a forked process.
Example
// Child process
var options = decode(process.argv.slice(2));
console.log('options', options); // options {port: 8000, env: 'production'}Params
| Name | Description | Type |
|---|---|---|
| args | The array from process.argv.slice(2), dropping the path to node bin and the file. | Array |
Return
| Description | Type |
|---|---|
| The date passed to the forked process. | Object |