@libs-ui/utils 0.2.281 → 0.2.283
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.
- package/esm2022/get-smart-axis-scale.mjs +177 -22
- package/esm2022/helpers.mjs +65 -1
- package/fesm2022/libs-ui-utils.mjs +239 -21
- package/fesm2022/libs-ui-utils.mjs.map +1 -1
- package/get-smart-axis-scale.d.ts +29 -7
- package/helpers.d.ts +64 -0
- package/package.json +2 -2
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
interface AxisScaleOptions {
|
|
2
2
|
minTickCount?: number;
|
|
3
3
|
maxTickCount?: number;
|
|
4
|
-
stepCandidates?:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
stepCandidates?: number[];
|
|
5
|
+
acceptNegative?: boolean;
|
|
6
|
+
minNegative?: number;
|
|
7
|
+
acceptStepIsTypeFloat?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface AxisScaleResult {
|
|
10
|
+
stepSize: number;
|
|
11
|
+
max: number;
|
|
12
|
+
min: number;
|
|
13
|
+
tickAmount: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Calculates smart axis scale for charts
|
|
17
|
+
*
|
|
18
|
+
* @description This function can throw errors if:
|
|
19
|
+
* - maxData < 0 and acceptNegative is false
|
|
20
|
+
* - minNegative is undefined and acceptNegative is true
|
|
21
|
+
* - maxData < minNegative (only when acceptNegative is true)
|
|
22
|
+
* - minNegative > 0 (only when acceptNegative is true)
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} Validation errors for invalid input combinations
|
|
25
|
+
* @required Always wrap this function in try-catch and handle exceptions
|
|
26
|
+
* @param maxData - Maximum data value
|
|
27
|
+
* @param options - Configuration options for axis scaling
|
|
28
|
+
* @returns Axis scale configuration
|
|
29
|
+
*/
|
|
30
|
+
export declare const getSmartAxisScale: (maxData: number, options?: AxisScaleOptions) => AxisScaleResult;
|
|
31
|
+
export {};
|
package/helpers.d.ts
CHANGED
|
@@ -35,6 +35,70 @@ export declare const isEmpty: (value: unknown) => boolean;
|
|
|
35
35
|
* omitBy(obj, isNil); // { a: 1, c: 3 }
|
|
36
36
|
*/
|
|
37
37
|
export declare const omitBy: <T>(objData: Record<string, any>, predicate: (val: any) => boolean) => T;
|
|
38
|
+
/**
|
|
39
|
+
* Lấy giá trị từ đối tượng theo đường dẫn chỉ định
|
|
40
|
+
*
|
|
41
|
+
* Hàm này giúp bạn truy cập vào các thuộc tính sâu bên trong một đối tượng một cách an toàn,
|
|
42
|
+
* tránh lỗi khi thuộc tính không tồn tại.
|
|
43
|
+
*
|
|
44
|
+
* @param obj Đối tượng nguồn cần lấy giá trị
|
|
45
|
+
* @param path Đường dẫn đến thuộc tính cần lấy. Có thể là:
|
|
46
|
+
* - Chuỗi: 'user.profile.name' hoặc 'items[0].title'
|
|
47
|
+
* - Mảng: ['user', 'profile', 'name'] hoặc ['items', '0', 'title']
|
|
48
|
+
* - Chuỗi rỗng '': trả về chính đối tượng gốc
|
|
49
|
+
* @param defaultValue Giá trị mặc định trả về khi không tìm thấy thuộc tính (mặc định: undefined)
|
|
50
|
+
* @param keepLastValueIfSignal Có giữ nguyên signal cuối cùng hay không (mặc định: false - sẽ gọi signal())
|
|
51
|
+
* @returns Giá trị tìm được hoặc giá trị mặc định
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Ví dụ cơ bản
|
|
55
|
+
* const user = { name: 'John', age: 30 };
|
|
56
|
+
* get(user, 'name'); // 'John'
|
|
57
|
+
* get(user, 'email'); // undefined
|
|
58
|
+
* get(user, 'email', 'no-email'); // 'no-email'
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // Truyền path rỗng - trả về chính đối tượng gốc
|
|
62
|
+
* const data = { name: 'Alice', age: 25 };
|
|
63
|
+
* get(data, ''); // { name: 'Alice', age: 25 } (chính đối tượng data)
|
|
64
|
+
* get(data, '', 'default'); // { name: 'Alice', age: 25 } (bỏ qua defaultValue)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Truy cập thuộc tính sâu
|
|
68
|
+
* const data = {
|
|
69
|
+
* user: {
|
|
70
|
+
* profile: {
|
|
71
|
+
* name: 'Alice',
|
|
72
|
+
* settings: { theme: 'dark' }
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* };
|
|
76
|
+
* get(data, 'user.profile.name'); // 'Alice'
|
|
77
|
+
* get(data, 'user.profile.settings.theme'); // 'dark'
|
|
78
|
+
* get(data, 'user.profile.avatar', 'default.jpg'); // 'default.jpg'
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Truy cập mảng
|
|
82
|
+
* const items = [
|
|
83
|
+
* { name: 'Item 1', price: 100 },
|
|
84
|
+
* { name: 'Item 2', price: 200 }
|
|
85
|
+
* ];
|
|
86
|
+
* get(items, '[0].name'); // 'Item 1'
|
|
87
|
+
* get(items, '0.price'); // 100
|
|
88
|
+
* get(items, '[1].name'); // 'Item 2'
|
|
89
|
+
* get(items, '[2].name', 'Not found'); // 'Not found'
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Sử dụng với mảng path
|
|
93
|
+
* const nested = { a: { b: { c: 'deep value' } } };
|
|
94
|
+
* get(nested, ['a', 'b', 'c']); // 'deep value'
|
|
95
|
+
* get(nested, ['a', 'b', 'd'], 'default'); // 'default'
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Trường hợp đặc biệt
|
|
99
|
+
* get(null, 'any.path'); // undefined
|
|
100
|
+
* get(undefined, 'any.path', 'fallback'); // 'fallback'
|
|
101
|
+
*/
|
|
38
102
|
export declare const get: <T = any>(obj: any, path: string | string[], defaultValue?: any, keepLastValueIfSignal?: boolean) => T;
|
|
39
103
|
/**
|
|
40
104
|
* Thiết lập giá trị cho một thuộc tính trong đối tượng theo đường dẫn chỉ định
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libs-ui/utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.283",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^18.2.0",
|
|
6
6
|
"@angular/core": "^18.2.0",
|
|
7
7
|
"crypto-es": "^2.1.0",
|
|
8
8
|
"dayjs": "1.11.5",
|
|
9
|
-
"@libs-ui/interfaces-types": "0.2.
|
|
9
|
+
"@libs-ui/interfaces-types": "0.2.283",
|
|
10
10
|
"rxjs": "~7.8.0"
|
|
11
11
|
},
|
|
12
12
|
"sideEffects": false,
|