@escapenavigator/utils 1.10.153 → 1.10.154

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.
@@ -3,6 +3,11 @@ type SlotPriceSource = {
3
3
  basePrice?: number;
4
4
  discount?: number;
5
5
  };
6
+ /**
7
+ * Плоская карта цен из тарифа слота.
8
+ * Принимает и `{ id, price: { "2": 1500 } }` (листинг), и `{ "2": 1500 }` (/slots/details).
9
+ */
10
+ export declare const getTariffPriceMap: (tariff: unknown) => Record<string, number>;
6
11
  /** Минимальная положительная цена из тарифа (без скидки слота). */
7
12
  export declare const getTariffBasePrice: (tariff: unknown) => number | null;
8
13
  /** Цена «от» для слота в расписании (с учётом скидки слота). */
@@ -1,20 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSlotRepresentativePrice = exports.getTariffBasePrice = void 0;
3
+ exports.getSlotRepresentativePrice = exports.getTariffBasePrice = exports.getTariffPriceMap = void 0;
4
4
  const applySlotDiscount = (base, discount) => {
5
5
  const value = discount || 0;
6
6
  if (!value)
7
7
  return base;
8
8
  return base - Math.floor((base / 10000) * value);
9
9
  };
10
- /** Минимальная положительная цена из тарифа (без скидки слота). */
11
- const getTariffBasePrice = (tariff) => {
10
+ /**
11
+ * Плоская карта цен из тарифа слота.
12
+ * Принимает и `{ id, price: { "2": 1500 } }` (листинг), и `{ "2": 1500 }` (/slots/details).
13
+ */
14
+ const getTariffPriceMap = (tariff) => {
12
15
  if (!tariff || typeof tariff !== 'object')
13
- return null;
16
+ return {};
14
17
  const raw = tariff;
15
- const priceMap = raw.price && typeof raw.price === 'object' && raw.price !== null
16
- ? raw.price
17
- : raw;
18
+ if (raw.price && typeof raw.price === 'object' && raw.price !== null) {
19
+ return raw.price;
20
+ }
21
+ return raw;
22
+ };
23
+ exports.getTariffPriceMap = getTariffPriceMap;
24
+ /** Минимальная положительная цена из тарифа (без скидки слота). */
25
+ const getTariffBasePrice = (tariff) => {
26
+ const priceMap = (0, exports.getTariffPriceMap)(tariff);
18
27
  const keys = Object.keys(priceMap)
19
28
  .filter((k) => k !== 'child' && !Number.isNaN(Number(k)))
20
29
  .map(Number)
@@ -2,6 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const slot_representative_price_1 = require("./slot-representative-price");
4
4
  describe('slot-representative-price', () => {
5
+ it('unwraps nested tariff.price map', () => {
6
+ expect((0, slot_representative_price_1.getTariffPriceMap)({
7
+ id: 1,
8
+ price: { 2: 10000, 3: 8000 },
9
+ })).toEqual({ 2: 10000, 3: 8000 });
10
+ });
11
+ it('returns plain price map as-is', () => {
12
+ expect((0, slot_representative_price_1.getTariffPriceMap)({ 2: 5000, 4: 4000 })).toEqual({ 2: 5000, 4: 4000 });
13
+ });
5
14
  it('reads price from tariff.price map', () => {
6
15
  expect((0, slot_representative_price_1.getTariffBasePrice)({
7
16
  id: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "1.10.153",
3
+ "version": "1.10.154",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -28,5 +28,5 @@
28
28
  "ts-jest": "^29.1.1",
29
29
  "typescript": "^5.6"
30
30
  },
31
- "gitHead": "141d0c0d4b5a5bbf13f481696d604cb4953a8bdb"
31
+ "gitHead": "8ac9c90c5d3971794408544fc837167b6495d246"
32
32
  }