Overview :
JsDK (JS dev kit) of Object Class.
How to use :
1. Extend Object Class :
;// import 'x-object'; //then :var object =a:1 b:2 c:3;var whitelist = 'a' 'b'Object;// {a:1, b:2} //-----------Opposite of filter (blacklist)var blacklist = 'a' 'b'Object// {c:3}//........
2. Import safe :
const XObject = ;// import XObject from 'x-object/safe';//then :XObject;//........
Methods :
1. Object.map( object, (k, v)=>)
- return another object with the same keys , but this same/different values according to the second argument which is callback accepts two arguments.
Object;// {f:2, l:3}//------------------- let students = sami : 8070 ahmed: 90100 ; let v / vlength ; Object; //{sami:75, ahmed: 95}
2.Object.filter(object, String|Array|RegExp|function)
-
Retrieve a sub-object of a current object.
-
Examples :
Object; // {age:23} Object; // {age:23, parent:'Ahmed'} Object; // {firstname:'Rami', lastname:'Toumi'} Object; // {f:'Rami', parent:'Ahmed'}
3.Object.vals(object) :
- As
Object.keys
however it returns the values of keys in arraym not the keys itself.
4. Object.belongsTo(childObject, parentObject) :
- It checks if the 1st argument is a sub-object of the 2nd argument.
5. Object.equals
- check quality of any two objects even if they are complex.
Unit tests :
Filter Class
✓ contains 4 non-static methods
✓ runs "byKey" method prefectly
✓ runs "byKeys" method prefectly
✓ runs "byRegExp" method prefectly by matching all keys ends with "name"
✓ runs "byCallback" method prefectly
Fitler#execute Method
✓ must forwards call to "byKey" whenever the argument is instance of "String class"
✓ must forwards call to "byKeys" whenever the argument is instance of "Array Class"
✓ must forwards call to "byRegExp" whenever the argument is regular expression
✓ must forwards call to "byCallback" whenever the argument is callback
✓ must return the same object if no argument is given
✓ must throw exception whenever the argument is not belong to one of the previous classes (String, Array, RegExp, Function)
Object.map
✓ returns an object with the same keys of target object
✓ calls the callback for each keys' iteration
Object.filter
✓ returns an object with 1 key whenever the 2nd arg is string & this key is belongs to keys of the target object
✓ returns an object with 2 key whenever the 2nd arg is string & keys belong to keys of the target object
Object.vals
✓ works fine
✓ returns an array of object values with a size equals to keys size
Object.belongsTo
✓ check if the 1st argument is SUB-OBJECT of the 2nd argument
Object.equals
✓ checks the equality of two strings
✓ checks the equality of two arrays
✓ checks the equality of two literal objects
✓ checks the equality of two dates
✓ checks the equality of two complex objects
Safe Import
✓ prevents the Object class from extension
✓ extends the Object class whenever "x-object" is imported
25 passing (24ms)