"use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

//文本
var 文本 = function () {
	function 文本() {
		_classCallCheck(this, 文本);
	}

	_createClass(文本, null, [{
		key: "取文本长度",
		value: function _(str) {
			if (str != null) {
				return str.length;
			} else {
				return 0;
			}
		}
	}, {
		key: "取文本行数",
		value: function _(str) {
			var lines = 0;
			try {
				lines = str.match(/[^\n]*\n[^\n]*/gi).length;
			} catch (e) {
				lines = 0;
			}
			lines++;
			return lines;
		}
	}, {
		key: "寻找文本",
		value: function _(str, sub, index) {
			if (str == null || sub == null) {
				return -1;
			}
			return str.indexOf(sub, index);
		}
	}, {
		key: "倒找文本",
		value: function _(str, sub, index) {
			if (str == null || sub == null) {
				return -1;
			}
			return str.lastIndexOf(sub, index);
		}
	}, {
		key: "取文本中间",
		value: function _(str, start, len) {
			if (str == null || start == null) {
				return "";
			}
			return str.substr(start, len);
		}
	}, {
		key: "取文本左边",
		value: function _(str, len) {
			if (isNaN(len) || len == null) {
				len = str.length;
			} else {
				if (parseInt(len) < 0 || parseInt(len) > str.length) {
					len = str.length;
				}
			}
			return str.substr(0, len);
		}
	}, {
		key: "取文本右边",
		value: function _(str, len) {
			if (isNaN(len) || len == null) {
				len = str.length;
			} else {
				if (parseInt(len) < 0 || parseInt(len) > str.length) {
					len = str.length;
				}
			}
			return str.substring(str.length - len, str.length);
		}
	}, {
		key: "取指定文本",
		value: function _(待取文本, 左边文本, 右边文本) {
			var pattern = new RegExp(左边文本 + "(.*?)" + 右边文本, "g");
			var result = new Array(0);
			while (pattern.exec(待取文本) != null) {
				//console.log(RegExp.$1);
				result.push(RegExp.$1);
			}
			return result;
		}
	}, {
		key: "子文本替换",
		value: function _(str, a, b) {
			if (str == null || a == null || b == null) {
				return "";
			}
			var regExp = new RegExp(a, "g");
			return str.replace(regExp, b);
		}
	}, {
		key: "分割文本",
		value: function _(str, separator) {
			if (str == null || separator == null) {
				return null;
			}
			return str.split(separator);
		}
	}, {
		key: "到大写",
		value: function _(str) {
			if (str == null) {
				return "";
			}
			return str.toUpperCase();
		}
	}, {
		key: "到小写",
		value: function _(str) {
			if (str == null) {
				return "";
			}
			return str.toLowerCase();
		}
	}, {
		key: "删首尾空",
		value: function _(str) {
			if (str == null) {
				return "";
			}
			return str.replace(/(^\s*)|(\s*$)/g, "");
		}
	}, {
		key: "删全部空",
		value: function _(str) {
			if (str == null) {
				return "";
			}
			return str.replace(/\s+/g, "");
		}
	}]);

	return 文本;
}();
//数组


var 数组 = function () {
	function 数组() {
		_classCallCheck(this, 数组);
	}

	_createClass(数组, null, [{
		key: "取成员数",
		value: function _(arr) {
			if (arr != null) {
				return arr.length;
			} else {
				return 0;
			}
		}
	}, {
		key: "合并数组",
		value: function _(arr1, arr2) {
			if (arr1 == null) {
				return arr2;
			}
			if (arr2 == null) {
				return arr1;
			}
			return arr1.concat(arr2);
		}
	}, {
		key: "连接成员",
		value: function _(arr, separator) {
			if (arr == null || separator == null) {
				return "";
			}
			return arr.join(separator);
		}
	}, {
		key: "加入首成员",
		value: function _(arr, element) {
			if (arr == null) {
				return 0;
			}
			arr.unshift(element);
			return arr.length;
		}
	}, {
		key: "加入尾成员",
		value: function _(arr, element) {
			if (arr == null) {
				return 0;
			}
			arr.push(element);
			return arr.length;
		}
	}, {
		key: "删除首成员",
		value: function _(arr) {
			if (arr == null) {
				return 0;
			}
			arr.shift();
			return arr.length;
		}
	}, {
		key: "删除尾成员",
		value: function _(arr) {
			if (arr == null) {
				return 0;
			}
			arr.pop();
			return arr.length;
		}
	}, {
		key: "删除成员",
		value: function _(arr, index) {
			if (arr == null) {
				return 0;
			}
			arr.splice(index, 1);
			return arr.length;
		}
	}, {
		key: "清空数组",
		value: function _(arr) {
			if (arr == null) {
				return 0;
			}
			arr.splice(0, arr.length);
			return arr.length;
		}
	}, {
		key: "翻转顺序",
		value: function _(arr) {
			if (arr != null) {
				arr.reverse();
			}
		}
	}, {
		key: "排列顺序",
		value: function _(arr, type) {
			if (arr != null) {
				if (type == 1) {
					arr.sort();
				} else {
					arr.sort(sortNumber);
				}
			}
		}
	}]);

	return 数组;
}();

