Sha256: f1142a3af338157c1c69ae8d8f5e77674d0b667d00396be882693d13345e27d6
Contents?: true
Size: 1.04 KB
Versions: 15
Compression:
Stored size: 1.04 KB
Contents
_.mixin({ // Strip an object any keys paired with null values compactObject: function(object) { let newObject = _.extend({}, object) _(newObject).each((v, k) => { if(v == null) { delete newObject[k] } }) return newObject }, // If arrayOrObject is an array, map over it with iteree, otherwise pass // arrayOrObject to iteree once. Useful for removing conditionals from methods // that need to handle individual items and also handle arrays of items by // performing the same operation on each item. This is common when processing // JSON API structures. mapIfArray: function(arrayOrObject, iteree) { if(_.isArray(arrayOrObject)) { return arrayOrObject.map(iteree) } else { return iteree(arrayOrObject) } }, // Similar to mapIfArray from above, but it also flattens the resulting array flatMapIfArray: function(arrayOrObject, iteree) { if(_.isArray(arrayOrObject)) { return _.flatten(arrayOrObject.map(iteree)) } else { return iteree(arrayOrObject) } }, })
Version data entries
15 entries across 15 versions & 1 rubygems