source: trip-planner-front/node_modules/cosmiconfig/dist/getPropertyByPath.js@ 1ad8e64

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

initial commit

  • Property mode set to 100644
File size: 938 bytes
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getPropertyByPath = getPropertyByPath;
7
8// Resolves property names or property paths defined with period-delimited
9// strings or arrays of strings. Property names that are found on the source
10// object are used directly (even if they include a period).
11// Nested property names that include periods, within a path, are only
12// understood in array paths.
13function getPropertyByPath(source, path) {
14 if (typeof path === 'string' && Object.prototype.hasOwnProperty.call(source, path)) {
15 return source[path];
16 }
17
18 const parsedPath = typeof path === 'string' ? path.split('.') : path; // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
20 return parsedPath.reduce((previous, key) => {
21 if (previous === undefined) {
22 return previous;
23 }
24
25 return previous[key];
26 }, source);
27}
28//# sourceMappingURL=getPropertyByPath.js.map
Note: See TracBrowser for help on using the repository browser.