@haloduck/util 2.0.1 → 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/fesm2022/haloduck-util.mjs +71 -0
- package/fesm2022/haloduck-util.mjs.map +1 -0
- package/index.d.ts +24 -0
- package/package.json +8 -10
- package/haloduck-util-1.0.0.tgz +0 -0
|
@@ -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,SA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AAG,EAAE,gBAAgB;AACrB,QAAA,OAAO,EAAE,oBAAoB;KAC9B,CAAC;AACH,CAAA;AAGG,SAAU,0BAA0B,CACxC,OAA+B,EAAA;IAE/B,OAAO;AACL,QAAA,OAAO,EAAE,aAAa;AACtB,QAAA,QAAQ,EAAE,OAAO;KAClB;AACH;MAKa,WAAW,CAAA;;AAEtB,IAAA,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC;AAE/B,IAAA,cAAc,CAAC,QAAgB,EAAA;AAC7B,QAAA,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE;AAC1D,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;;uGANtD,WAAW,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAX,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,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,16 +30,14 @@
|
|
|
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
42
|
"@angular/common": "^20.0.0",
|
|
45
43
|
"@angular/core": "^20.0.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
|