@libs-ui/utils 0.2.355-10 → 0.2.355-11

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 (2) hide show
  1. package/README.md +155 -2
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,3 +1,156 @@
1
- ## utils
1
+ # @libs-ui/utils
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ > Thư viện tập trung toàn bộ **utility functions** dùng chung cho các libs-ui trong project.
4
+
5
+ **Version**: `0.2.355-10`
6
+
7
+ ## Giới thiệu
8
+
9
+ Thư viện `@libs-ui/utils` cung cấp các hàm tiện ích dùng chung (format, transform, validate...) để:
10
+
11
+ - Giảm trùng lặp code utility trong nhiều libs khác nhau
12
+ - Dễ bảo trì và mở rộng khi cần thêm utility mới
13
+ - Chuẩn hóa cách xử lý dữ liệu trong toàn bộ project
14
+
15
+ ## Cài đặt
16
+
17
+ ```bash
18
+ npm install @libs-ui/utils
19
+ # hoặc
20
+ yarn add @libs-ui/utils
21
+ ```
22
+
23
+ ## Sử dụng
24
+
25
+ ### Import
26
+
27
+ ```typescript
28
+ import { isNil, isEmpty, get, set, cloneDeep, keyBy, groupBy, range, isEqual, uniqBy } from '@libs-ui/utils';
29
+ ```
30
+
31
+ ### Ví dụ cơ bản
32
+
33
+ #### Kiểm tra giá trị
34
+
35
+ ```typescript
36
+ import { isNil, isEmpty, isTruthy, isFalsy } from '@libs-ui/utils';
37
+
38
+ // Kiểm tra null/undefined
39
+ isNil(null); // true
40
+ isNil(undefined); // true
41
+ isNil(0); // false
42
+
43
+ // Kiểm tra rỗng
44
+ isEmpty(null); // true
45
+ isEmpty(''); // true
46
+ isEmpty({}); // true
47
+ isEmpty([]); // true
48
+ isEmpty({a:1}); // false
49
+ ```
50
+
51
+ #### Thao tác Object
52
+
53
+ ```typescript
54
+ import { get, set, cloneDeep } from '@libs-ui/utils';
55
+
56
+ const user = {
57
+ profile: {
58
+ name: 'John',
59
+ address: { city: 'Hanoi' }
60
+ }
61
+ };
62
+
63
+ // Lấy giá trị theo path
64
+ get(user, 'profile.name'); // 'John'
65
+ get(user, 'profile.address.city'); // 'Hanoi'
66
+ get(user, 'profile.email', 'N/A'); // 'N/A' (default value)
67
+
68
+ // Thiết lập giá trị theo path
69
+ set(user, 'profile.name', 'Jane');
70
+ set(user, 'profile.age', 25);
71
+
72
+ // Clone sâu
73
+ const cloned = cloneDeep(user);
74
+ cloned.profile.name = 'Bob'; // Không ảnh hưởng user gốc
75
+ ```
76
+
77
+ #### Thao tác Array
78
+
79
+ ```typescript
80
+ import { keyBy, groupBy, range, uniqBy, isEqual } from '@libs-ui/utils';
81
+
82
+ const users = [
83
+ { id: 1, name: 'John', type: 'admin' },
84
+ { id: 2, name: 'Jane', type: 'user' },
85
+ { id: 3, name: 'Bob', type: 'admin' }
86
+ ];
87
+
88
+ // Chuyển array thành object
89
+ keyBy(users, 'id');
90
+ // { "1": {id:1,name:"John",type:"admin"}, "2": {...}, "3": {...} }
91
+
92
+ // Nhóm theo type
93
+ groupBy(users, 'type');
94
+ // { "admin": [{...}, {...}], "user": [{...}] }
95
+
96
+ // Tạo mảng số
97
+ range(5); // [0, 1, 2, 3, 4]
98
+ range(1, 5); // [1, 2, 3, 4]
99
+ range(0, 10, 2); // [0, 2, 4, 6, 8]
100
+
101
+ // Loại bỏ trùng lặp
102
+ uniqBy([{id:1},{id:2},{id:1}], 'id'); // [{id:1}, {id:2}]
103
+
104
+ // So sánh deep equality
105
+ isEqual({a:1, b:2}, {a:1, b:2}); // true
106
+ isEqual([1,2,3], [1,2,3]); // true
107
+ ```
108
+
109
+ ## Important Notes
110
+
111
+ ⚠️ **Lưu ý quan trọng khi sử dụng**:
112
+
113
+ - Các functions hỗ trợ unwrap Signal tự động (trừ khi dùng option `ignoreUnWrapSignal`).
114
+ - `get()` và `set()` hỗ trợ path dạng string (vd: `"user.profile.name"`) hoặc array (vd: `["user", "profile", "name"]`).
115
+ - `cloneDeep()` có thể clone Signal, Date, RegExp, Map, Set và các object phức tạp khác.
116
+ - `isEqual()` có thể so sánh deep equality cho objects và arrays.
117
+
118
+ ## API Reference
119
+
120
+ Xem chi tiết API tại [Documentation](./docs/utils/utils.md) hoặc [Demo Live](http://localhost:4500/utils/helpers).
121
+
122
+ ### Các Functions chính
123
+
124
+ | Function | Mô tả |
125
+ | --- | --- |
126
+ | `isNil(value, options?)` | Kiểm tra giá trị có phải null hoặc undefined |
127
+ | `isEmpty(value, options?)` | Kiểm tra giá trị có rỗng không |
128
+ | `isTruthy(value, options?)` | Kiểm tra giá trị truthy |
129
+ | `isFalsy(value, options?)` | Kiểm tra giá trị falsy |
130
+ | `get(obj, path, defaultValue?, keepLastValueIfSignal?)` | Lấy giá trị theo path |
131
+ | `set(obj, path, value, options?)` | Thiết lập giá trị theo path |
132
+ | `cloneDeep(data, options?, seen?)` | Clone sâu object/array |
133
+ | `keyBy(data, key)` | Chuyển array thành object |
134
+ | `groupBy(data, key)` | Nhóm array theo key |
135
+ | `range(start, end?, step?)` | Tạo mảng số |
136
+ | `isEqual(value1, value2, options?)` | So sánh deep equality |
137
+ | `uniqBy(data, key?)` | Loại bỏ trùng lặp |
138
+ | `omitBy(objData, predicate)` | Loại bỏ thuộc tính theo điều kiện |
139
+ | `generateInterface(obj, interfaceName)` | Tạo interface từ object |
140
+
141
+ ## Demo
142
+
143
+ - **Local**: [http://localhost:4500/utils/helpers](http://localhost:4500/utils/helpers)
144
+ - **Production**: (Chưa có)
145
+
146
+ ## Công nghệ sử dụng
147
+
148
+ - **Angular**: >=18.0.0
149
+ - **TypeScript**: Latest
150
+ - **RxJS**: ~7.8.0
151
+ - **dayjs**: 1.11.5
152
+ - **crypto-es**: ^2.1.0
153
+
154
+ ## Tài liệu
155
+
156
+ Xem thêm tài liệu chi tiết tại [docs/utils/utils.md](../../docs/utils/utils.md).
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@libs-ui/utils",
3
- "version": "0.2.355-10",
3
+ "version": "0.2.355-11",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=18.0.0",
6
6
  "@angular/core": ">=18.0.0",
7
7
  "crypto-es": "^2.1.0",
8
8
  "dayjs": "1.11.5",
9
- "@libs-ui/interfaces-types": "0.2.355-10",
9
+ "@libs-ui/interfaces-types": "0.2.355-11",
10
10
  "rxjs": "~7.8.0"
11
11
  },
12
12
  "sideEffects": false,