o - JS Library for Object Manipulation


Intro

o - is simple lightweight JavaScript library for basic object manipulation. Compressed and gzipped weights around 0,5 kb. It should work on IE 5.5 and latter. Also there is lite version that doesn't make hasOwnProperty check that will run faster and with less code.
Download the source code on GitHub


-add:

Adding methods to the object:
Example:

var o1 = {a:1, b:"jdlsakjd", c:[1,2,3], d:{a:1,b:2,c:2}} o.add(o1,"f","hello world"); console.log(o1);

-remove:

Removing methods from the object:
Example:

o.remove(o1,"f"); console.log(o1); // true

-keys:

Object keys:
Example:

o.keys(o1); console.log(o1); // ["a", "b", "c", "d"]

-values:

Object values:
Example:

o.values(o1); console.log(o1); // [1, "jdlsakjd", [1,2,3], {a:1,b:2,c:2}]

-len:

Object length:
Example:

o.len(o1); console.log(o1); // 4

-has:

Object has method:
Example:

o.has(o1,"a"); console.log(o.has(o1,"a")); // true

-type:

Object method type:
Example:

o.type(o1,"a"); console.log(o.type(o1,"a")); //number

-isEmpty:

Object is empty:
Example:

o.isEmpty(o1); console.log(o.isEmpty(o1)); // false

-cloneAll:

Creates shallow-copy of the one or more objects:
Example:

o.cloneAll(o1, {e:5,f:6}); console.log(o.cloneAll(o1, {e:5,f:6})); // {a:1, b:"jdlsakjd", c:[1,2,3], d:{a:1,b:2,c:2}, e:5, f:6}

-extend:

Creates deep permanent copy of the parent object with child object:
Example:

o.extend(o1, {e:5,f:6}); console.log(o.cloneAll(o1, {e:5,f:6})); // {a:1, b:"jdlsakjd", c:[1,2,3], d:{a:1,b:2,c:2}, e:5, f:6}

-toJSON:

Converts the object to JSON - JSON.stringify
Example:

o.toJSON(o1) console.log(o.toJSON(o1)); // "{"a":1,"b":"jdlsakjd","c":[1,2,3],"d":{"a":1,"b":2,"c":2}}"

-toObject:

Converts JSON to object - JSON.parse
Example:

o.toObject('{"a":"1","b":"2"}'); console.log(o.toObject('{"a":"1","b":"2"}')); // {a:"1", b:"2"}

Note: Use the JavaScript browser console to try the examples.