@enonic/js-utils
Advanced tools
Comparing version 0.38.5 to 0.38.6
@@ -1,2 +0,1 @@ | ||
import type { AnyObject } from '../types'; | ||
export declare function getIn<O extends AnyObject, K extends keyof O, V extends O[K], D>(source: O, path: string | Array<string>, def?: D): V | D; | ||
export declare function getIn<O extends Object, K extends keyof O, V extends O[K], D>(source: O, path: string | Array<string | number> | number, def?: D): V | D; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIn = void 0; | ||
var isObject_1 = require("../value/isObject"); | ||
var isBasicObject_1 = require("../value/isBasicObject"); | ||
var isNumber_1 = require("../value/isNumber"); | ||
var hasOwnProperty_1 = require("./hasOwnProperty"); | ||
function getIn(source, path, def) { | ||
if (!Array.isArray(path)) { | ||
path = path.split('.'); | ||
if ((0, isNumber_1.isNumber)(path)) { | ||
path = [path]; | ||
} | ||
else { | ||
path = path.split('.'); | ||
} | ||
} | ||
@@ -17,3 +23,5 @@ var leafKey = path[0]; | ||
var branchKey = path[i]; | ||
if (!(0, isObject_1.isObject)(obj) || !(0, hasOwnProperty_1.hasOwnProperty)(obj, branchKey)) { | ||
if (!(0, isBasicObject_1.isBasicObject)(obj) | ||
|| !(0, hasOwnProperty_1.hasOwnProperty)(obj, branchKey) | ||
|| typeof obj[branchKey] === 'undefined') { | ||
return def; | ||
@@ -24,3 +32,3 @@ } | ||
} | ||
if (!(0, isObject_1.isObject)(obj) | ||
if (!(0, isBasicObject_1.isBasicObject)(obj) | ||
|| !(0, hasOwnProperty_1.hasOwnProperty)(obj, leafKey) | ||
@@ -27,0 +35,0 @@ || typeof obj[leafKey] === 'undefined') { |
@@ -1,2 +0,1 @@ | ||
import type { AnyObject } from '../types'; | ||
export declare function sortKeys<T extends AnyObject>(obj: T): T; | ||
export declare function sortKeys<T extends object>(obj: T): T; |
@@ -125,1 +125,4 @@ export type { App } from './App.d'; | ||
} from './Utility.d'; | ||
export type { | ||
Vhost | ||
} from './Vhost.d'; |
@@ -63,3 +63,3 @@ { | ||
}, | ||
"version": "0.38.5" | ||
"version": "0.38.6" | ||
} |
@@ -1,4 +0,3 @@ | ||
import type {AnyObject} from '../types'; | ||
import {isObject} from '../value/isObject'; | ||
import {isBasicObject} from '../value/isBasicObject'; | ||
import {isNumber} from '../value/isNumber'; | ||
import {hasOwnProperty} from './hasOwnProperty'; | ||
@@ -8,3 +7,3 @@ | ||
export function getIn< | ||
O extends AnyObject, | ||
O extends Object, // eslint-disable-line @typescript-eslint/ban-types | ||
K extends keyof O, | ||
@@ -15,10 +14,16 @@ V extends O[K], | ||
source :O, | ||
path :string | Array<string>, | ||
path :string | Array<string|number> | number, | ||
def? :D | ||
) :V|D { | ||
if (!Array.isArray(path)) { | ||
path = path.split('.'); | ||
if (isNumber(path)) { | ||
path = [path]; | ||
} else { | ||
path = path.split('.'); | ||
} | ||
} | ||
//console.debug('path:%s', path); | ||
let leafKey = path[0] as string; | ||
let leafKey = path[0] as string|number; | ||
//console.debug('leafKey:%s', leafKey); | ||
@@ -34,3 +39,7 @@ let obj = source as unknown; | ||
if (!isObject(obj) || !hasOwnProperty(obj, branchKey)) { | ||
if ( | ||
!isBasicObject(obj) | ||
|| !hasOwnProperty(obj, branchKey) | ||
|| typeof obj[branchKey] === 'undefined' | ||
) { | ||
return def as D; | ||
@@ -43,8 +52,9 @@ } | ||
//console.debug('leafKey:%s', leafKey); | ||
//console.debug('isBasicObject(obj):%s', isBasicObject(obj)); | ||
if ( | ||
!isObject(obj) | ||
!isBasicObject(obj) | ||
|| !hasOwnProperty(obj, leafKey) | ||
|| typeof obj[leafKey] === 'undefined' | ||
) { | ||
//console.debug('returing default:%s', def); | ||
return def as D; | ||
@@ -51,0 +61,0 @@ } |
@@ -1,4 +0,1 @@ | ||
import type {AnyObject} from '../types'; | ||
const {isArray} = Array; | ||
@@ -8,3 +5,3 @@ const {keys} = Object; | ||
export function sortKeys<T extends AnyObject>(obj: T) :T { | ||
export function sortKeys<T extends object>(obj: T) :T { | ||
if (typeof obj !== 'object' || isArray(obj)) { | ||
@@ -11,0 +8,0 @@ throw new Error('sortKeys'); |
@@ -1,4 +0,1 @@ | ||
//import type {AnyObject} from '../types'; | ||
const {isArray} = Array; | ||
@@ -5,0 +2,0 @@ const {keys} = Object; |
@@ -125,1 +125,4 @@ export type { App } from './App.d'; | ||
} from './Utility.d'; | ||
export type { | ||
Vhost | ||
} from './Vhost.d'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1624559
509
26902