@d-matrix/utils 1.27.0 → 1.28.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 (72) hide show
  1. package/dist/algorithm/binary.d.ts +8 -8
  2. package/dist/algorithm/binary.js +38 -38
  3. package/dist/algorithm/index.d.ts +2 -2
  4. package/dist/algorithm/index.js +2 -2
  5. package/dist/algorithm/tree.d.ts +34 -34
  6. package/dist/algorithm/tree.js +124 -124
  7. package/dist/array.d.ts +46 -5
  8. package/dist/array.js +129 -37
  9. package/dist/clipboard.d.ts +12 -12
  10. package/dist/clipboard.js +107 -107
  11. package/dist/color.d.ts +7 -7
  12. package/dist/color.js +41 -41
  13. package/dist/date.d.ts +34 -34
  14. package/dist/date.js +62 -62
  15. package/dist/decimal.d.ts +17 -17
  16. package/dist/decimal.js +23 -23
  17. package/dist/dom.d.ts +11 -11
  18. package/dist/dom.js +27 -27
  19. package/dist/echarts.d.ts +36 -36
  20. package/dist/echarts.js +112 -112
  21. package/dist/file.d.ts +49 -49
  22. package/dist/file.js +154 -154
  23. package/dist/i18n.d.ts +10 -10
  24. package/dist/i18n.js +12 -12
  25. package/dist/index.d.ts +16 -16
  26. package/dist/index.js +16 -16
  27. package/dist/number.d.ts +2 -2
  28. package/dist/number.js +4 -4
  29. package/dist/object.d.ts +13 -13
  30. package/dist/object.js +28 -28
  31. package/dist/operator.d.ts +6 -6
  32. package/dist/operator.js +6 -6
  33. package/dist/react/enhancedComponent.d.ts +12 -12
  34. package/dist/react/enhancedComponent.js +16 -16
  35. package/dist/react/index.d.ts +15 -12
  36. package/dist/react/index.js +15 -12
  37. package/dist/react/renderToString.d.ts +3 -3
  38. package/dist/react/renderToString.js +30 -30
  39. package/dist/react/types.d.ts +9 -9
  40. package/dist/react/types.js +1 -1
  41. package/dist/react/useCopyToClipboard.d.ts +21 -21
  42. package/dist/react/useCopyToClipboard.js +44 -44
  43. package/dist/react/useDeepCompareRef.d.ts +2 -2
  44. package/dist/react/useDeepCompareRef.js +11 -11
  45. package/dist/react/useDisableContextMenu.d.ts +7 -7
  46. package/dist/react/useDisableContextMenu.js +24 -24
  47. package/dist/react/useEventCallback.d.ts +7 -0
  48. package/dist/react/useEventCallback.js +19 -0
  49. package/dist/react/useForwardRef.d.ts +9 -9
  50. package/dist/react/useForwardRef.js +22 -22
  51. package/dist/react/useId.d.ts +1 -0
  52. package/dist/react/useId.js +12 -0
  53. package/dist/react/useIsFirstRender.d.ts +6 -6
  54. package/dist/react/useIsFirstRender.js +14 -14
  55. package/dist/react/useIsMounted.d.ts +2 -2
  56. package/dist/react/useIsMounted.js +13 -13
  57. package/dist/react/useIsomorphicLayoutEffect.d.ts +2 -2
  58. package/dist/react/useIsomorphicLayoutEffect.js +2 -2
  59. package/dist/react/useMediaQuery.d.ts +14 -14
  60. package/dist/react/useMediaQuery.js +42 -42
  61. package/dist/react/useSafeTimeout.d.ts +12 -0
  62. package/dist/react/useSafeTimeout.js +28 -0
  63. package/dist/react/useStateCallback.d.ts +2 -2
  64. package/dist/react/useStateCallback.js +17 -17
  65. package/dist/support.d.ts +12 -12
  66. package/dist/support.js +12 -12
  67. package/dist/timer.d.ts +5 -5
  68. package/dist/timer.js +5 -5
  69. package/dist/types.d.ts +128 -21
  70. package/dist/types.js +1 -1
  71. package/package.json +2 -2
  72. package/readme.md +5 -1
