@libs-ui/utils 0.2.282 → 0.2.284

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.
@@ -1,23 +1,34 @@
1
- /**
2
- * Hàm có thể trả về lỗi nếu:
3
- * - maxData < 0 và acceptNegative là false
4
- * - minNegative là undefined và acceptNegative là true
5
- * - maxData < minNegative (chỉ xảy ra khi acceptNegative là true)
6
- * - minNegative > 0 (chỉ xảy ra khi acceptNegative là true)
7
- * @throws {Error}
8
- * @required luôn đặt hàm này trong try catch và xử lý ngoại lệ
9
- * @hint Truyền 3 tham số: min,max và tick
10
- */
11
- export declare const getSmartAxisScale: (maxData: number, options?: {
1
+ interface AxisScaleOptions {
12
2
  minTickCount?: number;
13
3
  maxTickCount?: number;
14
- stepCandidates?: Array<number>;
4
+ stepCandidates?: number[];
15
5
  acceptNegative?: boolean;
16
6
  minNegative?: number;
17
7
  acceptStepIsTypeFloat?: boolean;
18
- }) => {
8
+ }
9
+ interface AxisScaleResult {
19
10
  stepSize: number;
20
11
  max: number;
21
12
  min: number;
22
13
  tickAmount: number;
23
- };
14
+ }
15
+ /**
16
+ * Tính toán smart axis scale cho biểu đồ
17
+ *
18
+ * @param maxData - Giá trị tối đa của dữ liệu
19
+ * @param options - Các tùy chọn cấu hình axis scale
20
+ * @returns Cấu hình axis scale bao gồm stepSize, max, min, tickAmount
21
+ *
22
+ * @throws {Error} INVALID_NEGATIVE_DATA - khi maxData < 0 mà acceptNegative = false
23
+ * @throws {Error} MISSING_MIN_NEGATIVE - khi acceptNegative = true nhưng thiếu minNegative
24
+ * @throws {Error} INVALID_RANGE - khi maxData < minNegative
25
+ * @throws {Error} INVALID_MIN_NEGATIVE - khi minNegative >= 0
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const result = getSmartAxisScale(100, { minTickCount: 5, maxTickCount: 10 });
30
+ * // returns { stepSize: 20, max: 120, min: 0, tickAmount: 6 }
31
+ * ```
32
+ */
33
+ export declare const getSmartAxisScale: (originalMaxData: number, options?: AxisScaleOptions) => AxisScaleResult;
34
+ 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.282",
3
+ "version": "0.2.284",
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.282",
9
+ "@libs-ui/interfaces-types": "0.2.284",
10
10
  "rxjs": "~7.8.0"
11
11
  },
12
12
  "sideEffects": false,