/** @module support */ __PluginManager__.register('support', function(module, exports, require, global){ window.pre = console.log; var node = { isRelate: function (node, container = document) { return node === container || container.contains(node); } }; var str = { ucFirst: function (str) { if (!str) return str; return str[0].toUpperCase() + str.slice(1); } }; var arr = { isKey: function (key) { var n = Number(key); return isInteger(n) && (''+n === ''+key); } }; function uniqueId (length = 32, firstLetter = true) { var idStr = ''; if(length < 1) return idStr; if(firstLetter) { length && (idStr = (Math.floor((Math.random() * 25)) + 10).toString(36)); if (length === 1) return idStr; } do { idStr += (Math.floor((Math.random() * 35))).toString(36); } while (idStr.length < length); return (idStr); } function valueEx(value) { var args = []; if(arguments.length > 1) for(var i = 1; arguments.length - 1 >= i;i++) { args.push(arguments[i]); } if(typeof value === 'function') { return value.apply(this, args); } return value; } function empty(val){ return arguments.length === 0 || val === undefined || val === null || Number.isNaN(val) === true || val === '' || val === 0 || val === false; } function emptyEx(val) { return empty(val) || (isObject(val) && (function () { for(v in val) return false; return true; })()); } function typeOf(value) { return typeof value; } function isObject(value) { return typeOf(value) === 'object' ? value !== null : typeof value === 'function'; } function isNumber(value) { return !Number.isNaN(value) && isFinite(value) && typeof value === 'number'; } /** * @return {number} */ function toNumber(value, def = 0) { var n = Number(value); return isNumber(n)?n:def; } function isInteger(value) { return isNumber(value) && (value % 1) === 0; } function isFloat(value) { return isNumber(value); } function isString(value) { return typeof value === 'string'; } function isNode(value) { return value instanceof Node; } function isElement(value) { return value instanceof Element; } function isNodeList(value) { return value instanceof NodeList; } function isDomObject(o) { return isNode(o) || isElement(o) || isNodeList(o); } /** * @param selector * @return Element */ function getNode(selector) { if(isString(selector) && selector !== '') { return document.querySelector(selector); } if(isNode(selector)) { return selector; } return null; } var extend = function(target) { if(!arguments[1]) { return; } for(i=1; i < arguments.length; i++) { var source = arguments[i]; for(var prop in source) { if(!target[prop] && source.hasOwnProperty(prop)) { target[prop] = source[prop]; } } } }; function isA(o,c){ return null!=c&&"undefined"!=typeof Symbol&&c[Symbol.hasInstance]?!!c[Symbol.hasInstance](o):o instanceof c } function makeNode(html = '') { if(isNode(html)) { return html; } if(isString(html)) { html = html.trim(); } var nodeWrap = document.createElement('div'); nodeWrap.innerHTML = html; var r = nodeWrap.firstChild; r.remove(); return r; } function makeNodeList(html = '') { if(isNodeList(html)) { return html; } if(isString(html)) { html = html.trim(); } var nodeWrap = document.createElement('div'); if(isNode(html)) { nodeWrap.append(html); } else { nodeWrap.innerHTML = html; } return nodeWrap.childNodes; } function setNodeData(node, key, value) { if(!isElement(node)) return false; node.kit = node.kit || {}; node.kit[key] = value; } function getNodeData(node, key) { if(!isElement(node)) return null; if(node.hasOwnProperty('kit') && node.kit.hasOwnProperty(key)) { return node.kit[key]; } return null; } function definePropertyGet(obj, key, val) { Object.defineProperty(obj, key, { get: function () { return valueEx(val); }, }); } function args2array(arguments) { var args = []; for (var i = 0; i < arguments.length; i++) { args.push(arguments[i]); } return args; } function innerHtml(wrap, content) { var wrapNode = getNode(wrap); if(!isElement(wrapNode)) { return false; } while (wrapNode.firstChild) { wrapNode.removeChild(wrapNode.firstChild); } if(isNode(content)) { wrapNode.append(content); } else if(isNodeList(content)) { content.forEach(function(node){ wrapNode.append(node); }); } else { wrapNode.innerHTML = content; } return true; } /** * @memberOf kit */ var support = { node: node, str: str, arr: arr, uniqueId, valueEx, empty, isNumber, typeOf, isObject, isInteger, isFloat, isString, isNode, isElement, getNode, extend, isA, makeNode, setNodeData, getNodeData, toNumber, definePropertyGet, args2array, innerHtml, makeNodeList }; return module.exports = support; });