function sortNumber(a, b) {
	return a - b;
}
//转换

var 转换 = function () {
	function 转换() {
		_classCallCheck(this, 转换);
	}

	_createClass(转换, null, [{
		key: "到文本",
		value: function _(value) {
			return "" + value;
		}
	}, {
		key: "到数值",
		value: function _(str) {
			return Number(str);
		}
	}, {
		key: "到十六进制",
		value: function _(value) {
			return value.toString(16);
		}
	}, {
		key: "到十进制",
		value: function _(str) {
			return parseInt(str, 16);
		}
	}, {
		key: "代码转字符",
		value: function _() {
			var result = "";
			for (var i = 0; i < arguments.length; i++) {
				result = result + String.fromCharCode(arguments[i]);
			}
			return result;
		}
	}, {
		key: "字符转代码",
		value: function _(str) {
			return str.charCodeAt(0);
		}
	}, {
		key: "文本转json",
		value: function json(str) {
			return JSON.parse(str);
		}
	}, {
		key: "json转文本",
		value: function json(_json) {
			return JSON.stringify(_json);
		}
	}, {
		key: "取数据类型",
		value: function _(value) {
			var a = typeof value === "undefined" ? "undefined" : _typeof(value);
			switch (a) {
				case "number":
					return 1;
					break;
				case "string":
					return 2;
					break;
				case "boolean":
					return 3;
					break;
				case "object":
					return 4;
					break;
				case "function":
					return 5;
					break;
				case "undefined":
					return 6;
					break;
				default:
					return 6;
			}
		}
	}, {
		key: "是否为非数字",
		value: function _(value) {
			return isNaN(value);
		}
	}, {
		key: "转换为金额",
		value: function _(n) {
			var fraction = ["角", "分"];
			var digit = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
			var unit = [["元", "万", "亿"], ["", "拾", "佰", "仟"]];
			var head = n < 0 ? "欠" : "";
			n = Math.abs(n);
			var s = "";
			for (var i = 0; i < fraction.length; i++) {
				s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, "");
			}
			s = s || "整";
			n = Math.floor(n);
			for (var i = 0; i < unit[0].length && n > 0; i++) {
				var p = "";
				for (var j = 0; j < unit[1].length && n > 0; j++) {
					p = digit[n % 10] + unit[1][j] + p;
					n = Math.floor(n / 10);
				}
				s = p.replace(/(零.)*零$/, "").replace(/^$/, "零") + unit[0][i] + s;
			}
			return head + s.replace(/(零.)*零元/, "元").replace(/(零.)+/g, "零").replace(/^整$/, "零元整");
		}
	}]);

	return 转换;
}();
//数学


var 数学 = function () {
	function 数学() {
		_classCallCheck(this, 数学);
	}

	_createClass(数学, null, [{
		key: "取随机数",
		value: function _(min, max) {
			return parseInt(Math.random() * (max - min + 1) + min, 10);
		}
	}, {
		key: "取绝对值",
		value: function _(value) {
			return Math.abs(value);
		}
	}, {
		key: "取余数",
		value: function _(a, b) {
			return a % b;
		}
	}, {
		key: "取整数",
		value: function _(value) {
			return parseInt(value);
		}
	}, {
		key: "取次方",
		value: function _(a, b) {
			return Math.pow(a, b);
		}
	}, {
		key: "四舍五入",
		value: function _(value, num) {
			//return value.toFixed(num);
			return Math.round(value * Math.pow(10, num)) / Math.pow(10, num);
		}
	}, {
		key: "表达式计算",
		value: function _(value) {
			return eval(value);
		}
	}]);

	return 数学;
}();
//时间日期


