@revolugo/common 6.9.3-beta.9 → 6.9.4-rc.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.
Files changed (42) hide show
  1. package/package.json +1 -4
  2. package/src/cancellation-policies.test.ts +9 -12
  3. package/src/cancellation-policies.ts +23 -30
  4. package/src/constants/countries.ts +1 -0
  5. package/src/constants/currencies.ts +2 -0
  6. package/src/types/index.ts +0 -1
  7. package/src/utils/array-tools.ts +2 -3
  8. package/src/utils/colors.ts +4 -4
  9. package/src/utils/countries.ts +2 -3
  10. package/src/utils/currency.ts +16 -19
  11. package/src/utils/dates.ts +7 -5
  12. package/src/utils/debounce.ts +2 -2
  13. package/src/utils/find-unique-keys.ts +2 -2
  14. package/src/utils/index.ts +1 -0
  15. package/src/utils/lang-default-fallbacks.ts +1 -1
  16. package/src/utils/math.ts +3 -3
  17. package/src/utils/numbers.ts +7 -8
  18. package/src/utils/object-tools.ts +2 -2
  19. package/src/utils/shake.ts +22 -0
  20. package/src/utils/strings.ts +2 -3
  21. package/src/types/elements/amenity.ts +0 -266
  22. package/src/types/elements/bed.ts +0 -20
  23. package/src/types/elements/booking-policy.ts +0 -80
  24. package/src/types/elements/booking.ts +0 -236
  25. package/src/types/elements/cancellation-policy.ts +0 -20
  26. package/src/types/elements/contact-person.ts +0 -158
  27. package/src/types/elements/currency.ts +0 -3
  28. package/src/types/elements/event-metadata.ts +0 -38
  29. package/src/types/elements/event.ts +0 -14
  30. package/src/types/elements/hotel-offer.ts +0 -359
  31. package/src/types/elements/hotel-review-rating.ts +0 -14
  32. package/src/types/elements/hotel-room-offer.ts +0 -367
  33. package/src/types/elements/hotel-room.ts +0 -102
  34. package/src/types/elements/hotel-rooming-list.ts +0 -150
  35. package/src/types/elements/hotel.ts +0 -279
  36. package/src/types/elements/index.ts +0 -13
  37. package/src/types/elements/invoice.ts +0 -21
  38. package/src/types/elements/payment-method.ts +0 -159
  39. package/src/types/elements/source-market.ts +0 -247
  40. package/src/types/elements/tag.ts +0 -32
  41. package/src/types/elements/tax.ts +0 -52
  42. package/src/types/elements/travel-times.ts +0 -45
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revolugo/common",
3
- "version": "6.9.3-beta.9",
3
+ "version": "6.9.4-rc.0",
4
4
  "private": false,
5
5
  "description": "Revolugo common",
6
6
  "author": "Revolugo",
@@ -8,9 +8,6 @@
8
8
  "files": [
9
9
  "src"
10
10
  ],
