X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Funcss%2Fnode_modules%2Flodash%2Finvert.js;fp=node_modules%2Funcss%2Fnode_modules%2Flodash%2Finvert.js;h=8c7a42934682c8c7718bba49c6b2531b78947441;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/uncss/node_modules/lodash/invert.js b/node_modules/uncss/node_modules/lodash/invert.js new file mode 100644 index 000000000..8c7a42934 --- /dev/null +++ b/node_modules/uncss/node_modules/lodash/invert.js @@ -0,0 +1,50 @@ +var arrayReduce = require('./internal/arrayReduce'), + keys = require('./keys'); + +/** Used for built-in method references. */ +var objectProto = global.Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Creates an object composed of the inverted keys and values of `object`. + * If `object` contains duplicate values, subsequent values overwrite property + * assignments of previous values unless `multiVal` is `true`. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to invert. + * @param {boolean} [multiVal] Allow multiple values per key. + * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`. + * @returns {Object} Returns the new inverted object. + * @example + * + * var object = { 'a': 1, 'b': 2, 'c': 1 }; + * + * _.invert(object); + * // => { '1': 'c', '2': 'b' } + * + * // with `multiVal` + * _.invert(object, true); + * // => { '1': ['a', 'c'], '2': ['b'] } + */ +function invert(object, multiVal, guard) { + return arrayReduce(keys(object), function(result, key) { + var value = object[key]; + if (multiVal && !guard) { + if (hasOwnProperty.call(result, value)) { + result[value].push(key); + } else { + result[value] = [key]; + } + } + else { + result[value] = key; + } + return result; + }, {}); +} + +module.exports = invert;