UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

51 lines (50 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasProp = hasProp; const isCallable_js_1 = require("./isCallable.js"); const isObject_js_1 = require("./isObject.js"); const isArrayOfStrings_js_1 = require("./isArrayOfStrings.js"); const isObjectOfStrings_js_1 = require("./isObjectOfStrings.js"); const isArray_js_1 = require("./isArray.js"); function hasProp(obj, prop, type) { if (!(0, isObject_js_1.isObject)(obj)) return false; if (!(prop in obj)) { return type === 'undefined'; } if (type === undefined) { return true; } const propValue = obj[prop]; if (type === 'undefined') { return propValue === undefined; } if (type === 'array') { return (0, isArray_js_1.isArray)(propValue); } if (type === 'object') { return (0, isObject_js_1.isObject)(propValue); } if (type === 'string[]') { return (0, isArrayOfStrings_js_1.isArrayOfStrings)(propValue); } if (type === 'string{}') { return (0, isObjectOfStrings_js_1.isObjectOfStrings)(propValue); } if (type === 'function') { return (0, isCallable_js_1.isCallable)(propValue); } if ((0, isArray_js_1.isArray)(type)) { return typeof propValue === 'string' && type.includes(propValue); } if (type === 'null') { return propValue === null; } if (type === 'true') { return propValue === true; } if (type === 'false') { return propValue === false; } return typeof propValue === type; }