js_ryl_v3 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +775 -0
  2. package/dist/base64Img/index.d.ts +5 -0
  3. package/dist/base64Img/index.js +50 -0
  4. package/dist/cookie/index.d.ts +14 -0
  5. package/dist/cookie/index.js +39 -0
  6. package/dist/copy/index.d.ts +9 -0
  7. package/dist/copy/index.js +18 -0
  8. package/dist/deepCopy/index.d.ts +1 -0
  9. package/dist/deepCopy/index.js +28 -0
  10. package/dist/downExcel/index.d.ts +5 -0
  11. package/dist/downExcel/index.js +43 -0
  12. package/dist/emoji/index.d.ts +1 -0
  13. package/dist/emoji/index.js +64 -0
  14. package/dist/emojiToUnicode/index.d.ts +1 -0
  15. package/dist/emojiToUnicode/index.js +8 -0
  16. package/dist/esm/base64Img/index.d.ts +5 -0
  17. package/dist/esm/base64Img/index.js +47 -0
  18. package/dist/esm/cookie/index.d.ts +14 -0
  19. package/dist/esm/cookie/index.js +37 -0
  20. package/dist/esm/copy/index.d.ts +9 -0
  21. package/dist/esm/copy/index.js +15 -0
  22. package/dist/esm/deepCopy/index.d.ts +1 -0
  23. package/dist/esm/deepCopy/index.js +25 -0
  24. package/dist/esm/downExcel/index.d.ts +5 -0
  25. package/dist/esm/downExcel/index.js +7 -0
  26. package/dist/esm/emoji/index.d.ts +1 -0
  27. package/dist/esm/emoji/index.js +61 -0
  28. package/dist/esm/emojiToUnicode/index.d.ts +1 -0
  29. package/dist/esm/emojiToUnicode/index.js +5 -0
  30. package/dist/esm/filterTable/index.d.ts +5 -0
  31. package/dist/esm/filterTable/index.js +21 -0
  32. package/dist/esm/flyToCart/index.d.ts +5 -0
  33. package/dist/esm/flyToCart/index.js +47 -0
  34. package/dist/esm/function/index.d.ts +11 -0
  35. package/dist/esm/function/index.js +23 -0
  36. package/dist/esm/getMonthDays/index.d.ts +1 -0
  37. package/dist/esm/getMonthDays/index.js +4 -0
  38. package/dist/esm/getParamsUtil/index.d.ts +12 -0
  39. package/dist/esm/getParamsUtil/index.js +85 -0
  40. package/dist/esm/highLight/index.d.ts +1 -0
  41. package/dist/esm/highLight/index.js +7 -0
  42. package/dist/esm/index.d.ts +17 -0
  43. package/dist/esm/index.js +17 -0
  44. package/dist/esm/number/index.d.ts +8 -0
  45. package/dist/esm/number/index.js +160 -0
  46. package/dist/esm/reg/index.d.ts +11 -0
  47. package/dist/esm/reg/index.js +35 -0
  48. package/dist/esm/time/index.d.ts +8 -0
  49. package/dist/esm/time/index.js +78 -0
  50. package/dist/esm/verCode/index.d.ts +6 -0
  51. package/dist/esm/verCode/index.js +37 -0
  52. package/dist/filterTable/index.d.ts +5 -0
  53. package/dist/filterTable/index.js +24 -0
  54. package/dist/flyToCart/index.d.ts +5 -0
  55. package/dist/flyToCart/index.js +50 -0
  56. package/dist/function/index.d.ts +11 -0
  57. package/dist/function/index.js +25 -0
  58. package/dist/getMonthDays/index.d.ts +1 -0
  59. package/dist/getMonthDays/index.js +7 -0
  60. package/dist/getParamsUtil/index.d.ts +12 -0
  61. package/dist/getParamsUtil/index.js +87 -0
  62. package/dist/highLight/index.d.ts +1 -0
  63. package/dist/highLight/index.js +10 -0
  64. package/dist/index.d.ts +17 -0
  65. package/dist/index.js +40 -0
  66. package/dist/number/index.d.ts +8 -0
  67. package/dist/number/index.js +162 -0
  68. package/dist/reg/index.d.ts +11 -0
  69. package/dist/reg/index.js +37 -0
  70. package/dist/time/index.d.ts +8 -0
  71. package/dist/time/index.js +80 -0
  72. package/dist/verCode/index.d.ts +6 -0
  73. package/dist/verCode/index.js +39 -0
  74. package/package.json +36 -0
  75. package/src/base64Img/index.ts +66 -0
  76. package/src/cookie/index.ts +47 -0
  77. package/src/copy/index.ts +23 -0
  78. package/src/deepCopy/index.ts +26 -0
  79. package/src/downExcel/index.ts +16 -0
  80. package/src/emoji/index.ts +63 -0
  81. package/src/emojiToUnicode/index.ts +9 -0
  82. package/src/filterTable/index.ts +33 -0
  83. package/src/flyToCart/index.ts +67 -0
  84. package/src/function/index.ts +37 -0
  85. package/src/getMonthDays/index.ts +4 -0
  86. package/src/getParamsUtil/index.ts +107 -0
  87. package/src/highLight/index.ts +10 -0
  88. package/src/index.ts +17 -0
  89. package/src/number/index.ts +133 -0
  90. package/src/reg/index.ts +36 -0
  91. package/src/time/index.ts +90 -0
  92. package/src/verCode/index.ts +42 -0