11
- "imports": {
12
- "#constants": "./src/constants/index.ts"
13
- },
14
11
  "exports": {
15
12
  "./cancellation-policies": "./src/cancellation-policies.ts",
16
13
  "./constants": "./src/constants/index.ts",
@@ -15,17 +15,13 @@ import type {
15
15
  } from './cancellation-policies.ts'
16
16
  import type { ICancellationPolicy } from './types/index.ts'
17
17
 
18
- function getUTCLocalTime(date: string, timezone: string): Dayjs {
19
- return dayjs.tz(date, timezone).utc()
20
- }
18
+ const getUTCLocalTime = (date: string, timezone: string): Dayjs =>
19
+ dayjs.tz(date, timezone).utc()
21
20
 
22
- function getFormattedUTCLocalTime(date: string, timezone: string): string {
23
- return getUTCLocalTime(date, timezone).format()
24
- }
21
+ const getFormattedUTCLocalTime = (date: string, timezone: string): string =>
22
+ getUTCLocalTime(date, timezone).format()
25
23
 
26
- function nextDay(date: string) {
27
- return dayjs(date).add(1, 'day').utc().format()
28
- }
24
+ const nextDay = (date: string) => dayjs(date).add(1, 'day').utc().format()
29
25
 
30
26
  const timezone = 'America/Los_Angeles'
31
27
 
@@ -83,7 +79,7 @@ const CANCELLATION_POLICIES = [
83
79
  ]
84
80
 
85
81
  describe('sanitizeCancellationPolicies', () => {
86
- function testCancellationPolicies({
82
+ const testCancellationPolicies = ({
87
83
  bookingDatetime,
88
84
  cancellationPolicies,
89
85
  checkInDate,
@@ -97,8 +93,8 @@ describe('sanitizeCancellationPolicies', () => {
97
93
  message: string
98
94
  releaseDate?: string
99
95
  results: ICancellationPolicy[]
100
- }): void {
101
- return test(message, () => {
96
+ }): void => {
97
+ test(message, () => {
102
98
  const sanitizedCancellationPolicies = sanitizeCancellationPolicies({
103
99
  bookingDatetime,
104
100
  cancellationPolicies,
@@ -1038,3 +1034,4 @@ describe('getCurrentPenaltyPercentage', () => {
1038
1034
  ).to.equal(PP_4)
1039
1035
  })
1040
1036
  })
1037
+ /* eslint-enable max-lines */
@@ -6,9 +6,7 @@ import { isEmpty } from './utils/is-empty.ts'
6
6
 
7
7
  import type { ICancellationPolicy } from './types/cancellation-policy.ts'
8
8
 
9
- function nextDay(date: string) {
10
- return dayjs(date).add(1, 'day').utc().format()
11
- }
9
+ const nextDay = (date: string) => dayjs(date).add(1, 'day').utc().format()
12
10
 
13
11
  function isUTCDate(date: string) {
14
12
  return /\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3])(?::[0-5]\d){2}(?:\.\d+|)(?:Z|[+-]\d{2}:?\d{2})/u.test(
@@ -16,17 +14,16 @@ function isUTCDate(date: string) {
16
14
  )
17
15
  }
18
16
 
19
- function filterMatchingCancellationPolicies({
17
+ const filterMatchingCancellationPolicies = ({
20
18
  cancellationPolicies,
21
19
  date,
22
20
  }: {
23
21
  cancellationPolicies: ICancellationPolicy[]
24
22
  date: string
25
- }) {
26
- return cancellationPolicies.filter(cp =>
23
+ }) =>
24
+ cancellationPolicies.filter(cp =>
27
25
  dayjs(date).isBetween(cp.dateFrom, cp.dateTo, undefined, '[)'),
28
26
  )
29
- }
30
27
 
31
28
  export interface SanitizeCancellationPolicies {
32
29
  bookingDatetime?: string
@@ -37,13 +34,13 @@ export interface SanitizeCancellationPolicies {
37
34
  }
38
35
 
39
36
  // eslint-disable-next-line complexity, max-statements, max-lines-per-function
40
- export function sanitizeCancellationPolicies({
37
+ export const sanitizeCancellationPolicies = ({
41
38
  bookingDatetime,
42
39
  cancellationPolicies,
43
40
  checkInDate,
44
41
  releaseDate,
45
42
  timezone,
46
- }: SanitizeCancellationPolicies): ICancellationPolicy[] {
43
+ }: SanitizeCancellationPolicies): ICancellationPolicy[] => {
47
44
  if (!bookingDatetime) {
48
45
  throw new Error('Missing "bookingDatetime" option')
49
46
  }
@@ -132,9 +129,8 @@ export function sanitizeCancellationPolicies({
132
129
  cancellationPolicies?.map(cp => ({ ...cp })),
133
130
  )
134
131
 
135
- function isValidCancellationPolicy(cp: ICancellationPolicy) {
136
- return cp.dateFrom && cp.dateTo && dayjs(cp.dateFrom).isBefore(cp.dateTo)
137
- }
132
+ const isValidCancellationPolicy = (cp: ICancellationPolicy) =>
133
+ cp.dateFrom && cp.dateTo && dayjs(cp.dateFrom).isBefore(cp.dateTo)
138
134
 
139
135
  const isValidCancellationPolicies = compactedCancellationPolicies.every(
140
136
  isValidCancellationPolicy,
@@ -288,14 +284,14 @@ export interface GetPenaltyPercentage {
288
284
  timezone?: string
289
285
  }
290
286
 
291
- export function getPenaltyPercentage({
287
+ export const getPenaltyPercentage = ({
292
288
  bookingDatetime,
293
289
  cancellationPolicies,
294
290
  checkInDate,
295
291
  datetime,
296
292
  releaseDate,
297
293
  timezone,
298
- }: GetPenaltyPercentage): number {
294
+ }: GetPenaltyPercentage): number => {
299
295
  if (!bookingDatetime) {
300
296
  throw new Error('Missing "bookingDatetime" option')
301
297
  }
@@ -348,7 +344,7 @@ export function getPenaltyPercentage({
348
344
  )
349
345
  }
350
346
 
351
- export function getCurrentPenaltyPercentage({
347
+ export const getCurrentPenaltyPercentage = ({
352
348
  bookingDatetime,
353
349
  cancellationPolicies,
354
350
  checkInDate,
@@ -360,7 +356,7 @@ export function getCurrentPenaltyPercentage({
360
356
  checkInDate: string
361
357
  releaseDate?: string
362
358
  timezone: string
363
- }): number {
359
+ }): number => {
364
360
  const datetimeUTC = dayjs().utc().format()
365
361
 
366
362
  return getPenaltyPercentage({
@@ -373,10 +369,10 @@ export function getCurrentPenaltyPercentage({
373
369
  })
374
370
  }
375
371
 
376
- export function isBetterCancellationPolicies(
372
+ export const isBetterCancellationPolicies = (
377
373
  newVal: ICancellationPolicy[],
378
374
  oldVal: ICancellationPolicy[],
379
- ): boolean {
375
+ ): boolean => {
380
376
  if (isEmpty(newVal)) {
381
377
  return true
382
378
  }
@@ -428,13 +424,13 @@ export function isBetterCancellationPolicies(
428
424
  })
429
425
  }
430
426
 
431
- export function parseCancellationPolicies(
427
+ export const parseCancellationPolicies = (
432
428
  cancellationPolicies: {
433
429
  dateFrom: string
434
430
  dateTo: string
435
431
  penaltyPercentage: number
436
432
  }[],
437
- ): ICancellationPolicy[] {
433
+ ): ICancellationPolicy[] => {
438
434
  if (typeof cancellationPolicies === 'string') {
439
435
  try {
440
436
  return JSON.parse(cancellationPolicies) as ICancellationPolicy[]
@@ -446,7 +442,7 @@ export function parseCancellationPolicies(
446
442
  return cancellationPolicies
447
443
  }
448
444
 
449
- export function getSanitizedCancellationPolicies({
445
+ export const getSanitizedCancellationPolicies = ({
450
446
  cancellationPolicies,
451
447
  checkInDate,
452
448
  initialDate,
@@ -456,7 +452,7 @@ export function getSanitizedCancellationPolicies({
456
452
  cancellationPolicies: ICancellationPolicy[]
457
453
  timezone: string
458
454
  initialDate?: string
459
- }): ICancellationPolicy[] {
455
+ }): ICancellationPolicy[] => {
460
456
  if (!cancellationPolicies.length) {
461
457
  return []
462
458
  }
@@ -469,15 +465,12 @@ export function getSanitizedCancellationPolicies({
469
465
  })
470
466
  }
471
467
 
472
- export function getCurrentCancellationPolicy(
468
+ export const getCurrentCancellationPolicy = (
473
469
  sanitizedCancellationPolicies: ICancellationPolicy[],
474
- ): ICancellationPolicy {
475
- return (
476
- sanitizedCancellationPolicies.find(policy =>
477
- dayjs().isBetween(dayjs(policy.dateFrom), dayjs(policy.dateTo)),
478
- ) || sanitizedCancellationPolicies[0]
479
- )
480
- }
470
+ ): ICancellationPolicy =>
471
+ sanitizedCancellationPolicies.find(policy =>
472
+ dayjs().isBetween(dayjs(policy.dateFrom), dayjs(policy.dateTo)),
473
+ ) || sanitizedCancellationPolicies[0]
481
474
 
482
475
  function adjustIfFullHour(date: string): Dayjs {
483
476
  const parsed = dayjs(date)
@@ -2754,6 +2754,7 @@ export const COUNTRIES: Record<string, Country> = {
2754
2754
  timezone: 'Africa/Harare',
2755
2755
  },
2756
2756
  }
2757
+ /* eslint-enable max-lines */
2757
2758
 
2758
2759
  export const ISO_COUNTRIES = Object.values(COUNTRIES).map(
2759
2760
  country => country.iso2,
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable max-lines */
2
+
2
3
  import { pick } from '../utils/object-tools.ts'
3
4
 
4
5
  import type { ICurrency } from '../types/currency.ts'
@@ -1974,3 +1975,4 @@ export const STRIPE_ZERO_DECIMAL_CURRENCIES = Object.values(CURRENCIES_MAP)
1974
1975
  currency => currency.zeroDecimal && currency.code in STRIPE_CURRENCIES_MAP,
1975
1976
  )
1976
1977
  .map(currency => currency.code)
1978
+ /* eslint-enable max-lines */
@@ -16,4 +16,3 @@ export * from './taxable.ts'
16
16
  export * from './severities.ts'
17
17
  export * from './http-exception/index.ts'
18
18
  export * from './hotel-rooming-list.ts'
19
- export * from './elements/index.ts'
@@ -6,9 +6,8 @@ export function chunk<T>(array: T[], size: number): T[][] {
6
6
  return chunks
7
7
  }
8
8
 
9
- export function getRandomElementFromArray<T>(array: readonly T[]): T {
10
- return array[Math.floor(Math.random() * array.length)]
11
- }
9
+ export const getRandomElementFromArray = <T>(array: readonly T[]): T =>
10
+ array[Math.floor(Math.random() * array.length)]
12
11
 
13
12
  export function shuffleArray<T>(array: T[]): T[] {
14
13
  const shuffled = [...array]
@@ -1,9 +1,9 @@
1
1
  import { generateNumbersFromStr } from './numbers.ts'
2
2
 
3
- export function generateRandomColorFromString(
3
+ export const generateRandomColorFromString = (
4
4
  str: string,
5
5
  existingColors: string[],
6
- ): string {
6
+ ): string => {
7
7
  const [num1, num2] = generateNumbersFromStr(str)
8
8
  // adjust this value to control how close the generated color is to the existing colors
9
9
  const hueRange = 5
@@ -20,7 +20,7 @@ export function generateRandomColorFromString(
20
20
  return newColor
21
21
  }
22
22
 
23
- export function hexToRgba(hex: string, opacity: number): string {
23
+ export const hexToRgba = (hex: string, opacity: number): string => {
24
24
  // Copy the value of 'hex' into a local variable without modifying the original parameter
25
25
  let hexWithoutHash = hex
26
26
 
@@ -44,7 +44,7 @@ export function hexToRgba(hex: string, opacity: number): string {
44
44
  const barColors = ['#006EFF', '#FF9800', '#9C27B0', '#F44336', '#4CAF50']
45
45
  const contractIdToColors = new Map<string, string>()
46
46
 
47
- export function getRangeColor(id: string): string {
47
+ export const getRangeColor = (id: string): string => {
48
48
  if (!contractIdToColors.has(id)) {
49
49
  contractIdToColors.set(id, generateRandomColorFromString(id, barColors))
50
50
  }
@@ -1,5 +1,4 @@
1
1
  import { EU_COUNTRIES_ISO2_CODE } from '../constants/countries.ts'
2
2
 
3
- export function isInEu(countryCode: string): boolean {
4
- return EU_COUNTRIES_ISO2_CODE.has(countryCode)
5
- }
3
+ export const isInEu = (countryCode: string): boolean =>
4
+ EU_COUNTRIES_ISO2_CODE.has(countryCode)
@@ -1,6 +1,6 @@
1
1
  import { CURRENCIES_MAP, type Currency } from '../constants/index.ts'
2
2
 
3
- export function getCurrencySymbol(currency: Currency): string {
3
+ export const getCurrencySymbol = (currency: Currency): string => {
4
4
  const symbol = CURRENCIES_MAP[currency]?.symbol
5
5
 
6
6
  if (!symbol) {
@@ -10,19 +10,16 @@ export function getCurrencySymbol(currency: Currency): string {
10
10
  return symbol
11
11
  }
12
12
 
13
- export function isZeroDecimal(currency: Currency): boolean {
14
- return (
15
- (CURRENCIES_MAP[currency] && CURRENCIES_MAP[currency].zeroDecimal) || false
16
- )
17
- }
13
+ export const isZeroDecimal = (currency: Currency): boolean =>
14
+ (CURRENCIES_MAP[currency] && CURRENCIES_MAP[currency].zeroDecimal) || false
18
15
 
19
- export function normalizeAmount({
16
+ export const normalizeAmount = ({
20
17
  amount,
21
18
  currency,
22
19
  }: {
23
20
  amount: number
24
21
  currency: Currency
25
- }): number {
22
+ }): number => {
26
23
  if (isZeroDecimal(currency)) {
27
24
  return amount
28
25
  }
@@ -30,13 +27,13 @@ export function normalizeAmount({
30
27
  return amount * 100
31
28
  }
32
29
 
33
- export function denormalizeAmount({
30
+ export const denormalizeAmount = ({
34
31
  amount,
35
32
  currency,
36
33
  }: {
37
34
  amount: number
38
35
  currency: Currency
39
- }): number {
36
+ }): number => {
40
37
  if (isZeroDecimal(currency)) {
41
38
  return amount
42
39
  }
@@ -44,7 +41,7 @@ export function denormalizeAmount({
44
41
  return amount / 100
45
42
  }
46
43
 
47
- export function formatAmount({
44
+ export const formatAmount = ({
48
45
  amount,
49
46
  currency,
50
47
  locale = 'en',
@@ -54,7 +51,7 @@ export function formatAmount({
54
51
  currency: string
55
52
  locale?: string
56
53
  space?: string
57
- }): string {
54
+ }): string => {
58
55
  const fractionDigits = amount.toFixed(2).endsWith('.00') ? 0 : 2
59
56
 
60
57
  return (
@@ -169,16 +166,16 @@ export class MoneyCalculator {
169
166
  return this
170
167
  }
171
168
 
172
- const startingIsNormalized = this.isNormalized
169
+ const { isNormalized } = this
173
170
 
174
- if (startingIsNormalized) {
171
+ if (isNormalized) {
175
172
  this.denormalize()
176
173
  }
177
174
 
178
175
  this.amount *= exchangeRate
179
176
  this.currency = currency
180
177
 
181
- if (startingIsNormalized) {
178
+ if (isNormalized) {
182
179
  this.normalize()
183
180
  }
184
181
 
@@ -186,13 +183,13 @@ export class MoneyCalculator {
186
183
  }
187
184
  }
188
185
 
189
- export function ceilNormalizedAmount({
186
+ export const ceilNormalizedAmount = ({
190
187
  amount,
191
188
  currency,
192
189
  }: {
193
190
  amount: number
194
191
  currency: Currency
195
- }): number {
192
+ }): number => {
196
193
  const denormalizedAmount = denormalizeAmount({
197
194
  amount,
198
195
  currency,
@@ -204,13 +201,13 @@ export function ceilNormalizedAmount({
204
201
  })
205
202
  }
206
203
 
207
- export function floorNormalizedAmount({
204
+ export const floorNormalizedAmount = ({
208
205
  amount,
209
206
  currency,
210
207
  }: {
211
208
  amount: number
212
209
  currency: Currency
213
- }): number {
210
+ }): number => {
214
211
  const denormalizedAmount = denormalizeAmount({
215
212
  amount,
216
213
  currency,
@@ -20,11 +20,11 @@ export function sortDates(dates: string[]): string[] {
20
20
  return validDates.sort((a, b) => (dayjs(a).isAfter(dayjs(b), 'day') ? 1 : -1))
21
21
  }
22
22
 
23
- export function getDateRange(
23
+ export const getDateRange = (
24
24
  start: Date | string,
25
25
  end: Date | string,
26
26
  format: string = DATE_STRING_FORMAT,
27
- ): string[] {
27
+ ): string[] => {
28
28
  const dates: string[] = []
29
29
  let current = dayjs(start)
30
30
 
@@ -80,9 +80,11 @@ export function generateDates(
80
80
  }
81
81
 
82
82
  const totalDays = end.diff(start, 'day') + 1
83
- const dates = Array.from({ length: totalDays }, (_, i) =>
84
- start.add(i, 'day').toDate(),
85
- )
83
+ const dates = new Array<Date>(totalDays)
84
+
85
+ for (let i = 0; i < totalDays; i++) {
86
+ dates[i] = start.add(i, 'day').toDate()
87
+ }
86
88
 
87
89
  return dates
88
90
  }
@@ -46,7 +46,7 @@ export function debounce<Args extends any[], F extends (...args: Args) => any>(
46
46
  return waitMilliseconds
47
47
  }
48
48
 
49
- function debouncedFunction(
49
+ const debouncedFunction = function debouncedFunction(
50
50
  this: ThisParameterType<F>,
51
51
  ...args: Parameters<F>
52
52
  ) {
@@ -54,7 +54,7 @@ export function debounce<Args extends any[], F extends (...args: Args) => any>(
54
54
  const context = this
55
55
  // eslint-disable-next-line consistent-return
56
56
  return new Promise<Awaited<ReturnType<F>>>((resolve, reject) => {
57
- function invokeFunction() {
57
+ const invokeFunction = function invokeFunction() {
58
58
  timeoutId = undefined
59
59
  lastInvokeTime = Date.now()
60
60
  if (!isImmediate) {
@@ -1,6 +1,6 @@
1
- export function findUniqueKeys(
1
+ export const findUniqueKeys = (
2
2
  objects: { [key: string]: unknown }[],
3
- ): string[] {
3
+ ): string[] => {
4
4
  const objectKeys = objects.flatMap(Object.keys)
5
5
  return [...new Set(objectKeys)]
6
6
  }
@@ -27,3 +27,4 @@ export * from './validators.ts'
27
27
  export * from './value-tools.ts'
28
28
  export * from './create-composite-key.ts'
29
29
  export * from './children-tools.ts'
30
+ export * from './shake.ts'
@@ -2,7 +2,7 @@ import { LOCALE_TO_LANG, Locale } from '../constants/locales.ts'
2
2
 
3
3
  import type { Lang } from '../constants/locales.ts'
4
4
 
5
- export function langDefaultFallbacks(lang?: Locale): Lang[] {
5
+ export const langDefaultFallbacks = (lang?: Locale): Lang[] => {
6
6
  if (!lang || lang === Locale.en_US) {
7
7
  return [LOCALE_TO_LANG[Locale.en_US]]
8
8
  }
package/src/utils/math.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function weightedMean(values: number[], weights: number[]): number {
1
+ export const weightedMean = (values: number[], weights: number[]): number => {
2
2
  const sum = values.reduce(
3
3
  (acc: number, val: number, i: number) => acc + val * weights[i],
4
4
  0,
@@ -8,11 +8,11 @@ export function weightedMean(values: number[], weights: number[]): number {
8
8
  return sum / sumWeights
9
9
  }
10
10
 
11
- export function amountFromPercentage(
11
+ export const amountFromPercentage = (
12
12
  percentage: number,
13
13
  amount: number,
14
14
  roundingType: 'none' | 'round' | 'ceil' | 'floor' = 'none',
15
- ): number {
15
+ ): number => {
16
16
  if (Number.isNaN(Number(percentage)) || Number.isNaN(Number(amount))) {
17
17
  throw new TypeError(`${percentage} || ${amount} is NaN`)
18
18
  }
@@ -1,4 +1,4 @@
1
- export function generateNumbersFromStr(str: string): [number, number] {
1
+ export const generateNumbersFromStr = (str: string): [number, number] => {
2
2
  let hash = 5381
3
3
  for (let i = 0; i < str.length; i++) {
4
4
  // eslint-disable-next-line no-bitwise
@@ -14,14 +14,13 @@ export function generateNumbersFromStr(str: string): [number, number] {
14
14
  return [num1, num2]
15
15
  }
16
16
 
17
- export function randomInt(min: number, max: number): number {
18
- return Math.floor(Math.random() * (max - min + 1) + min)
19
- }
17
+ export const randomInt = (min: number, max: number): number =>
18
+ Math.floor(Math.random() * (max - min + 1) + min)
20
19
 
21
- export function computeSellingPrice(
20
+ export const computeSellingPrice = (
22
21
  buyingPrice: number | string | null = 0,
23
22
  rate: number | string | null = 0,
24
- ): number {
23
+ ): number => {
25
24
  if (Number.isNaN(Number(buyingPrice)) || Number.isNaN(Number(rate))) {
26
25
  throw new TypeError('price or rate is NaN')
27
26
  }
@@ -31,10 +30,10 @@ export function computeSellingPrice(
31
30
  return Math.ceil(Math.floor(sellingPrice * 100) / 100)
32
31
  }
33
32
 
34
- export function computeMarginRate(
33
+ export const computeMarginRate = (
35
34
  buyingPrice: number | string,
36
35
  sellingPrice: number | string,
37
- ): number {
36
+ ): number => {
38
37
  const buyingPriceNum = Number(buyingPrice)
39
38
  const sellingPriceNum = Number(sellingPrice)
40
39
 
@@ -15,10 +15,10 @@ type Merge<T, S> = {
15
15
  : never
16
16
  }
17
17
 
18
- export function customMerge<T extends object, S extends object>(
18
+ export const customMerge = <T extends object, S extends object>(
19
19
  target: T,
20
20
  source: S,
21
- ): Merge<T, S> {
21
+ ): Merge<T, S> => {
22
22
  for (const key of Object.keys(source)) {
23
23
  const sourceValue = source[key as keyof S]
24
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Removes (shakes out) undefined entries from an
3
+ * object. Optional second argument shakes out values
4
+ * by custom evaluation.
5
+ */
6
+ export function shake<RemovedKeys extends string, T>(
7
+ obj: T,
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ filter: (value: any) => boolean = x => x === undefined,
10
+ ): Omit<T, RemovedKeys> {
11
+ if (!obj) {
12
+ return {} as T
13
+ }
14
+ const keys = Object.keys(obj) as (keyof T)[]
15
+ return keys.reduce((acc, key) => {
16
+ if (filter(obj[key])) {
17
+ return acc
18
+ }
19
+ acc[key] = obj[key]
20
+ return acc
21
+ }, {} as T)
22
+ }
@@ -1,6 +1,5 @@
1
- export function generatePseudoRandomString(length: number): string {
2
- return Array.from({ length }, () => Math.random().toString(36)[2]).join('')
3
- }
1
+ export const generatePseudoRandomString = (length: number): string =>
2
+ Array.from({ length }, () => Math.random().toString(36)[2]).join('')
4
3
 
5
4
  const TS_QUERY_SPECIAL_CHARS = new Set([
6
5
  '&',