var 时间 = function () {
	function 时间() {
		_classCallCheck(this, 时间);
	}

	_createClass(时间, null, [{
		key: "取当前日期时间",
		value: function _() {
			return new Date();
		}
	}, {
		key: "取现行日期",
		value: function _() {
			var date = new Date();
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = date.getFullYear() + "/" + month + "/" + strDate;
			return currentdate;
		}
	}, {
		key: "取现行时间",
		value: function _() {
			var date = new Date();
			var getHours = date.getHours();
			var getMinutes = date.getMinutes();
			var getSeconds = date.getSeconds();
			if (getHours >= 0 && getHours <= 9) {
				getHours = "0" + getHours;
			}
			if (getMinutes >= 0 && getMinutes <= 9) {
				getMinutes = "0" + getMinutes;
			}
			if (getSeconds >= 0 && getSeconds <= 9) {
				getSeconds = "0" + getSeconds;
			}
			var currenttime = getHours + ":" + getMinutes + ":" + getSeconds;
			return currenttime;
		}
	}, {
		key: "到日期时间",
		value: function _(年, 月, 日, 时, 分, 秒) {
			return new Date(年, 月 - 1, 日, 时, 分, 秒);
		}
	}, {
		key: "到日期时间2",
		value: function _(value) {
			return new Date(value);
		}
	}, {
		key: "时间到文本",
		value: function _(date) {
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = date.getFullYear() + "/" + month + "/" + strDate;

			var getHours = date.getHours();
			var getMinutes = date.getMinutes();
			var getSeconds = date.getSeconds();
			if (getHours >= 0 && getHours <= 9) {
				getHours = "0" + getHours;
			}
			if (getMinutes >= 0 && getMinutes <= 9) {
				getMinutes = "0" + getMinutes;
			}
			if (getSeconds >= 0 && getSeconds <= 9) {
				getSeconds = "0" + getSeconds;
			}
			var currenttime = getHours + ":" + getMinutes + ":" + getSeconds;

			return currentdate + " " + currenttime;
		}
	}, {
		key: "取时间间隔",
		value: function _(a, b) {
			return a.getTime() - b.getTime();
		}
	}, {
		key: "取年",
		value: function _(time) {
			return time.getFullYear();
		}
	}, {
		key: "取月",
		value: function _(time) {
			return time.getMonth() + 1;
		}
	}, {
		key: "取日",
		value: function _(time) {
			return time.getDate();
		}
	}, {
		key: "取时",
		value: function _(time) {
			return time.getHours();
		}
	}, {
		key: "取分",
		value: function _(time) {
			return time.getMinutes();
		}
	}, {
		key: "取秒",
		value: function _(time) {
			return time.getSeconds();
		}
	}, {
		key: "取星期几",
		value: function _(time) {
			return time.getDay();
		}
	}, {
		key: "取时间戳",
		value: function _(time) {
			return Date.parse(time);
		}
	}, {
		key: "时间戳到时间",
		value: function _(value) {
			return new Date(value);
		}
	}]);

	return 时间;
}();
//正则


var 正则 = function () {
	function 正则() {
		_classCallCheck(this, 正则);

		this.res;
		this.sl = 0;
		this.arr;
		this.bd = "";
		this.zz = "";
	}

	_createClass(正则, null, [{
		key: "创建正则",
		value: function _(所有文本, 正则文本, 不区分大小写, 多行查找) {
			this.bd = "";
			this.zz = "";
			this.zz = 正则文本;
			var zz = "g";
			if (不区分大小写) {
				zz = zz + "i";
				this.bd = this.bd + "i";
			}
			if (多行查找) {
				zz = zz + "m";
				this.bd = this.bd + "m";
			}
			this.res = 所有文本.match(RegExp(正则文本, zz));
		}
	}, {
		key: "取匹配数量",
		value: function _() {
			if (this.res == "" || this.res == null) {
				this.sl = 0;
			} else {
				this.sl = this.res.length;
			}

			return this.sl;
		}
	}, {
		key: "取匹配文本",
		value: function _(匹配索引) {
			if (this.res == "" || this.res == null) {
				return "";
			}

			if (匹配索引 == null) {
				return this.res;
			}
			return this.res[匹配索引];
		}
	}, {
		key: "取子匹配文本",
		value: function _(匹配索引, 子匹配索引) {
			if (this.res == "" || this.res == null) {
				return "";
			}
			this.arr = this.res[匹配索引].match(RegExp(this.zz, this.bd));
			return this.arr[子匹配索引];
		}
	}]);

	return 正则;
}();
//定时器


var 定时器 = function () {
	function 定时器() {
		_classCallCheck(this, 定时器);
	}

	_createClass(定时器, null, [{
		key: "延时调用",
		value: function _(callback, delay) {
			for (var _len = arguments.length, rest = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
				rest[_key - 2] = arguments[_key];
			}

			return setTimeout.apply(undefined, [callback, delay].concat(rest));
		}
	}, {
		key: "结束延时调用",
		value: function _(timeoutID) {
			clearTimeout(timeoutID);
		}
	}, {
		key: "时钟",
		value: function _(callback, delay) {
			for (var _len2 = arguments.length, rest = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
				rest[_key2 - 2] = arguments[_key2];
			}

			return setInterval.apply(undefined, [callback, delay].concat(rest));
		}
	}, {
		key: "结束时钟",
		value: function _(intervalID) {
			clearInterval(intervalID);
		}
	}]);

	return 定时器;
}();