@libs-ui/pipes-check-file-extension 0.2.356-8 → 0.2.357-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.
package/README.md
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
# @libs-ui/pipes-check-file-extension
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
>
|
|
5
|
-
> Pipe kiểm tra định dạng file dựa trên extension (đuôi file) để phân loại thành các nhóm định dạng phổ biến.
|
|
3
|
+
> Pipe kiểm tra định dạng file theo nhóm loại (image, video, word, xlsx, pdf, pptx, other), trả về `boolean`.
|
|
6
4
|
|
|
7
5
|
## Giới thiệu
|
|
8
6
|
|
|
9
|
-
`LibsUiPipesCheckFileExtensionPipe`
|
|
7
|
+
`LibsUiPipesCheckFileExtensionPipe` nhận vào một đối tượng `IFile` và một nhóm loại file, sau đó trả về `true` nếu file thuộc nhóm đó và `false` nếu không. Pipe hỗ trợ kiểm tra cả extension rút gọn (vd: `jpg`, `pdf`) lẫn MIME type đầy đủ (vd: `image/jpeg`, `application/pdf`). Thích hợp dùng trong danh sách file, màn hình upload, hoặc hiển thị icon file attachment.
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
## Tính năng
|
|
12
10
|
|
|
13
|
-
- ✅
|
|
14
|
-
- ✅ Hỗ trợ
|
|
15
|
-
- ✅
|
|
16
|
-
- ✅
|
|
17
|
-
- ✅
|
|
11
|
+
- ✅ Phân loại file theo 7 nhóm: `image`, `video`, `word`, `xlsx`, `pdf`, `pptx`, `other`
|
|
12
|
+
- ✅ Hỗ trợ extension rút gọn (vd: `jpg`, `mp4`, `docx`) và MIME type đầy đủ (vd: `application/pdf`)
|
|
13
|
+
- ✅ Tự động extract extension từ `name`, `mimetype`, `url` của `IFile`
|
|
14
|
+
- ✅ Case-insensitive: `JPG`, `jpg`, `Jpg` đều nhận diện đúng
|
|
15
|
+
- ✅ Nhóm `other` bắt tất cả định dạng không nằm trong các nhóm đã biết
|
|
16
|
+
- ✅ Standalone pipe, không cần NgModule
|
|
17
|
+
- ✅ Pure pipe, hiệu năng cao, an toàn trong danh sách dài
|
|
18
18
|
|
|
19
19
|
## Khi nào sử dụng
|
|
20
20
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
21
|
+
- Hiển thị icon/thumbnail khác nhau cho từng loại file trong danh sách attachment
|
|
22
|
+
- Lọc hoặc phân nhóm file trong màn hình upload preview
|
|
23
|
+
- Ẩn/hiện nút xem trước (preview) tùy theo file có phải image hay video không
|
|
24
|
+
- Validate loại file phía client trước khi gọi API upload
|
|
25
|
+
- Render component phù hợp (image viewer, video player, PDF viewer) dựa trên loại file
|
|
24
26
|
|
|
25
27
|
## Cài đặt
|
|
26
28
|
|
|
@@ -38,94 +40,202 @@ import { LibsUiPipesCheckFileExtensionPipe } from '@libs-ui/pipes-check-file-ext
|
|
|
38
40
|
imports: [LibsUiPipesCheckFileExtensionPipe],
|
|
39
41
|
// ...
|
|
40
42
|
})
|
|
43
|
+
export class MyComponent {}
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
##
|
|
46
|
+
## Ví dụ sử dụng
|
|
44
47
|
|
|
45
|
-
### 1.
|
|
46
|
-
|
|
47
|
-
```html
|
|
48
|
-
{{ fileImage | LibsUiPipesCheckFileExtensionPipe : 'image' }}
|
|
49
|
-
```
|
|
48
|
+
### 1. Hiển thị nhãn loại file trong template
|
|
50
49
|
|
|
51
50
|
```typescript
|
|
52
|
-
|
|
51
|
+
import { Component } from '@angular/core';
|
|
52
|
+
import { LibsUiPipesCheckFileExtensionPipe } from '@libs-ui/pipes-check-file-extension';
|
|
53
|
+
import { IFile } from '@libs-ui/interfaces-types';
|
|
54
|
+
|
|
55
|
+
@Component({
|
|
56
|
+
standalone: true,
|
|
57
|
+
imports: [LibsUiPipesCheckFileExtensionPipe],
|
|
58
|
+
template: `
|
|
59
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'image') {
|
|
60
|
+
<span class="libs-ui-font-h6r text-green-600">Ảnh</span>
|
|
61
|
+
}
|
|
62
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'video') {
|
|
63
|
+
<span class="libs-ui-font-h6r text-blue-600">Video</span>
|
|
64
|
+
}
|
|
65
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'pdf') {
|
|
66
|
+
<span class="libs-ui-font-h6r text-red-600">PDF</span>
|
|
67
|
+
}
|
|
68
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'other') {
|
|
69
|
+
<span class="libs-ui-font-h6r text-gray-500">Khác</span>
|
|
70
|
+
}
|
|
71
|
+
`,
|
|
72
|
+
})
|
|
73
|
+
export class FileTypeLabelComponent {
|
|
74
|
+
protected file: IFile = { name: 'report.pdf', mimetype: 'application/pdf' };
|
|
75
|
+
}
|
|
53
76
|
```
|
|
54
77
|
|
|
55
|
-
### 2.
|
|
78
|
+
### 2. Render danh sách file với icon theo loại
|
|
56
79
|
|
|
57
|
-
```
|
|
58
|
-
{
|
|
80
|
+
```typescript
|
|
81
|
+
import { Component } from '@angular/core';
|
|
82
|
+
import { LibsUiPipesCheckFileExtensionPipe } from '@libs-ui/pipes-check-file-extension';
|
|
83
|
+
import { IFile } from '@libs-ui/interfaces-types';
|
|
84
|
+
|
|
85
|
+
@Component({
|
|
86
|
+
standalone: true,
|
|
87
|
+
imports: [LibsUiPipesCheckFileExtensionPipe],
|
|
88
|
+
template: `
|
|
89
|
+
@for (file of attachments; track file.id) {
|
|
90
|
+
<div class="flex items-center gap-2 p-2 border border-gray-200 rounded mb-1">
|
|
91
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'image') {
|
|
92
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-green-500">
|
|
93
|
+
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
94
|
+
</svg>
|
|
95
|
+
}
|
|
96
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'video') {
|
|
97
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-blue-500">
|
|
98
|
+
<path d="M17 10.5V7c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4z"/>
|
|
99
|
+
</svg>
|
|
100
|
+
}
|
|
101
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'word') {
|
|
102
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-indigo-500">
|
|
103
|
+
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/>
|
|
104
|
+
</svg>
|
|
105
|
+
}
|
|
106
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'pdf') {
|
|
107
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-red-500">
|
|
108
|
+
<path d="M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-8.5 7.5c0 .83-.67 1.5-1.5 1.5H9v2H7.5V7H10c.83 0 1.5.67 1.5 1.5v1zm5 2c0 .83-.67 1.5-1.5 1.5h-2.5V7H15c.83 0 1.5.67 1.5 1.5v3zm4-3H19v1h1.5V11H19v2h-1.5V7h3v1.5zM9 9.5h1v-1H9v1zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm10 5.5h1v-3h-1v3z"/>
|
|
109
|
+
</svg>
|
|
110
|
+
}
|
|
111
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'xlsx') {
|
|
112
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-green-700">
|
|
113
|
+
<path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z"/>
|
|
114
|
+
</svg>
|
|
115
|
+
}
|
|
116
|
+
@if (file | LibsUiPipesCheckFileExtensionPipe : 'other') {
|
|
117
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-gray-400">
|
|
118
|
+
<path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/>
|
|
119
|
+
</svg>
|
|
120
|
+
}
|
|
121
|
+
<span class="libs-ui-font-h6r text-gray-700">{{ file.name }}</span>
|
|
122
|
+
</div>
|
|
123
|
+
}
|
|
124
|
+
`,
|
|
125
|
+
})
|
|
126
|
+
export class FileListComponent {
|
|
127
|
+
protected attachments: IFile[] = [
|
|
128
|
+
{ id: '1', name: 'avatar.jpg' },
|
|
129
|
+
{ id: '2', name: 'demo.mp4' },
|
|
130
|
+
{ id: '3', name: 'report.docx' },
|
|
131
|
+
{ id: '4', name: 'budget.xlsx' },
|
|
132
|
+
{ id: '5', name: 'spec.pdf' },
|
|
133
|
+
{ id: '6', name: 'slides.pptx' },
|
|
134
|
+
{ id: '7', name: 'readme.txt' },
|
|
135
|
+
];
|
|
136
|
+
}
|
|
59
137
|
```
|
|
60
138
|
|
|
139
|
+
### 3. Dùng standalone (pipe.transform) trong TypeScript
|
|
140
|
+
|
|
61
141
|
```typescript
|
|
62
|
-
|
|
63
|
-
|
|
142
|
+
import { LibsUiPipesCheckFileExtensionPipe } from '@libs-ui/pipes-check-file-extension';
|
|
143
|
+
import { IFile } from '@libs-ui/interfaces-types';
|
|
64
144
|
|
|
65
|
-
|
|
145
|
+
const pipe = new LibsUiPipesCheckFileExtensionPipe();
|
|
66
146
|
|
|
67
|
-
|
|
68
|
-
{{ fileDoc | LibsUiPipesCheckFileExtensionPipe : 'image' }}
|
|
69
|
-
```
|
|
147
|
+
const file: IFile = { name: 'photo.jpg' };
|
|
70
148
|
|
|
71
|
-
|
|
72
|
-
|
|
149
|
+
console.log(pipe.transform(file, 'image')); // true
|
|
150
|
+
console.log(pipe.transform(file, 'video')); // false
|
|
151
|
+
console.log(pipe.transform(file, 'other')); // false
|
|
152
|
+
|
|
153
|
+
const unknown: IFile = { name: 'archive.zip' };
|
|
154
|
+
console.log(pipe.transform(unknown, 'other')); // true
|
|
73
155
|
```
|
|
74
156
|
|
|
75
|
-
### 4.
|
|
157
|
+
### 4. Kết hợp với MIME type
|
|
76
158
|
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
159
|
+
```typescript
|
|
160
|
+
import { Component } from '@angular/core';
|
|
161
|
+
import { LibsUiPipesCheckFileExtensionPipe } from '@libs-ui/pipes-check-file-extension';
|
|
162
|
+
import { IFile } from '@libs-ui/interfaces-types';
|
|
163
|
+
|
|
164
|
+
@Component({
|
|
165
|
+
standalone: true,
|
|
166
|
+
imports: [LibsUiPipesCheckFileExtensionPipe],
|
|
167
|
+
template: `
|
|
168
|
+
@if (uploadedFile | LibsUiPipesCheckFileExtensionPipe : 'image') {
|
|
169
|
+
<img [src]="uploadedFile.url" alt="preview" class="w-32 h-32 object-cover rounded" />
|
|
85
170
|
}
|
|
86
|
-
@if (
|
|
87
|
-
<
|
|
171
|
+
@if (uploadedFile | LibsUiPipesCheckFileExtensionPipe : 'pdf') {
|
|
172
|
+
<div class="p-4 bg-red-50 rounded libs-ui-font-h6r text-red-600">
|
|
173
|
+
Tài liệu PDF — {{ uploadedFile.name }}
|
|
174
|
+
</div>
|
|
88
175
|
}
|
|
89
|
-
|
|
90
|
-
|
|
176
|
+
`,
|
|
177
|
+
})
|
|
178
|
+
export class UploadPreviewComponent {
|
|
179
|
+
// MIME type đầy đủ cũng được nhận diện
|
|
180
|
+
protected uploadedFile: IFile = {
|
|
181
|
+
name: 'contract.pdf',
|
|
182
|
+
mimetype: 'application/pdf',
|
|
183
|
+
url: 'https://example.com/files/contract.pdf',
|
|
184
|
+
};
|
|
91
185
|
}
|
|
92
186
|
```
|
|
93
187
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
188
|
+
## Transform (Pipe API)
|
|
189
|
+
|
|
190
|
+
| Tham số | Type | Bắt buộc | Mô tả | Ví dụ |
|
|
191
|
+
|---|---|---|---|---|
|
|
192
|
+
| `file` | `IFile` | Có | Đối tượng file cần kiểm tra. Pipe ưu tiên `mimetype` → `file.type` → extract từ `name`/`url` | `{ name: 'photo.jpg' }` |
|
|
193
|
+
| `type` | `'image' \| 'video' \| 'word' \| 'xlsx' \| 'pdf' \| 'pptx' \| 'other'` | Có | Nhóm định dạng muốn kiểm tra | `'image'` |
|
|
194
|
+
|
|
195
|
+
**Trả về:** `boolean` — `true` nếu file thuộc nhóm, `false` nếu không (kể cả khi không tìm được extension).
|
|
196
|
+
|
|
197
|
+
### Ví dụ template
|
|
198
|
+
|
|
199
|
+
```html
|
|
200
|
+
{{ file | LibsUiPipesCheckFileExtensionPipe : 'image' }}
|
|
100
201
|
```
|
|
101
202
|
|
|
102
|
-
|
|
203
|
+
### Ví dụ standalone
|
|
103
204
|
|
|
104
|
-
|
|
205
|
+
```typescript
|
|
206
|
+
const pipe = new LibsUiPipesCheckFileExtensionPipe();
|
|
207
|
+
pipe.transform({ name: 'photo.jpg' }, 'image'); // true
|
|
208
|
+
pipe.transform({ name: 'photo.jpg' }, 'video'); // false
|
|
209
|
+
```
|
|
105
210
|
|
|
106
|
-
|
|
211
|
+
## Danh sách extension hỗ trợ
|
|
107
212
|
|
|
108
|
-
|
|
|
109
|
-
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
213
|
+
| Nhóm | Extension / MIME type được nhận diện |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `image` | `gif`, `jpg`, `jpeg`, `png`, `webp`, `image/gif`, `image/jpeg`, `image/png` |
|
|
216
|
+
| `video` | `mp4`, `mov`, `mpg`, `avi`, `wmv`, `video/mp4`, `video/quicktime`, `video/mpeg`, `video/x-msvideo`, `video/x-ms-wmv` |
|
|
217
|
+
| `word` | `doc`, `docx`, `application/msword`, `application/vnd.openxmlformats-officedocument.wordprocessingml.document` |
|
|
218
|
+
| `xlsx` | `xls`, `xlsx`, `gsheet`, `application/vnd.ms-excel`, `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` |
|
|
219
|
+
| `pdf` | `pdf`, `application/pdf` |
|
|
220
|
+
| `pptx` | `ppt`, `pptx`, `application/vnd.ms-powerpoint`, `application/vnd.openxmlformats-officedocument.presentationml.presentation` |
|
|
221
|
+
| `other` | Bất kỳ extension nào **không** thuộc image, video, doc, xls, ppt, pdf, json, xml và các MIME type tương ứng |
|
|
112
222
|
|
|
113
223
|
## Types & Interfaces
|
|
114
224
|
|
|
115
|
-
### IFile
|
|
116
|
-
|
|
117
225
|
```typescript
|
|
226
|
+
import { IFile } from '@libs-ui/interfaces-types';
|
|
227
|
+
|
|
118
228
|
export interface IFile {
|
|
119
229
|
id?: string;
|
|
120
|
-
name?: string;
|
|
121
|
-
file?: File;
|
|
230
|
+
name?: string; // Tên file — pipe sẽ extract extension từ đây
|
|
231
|
+
file?: File; // Đối tượng File của browser — pipe đọc file.type
|
|
122
232
|
size?: string;
|
|
123
233
|
isUploading?: boolean;
|
|
124
234
|
percentUploading?: number;
|
|
125
235
|
isUpdate?: boolean;
|
|
126
|
-
url?: string;
|
|
127
|
-
origin_url?: string;
|
|
128
|
-
mimetype?: string;
|
|
236
|
+
url?: string; // Fallback khi không có name
|
|
237
|
+
origin_url?: string; // Fallback khi không có name và url
|
|
238
|
+
mimetype?: string; // Ưu tiên cao nhất khi extract extension
|
|
129
239
|
type?: TYPE_FILE;
|
|
130
240
|
error?: string;
|
|
131
241
|
isAvatar?: boolean;
|
|
@@ -134,30 +244,35 @@ export interface IFile {
|
|
|
134
244
|
export type TYPE_FILE = 'document' | 'image' | 'video' | 'audio';
|
|
135
245
|
```
|
|
136
246
|
|
|
137
|
-
**
|
|
247
|
+
**Thứ tự ưu tiên khi extract extension:**
|
|
248
|
+
1. `file.type` (nếu là đối tượng `File` gốc của browser)
|
|
249
|
+
2. `mimetype` của `IFile`
|
|
250
|
+
3. `file.file?.type` (nếu có File đính kèm)
|
|
251
|
+
4. Extension từ `name`
|
|
252
|
+
5. Extension từ `url` hoặc `origin_url`
|
|
138
253
|
|
|
139
|
-
## Lưu ý quan trọng
|
|
254
|
+
## Lưu ý quan trọng
|
|
140
255
|
|
|
141
|
-
|
|
142
|
-
>
|
|
143
|
-
> - **Yêu cầu đối tượng File**: Pipe này yêu cầu input là một object có ít nhất một trong các thuộc tính: `name`, `mimetype`, hoặc `type` (từ `file.type` nếu là File object). Pipe sẽ tự động extract extension từ `name` hoặc sử dụng trực tiếp `mimetype`/`type`. Nếu không tìm thấy, pipe sẽ trả về `false`.
|
|
144
|
-
> - **Hỗ trợ MIME Type**: Đối với các loại văn bản (word, xlsx, pdf...), pipe hỗ trợ kiểm tra cả extension rút gọn (ví dụ: `pdf`) và MIME type đầy đủ (ví dụ: `application/pdf`).
|
|
145
|
-
> - **Phân loại "Other"**: Loại `other` sẽ trả về `true` cho bất kỳ định dạng nào **KHÔNG** nằm trong danh sách mặc định của Image, Video và Documents phổ biến.
|
|
146
|
-
> - **Hiệu năng**: Pipe này là pure logic, có thể sử dụng an toàn trong các danh sách dài mà không gây ảnh hưởng hiệu năng đáng kể.
|
|
256
|
+
⚠️ **Extension không tìm được**: Nếu `IFile` không có `name`, `mimetype`, `url` hoặc đối tượng file browser, pipe trả về `false` cho mọi nhóm.
|
|
147
257
|
|
|
148
|
-
|
|
258
|
+
⚠️ **Case-insensitive**: Pipe tự động chuyển extension về chữ thường trước khi so sánh, vì vậy `JPG`, `jpg`, `Jpg` đều cho kết quả như nhau.
|
|
149
259
|
|
|
150
|
-
|
|
151
|
-
- TypeScript 5+
|
|
260
|
+
⚠️ **Nhóm `other`**: Trả về `true` cho các file không thuộc bất kỳ nhóm nào trong danh sách mặc định (bao gồm cả `json`, `xml`, `audio`). Dùng nhóm này để bắt các định dạng không xác định thay vì dùng `@else`.
|
|
152
261
|
|
|
153
|
-
|
|
262
|
+
⚠️ **MIME type**: Với file upload từ browser qua `<input type="file">`, đối tượng `File` gốc có thuộc tính `type` là MIME type đầy đủ. `IFile` hỗ trợ trường `file: File`, pipe sẽ ưu tiên đọc `file.type` nếu có.
|
|
154
263
|
|
|
155
|
-
|
|
264
|
+
⚠️ **`gsheet`**: Extension `gsheet` (Google Sheet) được nhận diện thuộc nhóm `xlsx`.
|
|
156
265
|
|
|
157
|
-
##
|
|
266
|
+
## Demo
|
|
158
267
|
|
|
159
|
-
|
|
268
|
+
```bash
|
|
269
|
+
npx nx serve core-ui
|
|
270
|
+
```
|
|
160
271
|
|
|
161
|
-
|
|
272
|
+
Truy cập: http://localhost:4500/pipes/check-file-extension
|
|
162
273
|
|
|
163
|
-
|
|
274
|
+
## Unit Tests
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
npx nx test libs-ui-pipes-check-file-extension --testFile=libs-ui/pipes/check-file-extension/src/check-file-extension.pipe.spec.ts
|
|
278
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libs-ui-pipes-check-file-extension.mjs","sources":["../../../../../libs-ui/pipes/check-file-extension/src/check-file-extension.pipe.ts","../../../../../libs-ui/pipes/check-file-extension/src/libs-ui-pipes-check-file-extension.ts"],"sourcesContent":["import { Pipe, PipeTransform } from '@angular/core';\nimport { IFile } from '@libs-ui/interfaces-types';\nimport { DocumentExtList, getFileExtension, ImageExtList, VideoExtList } from '@libs-ui/utils';\n\n@Pipe({\n name: 'LibsUiPipesCheckFileExtensionPipe',\n standalone: true,\n})\nexport class LibsUiPipesCheckFileExtensionPipe implements PipeTransform {\n transform(file: IFile, type: 'image' | 'video' | 'word' | 'xlsx' | 'pdf' | 'pptx' | 'other') {\n const fileExtension = getFileExtension(file);\n\n if (!fileExtension) {\n return false;\n }\n switch (type) {\n case 'image':\n return ImageExtList.includes(fileExtension);\n\n case 'video':\n return VideoExtList.includes(fileExtension);\n\n case 'word':\n return ['doc', 'docx', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'].includes(fileExtension);\n\n case 'xlsx':\n return ['xls', 'xlsx', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'gsheet'].includes(fileExtension);\n\n case 'pdf':\n return ['pdf', 'application/pdf'].includes(fileExtension);\n\n case 'pptx':\n return ['ppt', 'pptx', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'].includes(fileExtension);\n\n case 'other':\n return ![...ImageExtList, ...VideoExtList, ...DocumentExtList].includes(fileExtension);\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAQa,iCAAiC,CAAA;IAC5C,SAAS,CAAC,IAAW,EAAE,IAAoE,EAAA;AACzF,QAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"libs-ui-pipes-check-file-extension.mjs","sources":["../../../../../libs-ui/pipes/check-file-extension/src/check-file-extension.pipe.ts","../../../../../libs-ui/pipes/check-file-extension/src/libs-ui-pipes-check-file-extension.ts"],"sourcesContent":["import { Pipe, PipeTransform } from '@angular/core';\nimport { IFile } from '@libs-ui/interfaces-types';\nimport { DocumentExtList, getFileExtension, ImageExtList, VideoExtList } from '@libs-ui/utils';\n\n@Pipe({\n name: 'LibsUiPipesCheckFileExtensionPipe',\n standalone: true,\n})\nexport class LibsUiPipesCheckFileExtensionPipe implements PipeTransform {\n transform(file: IFile, type: 'image' | 'video' | 'word' | 'xlsx' | 'pdf' | 'pptx' | 'other') {\n const fileExtension = getFileExtension(file);\n\n if (!fileExtension) {\n return false;\n }\n switch (type) {\n case 'image':\n return ImageExtList.includes(fileExtension);\n\n case 'video':\n return VideoExtList.includes(fileExtension);\n\n case 'word':\n return ['doc', 'docx', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'].includes(fileExtension);\n\n case 'xlsx':\n return ['xls', 'xlsx', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'gsheet'].includes(fileExtension);\n\n case 'pdf':\n return ['pdf', 'application/pdf'].includes(fileExtension);\n\n case 'pptx':\n return ['ppt', 'pptx', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'].includes(fileExtension);\n\n case 'other':\n return ![...ImageExtList, ...VideoExtList, ...DocumentExtList].includes(fileExtension);\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAQa,iCAAiC,CAAA;IAC5C,SAAS,CAAC,IAAW,EAAE,IAAoE,EAAA;AACzF,QAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7C,IAAI,CAAC,aAAa,EAAE;AAClB,YAAA,OAAO,KAAK,CAAC;SACd;QACD,QAAQ,IAAI;AACV,YAAA,KAAK,OAAO;AACV,gBAAA,OAAO,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAE9C,YAAA,KAAK,OAAO;AACV,gBAAA,OAAO,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAE9C,YAAA,KAAK,MAAM;AACT,gBAAA,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,yEAAyE,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAElJ,YAAA,KAAK,MAAM;AACT,gBAAA,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,0BAA0B,EAAE,mEAAmE,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAE5J,YAAA,KAAK,KAAK;gBACR,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAE5D,YAAA,KAAK,MAAM;AACT,gBAAA,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,+BAA+B,EAAE,2EAA2E,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAE/J,YAAA,KAAK,OAAO;AACV,gBAAA,OAAO,CAAC,CAAC,GAAG,YAAY,EAAE,GAAG,YAAY,EAAE,GAAG,eAAe,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;SAC1F;KACF;wGA7BU,iCAAiC,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA,CAAA;sGAAjC,iCAAiC,EAAA,YAAA,EAAA,IAAA,EAAA,IAAA,EAAA,mCAAA,EAAA,CAAA,CAAA;;4FAAjC,iCAAiC,EAAA,UAAA,EAAA,CAAA;kBAJ7C,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA;AACJ,oBAAA,IAAI,EAAE,mCAAmC;AACzC,oBAAA,UAAU,EAAE,IAAI;AACjB,iBAAA,CAAA;;;ACPD;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libs-ui/pipes-check-file-extension",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.357-0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@angular/core": ">=18.0.0"
|
|
5
|
+
"@angular/core": ">=18.0.0",
|
|
6
|
+
"@libs-ui/interfaces-types": "0.2.357-0",
|
|
7
|
+
"@libs-ui/utils": "0.2.357-0"
|
|
6
8
|
},
|
|
7
9
|
"sideEffects": false,
|
|
8
10
|
"module": "fesm2022/libs-ui-pipes-check-file-extension.mjs",
|