UNPKG

40.3 kBJavaScriptView Raw
1/*!
2 * Buession prototype v2.2.0
3 *
4 * @link https://prototype.buession.com/
5 * @source https://github.com/buession/buession-prototype
6 * @copyright @ 2020-2023 Buession.com Inc.
7 * @license MIT
8 * @Build Time Wed, 01 Feb 2023 06:44:53 GMT
9 */
10
11/**
12 * Prototype 对象
13 */
14var Prototype = {
15 /**
16 * 版本
17 */
18 version: "v2.2.0",
19 /**
20 * 空方法
21 *
22 * @return void
23 */
24 emptyFunction: function () {
25 },
26 /**
27 *
28 * @param x 任意参数
29 * @return 任意值
30 */
31 K: function (x) {
32 return x;
33 }
34};
35window.Prototype = Prototype;
36
37/**
38 * Try 对象
39 */
40var Try = {
41 /**
42 * 接收任意数目的函数作为参数,返回第一个执行成功的函数(未抛出异常的函数)的结果
43 *
44 * @return 任意函数参数执行结果
45 */
46 these: function () {
47 var result;
48 for (var i = 0; i < arguments.length; i++) {
49 var lambda = arguments[i];
50 if (Object.isFunction(lambda)) {
51 try {
52 result = lambda();
53 break;
54 }
55 catch (e) {
56 console.error(e);
57 }
58 }
59 }
60 return result;
61 }
62};
63window.Try = Try;
64
65/**
66 * Optional 对象
67 */
68var Optional = /** @class */ (function () {
69 /**
70 * 构造函数
71 *
72 * @param value T 类型的值
73 */
74 function Optional(value) {
75 this.value = value;
76 }
77 /**
78 * 返回一个指定 T 类型的值的 Optional 实例
79 *
80 * @param value T 类型的值
81 * @return T 类型的值的 Optional 实例
82 */
83 Optional.of = function (value) {
84 return new Optional(value);
85 };
86 /**
87 * 如果为非 null 或 undefined,返回 Optional 描述的指定值的实例,否则返回空的 Optional 实例
88 *
89 * @param value T 类型的值
90 * @return T 类型的值的 Optional 实例,或空的 Optional 实例
91 */
92 Optional.ofNullable = function (value) {
93 return Object.isUndefinedOrNull(value) ? Optional.empty() : new Optional(value);
94 };
95 /**
96 * 返回空的 Optional 实例
97 *
98 * @return 空的 Optional 实例
99 */
100 Optional.empty = function () {
101 return new Optional(null);
102 };
103 /**
104 * 如果 value 不为 null 或 undefined,则返回 value 的值;否则抛出异常
105 *
106 * @return Optional 中包含这个值
107 */
108 Optional.prototype.get = function () {
109 if (this.value === null || typeof this.value === 'undefined') {
110 throw "No value present";
111 }
112 return this.value;
113 };
114 /**
115 * 如果 value 不为 null 或 undefined,则返回 value 的值;否则返回 other
116 *
117 * @param other 其它值
118 * @return value 不为 null 或 undefined,则返回 value 的值;否则返回 other
119 */
120 Optional.prototype.orElse = function (other) {
121 return Object.isUndefinedOrNull(this.value) ? other : this.value;
122 };
123 /**
124 * 如果 value 不为 null 或 undefined,则返回 true;否则返回 false
125 *
126 * @return value 不为 null 或 undefined,则返回 true;否则返回 false
127 */
128 Optional.prototype.isPresent = function () {
129 return Object.isUndefinedOrNull(this.value) === false;
130 };
131 return Optional;
132}());
133window.Optional = Optional;
134
135/**
136 * Object 对象扩展
137 */
138/**
139 * 获取对象数据类型
140 *
141 * @param obj 对象变量
142 * @return 对象数据类型
143 */
144Object.type = function (obj) {
145 return typeof obj;
146};
147/**
148 * 获取对象数据类型
149 *
150 * @param obj 对象变量
151 * @return 对象数据类型
152 */
153Object.rawType = function (obj) {
154 return Object.prototype.toString.call(obj).slice(8, -1);
155};
156/**
157 * 判断对象是否为 object 类型
158 *
159 * @param obj 任意对象
160 * @return boolean
161 */
162Object.isObject = function (obj) {
163 return obj !== null && typeof obj === "object";
164};
165/**
166 * 判断对象是否为 object 类型
167 *
168 * @param obj 任意对象
169 * @return boolean
170 */
171Object.isPlainObject = function (obj) {
172 return Object.prototype.toString.call(obj) === "[object Object]";
173};
174/**
175 * 判断对象是否为 Map 类型
176 *
177 * @param obj 任意对象
178 * @return boolean
179 */
180Object.isMap = function (obj) {
181 return Object.prototype.toString.call(obj) === "[object Map]";
182};
183/**
184 * 判断对象是否为 Set 类型
185 *
186 * @param obj 任意对象
187 * @return boolean
188 */
189Object.isSet = function (obj) {
190 return Object.prototype.toString.call(obj) === "[object Set]";
191};
192/**
193 * 判断对象是否为函数
194 *
195 * @param obj 任意对象
196 * @return boolean
197 */
198Object.isFunction = function (obj) {
199 return Object.type(obj) === "function";
200};
201/**
202 * 判断对象是否为 Symbol
203 *
204 * @param obj 任意对象
205 * @return boolean
206 */
207Object.isSymbol = function (obj) {
208 if (typeof obj === "symbol") {
209 return true;
210 }
211 try {
212 var toString_1 = Symbol.prototype.toString;
213 if (typeof obj.valueOf() !== "symbol") {
214 return false;
215 }
216 return /^Symbol\(.*\)$/.test(toString_1.call(obj));
217 }
218 catch (e) {
219 return false;
220 }
221};
222/**
223 * 判断对象是否为 Promise
224 *
225 * @param obj 任意对象
226 * @return boolean
227 */
228Object.isPromise = function (obj) {
229 return Object.isUndefinedOrNull(obj) === false && Object.isFunction(obj.then) && Object.isFunction(obj.catch);
230};
231/**
232 * 判断对象是否为原始类型
233 *
234 * @param obj 任意对象
235 * @return boolean
236 */
237Object.isPrimitive = function (obj) {
238 return Object.isBoolean(obj) || Object.isString(obj) || Object.isNumber(obj);
239};
240/**
241 * 判断对象是否为数组
242 *
243 * @param obj 任意对象
244 * @return boolean
245 */
246Object.isArray = function (obj) {
247 return Array.isArray(obj);
248};
249/**
250 * 判断对象是否为字符串对象
251 *
252 * @param obj 任意对象
253 * @return boolean
254 */
255Object.isString = function (obj) {
256 return Object.type(obj) === "string";
257};
258/**
259 * 判断对象是否为数字对象
260 *
261 * @param obj 任意对象
262 * @return boolean
263 */
264Object.isNumber = function (obj) {
265 return Object.type(obj) === "number";
266};
267/**
268 * 判断对象是否为布尔对象
269 *
270 * @param obj 任意对象
271 * @return boolean
272 */
273Object.isBoolean = function (obj) {
274 return Object.type(obj) === "boolean";
275};
276/**
277 * 判断对象是否为正则对象
278 *
279 * @param obj 任意对象
280 * @return boolean
281 */
282Object.isRegExp = function (obj) {
283 return Object.rawType(obj) === 'RegExp';
284};
285/**
286 * 判断对象是否为文件对象
287 *
288 * @param obj 任意对象
289 * @return boolean
290 */
291Object.isFile = function (obj) {
292 return obj instanceof File;
293};
294/**
295 * 判断对象是否为 windows 对象
296 *
297 * @param obj 任意对象
298 * @return boolean
299 */
300Object.isWindow = function (obj) {
301 return Object.isUndefinedOrNull(obj) && obj == obj.window;
302};
303/**
304 * 判断对象是否为 Element
305 *
306 * @param obj 任意对象
307 * @return boolean
308 */
309Object.isElement = function (obj) {
310 if (Object.isUndefinedOrNull(obj)) {
311 return false;
312 }
313 return !!(obj.nodeType == 1);
314};
315/**
316 * 判断对象是否为事件对象
317 *
318 * @param obj 任意对象
319 * @return boolean
320 */
321Object.isEvent = function (obj) {
322 return obj instanceof Event;
323};
324/**
325 * 判断对象是否为 null 对象
326 *
327 * @param obj 任意对象
328 * @return boolean
329 */
330Object.isNull = function (obj) {
331 return obj === null;
332};
333/**
334 * 判断对象是否为未定义
335 *
336 * @param obj 任意对象
337 * @return boolean
338 */
339Object.isUndefined = function (obj) {
340 return obj === undefined;
341};
342/**
343 * 判断对象是否为未定义或 null
344 *
345 * @param obj 任意对象
346 * @return boolean
347 */
348Object.isUndefinedOrNull = function (obj) {
349 return Object.isUndefined(obj) || Object.isNull(obj);
350};
351/**
352 * 克隆对象
353 *
354 * @param obj 任意对象
355 * @return 新对象实例
356 */
357Object.clone = function (obj) {
358 if (Object.isString(obj)) {
359 return String(obj);
360 }
361 else if (Object.isArray(obj)) {
362 return Array.prototype.slice.apply(obj);
363 }
364 else if (Object.isPlainObject(obj)) {
365 var result_1 = {};
366 Object.keys(obj).forEach(function (name) {
367 result_1[name] = Object.clone(obj[name]);
368 });
369 return result_1;
370 }
371 return obj;
372};
373/**
374 * 判断两个对象是否相等
375 *
376 * @param obj1 一个对象
377 * @param obj2 用于和 obj1 比较的对象
378 * @return 当两个对象相等时,返回 true;否则,返回 false
379 */
380Object.equals = function (obj1, obj2) {
381 if (obj1 === obj2) {
382 return true;
383 }
384 else if (!(obj1 instanceof Object) || !(obj2 instanceof Object)) {
385 return false;
386 }
387 else if (obj1.constructor !== obj2.constructor) {
388 return false;
389 }
390 else if (Object.isArray(obj1) && Object.isArray(obj2) && obj1.length === obj2.length) {
391 for (var i = 0; i < obj1.length; i++) {
392 if (Object.equals(obj1[i], obj2[i]) === false) {
393 return false;
394 }
395 }
396 }
397 else if (Object.isObject(obj1) && Object.isObject(obj2) && Object.keys(obj1).length === Object.keys(obj2).length) {
398 for (var key in obj1) {
399 if (obj1.hasOwnProperty.call(key)) {
400 if (Object.equals(obj1[key], obj2[key]) === false) {
401 return false;
402 }
403 }
404 }
405 }
406 else {
407 return false;
408 }
409 return true;
410};
411/**
412 * 克隆对象,但需要删除指定属性
413 *
414 * @param obj 任意对象
415 * @param fields 需要删除的属性
416 * @return 新对象实例
417 */
418Object.omit = function (obj) {
419 var fields = [];
420 for (var _i = 1; _i < arguments.length; _i++) {
421 fields[_i - 1] = arguments[_i];
422 }
423 var result = Object.assign({}, obj);
424 for (var i = 0; i < fields.length; i++) {
425 var key = fields[i];
426 delete result[key];
427 }
428 return result;
429};
430
431/**
432 * Array 对象扩展
433 */
434/**
435 * 判断数组是否为空数组
436 *
437 * @return boolean
438 */
439Array.prototype.isEmpty = function () {
440 return this.length === 0;
441};
442/**
443 * 判断元素是否在数组中
444 *
445 * @param item 查找对象
446 * @return boolean
447 */
448Array.prototype.exists = function (item) {
449 return this.indexOf(item) !== -1;
450};
451/**
452 * 获取一个元素
453 *
454 * @return 第一个元素
455 */
456Array.prototype.first = function () {
457 if (this.length === 0) {
458 throw "Array index out of range: 0";
459 }
460 return this[0];
461};
462/**
463 * 获取一个元素
464 *
465 * @return 第一个元素
466 */
467Array.prototype.last = function () {
468 if (this.length === 0) {
469 throw "Array index out of range: 0";
470 }
471 return this[this.length - 1];
472};
473/**
474 * 数组迭代
475 *
476 * @param callback 回调函数
477 * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
478 */
479Array.prototype.each = Array.prototype.forEach;
480/**
481 * 获取数组大小
482 *
483 * @return 数组大小
484 */
485Array.prototype.size = function () {
486 return this.length;
487};
488/**
489 * 克隆数组
490 *
491 * @return 克隆结果
492 */
493Array.prototype.merge = Array.prototype.concat;
494/**
495 * 返回一个不包含 null/undefined 值元素的数组的新版本
496 *
497 * @return 不包含 null/undefined 值元素的数组的新版本
498 */
499Array.prototype.compact = function () {
500 return this.filter(function (value) { return Object.isUndefinedOrNull(value); });
501};
502/**
503 * 对数组的元素进行去重
504 *
505 * @return 数组元素进行去重后的新版本
506 */
507Array.prototype.unique = function () {
508 var temp = new Array();
509 return this.filter(function (v) {
510 var ret = temp.includes(v) === false;
511 temp.push(v);
512 return ret;
513 });
514};
515/**
516 * 返回不包括参数中任意一个指定值的数组
517 *
518 * @param values 排除值数组
519 * @return 不包括参数中任意一个指定值的数组
520 */
521Array.prototype.without = function () {
522 var values = [];
523 for (var _i = 0; _i < arguments.length; _i++) {
524 values[_i] = arguments[_i];
525 }
526 return this.filter(function (v) {
527 return values.includes(v) === false;
528 });
529};
530/**
531 * 克隆数组
532 *
533 * @return 克隆结果
534 */
535Array.prototype.clone = function () {
536 return this.slice(0);
537};
538/**
539 * 清空数组
540 *
541 * @return 空数组
542 */
543Array.prototype.clear = function () {
544 this.length = 0;
545 return this;
546};
547
548/**
549 * Date 对象扩展
550 */
551/**
552 * 判断是否为闰年
553 *
554 * @return boolean
555 */
556Date.prototype.isLeapYear = function () {
557 var year = this.getFullYear();
558 return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
559};
560/**
561 * 获取季节
562 *
563 * @return 季节
564 */
565Date.prototype.getSeason = function () {
566 var month = this.getMonth();
567 if (month >= 3 && month <= 5) {
568 return 0;
569 }
570 else if (month >= 6 && month <= 8) {
571 return 1;
572 }
573 else if (month >= 9 && month <= 11) {
574 return 2;
575 }
576 else if (month >= 12 || month <= 2) {
577 return 3;
578 }
579 else {
580 return 0;
581 }
582};
583/**
584 * 获取年份中的第几天
585 *
586 * @return 年份中的第几天
587 */
588Date.prototype.getDayOfYear = function () {
589 var month_days = this.isLeapYear() == true ? [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
590 var days = this.getDate();
591 for (var m = 0; m < this.getMonth(); m++) {
592 days += month_days[m];
593 }
594 return days;
595};
596/**
597 * 获取年份总天数
598 *
599 * @return 年份总天数
600 */
601Date.prototype.getDaysOfYear = function () {
602 return this.isLeapYear() ? 366 : 365;
603};
604/**
605 * Format a date object into a string value.
606 * @param format string - the desired format of the date
607 *
608 * The format can be combinations of the following:
609 *
610 * y - 年
611 * n - 季度(1 到 4)
612 * N - 季度名称
613 * A - 季度中文名称
614 * M - 月
615 * f - 月(Jan 到 Dec)
616 * F - 月(January 到 December)
617 * C - 月,中文名称
618 * d - 日
619 * Y - 年份中的第几天(0 到 365)
620 * T - 月份有几天(28 到 30)
621 * j - 每月天数后面的英文后缀(st,nd,rd 或者 th)
622 * e - 星期几,数字表示,0(表示星期天)到 6(表示星期六)
623 * E - 星期几,数字表示,1(表示星期一)到 7(表示星期天)
624 * l - 星期几,文本表示,3 个字母(Mon 到 Sun)
625 * L - 星期几,完整的文本格式(Sunday 到 Saturday)
626 * w - 星期几,中文名称
627 * W - 一月中第几个星期几
628 * i - 月份中的第几周
629 * o - 年份中的第几周
630 * h - 小时(1~12)
631 * H - 小时(0~23)
632 * m - 分
633 * s - 秒
634 * S - 毫秒
635 * a - 上午/下午标记
636 * O - 与格林威治时间相差的小时数
637 * P - 与格林威治时间相差的小时数,小时和分钟之间有冒号分隔
638 * Z - 时区
639 *
640 * @return 格式化后的日期时间
641 */
642Date.prototype.format = function (format) {
643 if (Object.isString(format) === false) {
644 throw "Invalid argument format";
645 }
646 var $this = this;
647 var _season_map = {
648 "N": ["Spring", "Summer", "Autumn", "Winter"],
649 "A": ["\u6625", "\u590f", "\u79cb", "\u51ac"]
650 };
651 var _month_map = {
652 "f": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
653 "F": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
654 "C": ["\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D", "\u5341", "\u5341\u4E00", "\u5341\u4E8C"]
655 };
656 var _weekday_map = {
657 "W": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
658 "WW": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
659 "WC": ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"]
660 };
661 var seasonFn = function () { return Math.floor(($this.getMonth() + 3) / 3); };
662 var $funcs = {
663 // 年
664 "y": function (pattern) {
665 console.debug("y => pattern: " + pattern);
666 return ($this.getFullYear() + "").substring(4 - pattern.length);
667 },
668 // 季度(1 到 4)
669 "n": function (pattern) {
670 console.debug("n => pattern: " + pattern);
671 return seasonFn();
672 },
673 // 季度名称
674 "N": function (pattern) {
675 console.debug("N => pattern: " + pattern);
676 var n = seasonFn() - 1;
677 return _season_map["N"][n];
678 },
679 // 季度中文名称
680 "A": function (pattern) {
681 console.debug("A => pattern: " + pattern);
682 var n = seasonFn() - 1;
683 return _season_map["A"][n];
684 },
685 // 月
686 "M": function (pattern) {
687 console.debug("M => pattern: " + pattern);
688 var $month = $this.getMonth() + 1;
689 var result = $month < 10 ? "0" + $month : "" + $month;
690 return result.substring(2 - pattern.length);
691 },
692 // 月(Jan 到 Dec)
693 "f": function (pattern) {
694 console.debug("f => pattern: " + pattern);
695 var $month = $this.getMonth();
696 return _month_map["f"][$month];
697 },
698 // 月(January 到 December)
699 "F": function (pattern) {
700 console.debug("F => pattern: " + pattern);
701 var $month = $this.getMonth();
702 return _month_map["F"][$month];
703 },
704 // 月,中文名称
705 "C": function (pattern) {
706 console.debug("C => pattern: " + pattern);
707 var $month = $this.getMonth();
708 return _month_map["C"][$month];
709 },
710 // 星期数字,0 到 6 表示
711 "e": function (pattern) {
712 console.debug("e => pattern: " + pattern);
713 return $this.getDay();
714 },
715 // 星期数字,1 到 7 表示
716 "E": function (pattern) {
717 console.debug("E => pattern: " + pattern);
718 return $this.getDay() + 1;
719 },
720 // 星期英文缩写
721 "l": function (pattern) {
722 console.debug("l => pattern: " + pattern);
723 var $weekday = $this.getDay();
724 return _weekday_map["W"][$weekday];
725 },
726 // 星期英文全称
727 "L": function (pattern) {
728 console.debug("L => pattern: " + pattern);
729 var $weekday = $this.getDay();
730 return _weekday_map["WC"][$weekday];
731 },
732 // 星期中文名称
733 "w": function (pattern) {
734 console.debug("w => pattern: " + pattern);
735 var $weekday = $this.getDay();
736 return _weekday_map["WC"][$weekday];
737 },
738 // 日
739 "d": function (pattern) {
740 console.debug("d => pattern: " + pattern);
741 var $date = $this.getDate();
742 var result = $date < 10 ? "0" + $date : "" + $date;
743 return result.substring(2 - pattern.length);
744 },
745 // 小时
746 "h": function (pattern) {
747 console.debug("h => pattern: " + pattern);
748 var $hour = $this.getHours();
749 var result = $hour % 12 === 0 ? "12" : $hour % 12;
750 result = $hour < 10 ? "0" + $hour : "" + $hour;
751 return result.substring(2 - pattern.length);
752 },
753 // 小时
754 "H": function (pattern) {
755 console.debug("H => pattern: " + pattern);
756 var $hour = $this.getHours();
757 var result = $hour < 10 ? "0" + $hour : "" + $hour;
758 return result.substring(2 - pattern.length);
759 },
760 // 分钟
761 "m": function (pattern) {
762 console.debug("m => pattern: " + pattern);
763 var $minutes = $this.getMinutes();
764 var result = $minutes < 10 ? "0" + $minutes : "" + $minutes;
765 return result.substring(2 - pattern.length);
766 },
767 // 秒钟
768 "s": function (pattern) {
769 console.debug("s => pattern: " + pattern);
770 var $seconds = $this.getSeconds();
771 var result = $seconds < 10 ? "0" + $seconds : "" + $seconds;
772 return result.substring(2 - pattern.length);
773 },
774 // 毫秒
775 "S": function (pattern) {
776 console.debug("S => pattern: " + pattern);
777 var $mise = $this.getMilliseconds();
778 var result = $mise < 10 ? "0" + $mise : "" + $mise;
779 return result.substring(2 - pattern.length);
780 }
781 };
782 return format.replace(/([ynNAMfFCdYTjeElLwWiohHmsSaOPZ])+/g, function (all, t) {
783 var fn = $funcs[t];
784 if (Object.isFunction(fn) === true) {
785 return fn(all);
786 }
787 return all;
788 });
789};
790
791/**
792 * Document 对象扩展
793 */
794var SameSite;
795(function (SameSite) {
796 SameSite["NONE"] = "None";
797 SameSite["LAX"] = "Lax";
798 SameSite["STRICT"] = "Strict";
799})(SameSite || (SameSite = {}));
800var CookieInstance = /** @class */ (function () {
801 function CookieInstance() {
802 }
803 CookieInstance.prototype.set = function (name, value, options) {
804 var $name = name = encodeURIComponent(name)
805 .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);
806 var $value = value ? encodeURIComponent(value)
807 .replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent) : '';
808 var stringifiedAttributes = '';
809 if (options) {
810 stringifiedAttributes += options.domain ? '; domain=' + options.domain : '';
811 stringifiedAttributes += options.path ? '; path=' + options.path : '';
812 if (options.expires) {
813 var $expiresDate = options.expires instanceof Date ? options.expires : new Date(Date.now() + options.expires * 864e5);
814 stringifiedAttributes += options.expires ? '; expires=' + $expiresDate.toUTCString() : '';
815 }
816 stringifiedAttributes += options.sameSite ? '; sameSite=' + options.sameSite : '';
817 if (Object.isBoolean(options.secure) && options.secure) {
818 stringifiedAttributes += options.expires ? '; secure' : '';
819 }
820 if (Object.isBoolean(options.httpOnly) && options.httpOnly) {
821 stringifiedAttributes += options.httpOnly ? '; httpOnly' : '';
822 }
823 }
824 return document.cookie = $name + '=' + $value + stringifiedAttributes;
825 };
826 CookieInstance.prototype.get = function (name) {
827 var cookies = document.cookie ? document.cookie.split('; ') : [];
828 for (var i = 0; i < cookies.length; i++) {
829 var parts = cookies[i].split('=');
830 var $name = decodeURIComponent(parts[0]);
831 var $value = parts.slice(1).join('=');
832 if ($name === name) {
833 if ($value[0] === '"') {
834 $value = $value.slice(1, -1);
835 }
836 return $value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
837 }
838 }
839 return null;
840 };
841 CookieInstance.prototype.delete = function (name, options) {
842 var $options = options ? options : {};
843 $options.expires = -1;
844 this.set(name, '', $options);
845 };
846 return CookieInstance;
847}());
848/**
849 * 检测当前浏览器是否为全屏
850 *
851 * @return 当前浏览器是否为全屏
852 */
853Object.defineProperty(document, "fullScreen", {
854 value: Object.isUndefined(document.fullscreen) === false ? document.fullscreen : (Object.isUndefined(document.mozFullScreen) === false ? document.mozFullScreen : (Object.isUndefined(document.webkitIsFullScreen) === false ? document.webkitIsFullScreen : (Object.isUndefined(document.msFullScreen) === false ? document.msFullScreen : (Object.isUndefined(document.fullscreenElement) === false ? document.fullscreenElement !== null : (Object.isUndefined(document.mozFullScreenElement) === false ? document.mozFullScreenElement !== null : (Object.isUndefined(document.webkitFullscreenElement) === false ? document.webkitFullscreenElement !== null : (Object.isUndefined(document.msFullscreenElement) === false ? document.msFullscreenElement !== null : false))))))),
855 configurable: true,
856 writable: false
857});
858/**
859 * 检测当前浏览器是否支持全屏模式
860 *
861 * @return 当前浏览器是否支持全屏模式
862 */
863Object.defineProperty(document, "fullScreenEnabled", {
864 value: Object.isUndefined(document.mozFullScreenEnabled) === false ? document.mozFullScreenEnabled : (Object.isUndefined(document.webkitFullscreenEnabled) === false ? document.webkitFullscreenEnabled : (Object.isUndefined(document.msFullscreenEnabled) === false ? document.msFullscreenEnabled : (Object.isUndefined(document.fullscreenEnabled) === false ? document.fullscreenEnabled : false))),
865 configurable: true,
866 writable: false
867});
868/**
869 * 返回当前文档中正在以全屏模式显示的 Element 节点
870 *
871 * @return 当前文档中正在以全屏模式显示的 Element 节点
872 */
873Object.defineProperty(document, "fullScreenElement", {
874 value: Object.isUndefined(document.mozFullScreenElement) === false ? document.mozFullScreenElement : (Object.isUndefined(document.webkitFullscreenElement) === false ? document.webkitFullscreenElement : (Object.isUndefined(document.msFullscreenElement) === false ? document.msFullscreenElement : (Object.isUndefined(document.fullscreenElement) === false ? document.fullscreenElement : null))),
875 configurable: true,
876 writable: false
877});
878/**
879 * 返回 Cookie 对象
880 *
881 * @return Cookie 对象
882 */
883Object.defineProperty(document, "httpCookie", {
884 value: new CookieInstance(),
885 configurable: true,
886 writable: false
887});
888/**
889 * 请求进入全屏模式
890 *
891 * @return Promise
892 */
893Document.prototype.requestFullscreen = function () {
894 var doc = document.documentElement;
895 if (Object.isFunction(doc.mozRequestFullScreen)) {
896 return doc.mozRequestFullScreen();
897 }
898 else if (Object.isFunction(doc.webkitRequestFullscreen)) {
899 return doc.webkitRequestFullscreen();
900 }
901 else if (Object.isFunction(doc.msRequestFullscreen)) {
902 return doc.msRequestFullscreen();
903 }
904 else {
905 return doc.requestFullscreen();
906 }
907};
908/**
909 * 退出全屏模式
910 *
911 * @return Promise
912 */
913Document.prototype.exitFullscreen = function () {
914 if (Object.isFunction(document.mozCancelFullScreen)) {
915 return document.mozCancelFullScreen();
916 }
917 else if (Object.isFunction(document.mozExitFullScreen)) {
918 return document.mozExitFullScreen();
919 }
920 else if (Object.isFunction(document.webkitCancelFullScreen)) {
921 return document.webkitCancelFullScreen();
922 }
923 else if (Object.isFunction(document.webkitExitFullscreen)) {
924 return document.webkitExitFullscreen();
925 }
926 else if (Object.isFunction(document.msExitFullscreen)) {
927 return document.msExitFullscreen();
928 }
929 else {
930 return document.exitFullscreen();
931 }
932};
933
934/**
935 * Function 对象扩展
936 */
937/**
938 * 获取函数参数名称
939 *
940 * @return 函数参数名称列表
941 */
942Function.prototype.argumentNames = function () {
943 var method = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/);
944 if (method === null) {
945 return null;
946 }
947 var names = method[1].replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, "").replace(/\s+/g, "").split(", ");
948 return names.length === 1 && !names[0] ? [] : names;
949};
950/**
951 * 延时执行函数
952 *
953 * @param timeout 延时时间(单位:秒)
954 * @return mixed
955 */
956Function.prototype.delay = function (timeout) {
957 var __method = this;
958 var args = Array.prototype.slice.call(arguments, 1);
959 return window.setTimeout(__method.apply(__method, args), timeout * 1000);
960};
961
962/**
963 * Math 对象扩展
964 */
965/**
966 * 产生一个指定范围内的随机数
967 *
968 * @param min 返回的最低值(默认 0)
969 * @param max 返回的最高值
970 * @return 随机数
971 */
972Math.rand = function (min, max) {
973 min = min || 0;
974 max = max || Number.MAX_SAFE_INTEGER;
975 var result = Math.random() * (max - min + 1) + min;
976 result = Math.round(result);
977 if (result < min) {
978 result = min;
979 }
980 else if (result > max) {
981 result = max;
982 }
983 return result;
984};
985
986/**
987 * Number 对象扩展
988 */
989/**
990 * 数字填充
991 *
992 * @param length 长度
993 * @param radix 进制
994 * @return 填充后的字符串数字
995 */
996Number.prototype.toPaddedString = function (length, radix) {
997 var str = this.toString(radix || 10);
998 return "0".repeat(length - str.length) + str;
999};
1000/**
1001 * 判断数字是否为奇数
1002 *
1003 * @param num 需要判断的数字
1004 * @return boolean 数字是为奇数返回 true;否则返回 false
1005 */
1006Number.isOdd = function (num) {
1007 return num % 2 === 1;
1008};
1009/**
1010 * 判断数字是否为偶数
1011 *
1012 * @param num 需要判断的数字
1013 * @return boolean 数字是为偶数返回 true;否则返回 false
1014 */
1015Number.isEven = function (num) {
1016 return num % 2 === 0;
1017};
1018/**
1019 * 判断一个数字是否在另两个数字之间
1020 *
1021 * @param num 需要判断的数
1022 * @param min 最小值
1023 * @param max 最大值
1024 * @param match 是否包含最小值或最大值
1025 * @return boolean 数字是否在另两个数字之间,返回 true;否则返回 false
1026 */
1027Number.isBetween = function (num, min, max, match) {
1028 if (match === void 0) { match = false; }
1029 min = min || 0;
1030 max = max || 0;
1031 if (min > max) {
1032 min ^= max;
1033 max ^= min;
1034 min ^= max;
1035 }
1036 return match == true ? num >= min && num <= max : num > min && num < max;
1037};
1038
1039/**
1040 * String 对象扩展
1041 */
1042/**
1043 * 判断字符串是否存在
1044 *
1045 * @param str 子字符串
1046 * @return boolean
1047 */
1048String.prototype.exists = function (str) {
1049 return this.indexOf(str) >= 0;
1050};
1051/**
1052 * 判断字符串是否相等
1053 *
1054 * @param str 与此 String 进行比较的对象
1055 * @return boolean
1056 */
1057String.prototype.equals = function (str) {
1058 return Object.isUndefinedOrNull(str) == false && this === str;
1059};
1060/**
1061 * 判断字符串是否相等,不考虑大小写
1062 *
1063 * @param str 与此 String 进行比较的对象
1064 * @return boolean
1065 */
1066String.prototype.equalsIgnoreCase = function (str) {
1067 return str !== undefined && str !== null && this.toLowerCase() === str.toLowerCase();
1068};
1069/**
1070 * 判断是否为空字符串
1071 *
1072 * @return boolean
1073 */
1074String.prototype.isEmpty = function () {
1075 return this.length === 0;
1076};
1077/**
1078 * 判断是否不为空字符串
1079 *
1080 * @return boolean
1081 */
1082String.prototype.isNotEmpty = function () {
1083 return this.length > 0;
1084};
1085/**
1086 * 判断是否为空白字符串
1087 *
1088 * @return boolean
1089 */
1090String.prototype.isBlank = function () {
1091 return /^\s*$/.test(this.toString());
1092};
1093/**
1094 * 重复一个字符串
1095 *
1096 * @papram count 重复次数
1097 * @return 重复后的字符串
1098 */
1099String.prototype.repeat = function (count) {
1100 if (count < 1) {
1101 return "";
1102 }
1103 else {
1104 var result = this.toString();
1105 for (var i = 0; i < count; i++) {
1106 result += this.toString();
1107 }
1108 return result;
1109 }
1110};
1111/**
1112 * 截取字符串左边边指定数目的字符串
1113 *
1114 * @param length 截取长度
1115 * @return 子字符串
1116 */
1117String.prototype.left = function (length) {
1118 return this.substring(0, length);
1119};
1120/**
1121 * 截取字符串右边指定数目的字符串
1122 *
1123 * @param length 截取长度
1124 * @return 子字符串
1125 */
1126String.prototype.right = function (length) {
1127 return this.substring(this.length - length, this.length);
1128};
1129/**
1130 * 截取字符串,超出部分用 truncation 替代
1131 *
1132 * @param length 截取长度
1133 * @param truncation 替换字符串
1134 * @return 截取后的字符串
1135 * 实际截取长度:当 length 小于等于 truncation 的长度时为,length;当 length 大于 truncation 的长度时为,length - truncation.length
1136 */
1137String.prototype.truncation = function (length, truncation) {
1138 if (truncation === void 0) { truncation = '...'; }
1139 truncation = truncation || "...";
1140 return this.length > length ? this.slice(0, length <= truncation.length ? length : length - truncation.length) + truncation : String(this);
1141};
1142/**
1143 * 删除字符串开头的空白字符
1144 *
1145 * @return 删除了字符串最左边的空白字符的字符串
1146 */
1147String.prototype.ltrim = function () {
1148 return Object.isFunction(this.trimStart) ? this.trimStart() : this.replace(/^\s*/g, "");
1149};
1150/**
1151 * 删除字符串结尾的空白字符
1152 *
1153 * @return 删除了字符串最右边的空白字符的字符串
1154 */
1155String.prototype.rtrim = function () {
1156 return Object.isFunction(this.trimEnd) ? this.trimEnd() : this.replace(/\s*$/g, "");
1157};
1158/**
1159 * 判断字符串是否以给定的字符串开头
1160 *
1161 * @param str 搜索的字符串
1162 * @return boolean
1163 */
1164String.prototype.startsWith = function (str) {
1165 return this.indexOf(str) === 0;
1166};
1167/**
1168 * 判断字符串是否以给定的字符串结尾
1169 *
1170 * @param str 搜索的字符串
1171 * @return boolean
1172 */
1173String.prototype.endsWith = function (str) {
1174 var d = this.length - str.length;
1175 return d >= 0 && this.lastIndexOf(str) === d;
1176};
1177/**
1178 * 首字母小写
1179 *
1180 * @return 结果字符串
1181 */
1182String.prototype.lcfirst = function () {
1183 return this.charAt(0).toLowerCase() + this.substring(1);
1184};
1185/**
1186 * 首字母大写
1187 *
1188 * @return 结果字符串
1189 */
1190String.prototype.ucfirst = function () {
1191 return this.charAt(0).toUpperCase() + this.substring(1);
1192};
1193/**
1194 * 将 HTML 编码
1195 *
1196 * @return 编码后的字符串
1197 */
1198String.prototype.escapeHTML = function () {
1199 return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1200};
1201/**
1202 * 将 HTML 实体字符解码
1203 *
1204 * @return 解码后的字符串
1205 */
1206String.prototype.unescapeHTML = function () {
1207 return this.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
1208};
1209/**
1210 * 删除 HTML 标签
1211 *
1212 * @param tag HTML 标签
1213 * @returns 删除标签后的字符串
1214 */
1215String.prototype.stripTag = function (tag) {
1216 return this.replace(new RegExp("<" + tag + "(\\s+(\"[^\"]*\"|'[^']*'|[^>])+)?(\/)?>|<\/" + tag + ">", "gi"), "");
1217};
1218/**
1219 * 批量删除 HTML 标签
1220 *
1221 * @param tags 删除指定的标签
1222 * @return 删除标签后的字符串
1223 */
1224String.prototype.stripTags = function (tags) {
1225 if (typeof tags === "string") {
1226 return this.stripTag(tags);
1227 }
1228 else if (Array.isArray(tags)) {
1229 var result = this.toString();
1230 for (var i = 0; i < tags.length; i++) {
1231 result = result.stripTag(tags[i]);
1232 }
1233 return result;
1234 }
1235 else {
1236 return this.toString();
1237 }
1238};
1239/**
1240 * 删除 script 标签
1241 *
1242 * @return 删除 script 标签后的字符串
1243 */
1244String.prototype.stripScripts = function () {
1245 return this.replace(/<script[^>]*>([\S\s]*?)<\/script>/img, "");
1246};
1247/**
1248 * 将字符串转换为数组
1249 *
1250 * @param delimiter 分隔字符
1251 * @return 数组
1252 */
1253String.prototype.toArray = function (delimiter) {
1254 return this.split(delimiter || "");
1255};
1256/**
1257 * 返回一个数组的字符串表示形式
1258 *
1259 * @param useDoubleQuotes 是否使用双引号引住
1260 * @return 后的字符串
1261 */
1262String.prototype.inspect = function (useDoubleQuotes) {
1263 var specialChar = { '\b': '\\b', '\t': '\\t', '\r': '\\r', '\n': '\\n', '\f': '\\f', '\\': '\\\\' };
1264 var escapedString = this.replace(/[\x00-\x1f\\]/g, function (character) {
1265 if (character in specialChar) {
1266 return specialChar[character];
1267 }
1268 return '\\u00' + character.charCodeAt(0).toPaddedString(2, 16);
1269 });
1270 if (useDoubleQuotes) {
1271 return '"' + escapedString.replace(/"/g, '\\"') + '"';
1272 }
1273 else {
1274 return "'" + escapedString.replace(/'/g, '\\\'') + "'";
1275 }
1276};
1277/**
1278 * 获取字符串 hash code
1279 *
1280 * @return 字符串 hash code
1281 */
1282String.prototype.hashCode = function () {
1283 var result = 0;
1284 if (result === 0 && this.length > 0) {
1285 for (var i = 0; i < this.length; i++) {
1286 result = 31 * result + this.charCodeAt(i);
1287 }
1288 }
1289 return result;
1290};
1291/**
1292 * 生成随机字符串
1293 *
1294 * @param length 生成字符串的长度
1295 * @param type 生成类型
1296 * NUMERIC - 数字随机字符串
1297 * LETTER - 英文随机字符串
1298 * LETTER_NUMERIC - 英文数字混合随机字符串
1299 * CHINESE - 中文随机字符串
1300 *
1301 * @return 生成结果
1302 */
1303String.random = function (length, type) {
1304 if (type === void 0) { type = "LETTER_NUMERIC"; }
1305 var result = "";
1306 if (type === "CHINESE") {
1307 for (var i = 0; i < length; i++) {
1308 result += String.fromCharCode(Math.rand(19968, 40891));
1309 }
1310 return result;
1311 }
1312 var numeric = "0123456789";
1313 var letter = "abcdefghijklmnopqrstuvwxyz";
1314 var map = {
1315 "NUMERIC": numeric,
1316 "LETTER": letter + letter.toUpperCase(),
1317 "LETTER_NUMERIC": numeric + letter + letter.toUpperCase()
1318 };
1319 if (!map[type]) {
1320 throw "Invalid argument type value, must be: NUMERIC, LETTER, LETTER_NUMERIC or CHINESE";
1321 }
1322 for (var j = 0; j < length; j++) {
1323 result += map[type].charAt(Math.rand(0, map[type].length - 1));
1324 }
1325 return result;
1326};
1327
1328/**
1329 * Window 对象扩展
1330 */
1331Object.defineProperty(window, "browser", {
1332 value: {
1333 userAgent: navigator.userAgent,
1334 name: navigator.appName,
1335 version: navigator.appVersion,
1336 isMobile: ["Android", "iPhone", "iPod", "Windows Phone", "Mobile", "Coolpad", "mmp", "SmartPhone", "midp", "wap", "xoom", "Symbian", "J2ME", "Blackberry", "Wince"].some(function (value) { return navigator.userAgent.exists(value); }),
1337 isChrome: /\(KHTML, like Gecko\) Chrome\//.test(navigator.userAgent),
1338 isFirefox: navigator.userAgent.exists("Firefox"),
1339 isMozilla: navigator.userAgent.exists("Mozilla"),
1340 isEdge: navigator.userAgent.exists("Edge"),
1341 isMSIE: navigator.userAgent.exists("MSIE") && navigator.userAgent.exists("compatible"),
1342 isOpera: navigator.userAgent.exists("Opera"),
1343 isSafari: navigator.userAgent.exists("Safari"),
1344 isNetscape: /Netscape([\d]*)\/([^\s]+)/i.test(navigator.userAgent)
1345 },
1346 configurable: true,
1347 writable: false
1348});
1349/**
1350 * 将字符串复制到剪贴板
1351 *
1352 * @param str 字符串
1353 */
1354Window.prototype.copy = function (str) {
1355 try {
1356 if (Object.isObject(this.clipboardData)) {
1357 this.clipboardData.setData("text", str);
1358 }
1359 else {
1360 var fakeElement = document.createElement("textarea");
1361 fakeElement.style.border = "none";
1362 fakeElement.style.margin = "0";
1363 fakeElement.style.padding = "0";
1364 fakeElement.style.position = "absolute";
1365 fakeElement.style.top = "-9999px";
1366 fakeElement.style.left = "-9999px";
1367 fakeElement.value = str;
1368 fakeElement.setAttribute("readonly", "");
1369 document.body.appendChild(fakeElement);
1370 fakeElement.setSelectionRange(0, str.length);
1371 fakeElement.select();
1372 document.execCommand("copy");
1373 fakeElement.remove();
1374 }
1375 }
1376 catch (e) {
1377 console.error(e);
1378 }
1379};
1380/**
1381 * 获取所有的请求参数及值
1382 *
1383 * @return 所有的请求参数及值
1384 */
1385Location.prototype.getParameters = function () {
1386 var queryString = this.search;
1387 var parameters = new Object();
1388 if (queryString.indexOf("?") != -1) {
1389 queryString = queryString.substring(1);
1390 var parts = queryString.split("&");
1391 for (var i = 0; i < parts.length; i++) {
1392 var temp = parts[i].split("=");
1393 var val = temp.length == 2 ? encodeURIComponent(temp[1]) : "";
1394 if (Object.isUndefined(parameters[temp[0]])) {
1395 parameters[temp[0]] = val;
1396 }
1397 else {
1398 if (Object.isArray(parameters[temp[0]]) == false) {
1399 var oldVal = parameters[temp[0]];
1400 delete parameters[temp[0]];
1401 parameters[temp[0]] = [oldVal];
1402 }
1403 parameters[temp[0]].push(val);
1404 }
1405 }
1406 }
1407 return parameters;
1408};
1409/**
1410 * 获取指定请求参数的值
1411 *
1412 * @param name 参数名
1413 * @return 指定请求参数的值
1414 */
1415Location.prototype.getParameter = function (name) {
1416 var parameters = this.getParameters();
1417 return parameters[name];
1418};
1419//# sourceMappingURL=prototype.esm.js.map