@haloduck/util 2.0.0 → 2.0.2
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 +19 -93
- package/fesm2022/haloduck-util.mjs +71 -0
- package/fesm2022/haloduck-util.mjs.map +1 -0
- package/index.d.ts +24 -0
- package/package.json +11 -13
- package/haloduck-util-1.0.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
# @haloduck/util
|
|
2
2
|
|
|
3
|
-
HaloDuck Util Library
|
|
3
|
+
HaloDuck Util Library is a utility functions and services library for Angular-based applications.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @haloduck/util
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Key Features
|
|
12
12
|
|
|
13
|
-
###
|
|
14
|
-
- **download**:
|
|
13
|
+
### File Utilities
|
|
14
|
+
- **download**: File download function
|
|
15
15
|
|
|
16
|
-
###
|
|
17
|
-
- **hasRequired**:
|
|
18
|
-
- **hasError**:
|
|
19
|
-
- **getDirtyValues**:
|
|
20
|
-
- **englishAndNumberOnlyValidator**:
|
|
16
|
+
### Form Utilities
|
|
17
|
+
- **hasRequired**: Check required field validation
|
|
18
|
+
- **hasError**: Check form error status
|
|
19
|
+
- **getDirtyValues**: Extract only changed form values
|
|
20
|
+
- **englishAndNumberOnlyValidator**: Validator that allows only English and numbers
|
|
21
21
|
|
|
22
|
-
###
|
|
23
|
-
- **UtilService**:
|
|
24
|
-
- **provideHaloduckUtilIconSet**:
|
|
22
|
+
### Services
|
|
23
|
+
- **UtilService**: File icon URL provider service
|
|
24
|
+
- **provideHaloduckUtilIconSet**: File icon configuration provider
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Usage
|
|
27
27
|
|
|
28
|
-
###
|
|
28
|
+
### Basic Configuration
|
|
29
29
|
|
|
30
30
|
```typescript
|
|
31
31
|
export const appConfig: ApplicationConfig = {
|
|
@@ -41,89 +41,15 @@ export const appConfig: ApplicationConfig = {
|
|
|
41
41
|
};
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { download } from '@haloduck/util';
|
|
48
|
-
|
|
49
|
-
// 파일 다운로드
|
|
50
|
-
download('https://example.com/file.pdf');
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### 폼 유틸리티 사용
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
import {
|
|
57
|
-
hasRequired,
|
|
58
|
-
hasError,
|
|
59
|
-
getDirtyValues,
|
|
60
|
-
englishAndNumberOnlyValidator
|
|
61
|
-
} from '@haloduck/util';
|
|
62
|
-
|
|
63
|
-
@Component({...})
|
|
64
|
-
export class MyComponent {
|
|
65
|
-
form = new FormGroup({
|
|
66
|
-
name: new FormControl('', [englishAndNumberOnlyValidator]),
|
|
67
|
-
email: new FormControl('', [Validators.required, Validators.email])
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
checkField() {
|
|
71
|
-
const nameControl = this.form.get('name');
|
|
72
|
-
|
|
73
|
-
// 필수 필드인지 확인
|
|
74
|
-
console.log(hasRequired(nameControl));
|
|
75
|
-
|
|
76
|
-
// 에러가 있는지 확인
|
|
77
|
-
console.log(hasError(nameControl, 'pattern'));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
submitForm() {
|
|
81
|
-
// 변경된 값만 추출
|
|
82
|
-
const dirtyValues = getDirtyValues(this.form);
|
|
83
|
-
console.log(dirtyValues);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### 파일 아이콘 서비스
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
import {
|
|
92
|
-
UtilService,
|
|
93
|
-
provideHaloduckUtilIconSet
|
|
94
|
-
} from '@haloduck/util';
|
|
95
|
-
|
|
96
|
-
// 앱 설정에서 아이콘 설정 제공
|
|
97
|
-
export const appConfig: ApplicationConfig = {
|
|
98
|
-
providers: [
|
|
99
|
-
provideHaloduckUtilIconSet({
|
|
100
|
-
default: '/app/images/default-file-preview.svg',
|
|
101
|
-
stl: '/app/images/default-stl-preview.svg',
|
|
102
|
-
pdf: '/app/images/default-pdf-preview.svg',
|
|
103
|
-
}),
|
|
104
|
-
],
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// 컴포넌트에서 사용
|
|
108
|
-
@Component({...})
|
|
109
|
-
export class FileComponent {
|
|
110
|
-
constructor(private utilService: UtilService) {}
|
|
111
|
-
|
|
112
|
-
getFileIcon(filename: string) {
|
|
113
|
-
return this.utilService.getFileIconUrl(filename);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
## 의존성
|
|
44
|
+
## Dependencies
|
|
119
45
|
|
|
120
46
|
- Angular 19.2.0+
|
|
121
47
|
- Angular Forms 19.2.0+
|
|
122
48
|
|
|
123
|
-
##
|
|
49
|
+
## License
|
|
124
50
|
|
|
125
51
|
MIT License
|
|
126
52
|
|
|
127
|
-
##
|
|
53
|
+
## Support
|
|
128
54
|
|
|
129
|
-
|
|
55
|
+
If you have any issues or questions, please register
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Validators } from '@angular/forms';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { InjectionToken, inject, Injectable } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
function download(href) {
|
|
6
|
+
const link = document.createElement('a');
|
|
7
|
+
link.href = href;
|
|
8
|
+
link.target = '_blank';
|
|
9
|
+
document.body.appendChild(link);
|
|
10
|
+
link.click();
|
|
11
|
+
document.body.removeChild(link);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function hasRequired(control) {
|
|
15
|
+
return control?.hasValidator(Validators.required);
|
|
16
|
+
}
|
|
17
|
+
function hasError(control, errorType) {
|
|
18
|
+
return control?.touched && (control?.hasError(errorType) ?? false);
|
|
19
|
+
}
|
|
20
|
+
function getDirtyValues(fg) {
|
|
21
|
+
const dirtyValues = Object.keys(fg.controls)
|
|
22
|
+
.filter((key) => fg.controls[key].dirty)
|
|
23
|
+
.reduce((acc, key) => {
|
|
24
|
+
acc[key] = fg.controls[key].value;
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
27
|
+
return dirtyValues;
|
|
28
|
+
}
|
|
29
|
+
const englishAndNumberOnlyValidator = Validators.pattern(/^[0-9A-Za-z\s]*$/);
|
|
30
|
+
|
|
31
|
+
const FILE_ICON_SET = new InjectionToken('FILE_ICON_SET', {
|
|
32
|
+
providedIn: 'root',
|
|
33
|
+
factory: () => ({
|
|
34
|
+
pdf: 'assets/pdf.svg',
|
|
35
|
+
stl: 'assets/stl.svg',
|
|
36
|
+
default: 'assets/default.svg',
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
function provideHaloduckUtilIconSet(iconSet) {
|
|
40
|
+
return {
|
|
41
|
+
provide: FILE_ICON_SET,
|
|
42
|
+
useValue: iconSet,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
class UtilService {
|
|
46
|
+
// private readonly environmentInjector = inject(EnvironmentInjector);
|
|
47
|
+
iconSet = inject(FILE_ICON_SET);
|
|
48
|
+
getFileIconUrl(filename) {
|
|
49
|
+
const extension = filename.split('.').pop()?.toLowerCase();
|
|
50
|
+
return this.iconSet[extension || ''] || this.iconSet['default'];
|
|
51
|
+
}
|
|
52
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: UtilService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
53
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: UtilService, providedIn: 'root' });
|
|
54
|
+
}
|
|
55
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: UtilService, decorators: [{
|
|
56
|
+
type: Injectable,
|
|
57
|
+
args: [{
|
|
58
|
+
providedIn: 'root',
|
|
59
|
+
}]
|
|
60
|
+
}] });
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* Public API Surface of util
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Generated bundle index. Do not edit.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
export { FILE_ICON_SET, UtilService, download, englishAndNumberOnlyValidator, getDirtyValues, hasError, hasRequired, provideHaloduckUtilIconSet };
|
|
71
|
+
//# sourceMappingURL=haloduck-util.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"haloduck-util.mjs","sources":["../../../../projects/haloduck/util/src/lib/util.file.ts","../../../../projects/haloduck/util/src/lib/util.form.ts","../../../../projects/haloduck/util/src/lib/util.service.ts","../../../../projects/haloduck/util/src/public-api.ts","../../../../projects/haloduck/util/src/haloduck-util.ts"],"sourcesContent":["\nexport function download(href: string) {\n const link = document.createElement('a');\n link.href = href;\n link.target = '_blank';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n}\n","import { AbstractControl, Validators, FormGroup } from '@angular/forms';\n\nexport function hasRequired(control: AbstractControl<any, any> | null) {\n return control?.hasValidator(Validators.required);\n}\n\nexport function hasError(\n control: AbstractControl<any, any> | null,\n errorType: string\n): boolean | undefined {\n return control?.touched && (control?.hasError(errorType) ?? false);\n}\n\nexport function getDirtyValues(fg: FormGroup) {\n const dirtyValues = Object.keys(fg.controls)\n .filter((key) => fg.controls[key].dirty)\n .reduce((acc: { [key: string]: any }, key) => {\n acc[key] = fg.controls[key].value;\n return acc;\n }, {});\n\n return dirtyValues;\n}\n\nexport const englishAndNumberOnlyValidator =\n Validators.pattern(/^[0-9A-Za-z\\s]*$/);\n","import {\n Injectable,\n inject,\n InjectionToken,\n Provider,\n EnvironmentInjector,\n} from '@angular/core';\n\nexport const FILE_ICON_SET = new InjectionToken<Record<string, string>>(\n 'FILE_ICON_SET',\n {\n providedIn: 'root',\n factory: () => ({\n pdf: 'assets/pdf.svg',\n stl: 'assets/stl.svg',\n default: 'assets/default.svg',\n }),\n },\n);\n\nexport function provideHaloduckUtilIconSet(\n iconSet: Record<string, string>,\n): Provider {\n return {\n provide: FILE_ICON_SET,\n useValue: iconSet,\n };\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class UtilService {\n // private readonly environmentInjector = inject(EnvironmentInjector);\n iconSet = inject(FILE_ICON_SET);\n\n getFileIconUrl(filename: string): string {\n const extension = filename.split('.').pop()?.toLowerCase();\n return this.iconSet[extension || ''] || this.iconSet['default'];\n }\n}\n","/*\n * Public API Surface of util\n */\n\nexport * from './lib';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AACM,SAAU,QAAQ,CAAC,IAAY,EAAA;IACnC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC;AACxC,IAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,IAAA,IAAI,CAAC,MAAM,GAAG,QAAQ;AACtB,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,IAAI,CAAC,KAAK,EAAE;AACZ,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;AACjC;;ACNM,SAAU,WAAW,CAAC,OAAyC,EAAA;IACnE,OAAO,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC;AACnD;AAEM,SAAU,QAAQ,CACtB,OAAyC,EACzC,SAAiB,EAAA;AAEjB,IAAA,OAAO,OAAO,EAAE,OAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC;AACpE;AAEM,SAAU,cAAc,CAAC,EAAa,EAAA;IAC1C,MAAM,WAAW,GAAG,M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,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAW,cAFV,MAAM,EAAA,CAAA;;2FAEP,WAAW,EAAA,UAAA,EAAA,CAAA;kBAHvB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;AC/BD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as _angular_forms from '@angular/forms';
|
|
2
|
+
import { AbstractControl, FormGroup } from '@angular/forms';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { InjectionToken, Provider } from '@angular/core';
|
|
5
|
+
|
|
6
|
+
declare function download(href: string): void;
|
|
7
|
+
|
|
8
|
+
declare function hasRequired(control: AbstractControl<any, any> | null): boolean | undefined;
|
|
9
|
+
declare function hasError(control: AbstractControl<any, any> | null, errorType: string): boolean | undefined;
|
|
10
|
+
declare function getDirtyValues(fg: FormGroup): {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
declare const englishAndNumberOnlyValidator: _angular_forms.ValidatorFn;
|
|
14
|
+
|
|
15
|
+
declare const FILE_ICON_SET: InjectionToken<Record<string, string>>;
|
|
16
|
+
declare function provideHaloduckUtilIconSet(iconSet: Record<string, string>): Provider;
|
|
17
|
+
declare class UtilService {
|
|
18
|
+
iconSet: Record<string, string>;
|
|
19
|
+
getFileIconUrl(filename: string): string;
|
|
20
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<UtilService, never>;
|
|
21
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<UtilService>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { FILE_ICON_SET, UtilService, download, englishAndNumberOnlyValidator, getDirtyValues, hasError, hasRequired, provideHaloduckUtilIconSet };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haloduck/util",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "HaloDuck Util Library - Angular",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -30,20 +30,18 @@
|
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
32
|
"import": "./fesm2022/haloduck-util.mjs",
|
|
33
|
-
"require": "./bundles/haloduck-util.umd.js"
|
|
33
|
+
"require": "./bundles/haloduck-util.umd.js",
|
|
34
|
+
"types": "./index.d.ts",
|
|
35
|
+
"default": "./fesm2022/haloduck-util.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": {
|
|
38
|
+
"default": "./package.json"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build": "ng build @haloduck/util",
|
|
38
|
-
"build:prod": "ng build @haloduck/util --configuration production",
|
|
39
|
-
"test": "ng test @haloduck/util",
|
|
40
|
-
"lint": "ng lint @haloduck/util",
|
|
41
|
-
"prepublishOnly": "npm run build:prod"
|
|
42
|
-
},
|
|
43
41
|
"peerDependencies": {
|
|
44
|
-
"@angular/common": "^
|
|
45
|
-
"@angular/core": "^
|
|
46
|
-
"@angular/forms": "^
|
|
42
|
+
"@angular/common": "^20.0.0",
|
|
43
|
+
"@angular/core": "^20.0.0",
|
|
44
|
+
"@angular/forms": "^20.0.0"
|
|
47
45
|
},
|
|
48
46
|
"dependencies": {
|
|
49
47
|
"tslib": "^2.3.0"
|
|
@@ -52,4 +50,4 @@
|
|
|
52
50
|
"publishConfig": {
|
|
53
51
|
"access": "public"
|
|
54
52
|
}
|
|
55
|
-
}
|
|
53
|
+
}
|
package/haloduck-util-1.0.0.tgz
DELETED
|
Binary file
|