@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 +15 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -25
- package/dist/index.d.ts +10 -25
- package/dist/index.js +15 -24
- package/dist/index.js.map +1 -1
- package/llms.md +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -502,9 +502,9 @@ declare class CalculationBuilder<K extends string = never> {
|
|
|
502
502
|
/** A muted line that isn't summed, such as tax included or a % difference. */
|
|
503
503
|
info<NK extends string | undefined>(key: NK, label: string, formula: string | null, options?: LineOptions): CalculationBuilder<K | Defined<NK>>;
|
|
504
504
|
/**
|
|
505
|
-
* A tiered charge: per band, a
|
|
506
|
-
*
|
|
507
|
-
*
|
|
505
|
+
* A tiered charge: a charge per band, then a subtotal keyed `key` that's
|
|
506
|
+
* checked against `value`. Band n's quantity is the formula
|
|
507
|
+
* `clamp(quantity - before_n, 0, size_n) * periods`.
|
|
508
508
|
*/
|
|
509
509
|
tiers<NK extends string | undefined>(key: NK, options: TiersOptions): CalculationBuilder<K | Defined<NK>>;
|
|
510
510
|
/** A percentage of other lines, such as a discount: `rate * sum(of)`. */
|
|
@@ -533,26 +533,21 @@ declare class CalculationBuilder<K extends string = never> {
|
|
|
533
533
|
/** Starts a calculation: inputs, then lines in display order. */
|
|
534
534
|
declare function calculation(key: string, options?: CalculationOptions): CalculationBuilder;
|
|
535
535
|
type CalculationLike = CalculationBuilder<string> | Calculation;
|
|
536
|
-
/**
|
|
536
|
+
/**
|
|
537
|
+
* The units Recount formats specially. Any other unit is free text, such as
|
|
538
|
+
* `'kWh'` or `'MJ'`, and is shown as given. A currency code (`'AUD'`) is
|
|
539
|
+
* formatted as money, and `'AUD/kWh'` as a money rate.
|
|
540
|
+
*/
|
|
537
541
|
declare const units: {
|
|
542
|
+
/** A fraction shown as a percentage: `0.03` is `3%`. */
|
|
538
543
|
readonly percent: "%";
|
|
544
|
+
/** Counts: singular at 1 ("1 day"), and per one in a rate ("$0.67/day"). */
|
|
539
545
|
readonly days: "days";
|
|
540
546
|
readonly months: "months";
|
|
541
547
|
readonly years: "years";
|
|
542
548
|
readonly hours: "hours";
|
|
543
|
-
readonly kWh: "kWh";
|
|
544
|
-
readonly MWh: "MWh";
|
|
545
|
-
readonly MJ: "MJ";
|
|
546
|
-
readonly GJ: "GJ";
|
|
547
|
-
readonly kW: "kW";
|
|
548
|
-
readonly kVA: "kVA";
|
|
549
|
-
readonly kWhPerYear: "kWh/yr";
|
|
550
|
-
readonly m2: "m²";
|
|
551
|
-
readonly panels: "panels";
|
|
552
549
|
/** A rate per something: `units.per('AUD', 'kWh')` is `'AUD/kWh'`. */
|
|
553
550
|
readonly per: (unit: string, per: string) => string;
|
|
554
|
-
/** `units.perDay('AUD')` is `'AUD/day'`. */
|
|
555
|
-
readonly perDay: (unit: string) => string;
|
|
556
551
|
};
|
|
557
552
|
|
|
558
553
|
declare class SpanGroup {
|
|
@@ -783,17 +778,7 @@ declare const recount: {
|
|
|
783
778
|
readonly months: "months";
|
|
784
779
|
readonly years: "years";
|
|
785
780
|
readonly hours: "hours";
|
|
786
|
-
readonly kWh: "kWh";
|
|
787
|
-
readonly MWh: "MWh";
|
|
788
|
-
readonly MJ: "MJ";
|
|
789
|
-
readonly GJ: "GJ";
|
|
790
|
-
readonly kW: "kW";
|
|
791
|
-
readonly kVA: "kVA";
|
|
792
|
-
readonly kWhPerYear: "kWh/yr";
|
|
793
|
-
readonly m2: "m²";
|
|
794
|
-
readonly panels: "panels";
|
|
795
781
|
readonly per: (unit: string, per: string) => string;
|
|
796
|
-
readonly perDay: (unit: string) => string;
|
|
797
782
|
};
|
|
798
783
|
REDACTED: {
|
|
799
784
|
readonly __redacted: true;
|
package/dist/index.d.ts
CHANGED
|
@@ -502,9 +502,9 @@ declare class CalculationBuilder<K extends string = never> {
|
|
|
502
502
|
/** A muted line that isn't summed, such as tax included or a % difference. */
|
|
503
503
|
info<NK extends string | undefined>(key: NK, label: string, formula: string | null, options?: LineOptions): CalculationBuilder<K | Defined<NK>>;
|
|
504
504
|
/**
|
|
505
|
-
* A tiered charge: per band, a
|
|
506
|
-
*
|
|
507
|
-
*
|
|
505
|
+
* A tiered charge: a charge per band, then a subtotal keyed `key` that's
|
|
506
|
+
* checked against `value`. Band n's quantity is the formula
|
|
507
|
+
* `clamp(quantity - before_n, 0, size_n) * periods`.
|
|
508
508
|
*/
|
|
509
509
|
tiers<NK extends string | undefined>(key: NK, options: TiersOptions): CalculationBuilder<K | Defined<NK>>;
|
|
510
510
|
/** A percentage of other lines, such as a discount: `rate * sum(of)`. */
|
|
@@ -533,26 +533,21 @@ declare class CalculationBuilder<K extends string = never> {
|
|
|
533
533
|
/** Starts a calculation: inputs, then lines in display order. */
|
|
534
534
|
declare function calculation(key: string, options?: CalculationOptions): CalculationBuilder;
|
|
535
535
|
type CalculationLike = CalculationBuilder<string> | Calculation;
|
|
536
|
-
/**
|
|
536
|
+
/**
|
|
537
|
+
* The units Recount formats specially. Any other unit is free text, such as
|
|
538
|
+
* `'kWh'` or `'MJ'`, and is shown as given. A currency code (`'AUD'`) is
|
|
539
|
+
* formatted as money, and `'AUD/kWh'` as a money rate.
|
|
540
|
+
*/
|
|
537
541
|
declare const units: {
|
|
542
|
+
/** A fraction shown as a percentage: `0.03` is `3%`. */
|
|
538
543
|
readonly percent: "%";
|
|
544
|
+
/** Counts: singular at 1 ("1 day"), and per one in a rate ("$0.67/day"). */
|
|
539
545
|
readonly days: "days";
|
|
540
546
|
readonly months: "months";
|
|
541
547
|
readonly years: "years";
|
|
542
548
|
readonly hours: "hours";
|
|
543
|
-
readonly kWh: "kWh";
|
|
544
|
-
readonly MWh: "MWh";
|
|
545
|
-
readonly MJ: "MJ";
|
|
546
|
-
readonly GJ: "GJ";
|
|
547
|
-
readonly kW: "kW";
|
|
548
|
-
readonly kVA: "kVA";
|
|
549
|
-
readonly kWhPerYear: "kWh/yr";
|
|
550
|
-
readonly m2: "m²";
|
|
551
|
-
readonly panels: "panels";
|
|
552
549
|
/** A rate per something: `units.per('AUD', 'kWh')` is `'AUD/kWh'`. */
|
|
553
550
|
readonly per: (unit: string, per: string) => string;
|
|
554
|
-
/** `units.perDay('AUD')` is `'AUD/day'`. */
|
|
555
|
-
readonly perDay: (unit: string) => string;
|
|
556
551
|
};
|
|
557
552
|
|
|
558
553
|
declare class SpanGroup {
|
|
@@ -783,17 +778,7 @@ declare const recount: {
|
|
|
783
778
|
readonly months: "months";
|
|
784
779
|
readonly years: "years";
|
|
785
780
|
readonly hours: "hours";
|
|
786
|
-
readonly kWh: "kWh";
|
|
787
|
-
readonly MWh: "MWh";
|
|
788
|
-
readonly MJ: "MJ";
|
|
789
|
-
readonly GJ: "GJ";
|
|
790
|
-
readonly kW: "kW";
|
|
791
|
-
readonly kVA: "kVA";
|
|
792
|
-
readonly kWhPerYear: "kWh/yr";
|
|
793
|
-
readonly m2: "m²";
|
|
794
|
-
readonly panels: "panels";
|
|
795
781
|
readonly per: (unit: string, per: string) => string;
|
|
796
|
-
readonly perDay: (unit: string) => string;
|
|
797
782
|
};
|
|
798
783
|
REDACTED: {
|
|
799
784
|
readonly __redacted: true;
|
package/dist/index.js
CHANGED
|
@@ -461,9 +461,9 @@ var CalculationBuilder = class {
|
|
|
461
461
|
return __privateMethod(this, _CalculationBuilder_instances, kindLine_fn).call(this, "info", key, label, formula, options);
|
|
462
462
|
}
|
|
463
463
|
/**
|
|
464
|
-
* A tiered charge: per band, a
|
|
465
|
-
*
|
|
466
|
-
*
|
|
464
|
+
* A tiered charge: a charge per band, then a subtotal keyed `key` that's
|
|
465
|
+
* checked against `value`. Band n's quantity is the formula
|
|
466
|
+
* `clamp(quantity - before_n, 0, size_n) * periods`.
|
|
467
467
|
*/
|
|
468
468
|
tiers(key, options) {
|
|
469
469
|
return __privateMethod(this, _CalculationBuilder_instances, push_fn).call(this, { type: "tiers", key, options });
|
|
@@ -877,19 +877,19 @@ function addTiers(s, rawKey, options) {
|
|
|
877
877
|
const formula = p === void 0 || p === 1 || p === "1" ? amount : `${amount} * ${operandText(p)}`;
|
|
878
878
|
const range = size === null ? before === "0" ? `all${unitText}${perText}` : `over ${before}${unitText}${perText}` : i === 0 ? `first ${size}${unitText}${perText}` : `next ${size}${unitText}${perText}`;
|
|
879
879
|
const bandLabel = band?.label ?? `${base} tier ${n} (${range})`;
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
880
|
+
const bandKey = `${key}_${n}`;
|
|
881
|
+
const tooLong = formula.length > MAX_FORMULA;
|
|
882
|
+
if (tooLong) {
|
|
883
|
+
s.problems.push(
|
|
884
|
+
`${s.calcKey}.${bandKey}: quantity: the formula is ${formula.length} characters, over ${MAX_FORMULA}; the band isn't calculated`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
887
|
charges.push(
|
|
888
888
|
addLine(s, {
|
|
889
|
-
key:
|
|
889
|
+
key: bandKey,
|
|
890
890
|
label: bandLabel,
|
|
891
891
|
kind: "charge",
|
|
892
|
-
quantity:
|
|
892
|
+
quantity: tooLong ? null : formula,
|
|
893
893
|
rate: band?.rate,
|
|
894
894
|
options: {
|
|
895
895
|
...band?.value !== void 0 && { value: band.value },
|
|
@@ -1405,24 +1405,15 @@ function fromPlain(calc) {
|
|
|
1405
1405
|
return b;
|
|
1406
1406
|
}
|
|
1407
1407
|
var units = {
|
|
1408
|
+
/** A fraction shown as a percentage: `0.03` is `3%`. */
|
|
1408
1409
|
percent: "%",
|
|
1410
|
+
/** Counts: singular at 1 ("1 day"), and per one in a rate ("$0.67/day"). */
|
|
1409
1411
|
days: "days",
|
|
1410
1412
|
months: "months",
|
|
1411
1413
|
years: "years",
|
|
1412
1414
|
hours: "hours",
|
|
1413
|
-
kWh: "kWh",
|
|
1414
|
-
MWh: "MWh",
|
|
1415
|
-
MJ: "MJ",
|
|
1416
|
-
GJ: "GJ",
|
|
1417
|
-
kW: "kW",
|
|
1418
|
-
kVA: "kVA",
|
|
1419
|
-
kWhPerYear: "kWh/yr",
|
|
1420
|
-
m2: "m\xB2",
|
|
1421
|
-
panels: "panels",
|
|
1422
1415
|
/** A rate per something: `units.per('AUD', 'kWh')` is `'AUD/kWh'`. */
|
|
1423
|
-
per: (unit, per) => `${unit}/${per}
|
|
1424
|
-
/** `units.perDay('AUD')` is `'AUD/day'`. */
|
|
1425
|
-
perDay: (unit) => `${unit}/day`
|
|
1416
|
+
per: (unit, per) => `${unit}/${per}`
|
|
1426
1417
|
};
|
|
1427
1418
|
|
|
1428
1419
|
// src/trace.ts
|