@revolugo/common 7.2.4-alpha.20 → 7.2.4-alpha.22
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/package.json +1 -1
- package/src/constants/locales.ts +1 -1
- package/src/types/elements/allowed-payment-method.ts +1 -1
- package/src/utils/amount-from-percentage.ts +1 -1
- package/src/utils/case-transformers.ts +5 -5
- package/src/utils/create-composite-key.ts +1 -1
- package/src/utils/dates.ts +1 -1
- package/src/utils/group-by.ts +2 -2
- package/src/utils/images.ts +1 -1
- package/src/utils/key-by.ts +1 -1
- package/src/utils/map-keys.ts +2 -2
- package/src/utils/map-values.ts +1 -1
- package/src/utils/omit-by.ts +1 -1
- package/src/utils/omit.ts +1 -1
- package/src/utils/poller.ts +3 -3
- package/src/utils/sort-by.ts +1 -1
- package/src/utils/sum.ts +2 -2
- package/src/utils/to-lang.ts +8 -8
- package/src/utils/to-locale.ts +8 -8
- package/src/utils/uniq-by.ts +2 -2
- package/src/utils/uniq.ts +3 -3
package/package.json
CHANGED
package/src/constants/locales.ts
CHANGED
|
@@ -7,10 +7,10 @@ import type {
|
|
|
7
7
|
} from './payment-method.ts'
|
|
8
8
|
|
|
9
9
|
export type AllowedPaymentMethod =
|
|
10
|
+
| AllowedPaymentMethodPayLater
|
|
10
11
|
| BasePaymentMethodCoupon
|
|
11
12
|
| BasePaymentMethodCreditCard
|
|
12
13
|
| BasePaymentMethodDepositAccount
|
|
13
|
-
| AllowedPaymentMethodPayLater
|
|
14
14
|
|
|
15
15
|
export interface AllowedPaymentMethodPayLater extends BasePaymentMethodPayLater {
|
|
16
16
|
payload: PayloadPayLater
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function amountFromPercentage(
|
|
2
2
|
percentage: number,
|
|
3
3
|
amount: number,
|
|
4
|
-
roundingType: '
|
|
4
|
+
roundingType: 'ceil' | 'floor' | 'none' | 'round' = 'none',
|
|
5
5
|
): number {
|
|
6
6
|
if (Number.isNaN(Number(percentage)) || Number.isNaN(Number(amount))) {
|
|
7
7
|
throw new TypeError(`${percentage} || ${amount} is NaN`)
|
|
@@ -32,7 +32,7 @@ export const CASE_TRANSFORMERS_MAPPING = {
|
|
|
32
32
|
[CaseTransformer.Snake]: snakeCase,
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function changeCase<T extends string | string
|
|
35
|
+
export function changeCase<T extends string[] | string>(
|
|
36
36
|
input: T,
|
|
37
37
|
toCase: CaseTransformer,
|
|
38
38
|
): T extends string ? string : string[] {
|
|
@@ -47,7 +47,7 @@ export function changeCase<T extends string | string[]>(
|
|
|
47
47
|
: string[]
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
function matches(patterns: (
|
|
50
|
+
function matches(patterns: (RegExp | string)[], value: string) {
|
|
51
51
|
return patterns.some(pattern =>
|
|
52
52
|
typeof pattern === 'string' ? pattern === value : pattern.test(value),
|
|
53
53
|
)
|
|
@@ -62,14 +62,14 @@ export function keysChangeCase<T = any>(
|
|
|
62
62
|
obj: any[],
|
|
63
63
|
toCase: CaseTransformer,
|
|
64
64
|
|
|
65
|
-
options?: { deep?: boolean; exclude?: (
|
|
65
|
+
options?: { deep?: boolean; exclude?: (RegExp | string)[] },
|
|
66
66
|
): T[]
|
|
67
67
|
|
|
68
68
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
69
69
|
export function keysChangeCase<T = any>(
|
|
70
70
|
obj: unknown,
|
|
71
71
|
toCase: CaseTransformer,
|
|
72
|
-
options?: { deep?: boolean; exclude?: (
|
|
72
|
+
options?: { deep?: boolean; exclude?: (RegExp | string)[] },
|
|
73
73
|
): T
|
|
74
74
|
|
|
75
75
|
export function keysChangeCase<T>(
|
|
@@ -77,7 +77,7 @@ export function keysChangeCase<T>(
|
|
|
77
77
|
obj: any,
|
|
78
78
|
toCase: CaseTransformer,
|
|
79
79
|
|
|
80
|
-
options: { deep?: boolean; exclude?: (
|
|
80
|
+
options: { deep?: boolean; exclude?: (RegExp | string)[] } = { deep: true },
|
|
81
81
|
): unknown {
|
|
82
82
|
if (isObject(obj) && !(obj instanceof Date)) {
|
|
83
83
|
return Object.keys(obj).reduce<any>((result, key) => {
|
|
@@ -16,7 +16,7 @@ type CompositeKeyOptions<T> =
|
|
|
16
16
|
NonNullable<T> extends (infer U)[]
|
|
17
17
|
? CompositeKeyOptions<U>
|
|
18
18
|
: CompositeLeafAttributes & {
|
|
19
|
-
attributes: CompositeOmitAttributes<T>
|
|
19
|
+
attributes: CompositeAttributesType | CompositeOmitAttributes<T>
|
|
20
20
|
children?: {
|
|
21
21
|
[K in keyof T]?: NonNullable<T[K]> extends object
|
|
22
22
|
? CompositeKeyOptions<NonNullable<T[K]>>
|
package/src/utils/dates.ts
CHANGED
|
@@ -72,7 +72,7 @@ export function isDate(value: unknown): value is Date {
|
|
|
72
72
|
return value instanceof Date && !isNaN(value.getTime())
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export type DateInput =
|
|
75
|
+
export type DateInput = Date | string
|
|
76
76
|
|
|
77
77
|
export function generateDates(
|
|
78
78
|
startDate: DateInput,
|
package/src/utils/group-by.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @param keyOrGetter The key to group by or a function that returns the key.
|
|
5
5
|
* @returns An object where keys are the group identifiers and values are arrays of items.
|
|
6
6
|
*/
|
|
7
|
-
function groupBy<T, K extends
|
|
7
|
+
function groupBy<T, K extends number | string>(
|
|
8
8
|
array: T[],
|
|
9
|
-
keyOrGetter:
|
|
9
|
+
keyOrGetter: ((item: T) => K | undefined) | keyof T,
|
|
10
10
|
): Record<K, T[]> {
|
|
11
11
|
return array.reduce(
|
|
12
12
|
(acc, item) => {
|
package/src/utils/images.ts
CHANGED
package/src/utils/key-by.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export function keyBy<T>(
|
|
10
10
|
collection: T[] | null | undefined,
|
|
11
|
-
iteratee: ((value: T) =>
|
|
11
|
+
iteratee: ((value: T) => number | string) | keyof T,
|
|
12
12
|
): Record<string, T> {
|
|
13
13
|
return (
|
|
14
14
|
collection?.reduce<Record<string, T>>((acc, item) => {
|
package/src/utils/map-keys.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export const mapKeys = <
|
|
6
6
|
TValue,
|
|
7
|
-
TKey extends
|
|
8
|
-
TNewKey extends
|
|
7
|
+
TKey extends number | string | symbol,
|
|
8
|
+
TNewKey extends number | string | symbol,
|
|
9
9
|
>(
|
|
10
10
|
obj: Record<TKey, TValue>,
|
|
11
11
|
mapFunc: (key: TKey, value: TValue) => TNewKey,
|
package/src/utils/map-values.ts
CHANGED
package/src/utils/omit-by.ts
CHANGED
package/src/utils/omit.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// eslint-disable-next-line no-restricted-syntax
|
|
7
7
|
export function omit<T extends object, K extends keyof T>(
|
|
8
8
|
object: T | null | undefined,
|
|
9
|
-
keys: readonly K[]
|
|
9
|
+
keys: K | readonly K[],
|
|
10
10
|
// eslint-disable-next-line no-restricted-syntax
|
|
11
11
|
): Omit<T, K> {
|
|
12
12
|
if (object === null || object === undefined) {
|
package/src/utils/poller.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { CaseTransformer, keysChangeCase } from './case-transformers.ts'
|
|
|
6
6
|
export interface IPollerResponse<T = any> {
|
|
7
7
|
data?: T
|
|
8
8
|
meta?: {
|
|
9
|
-
status: '
|
|
9
|
+
status: 'COMPLETE' | 'IN_PROGRESS'
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export type TPollerRequestCallback<V> = () => Promise<V>
|
|
|
14
14
|
export type TPollerEventCallbackArg<
|
|
15
15
|
V extends IPollerResponse = IPollerResponse,
|
|
16
16
|
> = V | Error
|
|
17
|
-
export type TPollerEventName = '
|
|
17
|
+
export type TPollerEventName = 'complete' | 'data' | 'error'
|
|
18
18
|
export type TPollerEventCallback<V extends IPollerResponse = IPollerResponse> =
|
|
19
19
|
(arg?: TPollerEventCallbackArg<V>) => void
|
|
20
20
|
export type TPollerEvents<V extends IPollerResponse = IPollerResponse> = {
|
|
@@ -233,7 +233,7 @@ export function pollRequest<R extends IPollerResponse>(
|
|
|
233
233
|
request: TRequest<R>,
|
|
234
234
|
options: TOptions<R>,
|
|
235
235
|
pollerCallback?: TPollerCallback<R>,
|
|
236
|
-
): Promise<PollerReturn<R> | R | undefined> |
|
|
236
|
+
): PollerReturn<R> | Promise<PollerReturn<R> | R | undefined> | R | undefined {
|
|
237
237
|
const poller: Poller<R> = Poller.getInstance()
|
|
238
238
|
|
|
239
239
|
poller.poll(request, options)
|
package/src/utils/sort-by.ts
CHANGED
|
@@ -2,7 +2,7 @@ type Iteratee<T> = ((item: T) => unknown) | keyof T
|
|
|
2
2
|
type SortOrder = 'asc' | 'desc'
|
|
3
3
|
|
|
4
4
|
export function sortBy<T>(
|
|
5
|
-
collection:
|
|
5
|
+
collection: Record<string, T> | T[] | null | undefined,
|
|
6
6
|
iteratees?: Iteratee<T> | Iteratee<T>[] | string,
|
|
7
7
|
order?: SortOrder | SortOrder[],
|
|
8
8
|
): T[] {
|
package/src/utils/sum.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export function sum(arr: number[]): number
|
|
2
2
|
export function sum<T>(
|
|
3
3
|
arr: T[],
|
|
4
|
-
keyOrFunc:
|
|
4
|
+
keyOrFunc: ((item: T) => number) | keyof T,
|
|
5
5
|
): number
|
|
6
6
|
export function sum<T>(
|
|
7
7
|
arr: T[],
|
|
8
|
-
keyOrFunc?:
|
|
8
|
+
keyOrFunc?: ((item: T) => number) | keyof T,
|
|
9
9
|
): number {
|
|
10
10
|
if (arr.length === 0) {
|
|
11
11
|
return 0
|
package/src/utils/to-lang.ts
CHANGED
|
@@ -4,22 +4,22 @@ import type { ExtendedLocale } from '../constants/locales.ts'
|
|
|
4
4
|
|
|
5
5
|
export function toLang(localeOrLang: ExtendedLocale): Lang {
|
|
6
6
|
switch (localeOrLang) {
|
|
7
|
-
case Lang.EN:
|
|
8
|
-
case Locale.en_US: {
|
|
9
|
-
return Lang.EN
|
|
10
|
-
}
|
|
11
|
-
case Lang.FR:
|
|
12
|
-
case Locale.fr_FR: {
|
|
13
|
-
return Lang.FR
|
|
14
|
-
}
|
|
15
7
|
case Lang.DE:
|
|
16
8
|
case Locale.de_DE: {
|
|
17
9
|
return Lang.DE
|
|
18
10
|
}
|
|
11
|
+
case Lang.EN:
|
|
12
|
+
case Locale.en_US: {
|
|
13
|
+
return Lang.EN
|
|
14
|
+
}
|
|
19
15
|
case Lang.ES:
|
|
20
16
|
case Locale.es_ES: {
|
|
21
17
|
return Lang.ES
|
|
22
18
|
}
|
|
19
|
+
case Lang.FR:
|
|
20
|
+
case Locale.fr_FR: {
|
|
21
|
+
return Lang.FR
|
|
22
|
+
}
|
|
23
23
|
case Lang.IT:
|
|
24
24
|
case Locale.it_IT: {
|
|
25
25
|
return Lang.IT
|
package/src/utils/to-locale.ts
CHANGED
|
@@ -4,22 +4,22 @@ import type { ExtendedLocale } from '../constants/locales.ts'
|
|
|
4
4
|
|
|
5
5
|
export function toLocale(localeOrLang: ExtendedLocale): Locale {
|
|
6
6
|
switch (localeOrLang) {
|
|
7
|
-
case Lang.EN:
|
|
8
|
-
case Locale.en_US: {
|
|
9
|
-
return Locale.en_US
|
|
10
|
-
}
|
|
11
|
-
case Lang.FR:
|
|
12
|
-
case Locale.fr_FR: {
|
|
13
|
-
return Locale.fr_FR
|
|
14
|
-
}
|
|
15
7
|
case Lang.DE:
|
|
16
8
|
case Locale.de_DE: {
|
|
17
9
|
return Locale.de_DE
|
|
18
10
|
}
|
|
11
|
+
case Lang.EN:
|
|
12
|
+
case Locale.en_US: {
|
|
13
|
+
return Locale.en_US
|
|
14
|
+
}
|
|
19
15
|
case Lang.ES:
|
|
20
16
|
case Locale.es_ES: {
|
|
21
17
|
return Locale.es_ES
|
|
22
18
|
}
|
|
19
|
+
case Lang.FR:
|
|
20
|
+
case Locale.fr_FR: {
|
|
21
|
+
return Locale.fr_FR
|
|
22
|
+
}
|
|
23
23
|
case Lang.IT:
|
|
24
24
|
case Locale.it_IT: {
|
|
25
25
|
return Locale.it_IT
|
package/src/utils/uniq-by.ts
CHANGED
package/src/utils/uniq.ts
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function uniq<T>(
|
|
8
8
|
array: readonly T[],
|
|
9
|
-
toKey?: (item: T) =>
|
|
9
|
+
toKey?: (item: T) => number | string | symbol,
|
|
10
10
|
): T[] {
|
|
11
|
-
const valueMap = array.reduce<Record<
|
|
11
|
+
const valueMap = array.reduce<Record<number | string | symbol, T>>(
|
|
12
12
|
(acc, item) => {
|
|
13
|
-
const key = toKey ? toKey(item) : (item as
|
|
13
|
+
const key = toKey ? toKey(item) : (item as number | string | symbol)
|
|
14
14
|
if (acc[key]) {
|
|
15
15
|
return acc
|
|
16
16
|
}
|