@@ -1,12 +1,12 @@
1
- /**
2
- * 复制图片到剪贴板
3
- * @param element
4
- * @returns
5
- */
6
- export declare function writeImage(element: HTMLImageElement | null | string): Promise<unknown>;
7
- /**
8
- * 复制文本到剪贴板
9
- * @param text
10
- * @returns
11
- */
12
- export declare function writeText(text: string): Promise<void>;
1
+ /**
2
+ * 复制图片到剪贴板
3
+ * @param element
4
+ * @returns
5
+ */
6
+ export declare function writeImage(element: HTMLImageElement | null | string): Promise<unknown>;
7
+ /**
8
+ * 复制文本到剪贴板
9
+ * @param text
10
+ * @returns
11
+ */
12
+ export declare function writeText(text: string): Promise<void>;
package/dist/clipboard.js CHANGED
@@ -1,107 +1,107 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /**
11
- * 复制图片到剪贴板
12
- * @param element
13
- * @returns
14
- */
15
- export function writeImage(element) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- return new Promise((resolve, reject) => {
18
- if (!element)
19
- return reject('element is not defined');
20
- const canvas = document.createElement('canvas');
21
- const ctx = canvas.getContext('2d');
22
- if (ctx === null) {
23
- reject('canvas 2d context初始化失败');
24
- return;
25
- }
26
- const img = new Image();
27
- //浏览器在加载图像时要使用匿名身份验证,以允许跨域资源共享(CORS)。
28
- img.crossOrigin = 'anonymous';
29
- if (typeof element === 'string') {
30
- img.src = element;
31
- }
32
- else {
33
- img.src = element.src;
34
- }
35
- img.onload = () => {
36
- //创建一个画布,赋予画布宽高为图片的原始宽高
37
- if (typeof element === 'string') {
38
- canvas.width = img.width;
39
- canvas.height = img.height;
40
- }
41
- else {
42
- canvas.width = element.naturalWidth;
43
- canvas.height = element.naturalHeight;
44
- }
45
- //防止有缓存,绘制之前先清除画布
46
- ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
47
- ctx.drawImage(img, 0, 0);
48
- //将canvas转为blob
49
- canvas.toBlob((blob) => {
50
- if (blob === null) {
51
- reject('canvas to blob失败');
52
- return;
53
- }
54
- navigator.clipboard
55
- .write([
56
- new ClipboardItem({
57
- [blob.type]: blob,
58
- }),
59
- ])
60
- .then(resolve, reject);
61
- });
62
- };
63
- });
64
- });
65
- }
66
- const legacyWriteText = (text) => {
67
- const $textarea = document.createElement('textarea');
68
- $textarea.value = text;
69
- $textarea.id = '__textarea_for_clipboard__';
70
- $textarea.style.cssText = 'position: fixed; width: 20px; height: 20px; opacity: 0; top: -20px;';
71
- document.body.appendChild($textarea);
72
- $textarea.select();
73
- try {
74
- const isSuccess = document.execCommand('copy');
75
- if (!isSuccess && process.env.NODE_ENV === 'development') {
76
- console.error('复制文本失败, 操作不被支持或未被启用');
77
- }
78
- }
79
- catch (error) {
80
- if (process.env.NODE_ENV === 'development') {
81
- console.error('复制文本失败', error);
82
- }
83
- throw error;
84
- }
85
- finally {
86
- document.body.removeChild($textarea);
87
- }
88
- };
89
- /**
90
- * 复制文本到剪贴板
91
- * @param text
92
- * @returns
93
- */
94
- export function writeText(text) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- if (!navigator.clipboard) {
97
- legacyWriteText(text);
98
- return;
99
- }
100
- return navigator.clipboard.writeText(text).catch((error) => {
101
- if (process.env.NODE_ENV === 'development') {
102
- console.error('复制文本失败', error);
103
- }
104
- return Promise.reject(error);
105
- });
106
- });
107
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * 复制图片到剪贴板
12
+ * @param element
13
+ * @returns
14
+ */
15
+ export function writeImage(element) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ return new Promise((resolve, reject) => {
18
+ if (!element)
19
+ return reject('element is not defined');
20
+ const canvas = document.createElement('canvas');
21
+ const ctx = canvas.getContext('2d');
22
+ if (ctx === null) {
23
+ reject('canvas 2d context初始化失败');
24
+ return;
25
+ }
26
+ const img = new Image();
27
+ //浏览器在加载图像时要使用匿名身份验证,以允许跨域资源共享(CORS)。
28
+ img.crossOrigin = 'anonymous';
29
+ if (typeof element === 'string') {
30
+ img.src = element;
31
+ }
32
+ else {
33
+ img.src = element.src;
34
+ }
35
+ img.onload = () => {
36
+ //创建一个画布,赋予画布宽高为图片的原始宽高
37
+ if (typeof element === 'string') {
38
+ canvas.width = img.width;
39
+ canvas.height = img.height;
40
+ }
41
+ else {
42
+ canvas.width = element.naturalWidth;
43
+ canvas.height = element.naturalHeight;
44
+ }
45
+ //防止有缓存,绘制之前先清除画布
46
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
47
+ ctx.drawImage(img, 0, 0);
48
+ //将canvas转为blob
49
+ canvas.toBlob((blob) => {
50
+ if (blob === null) {
51
+ reject('canvas to blob失败');
52
+ return;
53
+ }
54
+ navigator.clipboard
55
+ .write([
56
+ new ClipboardItem({
57
+ [blob.type]: blob,
58
+ }),
59
+ ])
60
+ .then(resolve, reject);
61
+ });
62
+ };
63
+ });
64
+ });
65
+ }
66
+ const legacyWriteText = (text) => {
67
+ const $textarea = document.createElement('textarea');
68
+ $textarea.value = text;
69
+ $textarea.id = '__textarea_for_clipboard__';
70
+ $textarea.style.cssText = 'position: fixed; width: 20px; height: 20px; opacity: 0; top: -20px;';
71
+ document.body.appendChild($textarea);
72
+ $textarea.select();
73
+ try {
74
+ const isSuccess = document.execCommand('copy');
75
+ if (!isSuccess && process.env.NODE_ENV === 'development') {
76
+ console.error('复制文本失败, 操作不被支持或未被启用');
77
+ }
78
+ }
79
+ catch (error) {
80
+ if (process.env.NODE_ENV === 'development') {
81
+ console.error('复制文本失败', error);
82
+ }
83
+ throw error;
84
+ }
85
+ finally {
86
+ document.body.removeChild($textarea);
87
+ }
88
+ };
89
+ /**
90
+ * 复制文本到剪贴板
91
+ * @param text
92
+ * @returns
93
+ */
94
+ export function writeText(text) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ if (!navigator || !navigator.clipboard || typeof navigator.clipboard.writeText !== 'function') {
97
+ legacyWriteText(text);
98
+ return;
99
+ }
100
+ return navigator.clipboard.writeText(text).catch((error) => {
101
+ if (process.env.NODE_ENV === 'development') {
102
+ console.error('复制文本失败', error);
103
+ }
104
+ return Promise.reject(error);
105
+ });
106
+ });
107
+ }
package/dist/color.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- /**
2
- * 将十六进制颜色转换为 RGBA 颜色
3
- * @param hex 十六进制颜色
4
- * @param alpha 透明度,默认值为 1
5
- * @returns RGBA 颜色
6
- */
7
- export declare function hexToRGBA(hex: string, alpha?: number | string): string;
1
+ /**
2
+ * 将十六进制颜色转换为 RGBA 颜色
3
+ * @param hex 十六进制颜色
4
+ * @param alpha 透明度,默认值为 1
5
+ * @returns RGBA 颜色
6
+ */
7
+ export declare function hexToRGBA(hex: string, alpha?: number | string): string;
package/dist/color.js CHANGED
@@ -1,41 +1,41 @@
1
- /**
2
- * 将十六进制颜色转换为 RGBA 颜色
3
- * @param hex 十六进制颜色
4
- * @param alpha 透明度,默认值为 1
5
- * @returns RGBA 颜色
6
- */
7
- export function hexToRGBA(hex, alpha = 1) {
8
- // 移除井号并转为小写
9
- const processedHex = hex.replace(/^#/, '').toLowerCase();
10
- // 验证十六进制字符合法性
11
- if (!/^[0-9a-f]+$/.test(processedHex)) {
12
- throw new Error('Invalid hex character(s)');
13
- }
14
- // 验证长度合法性
15
- if (![3, 6].includes(processedHex.length)) {
16
- throw new Error('Hex must be 3 or 6 characters long');
17
- }
18
- // 扩展三位缩写为六位
19
- const fullHex = processedHex.length === 3
20
- ? processedHex
21
- .split('')
22
- .map((c) => c + c)
23
- .join('')
24
- : processedHex;
25
- // 解析颜色通道
26
- const parseChannel = (start, end) => parseInt(fullHex.substring(start, end), 16);
27
- const r = parseChannel(0, 2);
28
- const g = parseChannel(2, 4);
29
- const b = parseChannel(4, 6);
30
- // 处理透明度
31
- const numericAlpha = Number(alpha);
32
- if (isNaN(numericAlpha)) {
33
- throw new Error('Alpha must be a valid number');
34
- }
35
- if (numericAlpha < 0 || numericAlpha > 1) {
36
- throw new Error('Alpha must be between 0 and 1');
37
- }
38
- // 标准化输出格式
39
- const formattedAlpha = numericAlpha % 1 === 0 ? numericAlpha.toFixed(0) : numericAlpha.toFixed(2).replace(/0+$/, '').replace(/\.$/, '');
40
- return `rgba(${r}, ${g}, ${b}, ${formattedAlpha})`;
41
- }
1
+ /**
2
+ * 将十六进制颜色转换为 RGBA 颜色
3
+ * @param hex 十六进制颜色
4
+ * @param alpha 透明度,默认值为 1
5
+ * @returns RGBA 颜色
6
+ */
7
+ export function hexToRGBA(hex, alpha = 1) {
8
+ // 移除井号并转为小写
9
+ const processedHex = hex.replace(/^#/, '').toLowerCase();
10
+ // 验证十六进制字符合法性
11
+ if (!/^[0-9a-f]+$/.test(processedHex)) {
12
+ throw new Error('Invalid hex character(s)');
13
+ }
14
+ // 验证长度合法性
15
+ if (![3, 6].includes(processedHex.length)) {
16
+ throw new Error('Hex must be 3 or 6 characters long');
17
+ }
18
+ // 扩展三位缩写为六位
19
+ const fullHex = processedHex.length === 3
20
+ ? processedHex
21
+ .split('')
22
+ .map((c) => c + c)
23
+ .join('')
24
+ : processedHex;
25
+ // 解析颜色通道
26
+ const parseChannel = (start, end) => parseInt(fullHex.substring(start, end), 16);
27
+ const r = parseChannel(0, 2);
28
+ const g = parseChannel(2, 4);
29
+ const b = parseChannel(4, 6);
30
+ // 处理透明度
31
+ const numericAlpha = Number(alpha);
32
+ if (isNaN(numericAlpha)) {
33
+ throw new Error('Alpha must be a valid number');
34
+ }
35
+ if (numericAlpha < 0 || numericAlpha > 1) {
36
+ throw new Error('Alpha must be between 0 and 1');
37
+ }
38
+ // 标准化输出格式
39
+ const formattedAlpha = numericAlpha % 1 === 0 ? numericAlpha.toFixed(0) : numericAlpha.toFixed(2).replace(/0+$/, '').replace(/\.$/, '');
40
+ return `rgba(${r}, ${g}, ${b}, ${formattedAlpha})`;
41
+ }
package/dist/date.d.ts CHANGED
@@ -1,34 +1,34 @@
1
- import { i18n } from './i18n';
2
- /**
3
- * Generates an array of numbers representing a range of years between the start year and the end year.
4
- *
5
- * @param {number} start - the starting year of the range
6
- * @param {number} end - the ending year of the range (defaults to the current year)
7
- * @return {number[]} an array of numbers representing the range of years
8
- */
9
- export declare function rangeOfYears(start: number, end?: number): number[];
10
- export declare enum YearOptionKind {
11
- Numbers = 0,
12
- Objects = 1
13
- }
14
- export interface YearOption {
15
- label: string;
16
- value: number;
17
- }
18
- export declare type GetYearsOptions = {
19
- startYear?: number;
20
- recentYears?: number;
21
- endYear?: number;
22
- suffix?: string;
23
- };
24
- /**
25
- * 获取n年, 从大到小
26
- * @param options
27
- */
28
- export declare function getYears(options: GetYearsOptions & {
29
- type: YearOptionKind.Numbers;
30
- }): number[];
31
- export declare function getYears(options: GetYearsOptions & {
32
- type: YearOptionKind.Objects;
33
- }): YearOption[];
34
- export declare const dayOfWeek: (num: number, lang?: keyof typeof i18n) => string;
1
+ import { i18n } from './i18n';
2
+ /**
3
+ * Generates an array of numbers representing a range of years between the start year and the end year.
4
+ *
5
+ * @param {number} start - the starting year of the range
6
+ * @param {number} end - the ending year of the range (defaults to the current year)
7
+ * @return {number[]} an array of numbers representing the range of years
8
+ */
9
+ export declare function rangeOfYears(start: number, end?: number): number[];
10
+ export declare enum YearOptionKind {
11
+ Numbers = 0,
12
+ Objects = 1
13
+ }
14
+ export interface YearOption {
15
+ label: string;
16
+ value: number;
17
+ }
18
+ export declare type GetYearsOptions = {
19
+ startYear?: number;
20
+ recentYears?: number;
21
+ endYear?: number;
22
+ suffix?: string;
23
+ };
24
+ /**
25
+ * 获取n年, 从大到小
26
+ * @param options
27
+ */
28
+ export declare function getYears(options: GetYearsOptions & {
29
+ type: YearOptionKind.Numbers;
30
+ }): number[];
31
+ export declare function getYears(options: GetYearsOptions & {
32
+ type: YearOptionKind.Objects;
33
+ }): YearOption[];
34
+ export declare const dayOfWeek: (num: number, lang?: keyof typeof i18n) => string;
package/dist/date.js CHANGED
@@ -1,62 +1,62 @@
1
- import { i18n } from './i18n';
2
- /**
3
- * Generates an array of numbers representing a range of years between the start year and the end year.
4
- *
5
- * @param {number} start - the starting year of the range
6
- * @param {number} end - the ending year of the range (defaults to the current year)
7
- * @return {number[]} an array of numbers representing the range of years
8
- */
9
- export function rangeOfYears(start, end = new Date().getFullYear()) {
10
- return Array(end - start + 1)
11
- .fill(start)
12
- .map((year, index) => year + index);
13
- }
14
- export var YearOptionKind;
15
- (function (YearOptionKind) {
16
- YearOptionKind[YearOptionKind["Numbers"] = 0] = "Numbers";
17
- YearOptionKind[YearOptionKind["Objects"] = 1] = "Objects";
18
- })(YearOptionKind || (YearOptionKind = {}));
19
- export function getYears(options) {
20
- const { recentYears = 0, startYear, endYear, suffix = '年', type } = options;
21
- const endY = endYear ? endYear : new Date().getFullYear();
22
- let ranges = recentYears;
23
- if (typeof startYear === 'number') {
24
- // 包含startYear
25
- ranges = endY - startYear + 1;
26
- if (ranges <= 0) {
27
- if (process.env.NODE_ENV === 'development') {
28
- if (endYear === undefined) {
29
- console.error('startYear不能大于当前年份');
30
- }
31
- else if (typeof endYear === 'number') {
32
- console.error('endYear不能小于startYear');
33
- }
34
- }
35
- return [];
36
- }
37
- }
38
- if (type === YearOptionKind.Numbers) {
39
- const result = [];
40
- for (let i = 0; i < ranges; i++) {
41
- result.push(endY - i);
42
- }
43
- return result;
44
- }
45
- if (type === YearOptionKind.Objects) {
46
- const result = [];
47
- for (let i = 0; i < ranges; i++) {
48
- result.push({
49
- value: endY - i,
50
- label: `${endY - i}${suffix}`,
51
- });
52
- }
53
- return result;
54
- }
55
- throw new Error('type must be enum: YearOptionKind.Numbers or YearOptionKind.Objects');
56
- }
57
- export const dayOfWeek = (num, lang = 'zh') => {
58
- if (!Number.isInteger(num)) {
59
- throw new Error('请输入一个整数');
60
- }
61
- return i18n[lang].dayOfWeek[num % 7];
62
- };
1
+ import { i18n } from './i18n';
2
+ /**
3
+ * Generates an array of numbers representing a range of years between the start year and the end year.
4
+ *
5
+ * @param {number} start - the starting year of the range
6
+ * @param {number} end - the ending year of the range (defaults to the current year)
7
+ * @return {number[]} an array of numbers representing the range of years
8
+ */
9
+ export function rangeOfYears(start, end = new Date().getFullYear()) {
10
+ return Array(end - start + 1)
11
+ .fill(start)
12
+ .map((year, index) => year + index);
13
+ }
14
+ export var YearOptionKind;
15
+ (function (YearOptionKind) {
16
+ YearOptionKind[YearOptionKind["Numbers"] = 0] = "Numbers";
17
+ YearOptionKind[YearOptionKind["Objects"] = 1] = "Objects";
18
+ })(YearOptionKind || (YearOptionKind = {}));
19
+ export function getYears(options) {
20
+ const { recentYears = 0, startYear, endYear, suffix = '年', type } = options;
21
+ const endY = endYear ? endYear : new Date().getFullYear();
22
+ let ranges = recentYears;
23
+ if (typeof startYear === 'number') {
24
+ // 包含startYear
25
+ ranges = endY - startYear + 1;
26
+ if (ranges <= 0) {
27
+ if (process.env.NODE_ENV === 'development') {
28
+ if (endYear === undefined) {
29
+ console.error('startYear不能大于当前年份');
30
+ }
31
+ else if (typeof endYear === 'number') {
32
+ console.error('endYear不能小于startYear');
33
+ }
34
+ }
35
+ return [];
36
+ }
37
+ }
38
+ if (type === YearOptionKind.Numbers) {
39
+ const result = [];
40
+ for (let i = 0; i < ranges; i++) {
41
+ result.push(endY - i);
42
+ }
43
+ return result;
44
+ }
45
+ if (type === YearOptionKind.Objects) {
46
+ const result = [];
47
+ for (let i = 0; i < ranges; i++) {
48
+ result.push({
49
+ value: endY - i,
50
+ label: `${endY - i}${suffix}`,
51
+ });
52
+ }
53
+ return result;
54
+ }
55
+ throw new Error('type must be enum: YearOptionKind.Numbers or YearOptionKind.Objects');
56
+ }
57
+ export const dayOfWeek = (num, lang = 'zh') => {
58
+ if (!Number.isInteger(num)) {
59
+ throw new Error('请输入一个整数');
60
+ }
61
+ return i18n[lang].dayOfWeek[num % 7];
62
+ };
package/dist/decimal.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- export declare type FormatOptions = {
2
- decimalPlaces?: number | false;
3
- suffix?: string;
4
- prefix?: string;
5
- defaultValue?: string;
6
- operation?: {
7
- operator: 'add' | 'sub' | 'mul' | 'div' | 'toDecimalPlaces';
8
- value: number;
9
- }[];
10
- };
11
- /**
12
- * 格式化数字,默认保留3位小数,可添加前缀,后缀,默认值为'--'
13
- * @param value
14
- * @param options
15
- * @returns
16
- */
17
- export declare function format(value: number | string | undefined | null, options?: FormatOptions): string;
1
+ export declare type FormatOptions = {
2
+ decimalPlaces?: number | false;
3
+ suffix?: string;
4
+ prefix?: string;
5
+ defaultValue?: string;
6
+ operation?: {
7
+ operator: 'add' | 'sub' | 'mul' | 'div' | 'toDecimalPlaces';
8
+ value: number;
9
+ }[];
10
+ };
11
+ /**
12
+ * 格式化数字,默认保留3位小数,可添加前缀,后缀,默认值为'--'
13
+ * @param value
14
+ * @param options
15
+ * @returns
16
+ */
17
+ export declare function format(value: number | string | undefined | null, options?: FormatOptions): string;
package/dist/decimal.js CHANGED
@@ -1,23 +1,23 @@
1
- import Decimal from 'decimal.js-light';
2
- /**
3
- * 格式化数字,默认保留3位小数,可添加前缀,后缀,默认值为'--'
4
- * @param value
5
- * @param options
6
- * @returns
7
- */
8
- export function format(value, options) {
9
- const { decimalPlaces = 3, suffix = '', defaultValue = '--', prefix = '', operation } = options !== null && options !== void 0 ? options : {};
10
- if (value === null || value === undefined || isNaN(Number(value)) || value === '') {
11
- return defaultValue;
12
- }
13
- let decimalValue = new Decimal(value);
14
- if (Array.isArray(operation) && operation.length > 0) {
15
- operation.forEach((item) => {
16
- decimalValue = decimalValue[item.operator](item.value);
17
- });
18
- }
19
- if (decimalPlaces == false) {
20
- return prefix + decimalValue.toString() + suffix;
21
- }
22
- return prefix + decimalValue.toFixed(decimalPlaces) + suffix;
23
- }
1
+ import Decimal from 'decimal.js-light';
2
+ /**
3
+ * 格式化数字,默认保留3位小数,可添加前缀,后缀,默认值为'--'
4
+ * @param value
5
+ * @param options
6
+ * @returns
7
+ */
8
+ export function format(value, options) {
9
+ const { decimalPlaces = 3, suffix = '', defaultValue = '--', prefix = '', operation } = options !== null && options !== void 0 ? options : {};
10
+ if (value === null || value === undefined || isNaN(Number(value)) || value === '') {
11
+ return defaultValue;
12
+ }
13
+ let decimalValue = new Decimal(value);
14
+ if (Array.isArray(operation) && operation.length > 0) {
15
+ operation.forEach((item) => {
16
+ decimalValue = decimalValue[item.operator](item.value);
17
+ });
18
+ }
19
+ if (decimalPlaces == false) {
20
+ return prefix + decimalValue.toString() + suffix;
21
+ }
22
+ return prefix + decimalValue.toFixed(decimalPlaces) + suffix;
23
+ }
package/dist/dom.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- /**
2
- * 元素滚动条滚动到顶部
3
- */
4
- export declare function scrollToTop(element: Element | null | undefined): void;
5
- /**
6
- * Strips HTML tags from a given string and returns the plain text content.
7
- *
8
- * @param {string} html - The HTML string to strip tags from.
9
- * @return {string} The plain text content of the HTML string.
10
- */
11
- export declare function strip(html: string): string;
1
+ /**
2
+ * 元素滚动条滚动到顶部
3
+ */
4
+ export declare function scrollToTop(element: Element | null | undefined): void;
5
+ /**
6
+ * Strips HTML tags from a given string and returns the plain text content.
7
+ *
8
+ * @param {string} html - The HTML string to strip tags from.
9
+ * @return {string} The plain text content of the HTML string.
10
+ */
11
+ export declare function strip(html: string): string;