46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
import isWindow from "./isWindow.js";
|
|
import * as win from "./window.js";
|
|
|
|
const window = thing => thing === win.window || isWindow(thing);
|
|
|
|
const docFrag = thing => object(thing) && thing.nodeType === 11;
|
|
|
|
const object = thing => !!thing && typeof thing === 'object';
|
|
|
|
const func = thing => typeof thing === 'function';
|
|
|
|
const number = thing => typeof thing === 'number';
|
|
|
|
const bool = thing => typeof thing === 'boolean';
|
|
|
|
const string = thing => typeof thing === 'string';
|
|
|
|
const element = thing => {
|
|
if (!thing || typeof thing !== 'object') {
|
|
return false;
|
|
} // eslint-disable-next-line import/no-named-as-default-member
|
|
|
|
|
|
const _window = win.getWindow(thing) || win.window;
|
|
|
|
return /object|function/.test(typeof _window.Element) ? thing instanceof _window.Element // DOM2
|
|
: thing.nodeType === 1 && typeof thing.nodeName === 'string';
|
|
};
|
|
|
|
const plainObject = thing => object(thing) && !!thing.constructor && /function Object\b/.test(thing.constructor.toString());
|
|
|
|
const array = thing => object(thing) && typeof thing.length !== 'undefined' && func(thing.splice);
|
|
|
|
export default {
|
|
window,
|
|
docFrag,
|
|
object,
|
|
func,
|
|
number,
|
|
bool,
|
|
string,
|
|
element,
|
|
plainObject,
|
|
array
|
|
};
|
|
//# sourceMappingURL=is.js.map
|