all files / scour/utilities/ index.js

100% Statements 10/10
100% Branches 0/0
100% Functions 0/0
100% Lines 10/10
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172                                                                                                                                                                                                                                                                                                                                   
 
/**
 * Utility functions:
 * (Section) These are utilities that don't need a wrapped object.
 */
 
/**
 * scour.get : scour.get(object, keypath)
 * Gets a keypath from an object.
 *
 *     data = { users: { bob: { name: 'john' } } }
 *
 *     result = get(data, ['users', 'bob', 'name'])
 *     // => 'robert'
 *
 * This is also available as `require('scourjs/utilities/get')`.
 */
 
exports.get = require('./get')
 
/**
 * scour.set : scour.set(object, keypath, value)
 * Sets a `keypath` into an `object` immutably.
 *
 *     data = { users: { bob: { name: 'john' } } }
 *
 *     result = set(data, ['users', 'bob', 'name'], 'robert')
 *     // => { users: { bob: { name: 'robert' } } }
 *
 * This is also available as `require('scourjs/utilities/set')`.
 */
 
exports.set = require('./set')
 
/**
 * scour.del : scour.del(object, keypath)
 * Deletes a `keypath` from an `object` immutably.
 *
 *     data = { users: { bob: { name: 'robert' } } }
 *     result = del(data, ['users', 'bob', 'name'])
 *
 *     // => { users: { bob: {} } }
 *
 * This is also available as `require('scourjs/utilities/del')`.
 */
 
exports.del = require('./del')
 
/**
 * scour.extendIn : scour.extendIn(object, keypath, extensions...)
 * Extends a `keypath` from an `object` immutably.
 *
 *     data = { users: { bob: { name: 'robert' } } }
 *     result = extendIn(data, ['users', 'bob'], { email: 'bob@gmail.com' })
 *
 *     // => { users: { bob: { name: 'robert', email: 'bob@gmail.com' } } }
 *
 * This is also available as `require('scourjs/utilities/extend_in')`.
 */
 
exports.extendIn = require('./extend_in')
 
/**
 * scour.each : scour.each(iterable, fn)
 * Iterates through `iterable`, either an object or an array. This is an
 * implementation of [Array#forEach] that also works for objects. The callback
 * `fn` will be invoked with two parameters: `currentValue` and `key`, just
 * like `Array#forEach`.
 *
 * This is also available as `require('scourjs/utilities/each')`.
 *
 * [Array#forEach]: http://devdocs.io/javascript/global_objects/array/foreach
 */
 
exports.each = require('./each')
 
/**
 * scour.map : scour.map(iterable, fn)
 * Creates a new `Array` with with the results of calling a provided function
 * on every element in this array. Works like [Array#map], but also works on
 * objects as well as arrays.
 *
 * The callback `fn` will be invoked with two parameters: `currentValue` and
 * `key`, just like [Array#map].
 *
 * This is also available as `require('scourjs/utilities/map')`.
 *
 * [Array#map]: http://devdocs.io/javascript/global_objects/array/map
 */
 
exports.map = require('./map')
 
/**
 * scour.mapObject : scour.mapObject(iterable, fn)
 * Creates a new `Object` with with the results of calling a provided function
 * on every element in this array. Works like [Array#map], but also works on
 * objects as well as arrays, and it returns an object instead.
 *
 * The callback `fn` will be invoked with two parameters: `currentValue` and
 * `key`, just like [Array#map].
 *
 *     object = { a: 20, b: 30, c: 40 }
 *     result = scour.mapObject(object, (val, key) => {
 *       return '$' + val + '.00'
 *     })
 *
 *     // => { a: '$20.00', b: '$30.00', c: '$40.00' }
 *
 * This is also available as `require('scourjs/utilities/map_object')`.
 */
 
exports.mapObject = require('./map_object')
 
/**
 * scour.indexedMap : scour.indexedMap(iterable, fn)
 * Creates a new `Object` with with the results of calling a provided function
 * returning the keys and values for the new object.
 *
 * The callback `fn` will be invoked with two parameters: `currentValue` and
 * `key`, just like [Array#map].
 *
 * The callback `fn` should return an array with two elements: with `result[0]`
 * being the key, and `result[1]` being the value. These are what the new
 * object will be constructed with.
 *
 * The `iterable` parameter can be an object or an array. This works like
 * `Array#map`, but also works on objects as well as arrays.
 *
 *     list = ['Fred', 'Barney', 'Wilma']
 *
 *     object = scour.indexedMap(list, (val, key) => {
 *       var newkey = val.substr(0, 1)
 *       return [ newkey, val ]
 *     })
 *
 *     // => { f: 'Fred', b: 'Barney', w: 'Wilma' }
 *
 * This is also available as `require('scourjs/utilities/indexed_map')`.
 */
 
exports.indexedMap = require('./indexed_map')
 
/**
 * scour.filter : scour.filter(iterable, function(val, key), [isArray])
 * Creates a new Array or Object with all elements that pass the test
 * implemented by the provided function.
 *
 * Works like [Array#filter], but will return an object if an object is also passed.
 *
 * The optional `isArray` argument, when passed `true`, will always make this
 * return an `Array`. If `false`, it will always be an `Object`. Leave it
 * `undefined` for the default behavior.
 *
 * This is also available as `require('scourjs/utilities/filter')`.
 *
 * [Array#filter]: http://devdocs.io/javascript/global_objects/array/filter
 */
 
exports.filter = require('./filter')
 
/**
 * scour.sortBy : scour.sortBy(iterable, criteria)
 * Sorts by a given criteria.
 *
 *     list = [ { name: 'Fred' }, { name: 'Barney' }, { name: 'Wilma' } ]
 *     scour.sortBy(list, 'name')
 *
 * This is also available as `require('scourjs/utilities/sort_by')`.
 */
 
exports.sortBy = require('./sort_by')