@diia-inhouse/utils 5.3.30 → 6.0.9
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/dist/address.d.ts +7 -0
- package/dist/address.js +38 -41
- package/dist/applicationUtils.d.ts +225 -0
- package/dist/applicationUtils.js +576 -678
- package/dist/asserts.d.ts +6 -0
- package/dist/asserts.js +12 -19
- package/dist/dictionaries/phoneCodes.js +2435 -2442
- package/dist/guards.d.ts +22 -0
- package/dist/guards.js +58 -74
- package/dist/index.d.ts +36 -0
- package/dist/index.js +34 -70
- package/dist/integration.d.ts +6 -0
- package/dist/integration.js +7 -10
- package/dist/interfaces/asserts.d.ts +9 -0
- package/dist/interfaces/publicService.d.ts +11 -0
- package/dist/interfaces/slack.d.ts +6 -0
- package/dist/network.d.ts +17 -0
- package/dist/network.js +64 -72
- package/dist/payment.d.ts +8 -0
- package/dist/payment.js +19 -22
- package/dist/pdfUtils.d.ts +6 -0
- package/dist/pdfUtils.js +7 -10
- package/dist/phoneticChecker/index.d.ts +9 -0
- package/dist/phoneticChecker/index.js +18 -23
- package/dist/phoneticChecker/metaphone.js +38 -41
- package/dist/publicService.d.ts +59 -0
- package/dist/publicService.js +137 -150
- package/dist/random.d.ts +7 -0
- package/dist/random.js +11 -10
- package/dist/session.d.ts +7 -0
- package/dist/session.js +10 -19
- package/dist/slackFormatting.d.ts +13 -0
- package/dist/slackFormatting.js +41 -24
- package/dist/typeUtils.d.ts +8 -0
- package/dist/typeUtils.js +13 -15
- package/package.json +42 -27
- package/dist/address.js.map +0 -1
- package/dist/applicationUtils.js.map +0 -1
- package/dist/asserts.js.map +0 -1
- package/dist/dictionaries/phoneCodes.js.map +0 -1
- package/dist/guards.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/integration.js.map +0 -1
- package/dist/interfaces/applicationUtils.js +0 -3
- package/dist/interfaces/applicationUtils.js.map +0 -1
- package/dist/interfaces/asserts.js +0 -3
- package/dist/interfaces/asserts.js.map +0 -1
- package/dist/interfaces/error.js +0 -3
- package/dist/interfaces/error.js.map +0 -1
- package/dist/interfaces/publicService.js +0 -12
- package/dist/interfaces/publicService.js.map +0 -1
- package/dist/interfaces/slack.js +0 -3
- package/dist/interfaces/slack.js.map +0 -1
- package/dist/network.js.map +0 -1
- package/dist/payment.js.map +0 -1
- package/dist/pdfUtils.js.map +0 -1
- package/dist/phoneticChecker/index.js.map +0 -1
- package/dist/phoneticChecker/metaphone.js.map +0 -1
- package/dist/publicService.js.map +0 -1
- package/dist/random.js.map +0 -1
- package/dist/session.js.map +0 -1
- package/dist/slackFormatting.js.map +0 -1
- package/dist/typeUtils.js.map +0 -1
- package/dist/types/address.d.ts +0 -4
- package/dist/types/applicationUtils.d.ts +0 -212
- package/dist/types/asserts.d.ts +0 -2
- package/dist/types/dictionaries/phoneCodes.d.ts +0 -2
- package/dist/types/guards.d.ts +0 -18
- package/dist/types/index.d.ts +0 -86
- package/dist/types/integration.d.ts +0 -3
- package/dist/types/interfaces/applicationUtils.d.ts +0 -1
- package/dist/types/interfaces/asserts.d.ts +0 -5
- package/dist/types/interfaces/error.d.ts +0 -7
- package/dist/types/interfaces/publicService.d.ts +0 -15
- package/dist/types/interfaces/slack.d.ts +0 -3
- package/dist/types/network.d.ts +0 -13
- package/dist/types/payment.d.ts +0 -5
- package/dist/types/pdfUtils.d.ts +0 -3
- package/dist/types/phoneticChecker/index.d.ts +0 -7
- package/dist/types/phoneticChecker/metaphone.d.ts +0 -6
- package/dist/types/publicService.d.ts +0 -55
- package/dist/types/random.d.ts +0 -5
- package/dist/types/session.d.ts +0 -3
- package/dist/types/slackFormatting.d.ts +0 -7
- package/dist/types/typeUtils.d.ts +0 -5
package/dist/address.js
CHANGED
|
@@ -1,41 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
exports.AddressUtils = AddressUtils;
|
|
41
|
-
//# sourceMappingURL=address.js.map
|
|
1
|
+
//#region src/address.ts
|
|
2
|
+
var AddressUtils = class {
|
|
3
|
+
regionAtuIdByCode = {
|
|
4
|
+
"01": 1,
|
|
5
|
+
"05": 2,
|
|
6
|
+
"07": 3,
|
|
7
|
+
"12": 4,
|
|
8
|
+
"14": 5,
|
|
9
|
+
"18": 6,
|
|
10
|
+
"21": 7,
|
|
11
|
+
"23": 8,
|
|
12
|
+
"26": 9,
|
|
13
|
+
"32": 10,
|
|
14
|
+
"35": 11,
|
|
15
|
+
"44": 12,
|
|
16
|
+
"46": 13,
|
|
17
|
+
"48": 14,
|
|
18
|
+
"51": 15,
|
|
19
|
+
"53": 16,
|
|
20
|
+
"56": 17,
|
|
21
|
+
"59": 18,
|
|
22
|
+
"61": 19,
|
|
23
|
+
"63": 20,
|
|
24
|
+
"65": 21,
|
|
25
|
+
"68": 22,
|
|
26
|
+
"71": 23,
|
|
27
|
+
"73": 24,
|
|
28
|
+
"74": 25,
|
|
29
|
+
"80": 26,
|
|
30
|
+
"85": 27
|
|
31
|
+
};
|
|
32
|
+
getRegionAtuIdByKatottgCode(katottgCode) {
|
|
33
|
+
const code = katottgCode.slice(2, 4);
|
|
34
|
+
return this.regionAtuIdByCode[code] ?? null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { AddressUtils };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { ToRelativeUnit } from "luxon";
|
|
2
|
+
import { ApiError } from "@diia-inhouse/errors";
|
|
3
|
+
import { ActHeaders, ActionSession, ActionVersion, AppVersions, Gender, HashedFile, HashedFileWithSignature, PlatformType, SignedItem, TokenData, UserTokenData, WithAppVersions } from "@diia-inhouse/types";
|
|
4
|
+
|
|
5
|
+
//#region src/applicationUtils.d.ts
|
|
6
|
+
declare class ApplicationUtils {
|
|
7
|
+
private static documentTypeToCamelCaseExceptions;
|
|
8
|
+
private static camelCaseToDocumentTypeExceptions;
|
|
9
|
+
private static defaultItnDate;
|
|
10
|
+
private static defaultFormat;
|
|
11
|
+
private static readonly cyrillicToLatin;
|
|
12
|
+
private static readonly nameComponentsToLowerCase;
|
|
13
|
+
static documentTypeToCamelCase(documentType: string): string;
|
|
14
|
+
static camelCaseToDocumentType(camelCaseDocumentType: string): string;
|
|
15
|
+
static isItnChecksumValid(itn: string): boolean;
|
|
16
|
+
static getBirthDayFromItn(itn: string): string;
|
|
17
|
+
static getGenderFromItn(itn: string): Gender;
|
|
18
|
+
static isItnFormatValid(itn: string): boolean;
|
|
19
|
+
static capitalizeName(name: string | undefined | null): string;
|
|
20
|
+
static capitalizeFirstLetter(str: string): string;
|
|
21
|
+
static lowerFirstLetter(str: string): string;
|
|
22
|
+
static mapCyrillic(value: string): string;
|
|
23
|
+
static mapLatin(value: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Validates the Ukrainian IBAN number by format and checksum.
|
|
26
|
+
*/
|
|
27
|
+
static isIbanNumberValid(iban: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Extracts the bank code (МФО) from Ukrainian IBAN (4-10 digits). Does not validate the IBAN.
|
|
30
|
+
*
|
|
31
|
+
* @link https://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const bankCode = extractBankCodeFromIban('UA833052991234567890123456789') // '305299'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
static extractBankCodeFromIban(iban: string): string;
|
|
38
|
+
static getStreetName(street: string, streetType: string): string;
|
|
39
|
+
static toHashedFilesWithSignatures(hashedFiles: HashedFile[], signedItems: SignedItem[]): [HashedFileWithSignature[], string[]];
|
|
40
|
+
static handleError<T = never>(err: unknown, cb: (err: ApiError) => T): T;
|
|
41
|
+
static makeSession(data: TokenData): ActionSession;
|
|
42
|
+
static getActionNameWithVersion(actionName: string, actionVersion?: ActionVersion): string;
|
|
43
|
+
static getGreeting(fName: string, skipEmogi?: boolean): string;
|
|
44
|
+
/**
|
|
45
|
+
* Get age from birth date. Powered by {@link https://moment.github.io/luxon/#/ luxon}
|
|
46
|
+
*
|
|
47
|
+
* @param birthDay Input birth date.
|
|
48
|
+
* @param params Additional parameters. Default: `{ format: 'dd.MM.yyyy', unitOfTime: 'years' }`
|
|
49
|
+
* @param params.format Input date format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens). Default - 'dd.MM.yyyy'
|
|
50
|
+
* @param params.unitOfTime Unit of time to get the difference in. Default - 'years'
|
|
51
|
+
* @param params.relativeTo Date to compare the input date to. Default - current date
|
|
52
|
+
*
|
|
53
|
+
* @returns Age in years if other `unitOfTime` is not specified
|
|
54
|
+
* @throws If input date is invalid
|
|
55
|
+
*/
|
|
56
|
+
static getAge(birthDay: string, params?: {
|
|
57
|
+
format?: string;
|
|
58
|
+
unitOfTime?: ToRelativeUnit;
|
|
59
|
+
relativeTo?: string;
|
|
60
|
+
}): number;
|
|
61
|
+
static getFullName(lastName: string, firstName: string, middleName?: string, separator?: string): string;
|
|
62
|
+
static getShortName(lastName: string, firstName: string, middleName?: string): string;
|
|
63
|
+
static getUserFullName(user: UserTokenData): string;
|
|
64
|
+
static getPassportFullName({
|
|
65
|
+
lastNameUA,
|
|
66
|
+
firstNameUA,
|
|
67
|
+
middleNameUA
|
|
68
|
+
}: {
|
|
69
|
+
lastNameUA: string;
|
|
70
|
+
firstNameUA: string;
|
|
71
|
+
middleNameUA?: string;
|
|
72
|
+
}): string;
|
|
73
|
+
static getChildFullName({
|
|
74
|
+
child: {
|
|
75
|
+
lastName,
|
|
76
|
+
firstName,
|
|
77
|
+
middleName
|
|
78
|
+
}
|
|
79
|
+
}: {
|
|
80
|
+
child: {
|
|
81
|
+
lastName: string;
|
|
82
|
+
firstName: string;
|
|
83
|
+
middleName?: string;
|
|
84
|
+
};
|
|
85
|
+
}): string;
|
|
86
|
+
static encodeObjectToBase64<T>(object: T): string;
|
|
87
|
+
static decodeObjectFromBase64<T>(encodedObject: string): T;
|
|
88
|
+
/**
|
|
89
|
+
* Format string or Date to the specified string format. Powered by {@link https://moment.github.io/luxon/#/ luxon}
|
|
90
|
+
*
|
|
91
|
+
* @param date Input date
|
|
92
|
+
* @param format Output date format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens)
|
|
93
|
+
* @param fromFormat Input date format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens). Used for string `date`. Default - 'dd.MM.yyyy'
|
|
94
|
+
*
|
|
95
|
+
* @throws If input date is invalid
|
|
96
|
+
*/
|
|
97
|
+
static formatDate(date: string | Date, format: string, fromFormat?: string): string;
|
|
98
|
+
/**
|
|
99
|
+
* Check if the input date is valid. Powered by {@link https://moment.github.io/luxon/#/ luxon}
|
|
100
|
+
*
|
|
101
|
+
* @param date Input date.
|
|
102
|
+
* @param format `date` format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens). Default - 'yyyy-MM-dd'
|
|
103
|
+
*
|
|
104
|
+
* @throws If input date is invalid
|
|
105
|
+
*/
|
|
106
|
+
static validateDate(date: string, format?: string): void | never;
|
|
107
|
+
static formatPhoneNumber(rawPhone: string, separator?: string, prefix?: string): string;
|
|
108
|
+
/**
|
|
109
|
+
* Format number as: "XX XXX,XX {units}".
|
|
110
|
+
*
|
|
111
|
+
* @param amount Input number
|
|
112
|
+
* @param units Unit to be append at the end of the formatted number
|
|
113
|
+
* @param minimumFractionDigits Minimum number of fraction digits
|
|
114
|
+
*/
|
|
115
|
+
static formatAmountWithThousandsSeparator(amount: number, units?: string, minimumFractionDigits?: number): string;
|
|
116
|
+
static convertToPennies(amount: number): number;
|
|
117
|
+
static convertFromPennies(amount: number): number;
|
|
118
|
+
static multiplySum(amount: number, multiplier: number, decimalPlaces?: number): number;
|
|
119
|
+
static toDecimalPlaces(amount: number, decimalPlaces?: number): number;
|
|
120
|
+
static filterByAppVersions<T extends WithAppVersions>(items: T[], headers: Pick<ActHeaders, "appVersion" | "platformType"> | undefined): T[];
|
|
121
|
+
static isAppVersionMatch(appVersion: string, platformType: PlatformType, appVersions: AppVersions): boolean;
|
|
122
|
+
static getFileName(name: string, id: string, requestDateTime?: string, postFix?: string): string;
|
|
123
|
+
static sanitizeString(input: string): string;
|
|
124
|
+
/**
|
|
125
|
+
* Returns the appropriate plural form of a string based on the specified numeric value and locale.
|
|
126
|
+
* Uses the pluralization rules for the provided locale to determine the correct form among the options.
|
|
127
|
+
*
|
|
128
|
+
* @param value - The number used to determine the plural form.
|
|
129
|
+
* @param one - The form for singular (e.g., "one item").
|
|
130
|
+
* @param few - The form for a few items (e.g., "few items").
|
|
131
|
+
* @param many - The form for many items (e.g., "many items").
|
|
132
|
+
* @param other - Optional. The fallback form if none of the specific plural rules match.
|
|
133
|
+
* Defaults to the 'many' form if not provided.
|
|
134
|
+
* @param locale - The locale used for pluralization rules. Defaults to 'uk' (Ukrainian).
|
|
135
|
+
* @returns The appropriate pluralized string based on the value.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* getPluralForm(1, 'яблуко', 'яблука', 'яблук'); // 'яблуко'
|
|
139
|
+
* getPluralForm(2, 'яблуко', 'яблука', 'яблук'); // 'яблука'
|
|
140
|
+
* getPluralForm(0, 'яблуко', 'яблука', 'яблук', 'плоди'); // 'плоди'
|
|
141
|
+
* getPluralForm(0, 'яблуко', 'яблука', 'яблук'); // 'яблук' (uses 'many' as default fallback)
|
|
142
|
+
*/
|
|
143
|
+
static pluralizeString(value: number, one: string, few: string, many: string, other?: string, locale?: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* Returns the name of a service from a package.json in the current working directory (process.cwd()) converted to PascalCase.
|
|
146
|
+
* If the name is scoped, it will be returned without the scope.
|
|
147
|
+
* If the name is not found, an empty string is returned. Also, all whitespace characters are removed.
|
|
148
|
+
*
|
|
149
|
+
* @returns The name of the service in PascalCase.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* getServiceName() // 'my-service' -> 'MyService'
|
|
153
|
+
* getServiceName() // '@scope/my-service' -> 'MyService'
|
|
154
|
+
*/
|
|
155
|
+
static getServiceName(): string;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the version of a service from a package.json in the current working directory (process.cwd()).
|
|
158
|
+
* If the version is not found, an empty string is returned.
|
|
159
|
+
*
|
|
160
|
+
* @returns The version of the service.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* getServiceVersion() // '1.143.0-rc.2'
|
|
164
|
+
*/
|
|
165
|
+
static getServiceVersion(): string;
|
|
166
|
+
/**
|
|
167
|
+
* Format string according to mask pattern
|
|
168
|
+
*
|
|
169
|
+
* Basic Examples:
|
|
170
|
+
* '12345' with '##-###' -> '12-345'
|
|
171
|
+
* 'AB345' with '##-###' -> 'AB-345'
|
|
172
|
+
* '123456' with '##.####' -> '12.3456'
|
|
173
|
+
* '12345' with '### ##' -> '123 45'
|
|
174
|
+
* 'ABCDEF' with '##-##-##' -> 'AB-CD-EF'
|
|
175
|
+
*/
|
|
176
|
+
static formatMask(rawData: string, mask: string): string;
|
|
177
|
+
/**
|
|
178
|
+
* Memoize a function.
|
|
179
|
+
* The function is memoized by the arguments (`JSON.stringify(args)`) and the result is cached for the specified time to live in milliseconds.
|
|
180
|
+
* If the function is called with the same arguments again, the cached result is returned.
|
|
181
|
+
* If the function is called with the same arguments again after the time to live has expired, the function is called again and the result is cached again.
|
|
182
|
+
*
|
|
183
|
+
* @param fn - The function to memoize.
|
|
184
|
+
* @param ttl - The time to live for the cached value in milliseconds.
|
|
185
|
+
* @returns The memoized function.
|
|
186
|
+
*/
|
|
187
|
+
static memoize<T extends (...args: Parameters<T>) => ReturnType<T>>(fn: T, ttl?: number): T;
|
|
188
|
+
/**
|
|
189
|
+
* Recursively encodes all string values in an object or string using encodeURIComponent.
|
|
190
|
+
* For objects, it creates a deep clone and processes all string values.
|
|
191
|
+
* For strings, it directly applies the encoding.
|
|
192
|
+
*
|
|
193
|
+
* @param data Input data to encode - can be an object or string
|
|
194
|
+
* @returns Deep cloned object with encoded string values, or encoded string if input was string
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const data = { name: 'John Doe', email: 'john@example.com' }
|
|
198
|
+
* const encoded = ApplicationUtils.encodeValuesWithIterator(data)
|
|
199
|
+
* // Result: { name: 'John%20Doe', email: 'john%40example.com' }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
static encodeValuesWithIterator(data: object | string): object | string;
|
|
203
|
+
/**
|
|
204
|
+
* Recursively decodes all string values in an object or string using decodeURIComponent.
|
|
205
|
+
* For objects, it creates a deep clone and processes all string values.
|
|
206
|
+
* For strings, it directly applies the decoding.
|
|
207
|
+
*
|
|
208
|
+
* @param data Input data to decode - can be an object or string
|
|
209
|
+
* @returns Deep cloned object with decoded string values, or decoded string if input was string
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const data = { name: 'John%20Doe', email: 'john%40example.com' }
|
|
213
|
+
* const decoded = ApplicationUtils.decodeValuesWithIterator(data)
|
|
214
|
+
* // Result: { name: 'John Doe', email: 'john@example.com' }
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
static decodeValuesWithIterator(data: object | string): object | string;
|
|
218
|
+
private static mod97;
|
|
219
|
+
private static toApiError;
|
|
220
|
+
private static getPackageJson;
|
|
221
|
+
private static processObject;
|
|
222
|
+
private static processValues;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
export { ApplicationUtils };
|