UNPKG

vue-condition-watcher

Version:

Vue composition API for automatic data fetching. With conditions as the core. Easily control and sync to URL query string by conditions

27 lines (26 loc) 1.1 kB
export function containsProp(obj, ...props) { if (!isObject(obj)) return false; return props.some((k) => k in obj); } const STR_UNDEFINED = 'undefined'; export const hasWindow = () => typeof window != STR_UNDEFINED; export const hasDocument = () => typeof document != STR_UNDEFINED; export const isDocumentVisibility = () => hasDocument() && document.visibilityState === 'visible'; export const hasRequestAnimationFrame = () => hasWindow() && typeof window['requestAnimationFrame'] != STR_UNDEFINED; export const isNil = (val) => val === null || val === undefined; export const isObject = (val) => val !== null && typeof val === 'object'; export const isServer = !hasWindow(); export const rAF = (f) => hasRequestAnimationFrame() ? window['requestAnimationFrame'](f) : setTimeout(f, 1); export const isNoData = (data) => { if (typeof data === 'string' || Array.isArray(data)) { return data.length === 0; } if ([null, undefined].includes(data)) { return false; } if (isObject(data)) { return Object.keys.length === 0; } return !data; };