UNPKG

@n3okill/utils

Version:
25 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasProperty = hasProperty; const isString_1 = require("../type/isString"); const _internal_1 = require("./_internal"); /** * Check if the object has the property * @param obj The object to search for the property * @param name The name of the property can be on the form "a.b.c[1].d" */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function hasProperty(obj, name) { if ((0, isString_1.isString)(name) && obj && Object.prototype.hasOwnProperty.call(obj, name)) { return true; } const parts = (0, _internal_1.getNameParts)((0, isString_1.isString)(name) ? name.split(".") : name); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment let o = obj; while (o && parts.length) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment o = o[parts.shift()]; } return parts.length === 0; } //# sourceMappingURL=hasProperty.js.map