@refactorlabs/recount 0.10.0 → 0.11.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.
package/dist/index.cjs CHANGED
@@ -474,9 +474,9 @@ var CalculationBuilder = class {
474
474
  return __privateMethod(this, _CalculationBuilder_instances, kindLine_fn).call(this, "info", key, label, formula, options);
475
475
  }
476
476
  /**
477
- * A tiered charge: per band, a working line for its quantity and a
478
- * charge, then a subtotal keyed `key` that's checked against `value`.
479
- * Band n's quantity is `clamp(quantity - before_n, 0, size_n) * periods`.
477
+ * A tiered charge: a charge per band, then a subtotal keyed `key` that's
478
+ * checked against `value`. Band n's quantity is the formula
479
+ * `clamp(quantity - before_n, 0, size_n) * periods`.
480
480
  */
481
481
  tiers(key, options) {
482
482
  return __privateMethod(this, _CalculationBuilder_instances, push_fn).call(this, { type: "tiers", key, options });
@@ -890,19 +890,19 @@ function addTiers(s, rawKey, options) {
890
890
  const formula = p === void 0 || p === 1 || p === "1" ? amount : `${amount} * ${operandText(p)}`;
891
891
  const range = size === null ? before === "0" ? `all${unitText}${perText}` : `over ${before}${unitText}${perText}` : i === 0 ? `first ${size}${unitText}${perText}` : `next ${size}${unitText}${perText}`;
892
892
  const bandLabel = band?.label ?? `${base} tier ${n} (${range})`;
893
- const qtyKey = addLine(s, {
894
- key: `${key}_${n}_qty`,
895
- label: `${base} tier ${n} quantity`,
896
- kind: "working",
897
- formula,
898
- options: { ...unit !== void 0 && { unit } }
899
- });
893
+ const bandKey = `${key}_${n}`;
894
+ const tooLong = formula.length > MAX_FORMULA;
895
+ if (tooLong) {
896
+ s.problems.push(
897
+ `${s.calcKey}.${bandKey}: quantity: the formula is ${formula.length} characters, over ${MAX_FORMULA}; the band isn't calculated`
898
+ );
899
+ }
900
900
  charges.push(
901
901
  addLine(s, {
902
- key: `${key}_${n}`,
902
+ key: bandKey,
903
903
  label: bandLabel,
904
904
  kind: "charge",
905
- quantity: qtyKey,
905
+ quantity: tooLong ? null : formula,
906
906
  rate: band?.rate,
907
907
  options: {
908
908
  ...band?.value !== void 0 && { value: band.value },
@@ -1418,24 +1418,15 @@ function fromPlain(calc) {
1418
1418
  return b;
1419
1419
  }
1420
1420
  var units = {
1421
+ /** A fraction shown as a percentage: `0.03` is `3%`. */
1421
1422
  percent: "%",
1423
+ /** Counts: singular at 1 ("1 day"), and per one in a rate ("$0.67/day"). */
1422
1424
  days: "days",
1423
1425
  months: "months",
1424
1426
  years: "years",
1425
1427
  hours: "hours",
1426
- kWh: "kWh",
1427
- MWh: "MWh",
1428
- MJ: "MJ",
1429
- GJ: "GJ",
1430
- kW: "kW",
1431
- kVA: "kVA",
1432
- kWhPerYear: "kWh/yr",
1433
- m2: "m\xB2",
1434
- panels: "panels",
1435
1428
  /** A rate per something: `units.per('AUD', 'kWh')` is `'AUD/kWh'`. */
1436
- per: (unit, per) => `${unit}/${per}`,
1437
- /** `units.perDay('AUD')` is `'AUD/day'`. */
1438
- perDay: (unit) => `${unit}/day`
1429
+ per: (unit, per) => `${unit}/${per}`
1439
1430
  };
1440
1431
 
1441
1432
  // src/trace.ts