main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import constant from './constant.js';
|
---|
2 | import createInverter from './_createInverter.js';
|
---|
3 | import identity from './identity.js';
|
---|
4 |
|
---|
5 | /** Used for built-in method references. */
|
---|
6 | var objectProto = Object.prototype;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Used to resolve the
|
---|
10 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
---|
11 | * of values.
|
---|
12 | */
|
---|
13 | var nativeObjectToString = objectProto.toString;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Creates an object composed of the inverted keys and values of `object`.
|
---|
17 | * If `object` contains duplicate values, subsequent values overwrite
|
---|
18 | * property assignments of previous values.
|
---|
19 | *
|
---|
20 | * @static
|
---|
21 | * @memberOf _
|
---|
22 | * @since 0.7.0
|
---|
23 | * @category Object
|
---|
24 | * @param {Object} object The object to invert.
|
---|
25 | * @returns {Object} Returns the new inverted object.
|
---|
26 | * @example
|
---|
27 | *
|
---|
28 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
---|
29 | *
|
---|
30 | * _.invert(object);
|
---|
31 | * // => { '1': 'c', '2': 'b' }
|
---|
32 | */
|
---|
33 | var invert = createInverter(function(result, value, key) {
|
---|
34 | if (value != null &&
|
---|
35 | typeof value.toString != 'function') {
|
---|
36 | value = nativeObjectToString.call(value);
|
---|
37 | }
|
---|
38 |
|
---|
39 | result[value] = key;
|
---|
40 | }, constant(identity));
|
---|
41 |
|
---|
42 | export default invert;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.