@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revolugo/common",
3
- "version": "7.2.4-alpha.20",
3
+ "version": "7.2.4-alpha.22",
4
4
  "private": false,
5
5
  "description": "Revolugo common",
6
6
  "author": "Revolugo",
@@ -19,7 +19,7 @@ export enum Lang {
19
19
  PT = 'pt',
20
20
  }
21
21
 
22
- export type ExtendedLocale = Locale | Lang
22
+ export type ExtendedLocale = Lang | Locale
23
23
 
24
24
  export function langFromString(langStr: string): Lang | undefined {
25
25
  return Object.entries(Lang).find(entry => {
@@ -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: 'none' | 'round' | 'ceil' | 'floor' = 'none',
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: (string | RegExp)[], value: string) {
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?: (string | RegExp)[] },
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?: (string | RegExp)[] },
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?: (string | RegExp)[] } = { deep: true },
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> | CompositeAttributesType
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]>>
@@ -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 = string | Date
75
+ export type DateInput = Date | string
76
76
 
77
77
  export function generateDates(
78
78
  startDate: DateInput,
@@ -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 string | number>(
7
+ function groupBy<T, K extends number | string>(
8
8
  array: T[],
9
- keyOrGetter: keyof T | ((item: T) => K | undefined),
9
+ keyOrGetter: ((item: T) => K | undefined) | keyof T,
10
10
  ): Record<K, T[]> {
11
11
  return array.reduce(
12
12
  (acc, item) => {
@@ -26,7 +26,7 @@ export function generateImageUrls(
26
26
  )
27
27
  }
28
28
 
29
- type ImageSize = 'xs' | 's' | 'm' | 'l' | 'xl'
29
+ type ImageSize = 'l' | 'm' | 's' | 'xl' | 'xs'
30
30
 
31
31
  function selectBestSize(
32
32
  hotelImage: HotelImage,
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export function keyBy<T>(
10
10
  collection: T[] | null | undefined,
11
- iteratee: ((value: T) => string | number) | keyof 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) => {
@@ -4,8 +4,8 @@
4
4
  */
5
5
  export const mapKeys = <
6
6
  TValue,
7
- TKey extends string | number | symbol,
8
- TNewKey extends string | number | symbol,
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,
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const mapValues = <
5
5
  TValue,
6
- TKey extends string | number | symbol,
6
+ TKey extends number | string | symbol,
7
7
  TNewValue,
8
8
  >(
9
9
  obj: Record<TKey, TValue>,
@@ -9,7 +9,7 @@
9
9
  */
10
10
  export function omitBy<T extends object>(
11
11
  object: T,
12
- predicate: ((value: T[keyof T], key: keyof T) => boolean) | string,
12
+ predicate: string | ((value: T[keyof T], key: keyof T) => boolean),
13
13
  ): Partial<T> {
14
14
  const result = {} as Partial<T>
15
15
 
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[] | 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) {
@@ -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: 'IN_PROGRESS' | 'COMPLETE'
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 = 'data' | 'error' | 'complete'
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> | 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)
@@ -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: T[] | Record<string, T> | null | undefined,
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: keyof T | ((item: T) => number),
4
+ keyOrFunc: ((item: T) => number) | keyof T,
5
5
  ): number
6
6
  export function sum<T>(
7
7
  arr: T[],
8
- keyOrFunc?: keyof T | ((item: T) => number),
8
+ keyOrFunc?: ((item: T) => number) | keyof T,
9
9
  ): number {
10
10
  if (arr.length === 0) {
11
11
  return 0
@@ -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
@@ -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
@@ -1,6 +1,6 @@
1
1
  export function uniqBy<T>(
2
- array: T[] | undefined | null,
3
- iteratee: keyof T | ((item: T) => unknown),
2
+ array: T[] | null | undefined,
3
+ iteratee: ((item: T) => unknown) | keyof T,
4
4
  ): T[] {
5
5
  const seen = new Set()
6
6
  return (
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) => string | number | symbol,
9
+ toKey?: (item: T) => number | string | symbol,
10
10
  ): T[] {
11
- const valueMap = array.reduce<Record<string | number | symbol, T>>(
11
+ const valueMap = array.reduce<Record<number | string | symbol, T>>(
12
12
  (acc, item) => {
13
- const key = toKey ? toKey(item) : (item as string | number | symbol)
13
+ const key = toKey ? toKey(item) : (item as number | string | symbol)
14
14
  if (acc[key]) {
15
15
  return acc
16
16
  }