0.1.5 • Published 11 years ago

sak v0.1.5

Weekly downloads
3
License
MIT
Repository
github
Last release
11 years ago

Swiss Army Knife (SAK)

Build Status Dependency Status

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); // false

Params

NameDescriptionType
objAn object or any variable that needs to be cloned.Object

Return

DescriptionType
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

NameDescriptionType
objObjects that need to be merged, overwrites from right to left.Object

Return

DescriptionType
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 false

Params

NameDescriptionType
objVariable that might be an objectObject

Return

DescriptionType
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 false

Params

NameDescriptionType
fnVariable that might be a function.Object

Return

DescriptionType
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 string

Params

NameType
strString

Return

DescriptionType
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
NameDescriptionType
dataThe data to pass to the forked process.
Return
DescriptionType
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
NameDescriptionType
argsThe array from process.argv.slice(2), dropping the path to node bin and the file.Array
Return
DescriptionType
The date passed to the forked process.Object
0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago