@diia-inhouse/utils 5.3.30 → 6.0.8

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.
Files changed (85) hide show
  1. package/dist/address.d.ts +7 -0
  2. package/dist/address.js +38 -41
  3. package/dist/applicationUtils.d.ts +225 -0
  4. package/dist/applicationUtils.js +576 -678
  5. package/dist/asserts.d.ts +6 -0
  6. package/dist/asserts.js +12 -19
  7. package/dist/dictionaries/phoneCodes.js +2435 -2442
  8. package/dist/guards.d.ts +22 -0
  9. package/dist/guards.js +58 -74
  10. package/dist/index.d.ts +36 -0
  11. package/dist/index.js +34 -70
  12. package/dist/integration.d.ts +6 -0
  13. package/dist/integration.js +7 -10
  14. package/dist/interfaces/asserts.d.ts +9 -0
  15. package/dist/interfaces/publicService.d.ts +11 -0
  16. package/dist/interfaces/slack.d.ts +6 -0
  17. package/dist/network.d.ts +17 -0
  18. package/dist/network.js +64 -72
  19. package/dist/payment.d.ts +8 -0
  20. package/dist/payment.js +19 -22
  21. package/dist/pdfUtils.d.ts +6 -0
  22. package/dist/pdfUtils.js +7 -10
  23. package/dist/phoneticChecker/index.d.ts +9 -0
  24. package/dist/phoneticChecker/index.js +18 -23
  25. package/dist/phoneticChecker/metaphone.js +38 -41
  26. package/dist/publicService.d.ts +59 -0
  27. package/dist/publicService.js +137 -150
  28. package/dist/random.d.ts +7 -0
  29. package/dist/random.js +11 -10
  30. package/dist/session.d.ts +7 -0
  31. package/dist/session.js +10 -19
  32. package/dist/slackFormatting.d.ts +13 -0
  33. package/dist/slackFormatting.js +41 -24
  34. package/dist/typeUtils.d.ts +8 -0
  35. package/dist/typeUtils.js +13 -15
  36. package/package.json +42 -27
  37. package/dist/address.js.map +0 -1
  38. package/dist/applicationUtils.js.map +0 -1
  39. package/dist/asserts.js.map +0 -1
  40. package/dist/dictionaries/phoneCodes.js.map +0 -1
  41. package/dist/guards.js.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/integration.js.map +0 -1
  44. package/dist/interfaces/applicationUtils.js +0 -3
  45. package/dist/interfaces/applicationUtils.js.map +0 -1
  46. package/dist/interfaces/asserts.js +0 -3
  47. package/dist/interfaces/asserts.js.map +0 -1
  48. package/dist/interfaces/error.js +0 -3
  49. package/dist/interfaces/error.js.map +0 -1
  50. package/dist/interfaces/publicService.js +0 -12
  51. package/dist/interfaces/publicService.js.map +0 -1
  52. package/dist/interfaces/slack.js +0 -3
  53. package/dist/interfaces/slack.js.map +0 -1
  54. package/dist/network.js.map +0 -1
  55. package/dist/payment.js.map +0 -1
  56. package/dist/pdfUtils.js.map +0 -1
  57. package/dist/phoneticChecker/index.js.map +0 -1
  58. package/dist/phoneticChecker/metaphone.js.map +0 -1
  59. package/dist/publicService.js.map +0 -1
  60. package/dist/random.js.map +0 -1
  61. package/dist/session.js.map +0 -1
  62. package/dist/slackFormatting.js.map +0 -1
  63. package/dist/typeUtils.js.map +0 -1
  64. package/dist/types/address.d.ts +0 -4
  65. package/dist/types/applicationUtils.d.ts +0 -212
  66. package/dist/types/asserts.d.ts +0 -2
  67. package/dist/types/dictionaries/phoneCodes.d.ts +0 -2
  68. package/dist/types/guards.d.ts +0 -18
  69. package/dist/types/index.d.ts +0 -86
  70. package/dist/types/integration.d.ts +0 -3
  71. package/dist/types/interfaces/applicationUtils.d.ts +0 -1
  72. package/dist/types/interfaces/asserts.d.ts +0 -5
  73. package/dist/types/interfaces/error.d.ts +0 -7
  74. package/dist/types/interfaces/publicService.d.ts +0 -15
  75. package/dist/types/interfaces/slack.d.ts +0 -3
  76. package/dist/types/network.d.ts +0 -13
  77. package/dist/types/payment.d.ts +0 -5
  78. package/dist/types/pdfUtils.d.ts +0 -3
  79. package/dist/types/phoneticChecker/index.d.ts +0 -7
  80. package/dist/types/phoneticChecker/metaphone.d.ts +0 -6
  81. package/dist/types/publicService.d.ts +0 -55
  82. package/dist/types/random.d.ts +0 -5
  83. package/dist/types/session.d.ts +0 -3
  84. package/dist/types/slackFormatting.d.ts +0 -7
  85. package/dist/types/typeUtils.d.ts +0 -5
@@ -0,0 +1,7 @@
1
+ //#region src/address.d.ts
2
+ declare class AddressUtils {
3
+ private readonly regionAtuIdByCode;
4
+ getRegionAtuIdByKatottgCode(katottgCode: string): number | null;
5
+ }
6
+ //#endregion
7
+ export { AddressUtils };
package/dist/address.js CHANGED
@@ -1,41 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AddressUtils = void 0;
4
- class AddressUtils {
5
- // For details see https://uk.wikipedia.org/wiki/%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA_%D0%BA%D0%BE%D0%B4%D1%96%D0%B2_%D0%9A%D0%9E%D0%90%D0%A2%D0%A3%D0%A3_%D0%B4%D0%BB%D1%8F_%D0%BE%D0%B1%D0%BB%D0%B0%D1%81%D1%82%D0%B5%D0%B9
6
- regionAtuIdByCode = {
7
- '01': 1, // Автономна Республіка Крим
8
- '05': 2, // Вінницька область
9
- '07': 3, // Волинська область
10
- '12': 4, // Дніпропетровська область
11
- '14': 5, // Донецька область
12
- '18': 6, // Житомирська область
13
- '21': 7, // Закарпатська область
14
- '23': 8, // Запорізька область
15
- '26': 9, // Івано-Франківська область
16
- '32': 10, // Київська область
17
- '35': 11, // Кіровоградська область
18
- '44': 12, // Луганська область
19
- '46': 13, // Львівська область
20
- '48': 14, // Миколаївська область
21
- '51': 15, // Одеська область
22
- '53': 16, // Полтавська область
23
- '56': 17, // Рівненська область
24
- '59': 18, // Сумська область
25
- '61': 19, // Тернопільська область
26
- '63': 20, // Харківська область
27
- '65': 21, // Херсонська область
28
- '68': 22, // Хмельницька область
29
- '71': 23, // Черкаська область
30
- '73': 24, // Чернівецька область
31
- '74': 25, // Чернігівська область
32
- '80': 26, // Київ
33
- '85': 27, // Севастополь
34
- };
35
- getRegionAtuIdByKatottgCode(katottgCode) {
36
- const code = katottgCode.slice(2, 4);
37
- return this.regionAtuIdByCode[code] ?? null;
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 };