@mosa-ng/core 17.0.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/.eslintrc.json +31 -0
- package/README.md +24 -0
- package/ng-package.json +10 -0
- package/package.json +12 -0
- package/src/assets/i18n/mosa-de-DE.json +60 -0
- package/src/assets/i18n/mosa-en-US.json +60 -0
- package/src/lib/constants/local-storage.constant.ts +4 -0
- package/src/lib/enums/browser.enum.ts +9 -0
- package/src/lib/enums/content-position.enum.ts +11 -0
- package/src/lib/enums/i18n-supported.enum.ts +10 -0
- package/src/lib/enums/theme.enum.ts +4 -0
- package/src/lib/models/api-options.model.ts +21 -0
- package/src/lib/models/dictionary-item.model.ts +8 -0
- package/src/lib/models/key-map.model.ts +3 -0
- package/src/lib/models/logger/log-event.model.ts +8 -0
- package/src/lib/models/logger/log-message-data.model.ts +5 -0
- package/src/lib/models/logger/log-type.model.ts +1 -0
- package/src/lib/models/logger/log.model.ts +10 -0
- package/src/lib/models/logger/logger-base-config.model.ts +8 -0
- package/src/lib/models/logger/logger-config.model.ts +9 -0
- package/src/lib/models/logger/logger-default-config.model.ts +5 -0
- package/src/lib/models/mosa-duration.model.ts +1 -0
- package/src/lib/models/sieve/sieve-filter.model.ts +10 -0
- package/src/lib/models/sieve/sieve-operator.model.ts +69 -0
- package/src/lib/models/sieve/sieve-options.model.ts +13 -0
- package/src/lib/models/sieve/sieve-response.model.ts +4 -0
- package/src/lib/models/sieve/sieve-sort.model.ts +7 -0
- package/src/lib/models/token-settings.model.ts +5 -0
- package/src/lib/models/transform-matrix.model.ts +5 -0
- package/src/lib/mosa-core.module.ts +117 -0
- package/src/lib/pipes/dictionary-item-pipe/dictionary-item-pipe.module.ts +15 -0
- package/src/lib/pipes/dictionary-item-pipe/dictionary-item.pipe.ts +14 -0
- package/src/lib/pipes/find-in-array/find-in-array-pipe.module.ts +17 -0
- package/src/lib/pipes/find-in-array/find-in-array.pipe.spec.ts +8 -0
- package/src/lib/pipes/find-in-array/find-in-array.pipe.ts +34 -0
- package/src/lib/pipes/join/join-pipe.module.ts +17 -0
- package/src/lib/pipes/join/join.pipe.spec.ts +8 -0
- package/src/lib/pipes/join/join.pipe.ts +20 -0
- package/src/lib/pipes/mosa-date-pipe/mosa-date-pipe.module.ts +14 -0
- package/src/lib/pipes/mosa-date-pipe/mosa-date.pipe.ts +102 -0
- package/src/lib/pipes/mosa-duration-pipe/mosa-duration-pipe.module.ts +13 -0
- package/src/lib/pipes/mosa-duration-pipe/mosa-duration.pipe.ts +106 -0
- package/src/lib/services/api.service.ts +270 -0
- package/src/lib/services/core-logger.service.ts +219 -0
- package/src/lib/services/guards/can-deactivate.guard.ts +18 -0
- package/src/lib/services/mosa-socket.service.ts +46 -0
- package/src/lib/services/translation/assets-i18n-loader.service.ts +67 -0
- package/src/lib/services/translation/custom-translate-loader.service.ts +27 -0
- package/src/lib/services/translation/translate-collector.service.ts +60 -0
- package/src/lib/utils/commons.util.ts +100 -0
- package/src/lib/utils/dictionary.util.ts +140 -0
- package/src/lib/utils/item.util.ts +4 -0
- package/src/lib/utils/promise.util.ts +3 -0
- package/src/lib/utils/prototypes.util.ts +167 -0
- package/src/lib/utils/sieve.util.ts +169 -0
- package/src/lib/utils/size.util.ts +4 -0
- package/src/public-api.ts +1 -0
- package/tsconfig.lib.json +16 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +14 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
2
|
+
/**
|
|
3
|
+
* Cast any type
|
|
4
|
+
* @param data to be casted
|
|
5
|
+
* @returns casted data
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,max-classes-per-file
|
|
8
|
+
export function cast<T>(data: any): T {
|
|
9
|
+
return data as T;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class StringExtensions implements IStringExtensions {
|
|
13
|
+
public getPart(maxChars: number, appendDot?: boolean): string {
|
|
14
|
+
let newStr = cast<string>(this).replace(/\\n/g, ' ');
|
|
15
|
+
if (newStr.length > maxChars) {
|
|
16
|
+
newStr = newStr.substring(0, maxChars);
|
|
17
|
+
if (appendDot && newStr.length > maxChars - 3) {
|
|
18
|
+
newStr += '...';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return newStr;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public fromJSON<T>(): T {
|
|
25
|
+
let str: string = cast<string>(this);
|
|
26
|
+
if (typeof this !== 'string') {
|
|
27
|
+
str = JSON.stringify(str);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
str = JSON.parse(str);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof str === 'object') {
|
|
37
|
+
return str as T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public toCSSClass(): string {
|
|
44
|
+
return cast<string>(this)?.replace(/([a-z])([A-Z])/, '$1-$2').toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public toUTC(): string {
|
|
48
|
+
return `${cast<string>(this)}Z`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class ArrayExtensions implements IArrayExtensions {
|
|
53
|
+
public hasChanges<T>(data: T[]): boolean {
|
|
54
|
+
return JSON.stringify(this) !== JSON.stringify(data);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public replaceRange<T>(data: T[], start: number, end: number): T[] {
|
|
58
|
+
const array: T[] = cast<T[]>(this);
|
|
59
|
+
let replaceDataIndex: number = 0;
|
|
60
|
+
for (let i: number = start; i < end; i++) {
|
|
61
|
+
if (!array[ i ] && !data[ replaceDataIndex ]) {
|
|
62
|
+
array.splice(i, 1);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
array[ i ] = data[ replaceDataIndex ];
|
|
67
|
+
replaceDataIndex++;
|
|
68
|
+
}
|
|
69
|
+
return array;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class NumberExtensions implements INumberExtensions {
|
|
74
|
+
public between(start: number, end: number): boolean {
|
|
75
|
+
const num: number = cast<number>(this);
|
|
76
|
+
return num >= start && num <= end;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @interface StringExtensions
|
|
82
|
+
*/
|
|
83
|
+
export interface IStringExtensions {
|
|
84
|
+
/**
|
|
85
|
+
* Gets a part of a string
|
|
86
|
+
* @param maxChars maximum amount of chars
|
|
87
|
+
* @param appendDot append three dots at the end
|
|
88
|
+
* @returns splitted string
|
|
89
|
+
*/
|
|
90
|
+
getPart(maxChars: number, appendDot?: boolean): string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Converts a string from json
|
|
94
|
+
* @returns object of expected type
|
|
95
|
+
*/
|
|
96
|
+
fromJSON<T>(): T;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Converts a string to a css class
|
|
100
|
+
* @returns converted kebab case css class
|
|
101
|
+
*/
|
|
102
|
+
toCSSClass(): string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Converts a datetime string to utc format
|
|
106
|
+
*/
|
|
107
|
+
toUTC(): string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface IArrayExtensions {
|
|
111
|
+
/**
|
|
112
|
+
* Checks if array has changes
|
|
113
|
+
* @param data array passed
|
|
114
|
+
* @deprecated learn how to program
|
|
115
|
+
*/
|
|
116
|
+
hasChanges: <T>(data: T[]) => boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Replaces a specific element range in an array
|
|
119
|
+
* @param data
|
|
120
|
+
*/
|
|
121
|
+
replaceRange: <T>(replaceData: T[], start: number, end: number) => T[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface INumberExtensions {
|
|
125
|
+
/**
|
|
126
|
+
* checks if a number in a range
|
|
127
|
+
* @param start of range
|
|
128
|
+
* @param end of range
|
|
129
|
+
*/
|
|
130
|
+
between(start: number, end: number): boolean;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare global {
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface,id-blacklist
|
|
135
|
+
interface String extends IStringExtensions {
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars
|
|
139
|
+
interface Array<T> extends IArrayExtensions {
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface,id-blacklist
|
|
143
|
+
interface Number extends INumberExtensions {
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export class Prototypes {
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Initialize prototypes
|
|
151
|
+
*/
|
|
152
|
+
public static init(): void {
|
|
153
|
+
const stringExtensions = new StringExtensions();
|
|
154
|
+
const arrayExtensions = new ArrayExtensions();
|
|
155
|
+
const numberExtensions = new NumberExtensions();
|
|
156
|
+
|
|
157
|
+
String.prototype.getPart = stringExtensions.getPart;
|
|
158
|
+
String.prototype.fromJSON = stringExtensions.fromJSON;
|
|
159
|
+
String.prototype.toCSSClass = stringExtensions.toCSSClass;
|
|
160
|
+
String.prototype.toUTC = stringExtensions.toUTC;
|
|
161
|
+
|
|
162
|
+
Array.prototype.hasChanges = arrayExtensions.hasChanges;
|
|
163
|
+
Array.prototype.replaceRange = arrayExtensions.replaceRange;
|
|
164
|
+
|
|
165
|
+
Number.prototype.between = numberExtensions.between;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { ISieveFilter } from '../models/sieve/sieve-filter.model';
|
|
2
|
+
import { SieveOperator } from '../models/sieve/sieve-operator.model';
|
|
3
|
+
import { ISieveOptions } from '../models/sieve/sieve-options.model';
|
|
4
|
+
import { ISieveSort } from '../models/sieve/sieve-sort.model';
|
|
5
|
+
|
|
6
|
+
export class Sieve {
|
|
7
|
+
|
|
8
|
+
private readonly options: ISieveOptions;
|
|
9
|
+
|
|
10
|
+
constructor(options: ISieveOptions) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.options.baseUrl = options.baseUrl || '';
|
|
13
|
+
this.options.filters = options.filters || [];
|
|
14
|
+
this.options.sorts = options.sorts || [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* public getter to get page size
|
|
19
|
+
*/
|
|
20
|
+
public get pageSize(): number {
|
|
21
|
+
return this.options.pageSize;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Setter to set page size
|
|
26
|
+
*/
|
|
27
|
+
public set pageSize(pageSize: number) {
|
|
28
|
+
this.options.pageSize = pageSize;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* public getter to get page
|
|
33
|
+
*/
|
|
34
|
+
public get page(): number {
|
|
35
|
+
return this.options.page;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Setter to set page
|
|
40
|
+
*/
|
|
41
|
+
public set page(page: number) {
|
|
42
|
+
this.options.page = page;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* public getter to get filters
|
|
47
|
+
*/
|
|
48
|
+
public get filters(): ISieveFilter[] {
|
|
49
|
+
return this.options.filters;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Setter to set filters
|
|
54
|
+
*/
|
|
55
|
+
public set filters(filters: ISieveFilter[]) {
|
|
56
|
+
this.options.filters = filters;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* public getter to get sorts
|
|
61
|
+
*/
|
|
62
|
+
public get sorts(): ISieveSort[] {
|
|
63
|
+
return this.options.sorts;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Setter to set sorts
|
|
68
|
+
*/
|
|
69
|
+
public set sorts(sorts: ISieveSort[]) {
|
|
70
|
+
this.options.sorts = sorts;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* method to add a sort option
|
|
75
|
+
* @param name of the item to sort
|
|
76
|
+
* @param desc sort descending
|
|
77
|
+
*/
|
|
78
|
+
public addSort(name: string, desc?: boolean): void {
|
|
79
|
+
this.options.sorts.push({
|
|
80
|
+
name,
|
|
81
|
+
desc,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* method to add a filter option
|
|
87
|
+
* @param key of the item
|
|
88
|
+
* @param operator { SieveOperator }
|
|
89
|
+
* @param value filtered value
|
|
90
|
+
*/
|
|
91
|
+
public addFilter(key: string, operator: SieveOperator, value: string): void {
|
|
92
|
+
this.options.filters.push({
|
|
93
|
+
key,
|
|
94
|
+
operator,
|
|
95
|
+
value,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Getter for base url
|
|
101
|
+
*/
|
|
102
|
+
public get baseUrl(): string {
|
|
103
|
+
return this.options.baseUrl;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Setter for base url
|
|
108
|
+
* @param url
|
|
109
|
+
*/
|
|
110
|
+
public set baseUrl(url: string) {
|
|
111
|
+
this.options.baseUrl = url;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Convert to queried string
|
|
116
|
+
*/
|
|
117
|
+
public getUrl(): string {
|
|
118
|
+
return `${ this.options.baseUrl }${ this.toQuery() }`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* to Query
|
|
123
|
+
* @private converts options to actual query
|
|
124
|
+
*/
|
|
125
|
+
private toQuery(): string {
|
|
126
|
+
let query = '?';
|
|
127
|
+
|
|
128
|
+
if (this.page) {
|
|
129
|
+
query += `page=${ this.page }`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this.pageSize) {
|
|
133
|
+
query += `&pageSize=${ this.pageSize }`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (this.filters?.length) {
|
|
137
|
+
let filterQuery: string = '&filters=';
|
|
138
|
+
|
|
139
|
+
for (const filter of this.filters) {
|
|
140
|
+
if (filter.value) {
|
|
141
|
+
filterQuery += `${ filter.key }${ filter.operator }${ filter.value },`;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (filterQuery !== '&filters=') {
|
|
146
|
+
filterQuery = filterQuery.slice(0, -1);
|
|
147
|
+
query += filterQuery;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (this.sorts?.length) {
|
|
152
|
+
let sortQuery: string = '&sorts=';
|
|
153
|
+
|
|
154
|
+
for (const sort of this.sorts) {
|
|
155
|
+
sortQuery += `${ sort.desc ? '-' : '+' }${ sort.name },`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
sortQuery = sortQuery.slice(0, -1);
|
|
159
|
+
query += sortQuery;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (query.startsWith('&')) {
|
|
163
|
+
query = query.slice(1);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return query;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/mosa-core.module';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/lib",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"inlineSources": true,
|
|
9
|
+
"types": [
|
|
10
|
+
"node",
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"exclude": [
|
|
14
|
+
"**/*.spec.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/spec",
|
|
6
|
+
"types": [
|
|
7
|
+
"jasmine"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"**/*.spec.ts",
|
|
12
|
+
"**/*.d.ts"
|
|
13
|
+
]
|
|
14
|
+
}
|