@shushed/helpers 0.0.216 → 0.0.217
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.
|
@@ -338,17 +338,26 @@ function onResponse(config, options, requiredFlag) {
|
|
|
338
338
|
cacheMaxAge: 0,
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
|
-
function parsePrices(priceData, timeZone = 'UTC') {
|
|
341
|
+
function parsePrices(priceData, timeZone = 'UTC', options) {
|
|
342
342
|
const result = [];
|
|
343
343
|
const defaultStartDate = convertDateToDatetimeTZ(new Date(0).toISOString(), timeZone);
|
|
344
344
|
const defaultEndDate = convertDateToDatetimeTZ(new Date('2099-01-01T00:00:00Z').toISOString(), timeZone);
|
|
345
345
|
for (let i = 0; i < priceData.length; i += 1) {
|
|
346
|
-
const priceChanges = (priceData[i].price_changes || []).map(
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
346
|
+
const priceChanges = (priceData[i].price_changes || []).map((priceChange) => {
|
|
347
|
+
let x = priceChange;
|
|
348
|
+
if (options?.overridePrices) {
|
|
349
|
+
x = options.overridePrices(priceChange);
|
|
350
|
+
}
|
|
351
|
+
if (x !== null) {
|
|
352
|
+
return {
|
|
353
|
+
effective_from: x.effective_from ? (!isNaN(new Date(x.effective_from).getTime()) ? convertDateToDatetimeTZ(x.effective_from, timeZone) : null) : defaultStartDate,
|
|
354
|
+
effective_until: x.effective_until ? (!isNaN(new Date(x.effective_until).getTime()) ? convertDateToDatetimeTZ(x.effective_until, timeZone) : null) : defaultEndDate,
|
|
355
|
+
price: x.price,
|
|
356
|
+
price_type: x.price_type,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}).filter((x) => x !== null);
|
|
352
361
|
const rrpPriceTypes = parsePriceType(priceChanges.filter((x) => x.price_type === 'rrp'));
|
|
353
362
|
const permPriceTypes = parsePriceType(priceChanges.filter((x) => x.price_type === 'perm'));
|
|
354
363
|
const posPriceTypes = parsePriceType(priceChanges.filter((x) => x.price_type === 'pos'));
|
|
@@ -368,6 +377,7 @@ function parsePrices(priceData, timeZone = 'UTC') {
|
|
|
368
377
|
}
|
|
369
378
|
result.push({
|
|
370
379
|
...priceData[i],
|
|
380
|
+
...(options?.overrideCurrency ? { currency: options.overrideCurrency } : {}),
|
|
371
381
|
current_price: currentPrice,
|
|
372
382
|
current_price_type: currentPriceType,
|
|
373
383
|
rrp: rrpPriceTypes,
|
|
@@ -79,7 +79,10 @@ type NormPrice = {
|
|
|
79
79
|
price: number;
|
|
80
80
|
price_type: 'rrp' | 'perm' | 'pos';
|
|
81
81
|
};
|
|
82
|
-
export declare function parsePrices<T extends Price>(priceData: T[], timeZone?: string
|
|
82
|
+
export declare function parsePrices<T extends Price>(priceData: T[], timeZone?: string, options?: {
|
|
83
|
+
overrideCurrency?: string;
|
|
84
|
+
overridePrices?: (priceData: Exclude<T['price_changes'], undefined>[number]) => Exclude<Exclude<T['price_changes'], undefined>[number], undefined> | null;
|
|
85
|
+
}): (T & {
|
|
83
86
|
rrp: {
|
|
84
87
|
current: NormPrice | undefined;
|
|
85
88
|
future: NormPrice[];
|