Code coverage report for src/Common/Obj.js

Statements: 100% (9 / 9)      Branches: 100% (2 / 2)      Functions: 100% (2 / 2)      Lines: 100% (9 / 9)      Ignored: none     

All files » src/Common/ » Obj.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42    1       1                             3 3   3       6 3     6                 1
'use strict';
 
var _           = require("lodash"),
    Safe        = require("./Safe");
 
 
var Obj = {
 
    /**
     *
     * Get the object keys. If a filter is specified it returns the keys
     * that match the filter regular expression.
     *
     * @param {Object}          obj
     * @param {String|RegExp}   filter
     *
     * @return {Array}
     *
     */
    filter: function(obj, filter){
 
        obj         = Safe.object(obj);
        filter      = Safe.regexp(filter, "/.*/");
 
        return _.transform(
            obj,
            function(result, val, key){
 
                if(filter.exec(key)){
                    result.push(key);
                }
 
                return result;
 
            },
            []);
 
    }
 
};
 
module.exports = Obj;