source: trip-planner-front/node_modules/get-value/index.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/*!
2 * get-value <https://github.com/jonschlinkert/get-value>
3 *
4 * Copyright (c) 2014-2015, Jon Schlinkert.
5 * Licensed under the MIT License.
6 */
7
8module.exports = function(obj, prop, a, b, c) {
9 if (!isObject(obj) || !prop) {
10 return obj;
11 }
12
13 prop = toString(prop);
14
15 // allowing for multiple properties to be passed as
16 // a string or array, but much faster (3-4x) than doing
17 // `[].slice.call(arguments)`
18 if (a) prop += '.' + toString(a);
19 if (b) prop += '.' + toString(b);
20 if (c) prop += '.' + toString(c);
21
22 if (prop in obj) {
23 return obj[prop];
24 }
25
26 var segs = prop.split('.');
27 var len = segs.length;
28 var i = -1;
29
30 while (obj && (++i < len)) {
31 var key = segs[i];
32 while (key[key.length - 1] === '\\') {
33 key = key.slice(0, -1) + '.' + segs[++i];
34 }
35 obj = obj[key];
36 }
37 return obj;
38};
39
40function isObject(val) {
41 return val !== null && (typeof val === 'object' || typeof val === 'function');
42}
43
44function toString(val) {
45 if (!val) return '';
46 if (Array.isArray(val)) {
47 return val.join('.');
48 }
49 return val;
50}
Note: See TracBrowser for help on using the repository browser.