@@ -0,0 +1,47 @@
1
+ interface CookieOptions {
2
+ path?: string;
3
+ domain?: string;
4
+ expires?: number | Date;
5
+ }
6
+
7
+ interface CookieSetOptions extends CookieOptions {
8
+ domain?: 'domain' | string;
9
+ }
10
+
11
+ const cookie = {
12
+ set: (key: string, val: string, ops?: CookieSetOptions): void => {
13
+ ops = ops || {};
14
+ let path = ops.path ? ";Path=" + ops.path : "";
15
+ let domain = '';
16
+ if (ops.domain && ops.domain === 'domain') {
17
+ const hostname = window.location.hostname;
18
+ const parts = hostname.split('.');
19
+ const set_domain = parts.slice(-2).join('.');
20
+ domain = ";domain=" + set_domain;
21
+ }
22
+ let expires = "";
23
+ if (ops.expires) {
24
+ const exp = String(ops.expires).length === 10
25
+ ? new Date(Number(ops.expires) * 1000)
26
+ : new Date(ops.expires);
27
+ expires = ";expires=" + exp.toUTCString();
28
+ }
29
+ document.cookie = `${key}=${encodeURIComponent(val)}${domain}${path}${expires}`;
30
+ },
31
+ get: (name: string): string | null => {
32
+ const value = `; ${document.cookie}`;
33
+ const parts = value.split(`; ${name}=`);
34
+ if (parts.length === 2) {
35
+ return decodeURIComponent(parts.pop()!.split(';').shift()!);
36
+ } else {
37
+ return null;
38
+ }
39
+ },
40
+ remove: (key: string, ops?: CookieOptions): void => {
41
+ ops = ops || {};
42
+ ops.expires = -1;
43
+ cookie.set(key, '', ops as CookieSetOptions);
44
+ }
45
+ };
46
+
47
+ export default cookie;
@@ -0,0 +1,23 @@
1
+ interface CopyResult {
2
+ code: number;
3
+ msg: string;
4
+ }
5
+
6
+ interface CopyCallback {
7
+ (result: CopyResult): void;
8
+ }
9
+
10
+ export default function copy(content: string, callback: CopyCallback): void {
11
+ const newInput = document.createElement("input");
12
+ newInput.setAttribute("readonly", "readonly");
13
+ newInput.setAttribute("value", content);
14
+ document.body.appendChild(newInput);
15
+ if (document.execCommand("copy")) {
16
+ newInput.select();
17
+ document.execCommand("copy");
18
+ callback({ code: 200, msg: "复制成功" });
19
+ } else {
20
+ callback({ code: 100, msg: "当前浏览器不支持,请更换浏览器后重试" });
21
+ }
22
+ document.body.removeChild(newInput);
23
+ }
@@ -0,0 +1,26 @@
1
+ export default function deepCopy<T extends Record<string, any>>(
2
+ obj: T = {} as T,
3
+ tar?: Record<string, any>
4
+ ): T {
5
+ const dest: Record<string, any> = obj || {};
6
+ if (!tar) return dest as T;
7
+
8
+ for (const key in tar) {
9
+ if (!tar.hasOwnProperty(key)) continue;
10
+
11
+ const val = tar[key];
12
+
13
+ if (val === null || val === undefined) {
14
+ dest[key] = val;
15
+ } else if (Array.isArray(val)) {
16
+ dest[key] = [];
17
+ deepCopy(dest[key], val);
18
+ } else if (typeof val === 'object') {
19
+ dest[key] = {};
20
+ deepCopy(dest[key], val);
21
+ } else {
22
+ dest[key] = val;
23
+ }
24
+ }
25
+ return dest as T;
26
+ }
@@ -0,0 +1,16 @@
1
+ import * as XLSX from 'xlsx';
2
+
3
+ interface ExcelData {
4
+ [key: string]: any;
5
+ }
6
+
7
+ export default function downExcel(
8
+ data: ExcelData[],
9
+ fileName: string = '列表',
10
+ sheetName: string = 'Sheet1'
11
+ ): void {
12
+ const worksheet = XLSX.utils.json_to_sheet(data);
13
+ const workbook = XLSX.utils.book_new();
14
+ XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
15
+ XLSX.writeFile(workbook, fileName + '.xlsx');
16
+ }
@@ -0,0 +1,63 @@
1
+ const emojiRanges: [number, number][] = [
2
+ [0x231A, 0x231B], [0x23E9, 0x23EC], [0x23F0, 0x23F0], [0x23F3, 0x23F3],
3
+ [0x25AA, 0x25AB], [0x25B6, 0x25B6], [0x25C0, 0x25C0], [0x25FB, 0x25FE],
4
+ [0x2600, 0x2604], [0x260E, 0x260E], [0x2611, 0x2611], [0x2614, 0x2615],
5
+ [0x2618, 0x2618], [0x261D, 0x261D], [0x2620, 0x2620], [0x2622, 0x2623],
6
+ [0x2626, 0x2626], [0x262A, 0x262A], [0x262E, 0x262F], [0x2638, 0x263A],
7
+ [0x2640, 0x2640], [0x2642, 0x2642], [0x2648, 0x2653], [0x265F, 0x2660],
8
+ [0x2663, 0x2663], [0x2665, 0x2666], [0x2668, 0x2668], [0x267B, 0x267B],
9
+ [0x267F, 0x267F], [0x2692, 0x2697], [0x2699, 0x2699], [0x269B, 0x269C],
10
+ [0x26A0, 0x26A1], [0x26AA, 0x26AB], [0x26B0, 0x26B1], [0x26BD, 0x26BE],
11
+ [0x26C4, 0x26C5], [0x26C8, 0x26C8], [0x26CE, 0x26CF], [0x26D1, 0x26D1],
12
+ [0x26D3, 0x26D4], [0x26E9, 0x26EA], [0x26F0, 0x26F5], [0x26F7, 0x26FA],
13
+ [0x26FD, 0x26FD], [0x2702, 0x2702], [0x2705, 0x2705], [0x2708, 0x270D],
14
+ [0x270F, 0x270F], [0x2712, 0x2712], [0x2714, 0x2714], [0x2716, 0x2716],
15
+ [0x271D, 0x271D], [0x2721, 0x2721], [0x2728, 0x2728], [0x2733, 0x2734],
16
+ [0x2744, 0x2744], [0x2747, 0x2747], [0x274C, 0x274C], [0x274E, 0x274E],
17
+ [0x2753, 0x2755], [0x2757, 0x2757], [0x2763, 0x2764], [0x2795, 0x2797],
18
+ [0x27A1, 0x27A1], [0x27B0, 0x27B0], [0x27BF, 0x27BF], [0x2934, 0x2935],
19
+ [0x2B05, 0x2B07], [0x2B1B, 0x2B1C], [0x2B50, 0x2B50], [0x2B55, 0x2B55],
20
+ [0x1F004, 0x1F004], [0x1F0CF, 0x1F0CF], [0x1F170, 0x1F171], [0x1F17E, 0x1F17F],
21
+ [0x1F18E, 0x1F18E], [0x1F191, 0x1F19A], [0x1F1E6, 0x1F1FF], [0x1F201, 0x1F202],
22
+ [0x1F21A, 0x1F21A], [0x1F22F, 0x1F22F], [0x1F232, 0x1F23A], [0x1F250, 0x1F251],
23
+ [0x1F300, 0x1F5FF], [0x1F600, 0x1F64F], [0x1F680, 0x1F6FF], [0x1F700, 0x1F77F],
24
+ [0x1F780, 0x1F7FF], [0x1F800, 0x1F8FF], [0x1F900, 0x1F9FF], [0x1FA00, 0x1FA6F],
25
+ [0x1FA70, 0x1FAFF], [0x1FB00, 0x1FBFF],
26
+ ];
27
+
28
+ function isEmoji(codePoint: number): boolean {
29
+ return emojiRanges.some(([start, end]) => codePoint >= start && codePoint <= end);
30
+ }
31
+
32
+ function canDisplayChar(char: string): boolean {
33
+ return char !== '\uFFFD';
34
+ }
35
+
36
+ export default function emoji(str: string): string {
37
+ if (!str) return str;
38
+ const regex = /U\+([0-9A-Fa-f]{4,6})|\[u\+([0-9A-Fa-f]{4,6})\]|\\u\{([0-9A-Fa-f]{4,6})\}/g;
39
+ return str.replace(regex, (match, p1, p2, p3) => {
40
+ const hexStr = p1 || p2 || p3;
41
+ const codePoint = parseInt(hexStr, 16);
42
+
43
+ if (isNaN(codePoint) || codePoint < 0 || codePoint > 0x10FFFF) {
44
+ return match;
45
+ }
46
+
47
+ try {
48
+ const char = String.fromCodePoint(codePoint);
49
+
50
+ if (isEmoji(codePoint)) {
51
+ return char;
52
+ } else {
53
+ if (canDisplayChar(char)) {
54
+ return char;
55
+ } else {
56
+ return match;
57
+ }
58
+ }
59
+ } catch (e) {
60
+ return match;
61
+ }
62
+ });
63
+ }
@@ -0,0 +1,9 @@
1
+ export default function emojiToUnicode(msg: string): string {
2
+ const rex =
3
+ /[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/gu;
4
+ const updated = msg.replace(
5
+ rex,
6
+ (match) => `[u+${match.codePointAt(0)!.toString(16)}]`
7
+ );
8
+ return updated;
9
+ }
@@ -0,0 +1,33 @@
1
+ interface TableData {
2
+ [key: string]: any;
3
+ }
4
+
5
+ const defaultTypes: (string | undefined | null)[] = ['', undefined, null];
6
+
7
+ function filterType(val: any, types: (string | undefined | null)[]): boolean {
8
+ return types.some(v => v === val);
9
+ }
10
+
11
+ export default function filterTable(
12
+ data: TableData[],
13
+ params: string = '--',
14
+ more?: (string | undefined | null)[]
15
+ ): TableData[] {
16
+ const types = more && more.length ? [...defaultTypes, ...more] : defaultTypes;
17
+ const newArr: TableData[] = [];
18
+
19
+ for (const key in data) {
20
+ const obj: TableData = {};
21
+ const re = Object.entries(data[key]);
22
+ for (let i = 0; i < re.length; i++) {
23
+ const d = re[i];
24
+ if (filterType(d[1], types)) {
25
+ d[1] = params;
26
+ }
27
+ obj[d[0]] = d[1];
28
+ }
29
+ newArr.push(obj);
30
+ }
31
+
32
+ return newArr;
33
+ }
@@ -0,0 +1,67 @@
1
+ interface FlyToCartCallback {
2
+ (): void;
3
+ }
4
+
5
+ export default function flyToCart(
6
+ event: MouseEvent,
7
+ image: string,
8
+ targets: HTMLElement,
9
+ callback: FlyToCartCallback = () => {}
10
+ ): void {
11
+ const button = event.target as HTMLElement;
12
+ const flyEl = document.createElement('img');
13
+
14
+ flyEl.style.cssText = `position: fixed;
15
+ width: 20px;
16
+ height: 20px;
17
+ border-radius: 50%;
18
+ pointer-events: none;
19
+ transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s;
20
+ z-index: 10000;
21
+ opacity: 1;
22
+ transform-origin: center center;`;
23
+
24
+ flyEl.setAttribute('src', image);
25
+ document.body.appendChild(flyEl);
26
+
27
+ const startRect = button.getBoundingClientRect();
28
+ const startX = startRect.left + startRect.width / 2;
29
+ const startY = startRect.top + startRect.height / 2;
30
+
31
+ const cartRect = targets.getBoundingClientRect();
32
+ const endX = cartRect.left + cartRect.width / 2;
33
+ const endY = cartRect.top + cartRect.height / 2;
34
+
35
+ const controlX = (startX + endX) / 2;
36
+ const controlY = Math.min(startY, endY) - 150;
37
+
38
+ flyEl.style.left = startX + 'px';
39
+ flyEl.style.top = startY + 'px';
40
+
41
+ let t = 0;
42
+ const duration = 800;
43
+ const startTime = performance.now();
44
+
45
+ const animate = (time: number) => {
46
+ t = (time - startTime) / duration;
47
+ if (t > 1) t = 1;
48
+
49
+ const x = (1 - t) * (1 - t) * startX + 2 * (1 - t) * t * controlX + t * t * endX;
50
+ const y = (1 - t) * (1 - t) * startY + 2 * (1 - t) * t * controlY + t * t * endY;
51
+
52
+ flyEl.style.left = x + 'px';
53
+ flyEl.style.top = y + 'px';
54
+
55
+ flyEl.style.transform = `scale(${1 - t * 0.7})`;
56
+ flyEl.style.opacity = `${1 - t}`;
57
+
58
+ if (t < 1) {
59
+ requestAnimationFrame(animate);
60
+ } else {
61
+ flyEl.remove();
62
+ callback();
63
+ }
64
+ };
65
+
66
+ requestAnimationFrame(animate);
67
+ }
@@ -0,0 +1,37 @@
1
+ interface ThrottleFunction<T extends (...args: any[]) => any> {
2
+ (...args: Parameters<T>): void;
3
+ }
4
+
5
+ interface DebounceFunction<T extends (...args: any[]) => any> {
6
+ (...args: Parameters<T>): void;
7
+ }
8
+
9
+ const fun = {
10
+ throole<T extends (...args: any[]) => any>(
11
+ fn: T,
12
+ delay: number = 500
13
+ ): ThrottleFunction<T> {
14
+ let lastTime = 0;
15
+ return function (this: any, ...args: Parameters<T>) {
16
+ const nowTime = Date.now();
17
+ if (nowTime - lastTime > delay) {
18
+ fn.apply(this, args);
19
+ lastTime = nowTime;
20
+ }
21
+ };
22
+ },
23
+ debounce<T extends (...args: any[]) => any>(
24
+ fn: T,
25
+ delay: number = 500
26
+ ): DebounceFunction<T> {
27
+ let timer: ReturnType<typeof setTimeout> | null = null;
28
+ return function (this: any, ...args: Parameters<T>) {
29
+ if (timer) clearTimeout(timer);
30
+ timer = setTimeout(() => {
31
+ fn.apply(this, args);
32
+ }, delay);
33
+ };
34
+ }
35
+ };
36
+
37
+ export default fun;
@@ -0,0 +1,4 @@
1
+ export default function getMonthDays(year: number, month: number): number {
2
+ const thisDate = new Date(year, month, 0);
3
+ return thisDate.getDate();
4
+ }
@@ -0,0 +1,107 @@
1
+ type ParamType = 'string' | 'number' | 'boolean' | 'object';
2
+
3
+ interface ParamsObject {
4
+ [key: string]: string | string[];
5
+ }
6
+
7
+ const getParamsUtil = {
8
+ getParam<T = any>(
9
+ name: string,
10
+ url?: string,
11
+ defaultValue?: T,
12
+ type?: ParamType
13
+ ): T {
14
+ const params = this.getParams(url);
15
+ let value = params[name];
16
+
17
+ if (value === undefined) {
18
+ return defaultValue as T;
19
+ }
20
+
21
+ if (type === 'number') {
22
+ return Number(value) as T;
23
+ } else if (type === 'boolean') {
24
+ return ((value === 'true' || value === '1') as unknown) as T;
25
+ } else if (type === 'object') {
26
+ try {
27
+ return JSON.parse(String(value)) as T;
28
+ } catch (e) {
29
+ return defaultValue as T;
30
+ }
31
+ }
32
+
33
+ return value as unknown as T;
34
+ },
35
+
36
+ getParams(url: string = window.location.href): ParamsObject {
37
+ const params: ParamsObject = {};
38
+ const search = url.split('?')[1];
39
+
40
+ if (!search) {
41
+ return params;
42
+ }
43
+
44
+ const pairs = search.split('&');
45
+ pairs.forEach(pair => {
46
+ const [key, value] = pair.split('=');
47
+ if (key) {
48
+ const decodedKey = decodeURIComponent(key);
49
+ const decodedValue = value ? decodeURIComponent(value) : '';
50
+
51
+ if (params[decodedKey]) {
52
+ if (Array.isArray(params[decodedKey])) {
53
+ params[decodedKey].push(decodedValue);
54
+ } else {
55
+ params[decodedKey] = [params[decodedKey] as string, decodedValue];
56
+ }
57
+ } else {
58
+ params[decodedKey] = decodedValue;
59
+ }
60
+ }
61
+ });
62
+
63
+ return params;
64
+ },
65
+
66
+ buildQueryString(params: Record<string, any>): string {
67
+ const query: string[] = [];
68
+
69
+ Object.entries(params).forEach(([key, value]) => {
70
+ if (value !== undefined && value !== null) {
71
+ if (Array.isArray(value)) {
72
+ value.forEach(item => {
73
+ query.push(`${encodeURIComponent(key)}=${encodeURIComponent(item)}`);
74
+ });
75
+ } else {
76
+ query.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
77
+ }
78
+ }
79
+ });
80
+
81
+ return query.join('&');
82
+ },
83
+
84
+ joinParams(url: string, params: Record<string, any>): string {
85
+ const [baseUrl] = url.split('?');
86
+ const existingParams = this.getParams(url);
87
+ const mergedParams = { ...existingParams, ...params };
88
+ const queryString = this.buildQueryString(mergedParams);
89
+
90
+ return queryString ? `${baseUrl}?${queryString}` : baseUrl;
91
+ },
92
+
93
+ removeParams(url: string, keys: string | string[]): string {
94
+ const [baseUrl] = url.split('?');
95
+ const params = this.getParams(url);
96
+ const keysArray = Array.isArray(keys) ? keys : [keys];
97
+
98
+ keysArray.forEach(key => {
99
+ delete params[key];
100
+ });
101
+
102
+ const queryString = this.buildQueryString(params);
103
+ return queryString ? `${baseUrl}?${queryString}` : baseUrl;
104
+ }
105
+ };
106
+
107
+ export default getParamsUtil;
@@ -0,0 +1,10 @@
1
+ export default function highlight(
2
+ searchName: string,
3
+ backText: string,
4
+ className: string
5
+ ): string {
6
+ if (!searchName) return backText;
7
+ const escapedKeyword = searchName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
8
+ const regex = new RegExp(`(${escapedKeyword})`, 'gi');
9
+ return backText.replace(regex, `<span class="${className}">$1</span>`);
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ export { default as base64Img } from './base64Img';
2
+ export { default as cookie } from './cookie';
3
+ export { default as copy } from './copy';
4
+ export { default as deepCopy } from './deepCopy';
5
+ export { default as downExcel } from './downExcel';
6
+ export { default as emoji } from './emoji';
7
+ export { default as emojiToUnicode } from './emojiToUnicode';
8
+ export { default as filterTable } from './filterTable';
9
+ export { default as flyToCart } from './flyToCart';
10
+ export { default as fun } from './function';
11
+ export { default as getMonthDays } from './getMonthDays';
12
+ export { default as getParamsUtil } from './getParamsUtil';
13
+ export { default as highlight } from './highLight';
14
+ export { default as num } from './number';
15
+ export { default as reg } from './reg';
16
+ export { default as time } from './time';
17
+ export { default as verCode } from './verCode';
@@ -0,0 +1,133 @@
1
+ function countDecimals(num: number): number {
2
+ let len = 0;
3
+ try {
4
+ num = Number(num);
5
+ const str = num.toString().toUpperCase();
6
+ if (str.split('E').length === 2) {
7
+ let isDecimal = false;
8
+ if (str.split('.').length === 2) {
9
+ str.split('.')[1];
10
+ if (parseInt(str.split('E')[0]) !== 0) {
11
+ isDecimal = true;
12
+ }
13
+ }
14
+ const x = str.split('E');
15
+ if (isDecimal) {
16
+ len = x[0].length;
17
+ }
18
+ len -= parseInt(x[1]);
19
+ } else if (str.split('.').length === 2) {
20
+ if (parseInt(str.split('.')[1]) !== 0) {
21
+ len = str.split('.')[1].length;
22
+ }
23
+ }
24
+ } catch (e) {
25
+ throw e;
26
+ } finally {
27
+ if (isNaN(len) || len < 0) {
28
+ len = 0;
29
+ }
30
+ return len;
31
+ }
32
+ }
33
+
34
+ function convertToInt(num: number): number {
35
+ num = Number(num);
36
+ let newNum = num;
37
+ const times = countDecimals(num);
38
+ const temp_num = num.toString().toUpperCase();
39
+ if (temp_num.split('E').length === 2) {
40
+ newNum = Math.round(num * Math.pow(10, times));
41
+ } else {
42
+ newNum = Number(temp_num.replace(".", ""));
43
+ }
44
+ return newNum;
45
+ }
46
+
47
+ function getCorrectResult(type: 'add' | 'sub' | 'div' | 'mul', num1: number, num2: number, result: number): number {
48
+ let temp_result = 0;
49
+ switch (type) {
50
+ case "add":
51
+ temp_result = num1 + num2;
52
+ break;
53
+ case "sub":
54
+ temp_result = num1 - num2;
55
+ break;
56
+ case "div":
57
+ temp_result = num1 / num2;
58
+ break;
59
+ case "mul":
60
+ temp_result = num1 * num2;
61
+ break;
62
+ }
63
+ if (Math.abs(result - temp_result) > 1) {
64
+ return temp_result;
65
+ }
66
+ if (!isLessThanTwoDecimalPlaces(result)) {
67
+ result = Number(result.toFixed(2));
68
+ }
69
+ return result;
70
+ }
71
+
72
+ function isLessThanTwoDecimalPlaces(num: number): boolean {
73
+ return Math.floor(num * 100) === num * 100;
74
+ }
75
+
76
+ const num = {
77
+ NumFilter(v: number): number {
78
+ const x = String(v).indexOf(".") + 1;
79
+ const y = String(v).length - x;
80
+ if (y > 0 && y >= 3) {
81
+ v = Math.floor(v * 100) / 100;
82
+ }
83
+ return v;
84
+ },
85
+
86
+ add(num1: number | string, num2: number | string): number {
87
+ const n1 = this.NumFilter(Number(num1));
88
+ const n2 = this.NumFilter(Number(num2));
89
+ let dec1 = 0, dec2 = 0, times: number;
90
+ try { dec1 = countDecimals(n1) + 1; } catch (e) { dec1 = 0; }
91
+ try { dec2 = countDecimals(n2) + 1; } catch (e) { dec2 = 0; }
92
+ times = Math.pow(10, Math.max(dec1, dec2));
93
+ const result = (this.mul(n1, times) + this.mul(n2, times)) / times;
94
+ return getCorrectResult("add", n1, n2, result);
95
+ },
96
+
97
+ sub(num1: number | string, num2: number | string): number {
98
+ const n1 = this.NumFilter(Number(num1));
99
+ const n2 = this.NumFilter(Number(num2));
100
+ let dec1 = 0, dec2 = 0, times: number;
101
+ try { dec1 = countDecimals(n1) + 1; } catch (e) { dec1 = 0; }
102
+ try { dec2 = countDecimals(n2) + 1; } catch (e) { dec2 = 0; }
103
+ times = Math.pow(10, Math.max(dec1, dec2));
104
+ const result = Number((this.mul(n1, times) - this.mul(n2, times)) / times);
105
+ return getCorrectResult("sub", n1, n2, result);
106
+ },
107
+
108
+ div(num1: number | string, num2: number | string): number {
109
+ const n1 = Number(num1);
110
+ const n2 = Number(num2);
111
+ let t1 = 0, t2 = 0, dec1: number, dec2: number;
112
+ try { t1 = countDecimals(n1); } catch (e) { }
113
+ try { t2 = countDecimals(n2); } catch (e) { }
114
+ dec1 = convertToInt(n1);
115
+ dec2 = convertToInt(n2);
116
+ const result = this.mul((dec1 / dec2), Math.pow(10, t2 - t1));
117
+ return getCorrectResult("div", n1, n2, result);
118
+ },
119
+
120
+ mul(num1: number | string, num2: number | string): number {
121
+ const n1 = Number(num1);
122
+ const n2 = Number(num2);
123
+ let times = 0;
124
+ const s1 = n1.toString();
125
+ const s2 = n2.toString();
126
+ try { times += countDecimals(n1); } catch (e) { }
127
+ try { times += countDecimals(n2); } catch (e) { }
128
+ const result = convertToInt(n1) * convertToInt(n2) / Math.pow(10, times);
129
+ return getCorrectResult("mul", n1, n2, result);
130
+ }
131
+ };
132
+
133
+ export default num;
@@ -0,0 +1,36 @@
1
+ const reg = {
2
+ Phone(value: string): boolean {
3
+ const regex = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
4
+ return regex.test(value);
5
+ },
6
+ Email(value: string): boolean {
7
+ const regex = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;
8
+ return regex.test(value);
9
+ },
10
+ IdCard(value: string): boolean {
11
+ const regex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
12
+ return regex.test(value);
13
+ },
14
+ Common(value: string): boolean {
15
+ const regex = /^[a-zA-Z0-9_]+$/;
16
+ return regex.test(value);
17
+ },
18
+ QQ(value: string): boolean {
19
+ const regex = /^[1-9][0-9]{4,10}$/gim;
20
+ return regex.test(value);
21
+ },
22
+ Money(value: string): boolean {
23
+ const regex = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
24
+ return regex.test(value);
25
+ },
26
+ imgUrl(value: string): boolean {
27
+ const regex = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)\s*$/i;
28
+ return regex.test(value);
29
+ },
30
+ verChinese(value: string): boolean {
31
+ const regex = /[\u4e00-\u9fa5]/;
32
+ return regex.test(value);
33
+ }
34
+ };
35
+
36
+ export default reg;