UNPKG

streamer-client

Version:

A node.js client for the Duke OIT Streamer API

25 lines (21 loc) 758 B
var _ = require('underscore'); /** * Maps function to selected keys of object, returning a transformed * version of the object * @param {Object} object The object to apply transformation to * @param {String[]} keys Array of keys to apply transformation to * @param {function} func Function to apply to values of keys * @return {Object} Transformed object */ module.exports.keyMap = function(object, keys, func) { var transformedSubset = _.object(_.map(_.pick(object, keys), function(val, key) { return [key, func(val)]; })); return _.extend(object, transformedSubset); }; /** * Strips whitespace from string * @param {String} str String to strip */ module.exports.strip = function(str) { return str.replace(/(^\s+|\s+$)/g,''); };