@utilix-tech/sdk 0.21.0 → 0.23.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.
@@ -6,6 +6,7 @@
6
6
  * - date-diff : parseDate, humanizeDiff, diffDates, COMMON_DATE_PRESETS
7
7
  * - timezone : TIMEZONES, getTimezoneOffset, convertTime, formatInTimezone, getAllZonesForTime
8
8
  * - cron-next : parseCronExpression, getNextRuns, formatRunDate, getRunInterval
9
+ * - iso8601-duration : parseIso8601Duration, formatIso8601Duration
9
10
  */
10
11
  interface TimestampResult {
11
12
  unix: number;
@@ -111,6 +112,47 @@ declare function getNextRuns(expr: string, count?: number, fromDate?: Date): Dat
111
112
  };
112
113
  declare function formatRunDate(date: Date, timezone?: string): string;
113
114
  declare function getRunInterval(dates: Date[]): string;
115
+ interface DurationParseResult {
116
+ input: string;
117
+ years: number;
118
+ months: number;
119
+ weeks: number;
120
+ days: number;
121
+ hours: number;
122
+ minutes: number;
123
+ seconds: number;
124
+ totalSeconds: number;
125
+ approximate: boolean;
126
+ human: string;
127
+ }
128
+ interface DurationFormatResult {
129
+ seconds: number;
130
+ iso: string;
131
+ days: number;
132
+ hours: number;
133
+ minutes: number;
134
+ human: string;
135
+ }
136
+ /**
137
+ * Parse an ISO 8601 duration string (e.g. "P3DT4H30M", "PT1H", "P1Y6M") into
138
+ * its individual components plus a total number of seconds. Years and months
139
+ * have no fixed length, so when either is present `totalSeconds` uses nominal
140
+ * conversions (1 year = 365 days, 1 month = 30 days) and `approximate` is set
141
+ * to true. Weeks, days, hours, minutes, and seconds are exact. Fractional
142
+ * seconds are supported.
143
+ */
144
+ declare function parseIso8601Duration(input: string): DurationParseResult | {
145
+ error: string;
146
+ };
147
+ /**
148
+ * Format a non-negative number of seconds into a canonical ISO 8601 duration
149
+ * string. The output uses only days, hours, minutes, and seconds (never years
150
+ * or months, which have no fixed length), e.g. 90061 -> "P1DT1H1M1S". Zero is
151
+ * rendered as "PT0S". Fractional seconds are preserved.
152
+ */
153
+ declare function formatIso8601Duration(seconds: number): DurationFormatResult | {
154
+ error: string;
155
+ };
114
156
 
115
157
  declare const time_COMMON_CRONS: typeof COMMON_CRONS;
116
158
  declare const time_COMMON_DATE_PRESETS: typeof COMMON_DATE_PRESETS;
@@ -118,6 +160,8 @@ type time_CronField = CronField;
118
160
  type time_CronNextField = CronNextField;
119
161
  type time_CronResult = CronResult;
120
162
  type time_DateDiffResult = DateDiffResult;
163
+ type time_DurationFormatResult = DurationFormatResult;
164
+ type time_DurationParseResult = DurationParseResult;
121
165
  type time_ParsedCron = ParsedCron;
122
166
  declare const time_TIMEZONES: typeof TIMEZONES;
123
167
  type time_TimestampResult = TimestampResult;
@@ -125,6 +169,7 @@ type time_TimezoneEntry = TimezoneEntry;
125
169
  declare const time_convertTime: typeof convertTime;
126
170
  declare const time_diffDates: typeof diffDates;
127
171
  declare const time_formatInTimezone: typeof formatInTimezone;
172
+ declare const time_formatIso8601Duration: typeof formatIso8601Duration;
128
173
  declare const time_formatRelative: typeof formatRelative;
129
174
  declare const time_formatRunDate: typeof formatRunDate;
130
175
  declare const time_fromIsoString: typeof fromIsoString;
@@ -138,8 +183,9 @@ declare const time_humanizeDiff: typeof humanizeDiff;
138
183
  declare const time_parseCron: typeof parseCron;
139
184
  declare const time_parseCronExpression: typeof parseCronExpression;
140
185
  declare const time_parseDate: typeof parseDate;
186
+ declare const time_parseIso8601Duration: typeof parseIso8601Duration;
141
187
  declare namespace time {
142
- export { time_COMMON_CRONS as COMMON_CRONS, time_COMMON_DATE_PRESETS as COMMON_DATE_PRESETS, type time_CronField as CronField, type time_CronNextField as CronNextField, type time_CronResult as CronResult, type time_DateDiffResult as DateDiffResult, type time_ParsedCron as ParsedCron, time_TIMEZONES as TIMEZONES, type time_TimestampResult as TimestampResult, type time_TimezoneEntry as TimezoneEntry, time_convertTime as convertTime, time_diffDates as diffDates, time_formatInTimezone as formatInTimezone, time_formatRelative as formatRelative, time_formatRunDate as formatRunDate, time_fromIsoString as fromIsoString, time_fromUnix as fromUnix, time_getAllZonesForTime as getAllZonesForTime, time_getNextRuns as getNextRuns, time_getNow as getNow, time_getRunInterval as getRunInterval, time_getTimezoneOffset as getTimezoneOffset, time_humanizeDiff as humanizeDiff, time_parseCron as parseCron, time_parseCronExpression as parseCronExpression, time_parseDate as parseDate };
188
+ export { time_COMMON_CRONS as COMMON_CRONS, time_COMMON_DATE_PRESETS as COMMON_DATE_PRESETS, type time_CronField as CronField, type time_CronNextField as CronNextField, type time_CronResult as CronResult, type time_DateDiffResult as DateDiffResult, type time_DurationFormatResult as DurationFormatResult, type time_DurationParseResult as DurationParseResult, type time_ParsedCron as ParsedCron, time_TIMEZONES as TIMEZONES, type time_TimestampResult as TimestampResult, type time_TimezoneEntry as TimezoneEntry, time_convertTime as convertTime, time_diffDates as diffDates, time_formatInTimezone as formatInTimezone, time_formatIso8601Duration as formatIso8601Duration, time_formatRelative as formatRelative, time_formatRunDate as formatRunDate, time_fromIsoString as fromIsoString, time_fromUnix as fromUnix, time_getAllZonesForTime as getAllZonesForTime, time_getNextRuns as getNextRuns, time_getNow as getNow, time_getRunInterval as getRunInterval, time_getTimezoneOffset as getTimezoneOffset, time_humanizeDiff as humanizeDiff, time_parseCron as parseCron, time_parseCronExpression as parseCronExpression, time_parseDate as parseDate, time_parseIso8601Duration as parseIso8601Duration };
143
189
  }
144
190
 
145
- export { COMMON_CRONS as C, type DateDiffResult as D, type ParsedCron as P, TIMEZONES as T, COMMON_DATE_PRESETS as a, type CronField as b, type CronNextField as c, type CronResult as d, type TimestampResult as e, type TimezoneEntry as f, convertTime as g, diffDates as h, formatInTimezone as i, formatRelative as j, formatRunDate as k, fromIsoString as l, fromUnix as m, getAllZonesForTime as n, getNextRuns as o, getNow as p, getRunInterval as q, getTimezoneOffset as r, humanizeDiff as s, time as t, parseCron as u, parseCronExpression as v, parseDate as w };
191
+ export { parseIso8601Duration as A, COMMON_CRONS as C, type DateDiffResult as D, type ParsedCron as P, TIMEZONES as T, COMMON_DATE_PRESETS as a, type CronField as b, type CronNextField as c, type CronResult as d, type DurationFormatResult as e, type DurationParseResult as f, type TimestampResult as g, type TimezoneEntry as h, convertTime as i, diffDates as j, formatInTimezone as k, formatIso8601Duration as l, formatRelative as m, formatRunDate as n, fromIsoString as o, fromUnix as p, getAllZonesForTime as q, getNextRuns as r, getNow as s, time as t, getRunInterval as u, getTimezoneOffset as v, humanizeDiff as w, parseCron as x, parseCronExpression as y, parseDate as z };
@@ -6,6 +6,7 @@
6
6
  * - date-diff : parseDate, humanizeDiff, diffDates, COMMON_DATE_PRESETS
7
7
  * - timezone : TIMEZONES, getTimezoneOffset, convertTime, formatInTimezone, getAllZonesForTime
8
8
  * - cron-next : parseCronExpression, getNextRuns, formatRunDate, getRunInterval
9
+ * - iso8601-duration : parseIso8601Duration, formatIso8601Duration
9
10
  */
10
11
  interface TimestampResult {
11
12
  unix: number;
@@ -111,6 +112,47 @@ declare function getNextRuns(expr: string, count?: number, fromDate?: Date): Dat
111
112
  };
112
113
  declare function formatRunDate(date: Date, timezone?: string): string;
113
114
  declare function getRunInterval(dates: Date[]): string;
115
+ interface DurationParseResult {
116
+ input: string;
117
+ years: number;
118
+ months: number;
119
+ weeks: number;
120
+ days: number;
121
+ hours: number;
122
+ minutes: number;
123
+ seconds: number;
124
+ totalSeconds: number;
125
+ approximate: boolean;
126
+ human: string;
127
+ }
128
+ interface DurationFormatResult {
129
+ seconds: number;
130
+ iso: string;
131
+ days: number;
132
+ hours: number;
133
+ minutes: number;
134
+ human: string;
135
+ }
136
+ /**
137
+ * Parse an ISO 8601 duration string (e.g. "P3DT4H30M", "PT1H", "P1Y6M") into
138
+ * its individual components plus a total number of seconds. Years and months
139
+ * have no fixed length, so when either is present `totalSeconds` uses nominal
140
+ * conversions (1 year = 365 days, 1 month = 30 days) and `approximate` is set
141
+ * to true. Weeks, days, hours, minutes, and seconds are exact. Fractional
142
+ * seconds are supported.
143
+ */
144
+ declare function parseIso8601Duration(input: string): DurationParseResult | {
145
+ error: string;
146
+ };
147
+ /**
148
+ * Format a non-negative number of seconds into a canonical ISO 8601 duration
149
+ * string. The output uses only days, hours, minutes, and seconds (never years
150
+ * or months, which have no fixed length), e.g. 90061 -> "P1DT1H1M1S". Zero is
151
+ * rendered as "PT0S". Fractional seconds are preserved.
152
+ */
153
+ declare function formatIso8601Duration(seconds: number): DurationFormatResult | {
154
+ error: string;
155
+ };
114
156
 
115
157
  declare const time_COMMON_CRONS: typeof COMMON_CRONS;
116
158
  declare const time_COMMON_DATE_PRESETS: typeof COMMON_DATE_PRESETS;
@@ -118,6 +160,8 @@ type time_CronField = CronField;
118
160
  type time_CronNextField = CronNextField;
119
161
  type time_CronResult = CronResult;
120
162
  type time_DateDiffResult = DateDiffResult;
163
+ type time_DurationFormatResult = DurationFormatResult;
164
+ type time_DurationParseResult = DurationParseResult;
121
165
  type time_ParsedCron = ParsedCron;
122
166
  declare const time_TIMEZONES: typeof TIMEZONES;
123
167
  type time_TimestampResult = TimestampResult;
@@ -125,6 +169,7 @@ type time_TimezoneEntry = TimezoneEntry;
125
169
  declare const time_convertTime: typeof convertTime;
126
170
  declare const time_diffDates: typeof diffDates;
127
171
  declare const time_formatInTimezone: typeof formatInTimezone;
172
+ declare const time_formatIso8601Duration: typeof formatIso8601Duration;
128
173
  declare const time_formatRelative: typeof formatRelative;
129
174
  declare const time_formatRunDate: typeof formatRunDate;
130
175
  declare const time_fromIsoString: typeof fromIsoString;
@@ -138,8 +183,9 @@ declare const time_humanizeDiff: typeof humanizeDiff;
138
183
  declare const time_parseCron: typeof parseCron;
139
184
  declare const time_parseCronExpression: typeof parseCronExpression;
140
185
  declare const time_parseDate: typeof parseDate;
186
+ declare const time_parseIso8601Duration: typeof parseIso8601Duration;
141
187
  declare namespace time {
142
- export { time_COMMON_CRONS as COMMON_CRONS, time_COMMON_DATE_PRESETS as COMMON_DATE_PRESETS, type time_CronField as CronField, type time_CronNextField as CronNextField, type time_CronResult as CronResult, type time_DateDiffResult as DateDiffResult, type time_ParsedCron as ParsedCron, time_TIMEZONES as TIMEZONES, type time_TimestampResult as TimestampResult, type time_TimezoneEntry as TimezoneEntry, time_convertTime as convertTime, time_diffDates as diffDates, time_formatInTimezone as formatInTimezone, time_formatRelative as formatRelative, time_formatRunDate as formatRunDate, time_fromIsoString as fromIsoString, time_fromUnix as fromUnix, time_getAllZonesForTime as getAllZonesForTime, time_getNextRuns as getNextRuns, time_getNow as getNow, time_getRunInterval as getRunInterval, time_getTimezoneOffset as getTimezoneOffset, time_humanizeDiff as humanizeDiff, time_parseCron as parseCron, time_parseCronExpression as parseCronExpression, time_parseDate as parseDate };
188
+ export { time_COMMON_CRONS as COMMON_CRONS, time_COMMON_DATE_PRESETS as COMMON_DATE_PRESETS, type time_CronField as CronField, type time_CronNextField as CronNextField, type time_CronResult as CronResult, type time_DateDiffResult as DateDiffResult, type time_DurationFormatResult as DurationFormatResult, type time_DurationParseResult as DurationParseResult, type time_ParsedCron as ParsedCron, time_TIMEZONES as TIMEZONES, type time_TimestampResult as TimestampResult, type time_TimezoneEntry as TimezoneEntry, time_convertTime as convertTime, time_diffDates as diffDates, time_formatInTimezone as formatInTimezone, time_formatIso8601Duration as formatIso8601Duration, time_formatRelative as formatRelative, time_formatRunDate as formatRunDate, time_fromIsoString as fromIsoString, time_fromUnix as fromUnix, time_getAllZonesForTime as getAllZonesForTime, time_getNextRuns as getNextRuns, time_getNow as getNow, time_getRunInterval as getRunInterval, time_getTimezoneOffset as getTimezoneOffset, time_humanizeDiff as humanizeDiff, time_parseCron as parseCron, time_parseCronExpression as parseCronExpression, time_parseDate as parseDate, time_parseIso8601Duration as parseIso8601Duration };
143
189
  }
144
190
 
145
- export { COMMON_CRONS as C, type DateDiffResult as D, type ParsedCron as P, TIMEZONES as T, COMMON_DATE_PRESETS as a, type CronField as b, type CronNextField as c, type CronResult as d, type TimestampResult as e, type TimezoneEntry as f, convertTime as g, diffDates as h, formatInTimezone as i, formatRelative as j, formatRunDate as k, fromIsoString as l, fromUnix as m, getAllZonesForTime as n, getNextRuns as o, getNow as p, getRunInterval as q, getTimezoneOffset as r, humanizeDiff as s, time as t, parseCron as u, parseCronExpression as v, parseDate as w };
191
+ export { parseIso8601Duration as A, COMMON_CRONS as C, type DateDiffResult as D, type ParsedCron as P, TIMEZONES as T, COMMON_DATE_PRESETS as a, type CronField as b, type CronNextField as c, type CronResult as d, type DurationFormatResult as e, type DurationParseResult as f, type TimestampResult as g, type TimezoneEntry as h, convertTime as i, diffDates as j, formatInTimezone as k, formatIso8601Duration as l, formatRelative as m, formatRunDate as n, fromIsoString as o, fromUnix as p, getAllZonesForTime as q, getNextRuns as r, getNow as s, time as t, getRunInterval as u, getTimezoneOffset as v, humanizeDiff as w, parseCron as x, parseCronExpression as y, parseDate as z };
@@ -659,6 +659,97 @@ function getRunInterval(dates) {
659
659
  const days = Math.round(diffMins / 1440);
660
660
  return `Every ${days} days`;
661
661
  }
662
+ var DURATION_SECONDS_PER_YEAR = 365 * 86400;
663
+ var DURATION_SECONDS_PER_MONTH = 30 * 86400;
664
+ function humanizeDurationParts(parts) {
665
+ const pieces = [];
666
+ for (const [value, label] of parts) {
667
+ if (value === 0) continue;
668
+ pieces.push(`${value} ${label}${value === 1 ? "" : "s"}`);
669
+ }
670
+ return pieces.length > 0 ? pieces.join(", ") : "0 seconds";
671
+ }
672
+ function parseIso8601Duration(input) {
673
+ if (typeof input !== "string") return { error: "Duration must be a string" };
674
+ const trimmed = input.trim();
675
+ if (trimmed.length === 0) return { error: "Duration is empty" };
676
+ const match = trimmed.match(
677
+ /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/
678
+ );
679
+ if (!match) {
680
+ return { error: 'Not a valid ISO 8601 duration (expected a form like "P3DT4H30M")' };
681
+ }
682
+ const years = match[1] ? parseInt(match[1], 10) : 0;
683
+ const months = match[2] ? parseInt(match[2], 10) : 0;
684
+ const weeks = match[3] ? parseInt(match[3], 10) : 0;
685
+ const days = match[4] ? parseInt(match[4], 10) : 0;
686
+ const hours = match[5] ? parseInt(match[5], 10) : 0;
687
+ const minutes = match[6] ? parseInt(match[6], 10) : 0;
688
+ const seconds = match[7] ? parseFloat(match[7]) : 0;
689
+ if (years + months + weeks + days + hours + minutes + seconds === 0) {
690
+ return { error: 'Duration has no components (a bare "P" or "PT" is not valid)' };
691
+ }
692
+ const approximate = years > 0 || months > 0;
693
+ const totalSeconds = years * DURATION_SECONDS_PER_YEAR + months * DURATION_SECONDS_PER_MONTH + weeks * 7 * 86400 + days * 86400 + hours * 3600 + minutes * 60 + seconds;
694
+ const human = humanizeDurationParts([
695
+ [years, "year"],
696
+ [months, "month"],
697
+ [weeks, "week"],
698
+ [days, "day"],
699
+ [hours, "hour"],
700
+ [minutes, "minute"],
701
+ [seconds, "second"]
702
+ ]);
703
+ return {
704
+ input: trimmed,
705
+ years,
706
+ months,
707
+ weeks,
708
+ days,
709
+ hours,
710
+ minutes,
711
+ seconds,
712
+ totalSeconds: Math.round(totalSeconds * 1e6) / 1e6,
713
+ approximate,
714
+ human
715
+ };
716
+ }
717
+ function formatIso8601Duration(seconds) {
718
+ if (typeof seconds !== "number" || !Number.isFinite(seconds) || seconds < 0) {
719
+ return { error: "Seconds must be zero or a positive number" };
720
+ }
721
+ const totalDays = Math.floor(seconds / 86400);
722
+ let rem = seconds - totalDays * 86400;
723
+ const hours = Math.floor(rem / 3600);
724
+ rem -= hours * 3600;
725
+ const minutes = Math.floor(rem / 60);
726
+ let secs = rem - minutes * 60;
727
+ secs = Math.round(secs * 1e6) / 1e6;
728
+ let iso = "P";
729
+ if (totalDays > 0) iso += `${totalDays}D`;
730
+ const hasTime = hours > 0 || minutes > 0 || secs > 0;
731
+ if (hasTime) {
732
+ iso += "T";
733
+ if (hours > 0) iso += `${hours}H`;
734
+ if (minutes > 0) iso += `${minutes}M`;
735
+ if (secs > 0) iso += `${secs}S`;
736
+ }
737
+ if (iso === "P") iso = "PT0S";
738
+ const human = humanizeDurationParts([
739
+ [totalDays, "day"],
740
+ [hours, "hour"],
741
+ [minutes, "minute"],
742
+ [secs, "second"]
743
+ ]);
744
+ return {
745
+ seconds,
746
+ iso,
747
+ days: totalDays,
748
+ hours,
749
+ minutes,
750
+ human
751
+ };
752
+ }
662
753
 
663
754
  exports.COMMON_CRONS = COMMON_CRONS;
664
755
  exports.COMMON_DATE_PRESETS = COMMON_DATE_PRESETS;
@@ -666,6 +757,7 @@ exports.TIMEZONES = TIMEZONES;
666
757
  exports.convertTime = convertTime;
667
758
  exports.diffDates = diffDates;
668
759
  exports.formatInTimezone = formatInTimezone;
760
+ exports.formatIso8601Duration = formatIso8601Duration;
669
761
  exports.formatRelative = formatRelative;
670
762
  exports.formatRunDate = formatRunDate;
671
763
  exports.fromIsoString = fromIsoString;
@@ -679,3 +771,4 @@ exports.humanizeDiff = humanizeDiff;
679
771
  exports.parseCron = parseCron;
680
772
  exports.parseCronExpression = parseCronExpression;
681
773
  exports.parseDate = parseDate;
774
+ exports.parseIso8601Duration = parseIso8601Duration;
@@ -1 +1 @@
1
- export { C as COMMON_CRONS, a as COMMON_DATE_PRESETS, b as CronField, c as CronNextField, d as CronResult, D as DateDiffResult, P as ParsedCron, T as TIMEZONES, e as TimestampResult, f as TimezoneEntry, g as convertTime, h as diffDates, i as formatInTimezone, j as formatRelative, k as formatRunDate, l as fromIsoString, m as fromUnix, n as getAllZonesForTime, o as getNextRuns, p as getNow, q as getRunInterval, r as getTimezoneOffset, s as humanizeDiff, u as parseCron, v as parseCronExpression, w as parseDate } from '../time-DbT8fjaF.cjs';
1
+ export { C as COMMON_CRONS, a as COMMON_DATE_PRESETS, b as CronField, c as CronNextField, d as CronResult, D as DateDiffResult, e as DurationFormatResult, f as DurationParseResult, P as ParsedCron, T as TIMEZONES, g as TimestampResult, h as TimezoneEntry, i as convertTime, j as diffDates, k as formatInTimezone, l as formatIso8601Duration, m as formatRelative, n as formatRunDate, o as fromIsoString, p as fromUnix, q as getAllZonesForTime, r as getNextRuns, s as getNow, u as getRunInterval, v as getTimezoneOffset, w as humanizeDiff, x as parseCron, y as parseCronExpression, z as parseDate, A as parseIso8601Duration } from '../time-KqJjdqII.cjs';
@@ -1 +1 @@
1
- export { C as COMMON_CRONS, a as COMMON_DATE_PRESETS, b as CronField, c as CronNextField, d as CronResult, D as DateDiffResult, P as ParsedCron, T as TIMEZONES, e as TimestampResult, f as TimezoneEntry, g as convertTime, h as diffDates, i as formatInTimezone, j as formatRelative, k as formatRunDate, l as fromIsoString, m as fromUnix, n as getAllZonesForTime, o as getNextRuns, p as getNow, q as getRunInterval, r as getTimezoneOffset, s as humanizeDiff, u as parseCron, v as parseCronExpression, w as parseDate } from '../time-DbT8fjaF.js';
1
+ export { C as COMMON_CRONS, a as COMMON_DATE_PRESETS, b as CronField, c as CronNextField, d as CronResult, D as DateDiffResult, e as DurationFormatResult, f as DurationParseResult, P as ParsedCron, T as TIMEZONES, g as TimestampResult, h as TimezoneEntry, i as convertTime, j as diffDates, k as formatInTimezone, l as formatIso8601Duration, m as formatRelative, n as formatRunDate, o as fromIsoString, p as fromUnix, q as getAllZonesForTime, r as getNextRuns, s as getNow, u as getRunInterval, v as getTimezoneOffset, w as humanizeDiff, x as parseCron, y as parseCronExpression, z as parseDate, A as parseIso8601Duration } from '../time-KqJjdqII.js';
@@ -1,2 +1,2 @@
1
- export { COMMON_CRONS, COMMON_DATE_PRESETS, TIMEZONES, convertTime, diffDates, formatInTimezone, formatRelative, formatRunDate, fromIsoString, fromUnix, getAllZonesForTime, getNextRuns, getNow, getRunInterval, getTimezoneOffset, humanizeDiff, parseCron, parseCronExpression, parseDate } from '../chunk-ZPQZEIXP.js';
1
+ export { COMMON_CRONS, COMMON_DATE_PRESETS, TIMEZONES, convertTime, diffDates, formatInTimezone, formatIso8601Duration, formatRelative, formatRunDate, fromIsoString, fromUnix, getAllZonesForTime, getNextRuns, getNow, getRunInterval, getTimezoneOffset, humanizeDiff, parseCron, parseCronExpression, parseDate, parseIso8601Duration } from '../chunk-IEPWZERQ.js';
2
2
  import '../chunk-MLKGABMK.js';
@@ -1287,6 +1287,105 @@ function calculatePercentageChange(oldValue, newValue) {
1287
1287
  multiplier: round4(multiplier)
1288
1288
  };
1289
1289
  }
1290
+ function convertAprApy(rate, compoundsPerYear, direction) {
1291
+ if (!Number.isFinite(rate) || rate < 0) return { error: "Rate must be zero or a positive number" };
1292
+ if (!Number.isInteger(compoundsPerYear) || compoundsPerYear <= 0) {
1293
+ return { error: "Compounding frequency must be a positive whole number of periods per year" };
1294
+ }
1295
+ if (direction !== "apr-to-apy" && direction !== "apy-to-apr") {
1296
+ return { error: 'Direction must be "apr-to-apy" or "apy-to-apr"' };
1297
+ }
1298
+ const round6 = (n2) => Math.round(n2 * 1e6) / 1e6;
1299
+ const round8 = (n2) => Math.round(n2 * 1e8) / 1e8;
1300
+ const n = compoundsPerYear;
1301
+ let aprDecimal;
1302
+ let apyDecimal;
1303
+ if (direction === "apr-to-apy") {
1304
+ aprDecimal = rate / 100;
1305
+ apyDecimal = Math.pow(1 + aprDecimal / n, n) - 1;
1306
+ } else {
1307
+ apyDecimal = rate / 100;
1308
+ aprDecimal = n * (Math.pow(1 + apyDecimal, 1 / n) - 1);
1309
+ }
1310
+ const apr = round6(aprDecimal * 100);
1311
+ const apy = round6(apyDecimal * 100);
1312
+ return {
1313
+ direction,
1314
+ compoundsPerYear: n,
1315
+ apr,
1316
+ apy,
1317
+ aprDecimal: round8(aprDecimal),
1318
+ apyDecimal: round8(apyDecimal),
1319
+ difference: round6(apy - apr)
1320
+ };
1321
+ }
1322
+ var _MARGIN_FIELDS = ["cost", "price", "marginPercent", "markupPercent"];
1323
+ function calculateMarginMarkup(input) {
1324
+ const provided = (v) => typeof v === "number" && Number.isFinite(v);
1325
+ const given = _MARGIN_FIELDS.filter((f) => provided(input[f]));
1326
+ if (given.length !== 2) {
1327
+ return { error: `Provide exactly two of cost, price, marginPercent, markupPercent (got ${given.length})` };
1328
+ }
1329
+ const has = (f) => given.includes(f);
1330
+ const cost0 = input.cost;
1331
+ const price0 = input.price;
1332
+ const margin0 = input.marginPercent;
1333
+ const markup0 = input.markupPercent;
1334
+ if (has("cost") && cost0 <= 0) return { error: "Cost must be greater than zero" };
1335
+ if (has("price") && price0 <= 0) return { error: "Price must be greater than zero" };
1336
+ if (has("marginPercent") && margin0 >= 100) {
1337
+ return { error: "Margin percent must be below 100 (a 100% margin implies a zero cost)" };
1338
+ }
1339
+ if (has("markupPercent") && markup0 <= -100) {
1340
+ return { error: "Markup percent must be greater than -100" };
1341
+ }
1342
+ let cost;
1343
+ let price;
1344
+ if (has("cost") && has("price")) {
1345
+ cost = cost0;
1346
+ price = price0;
1347
+ } else if (has("cost") && has("marginPercent")) {
1348
+ cost = cost0;
1349
+ price = cost0 / (1 - margin0 / 100);
1350
+ } else if (has("cost") && has("markupPercent")) {
1351
+ cost = cost0;
1352
+ price = cost0 * (1 + markup0 / 100);
1353
+ } else if (has("price") && has("marginPercent")) {
1354
+ price = price0;
1355
+ cost = price0 * (1 - margin0 / 100);
1356
+ } else if (has("price") && has("markupPercent")) {
1357
+ price = price0;
1358
+ cost = price0 / (1 + markup0 / 100);
1359
+ } else {
1360
+ return { error: "Margin and markup alone cannot be solved: also provide a cost or a price" };
1361
+ }
1362
+ if (!Number.isFinite(cost) || !Number.isFinite(price)) return { error: "Inputs produce a non-finite result" };
1363
+ if (cost <= 0) return { error: "Those inputs imply a cost of zero or less" };
1364
+ if (price <= 0) return { error: "Those inputs imply a price of zero or less" };
1365
+ const round4 = (n) => Math.round(n * 1e4) / 1e4;
1366
+ const profit = price - cost;
1367
+ return {
1368
+ cost: round4(cost),
1369
+ price: round4(price),
1370
+ profit: round4(profit),
1371
+ marginPercent: round4(profit / price * 100),
1372
+ markupPercent: round4(profit / cost * 100),
1373
+ given,
1374
+ solvedFor: _MARGIN_FIELDS.filter((f) => !given.includes(f))
1375
+ };
1376
+ }
1377
+ function marginToMarkup(marginPercent) {
1378
+ if (!Number.isFinite(marginPercent) || marginPercent >= 100) {
1379
+ return { error: "Margin percent must be a finite number below 100" };
1380
+ }
1381
+ return Math.round(marginPercent / (100 - marginPercent) * 100 * 1e4) / 1e4;
1382
+ }
1383
+ function markupToMargin(markupPercent) {
1384
+ if (!Number.isFinite(markupPercent) || markupPercent <= -100) {
1385
+ return { error: "Markup percent must be a finite number greater than -100" };
1386
+ }
1387
+ return Math.round(markupPercent / (100 + markupPercent) * 100 * 1e4) / 1e4;
1388
+ }
1290
1389
 
1291
1390
  exports.BASE_LABELS = BASE_LABELS;
1292
1391
  exports.BASE_PREFIXES = BASE_PREFIXES;
@@ -1305,6 +1404,7 @@ exports.calcAspectRatio = calcAspectRatio;
1305
1404
  exports.calcSubnet = calcSubnet;
1306
1405
  exports.calculateCompoundInterest = calculateCompoundInterest;
1307
1406
  exports.calculateLoan = calculateLoan;
1407
+ exports.calculateMarginMarkup = calculateMarginMarkup;
1308
1408
  exports.calculatePercentageChange = calculatePercentageChange;
1309
1409
  exports.calculateSimpleInterest = calculateSimpleInterest;
1310
1410
  exports.calculateTax = calculateTax;
@@ -1312,6 +1412,7 @@ exports.calculateTimeValue = calculateTimeValue;
1312
1412
  exports.calculateTipSplit = calculateTipSplit;
1313
1413
  exports.compareSemver = compareSemver;
1314
1414
  exports.convert = convert;
1415
+ exports.convertAprApy = convertAprApy;
1315
1416
  exports.convertBytes = convertBytes;
1316
1417
  exports.convertIp = convertIp;
1317
1418
  exports.coverBox = coverBox;
@@ -1336,6 +1437,8 @@ exports.isValid = isValid;
1336
1437
  exports.isValidCidr = isValidCidr;
1337
1438
  exports.isValidIp = isValidIp;
1338
1439
  exports.isValidIpv4 = isValidIpv4;
1440
+ exports.marginToMarkup = marginToMarkup;
1441
+ exports.markupToMargin = markupToMargin;
1339
1442
  exports.octalToPermissions = octalToPermissions;
1340
1443
  exports.parseFileSize = parseFileSize;
1341
1444
  exports.parseInput = parseInput;
@@ -1 +1 @@
1
- export { A as AmortizationRow, a as AspectRatioResult, B as BASE_LABELS, b as BASE_PREFIXES, c as BYTE_UNITS, d as BarcodeFormat, e as BarcodeValidationResult, f as BaseConvertResult, g as ByteConvertResult, h as ByteUnit, C as COMMON_CURRENCIES, i as COMMON_LOCALES, j as COMMON_PERMISSIONS, k as COMMON_RATIOS, l as COMMON_SIZES, m as COMMON_TAX_RATES, n as COMMON_TIP_PERCENTAGES, o as COMMON_VIEWPORTS, p as CardValidationResult, q as CompoundInterestResult, r as CompoundYearRow, D as Dimensions, F as FilePermissions, s as FormatOptions, I as IbanValidationResult, t as IpConversion, v as IsbnFormat, w as IsbnResult, L as LoanResult, N as NotationStyle, x as NumberBase, P as PercentChangeDirection, y as PercentageChangeResult, z as Permission, E as PxConvertResult, S as SemverVersion, G as SimpleInterestResult, H as SubnetInfo, T as TaxDirection, J as TaxResult, K as TimeValueDirection, M as TimeValueResult, O as TipSplitResult, V as ViewportConvertResult, Q as autoFormat, R as bumpVersion, U as calcAspectRatio, W as calcSubnet, X as calculateCompoundInterest, Y as calculateLoan, Z as calculatePercentageChange, _ as calculateSimpleInterest, $ as calculateTax, a0 as calculateTimeValue, a1 as calculateTipSplit, a2 as compareSemver, a3 as convert, a4 as convertBytes, a5 as convertIp, a6 as coverBox, a7 as decimalToIp, a8 as decimalToIpCidr, a9 as describePermissions, aa as fitIntoBox, ab as formatNumber, ac as formatValue, ad as formatVwValue, ae as formatWithSeparator, af as gcd, ag as ipFromBinary, ah as ipFromDecimal, ai as ipFromHex, aj as ipToBinary, ak as ipToDecimal, al as ipToDecimalCidr, am as ipToHex, an as ipToOctal, ao as isValid, ap as isValidCidr, aq as isValidIp, ar as isValidIpv4, as as octalToPermissions, at as parseFileSize, au as parseInput, av as parseNumberString, aw as parseSemver, ax as permissionsToChmod, ay as permissionsToOctal, az as permissionsToSymbolic, aA as ptToPx, aB as pxToAll, aC as pxToViewport, aD as remToPx, aE as satisfiesRange, aF as scaleByHeight, aG as scaleByWidth, aH as sortVersions, aI as splitSubnet, aJ as symbolicToPermissions, aK as validateBarcode, aL as validateCardNumber, aM as validateIban, aN as validateIsbn, aO as viewportToPx } from '../units-pIRkHnsU.cjs';
1
+ export { A as AmortizationRow, a as AprApyDirection, b as AprApyResult, c as AspectRatioResult, B as BASE_LABELS, d as BASE_PREFIXES, e as BYTE_UNITS, f as BarcodeFormat, g as BarcodeValidationResult, h as BaseConvertResult, i as ByteConvertResult, j as ByteUnit, C as COMMON_CURRENCIES, k as COMMON_LOCALES, l as COMMON_PERMISSIONS, m as COMMON_RATIOS, n as COMMON_SIZES, o as COMMON_TAX_RATES, p as COMMON_TIP_PERCENTAGES, q as COMMON_VIEWPORTS, r as CardValidationResult, s as CompoundInterestResult, t as CompoundYearRow, D as Dimensions, F as FilePermissions, v as FormatOptions, I as IbanValidationResult, w as IpConversion, x as IsbnFormat, y as IsbnResult, L as LoanResult, M as MarginMarkupField, z as MarginMarkupInput, E as MarginMarkupResult, N as NotationStyle, G as NumberBase, P as PercentChangeDirection, H as PercentageChangeResult, J as Permission, K as PxConvertResult, S as SemverVersion, O as SimpleInterestResult, Q as SubnetInfo, T as TaxDirection, R as TaxResult, U as TimeValueDirection, V as TimeValueResult, W as TipSplitResult, X as ViewportConvertResult, Y as autoFormat, Z as bumpVersion, _ as calcAspectRatio, $ as calcSubnet, a0 as calculateCompoundInterest, a1 as calculateLoan, a2 as calculateMarginMarkup, a3 as calculatePercentageChange, a4 as calculateSimpleInterest, a5 as calculateTax, a6 as calculateTimeValue, a7 as calculateTipSplit, a8 as compareSemver, a9 as convert, aa as convertAprApy, ab as convertBytes, ac as convertIp, ad as coverBox, ae as decimalToIp, af as decimalToIpCidr, ag as describePermissions, ah as fitIntoBox, ai as formatNumber, aj as formatValue, ak as formatVwValue, al as formatWithSeparator, am as gcd, an as ipFromBinary, ao as ipFromDecimal, ap as ipFromHex, aq as ipToBinary, ar as ipToDecimal, as as ipToDecimalCidr, at as ipToHex, au as ipToOctal, av as isValid, aw as isValidCidr, ax as isValidIp, ay as isValidIpv4, az as marginToMarkup, aA as markupToMargin, aB as octalToPermissions, aC as parseFileSize, aD as parseInput, aE as parseNumberString, aF as parseSemver, aG as permissionsToChmod, aH as permissionsToOctal, aI as permissionsToSymbolic, aJ as ptToPx, aK as pxToAll, aL as pxToViewport, aM as remToPx, aN as satisfiesRange, aO as scaleByHeight, aP as scaleByWidth, aQ as sortVersions, aR as splitSubnet, aS as symbolicToPermissions, aT as validateBarcode, aU as validateCardNumber, aV as validateIban, aW as validateIsbn, aX as viewportToPx } from '../units-h4rHQGp5.cjs';
@@ -1 +1 @@
1
- export { A as AmortizationRow, a as AspectRatioResult, B as BASE_LABELS, b as BASE_PREFIXES, c as BYTE_UNITS, d as BarcodeFormat, e as BarcodeValidationResult, f as BaseConvertResult, g as ByteConvertResult, h as ByteUnit, C as COMMON_CURRENCIES, i as COMMON_LOCALES, j as COMMON_PERMISSIONS, k as COMMON_RATIOS, l as COMMON_SIZES, m as COMMON_TAX_RATES, n as COMMON_TIP_PERCENTAGES, o as COMMON_VIEWPORTS, p as CardValidationResult, q as CompoundInterestResult, r as CompoundYearRow, D as Dimensions, F as FilePermissions, s as FormatOptions, I as IbanValidationResult, t as IpConversion, v as IsbnFormat, w as IsbnResult, L as LoanResult, N as NotationStyle, x as NumberBase, P as PercentChangeDirection, y as PercentageChangeResult, z as Permission, E as PxConvertResult, S as SemverVersion, G as SimpleInterestResult, H as SubnetInfo, T as TaxDirection, J as TaxResult, K as TimeValueDirection, M as TimeValueResult, O as TipSplitResult, V as ViewportConvertResult, Q as autoFormat, R as bumpVersion, U as calcAspectRatio, W as calcSubnet, X as calculateCompoundInterest, Y as calculateLoan, Z as calculatePercentageChange, _ as calculateSimpleInterest, $ as calculateTax, a0 as calculateTimeValue, a1 as calculateTipSplit, a2 as compareSemver, a3 as convert, a4 as convertBytes, a5 as convertIp, a6 as coverBox, a7 as decimalToIp, a8 as decimalToIpCidr, a9 as describePermissions, aa as fitIntoBox, ab as formatNumber, ac as formatValue, ad as formatVwValue, ae as formatWithSeparator, af as gcd, ag as ipFromBinary, ah as ipFromDecimal, ai as ipFromHex, aj as ipToBinary, ak as ipToDecimal, al as ipToDecimalCidr, am as ipToHex, an as ipToOctal, ao as isValid, ap as isValidCidr, aq as isValidIp, ar as isValidIpv4, as as octalToPermissions, at as parseFileSize, au as parseInput, av as parseNumberString, aw as parseSemver, ax as permissionsToChmod, ay as permissionsToOctal, az as permissionsToSymbolic, aA as ptToPx, aB as pxToAll, aC as pxToViewport, aD as remToPx, aE as satisfiesRange, aF as scaleByHeight, aG as scaleByWidth, aH as sortVersions, aI as splitSubnet, aJ as symbolicToPermissions, aK as validateBarcode, aL as validateCardNumber, aM as validateIban, aN as validateIsbn, aO as viewportToPx } from '../units-pIRkHnsU.js';
1
+ export { A as AmortizationRow, a as AprApyDirection, b as AprApyResult, c as AspectRatioResult, B as BASE_LABELS, d as BASE_PREFIXES, e as BYTE_UNITS, f as BarcodeFormat, g as BarcodeValidationResult, h as BaseConvertResult, i as ByteConvertResult, j as ByteUnit, C as COMMON_CURRENCIES, k as COMMON_LOCALES, l as COMMON_PERMISSIONS, m as COMMON_RATIOS, n as COMMON_SIZES, o as COMMON_TAX_RATES, p as COMMON_TIP_PERCENTAGES, q as COMMON_VIEWPORTS, r as CardValidationResult, s as CompoundInterestResult, t as CompoundYearRow, D as Dimensions, F as FilePermissions, v as FormatOptions, I as IbanValidationResult, w as IpConversion, x as IsbnFormat, y as IsbnResult, L as LoanResult, M as MarginMarkupField, z as MarginMarkupInput, E as MarginMarkupResult, N as NotationStyle, G as NumberBase, P as PercentChangeDirection, H as PercentageChangeResult, J as Permission, K as PxConvertResult, S as SemverVersion, O as SimpleInterestResult, Q as SubnetInfo, T as TaxDirection, R as TaxResult, U as TimeValueDirection, V as TimeValueResult, W as TipSplitResult, X as ViewportConvertResult, Y as autoFormat, Z as bumpVersion, _ as calcAspectRatio, $ as calcSubnet, a0 as calculateCompoundInterest, a1 as calculateLoan, a2 as calculateMarginMarkup, a3 as calculatePercentageChange, a4 as calculateSimpleInterest, a5 as calculateTax, a6 as calculateTimeValue, a7 as calculateTipSplit, a8 as compareSemver, a9 as convert, aa as convertAprApy, ab as convertBytes, ac as convertIp, ad as coverBox, ae as decimalToIp, af as decimalToIpCidr, ag as describePermissions, ah as fitIntoBox, ai as formatNumber, aj as formatValue, ak as formatVwValue, al as formatWithSeparator, am as gcd, an as ipFromBinary, ao as ipFromDecimal, ap as ipFromHex, aq as ipToBinary, ar as ipToDecimal, as as ipToDecimalCidr, at as ipToHex, au as ipToOctal, av as isValid, aw as isValidCidr, ax as isValidIp, ay as isValidIpv4, az as marginToMarkup, aA as markupToMargin, aB as octalToPermissions, aC as parseFileSize, aD as parseInput, aE as parseNumberString, aF as parseSemver, aG as permissionsToChmod, aH as permissionsToOctal, aI as permissionsToSymbolic, aJ as ptToPx, aK as pxToAll, aL as pxToViewport, aM as remToPx, aN as satisfiesRange, aO as scaleByHeight, aP as scaleByWidth, aQ as sortVersions, aR as splitSubnet, aS as symbolicToPermissions, aT as validateBarcode, aU as validateCardNumber, aV as validateIban, aW as validateIsbn, aX as viewportToPx } from '../units-h4rHQGp5.js';
@@ -1,2 +1,2 @@
1
- export { BASE_LABELS, BASE_PREFIXES, BYTE_UNITS, COMMON_CURRENCIES, COMMON_LOCALES, COMMON_PERMISSIONS, COMMON_RATIOS, COMMON_SIZES, COMMON_TAX_RATES, COMMON_TIP_PERCENTAGES, COMMON_VIEWPORTS, autoFormat, bumpVersion, calcAspectRatio, calcSubnet, calculateCompoundInterest, calculateLoan, calculatePercentageChange, calculateSimpleInterest, calculateTax, calculateTimeValue, calculateTipSplit, compareSemver, convert, convertBytes, convertIp, coverBox, decimalToIp, decimalToIpCidr, describePermissions, fitIntoBox, formatNumber, formatValue, formatVwValue, formatWithSeparator, gcd, ipFromBinary, ipFromDecimal, ipFromHex, ipToBinary, ipToDecimal, ipToDecimalCidr, ipToHex, ipToOctal, isValid, isValidCidr, isValidIp, isValidIpv4, octalToPermissions, parseFileSize, parseInput, parseNumberString, parseSemver, permissionsToChmod, permissionsToOctal, permissionsToSymbolic, ptToPx, pxToAll, pxToViewport, remToPx, satisfiesRange, scaleByHeight, scaleByWidth, sortVersions, splitSubnet, symbolicToPermissions, validateBarcode, validateCardNumber, validateIban, validateIsbn, viewportToPx } from '../chunk-TFNCFD3E.js';
1
+ export { BASE_LABELS, BASE_PREFIXES, BYTE_UNITS, COMMON_CURRENCIES, COMMON_LOCALES, COMMON_PERMISSIONS, COMMON_RATIOS, COMMON_SIZES, COMMON_TAX_RATES, COMMON_TIP_PERCENTAGES, COMMON_VIEWPORTS, autoFormat, bumpVersion, calcAspectRatio, calcSubnet, calculateCompoundInterest, calculateLoan, calculateMarginMarkup, calculatePercentageChange, calculateSimpleInterest, calculateTax, calculateTimeValue, calculateTipSplit, compareSemver, convert, convertAprApy, convertBytes, convertIp, coverBox, decimalToIp, decimalToIpCidr, describePermissions, fitIntoBox, formatNumber, formatValue, formatVwValue, formatWithSeparator, gcd, ipFromBinary, ipFromDecimal, ipFromHex, ipToBinary, ipToDecimal, ipToDecimalCidr, ipToHex, ipToOctal, isValid, isValidCidr, isValidIp, isValidIpv4, marginToMarkup, markupToMargin, octalToPermissions, parseFileSize, parseInput, parseNumberString, parseSemver, permissionsToChmod, permissionsToOctal, permissionsToSymbolic, ptToPx, pxToAll, pxToViewport, remToPx, satisfiesRange, scaleByHeight, scaleByWidth, sortVersions, splitSubnet, symbolicToPermissions, validateBarcode, validateCardNumber, validateIban, validateIsbn, viewportToPx } from '../chunk-AIKSKJ77.js';
2
2
  import '../chunk-MLKGABMK.js';
@@ -21,6 +21,10 @@
21
21
  * - isbn-validator : validateIsbn
22
22
  * - tip-calculator : calculateTipSplit
23
23
  * - simple-interest-calculator : calculateSimpleInterest
24
+ * - present-value-calculator : calculateTimeValue
25
+ * - percentage-change-calculator : calculatePercentageChange
26
+ * - apr-apy-converter : convertAprApy
27
+ * - margin-markup-calculator : calculateMarginMarkup, marginToMarkup, markupToMargin
24
28
  */
25
29
  interface PxConvertResult {
26
30
  px: number;
@@ -448,8 +452,69 @@ interface PercentageChangeResult {
448
452
  declare function calculatePercentageChange(oldValue: number, newValue: number): PercentageChangeResult | {
449
453
  error: string;
450
454
  };
455
+ type AprApyDirection = "apr-to-apy" | "apy-to-apr";
456
+ interface AprApyResult {
457
+ direction: AprApyDirection;
458
+ compoundsPerYear: number;
459
+ apr: number;
460
+ apy: number;
461
+ aprDecimal: number;
462
+ apyDecimal: number;
463
+ difference: number;
464
+ }
465
+ /**
466
+ * Convert between a nominal annual rate (APR) and the effective annual yield
467
+ * (APY) for a given compounding frequency. With direction "apr-to-apy" the
468
+ * input rate is treated as the nominal APR and the effective APY is computed
469
+ * as (1 + apr/n)^n - 1; with "apy-to-apr" the input is the effective APY and
470
+ * the nominal APR is recovered as n * ((1 + apy)^(1/n) - 1). Both rates are
471
+ * percentages, `difference` is apy - apr in percentage points, and n is the
472
+ * number of compounding periods per year. Pure closed-form formula, no live
473
+ * rate feed.
474
+ */
475
+ declare function convertAprApy(rate: number, compoundsPerYear: number, direction: AprApyDirection): AprApyResult | {
476
+ error: string;
477
+ };
478
+ type MarginMarkupField = "cost" | "price" | "marginPercent" | "markupPercent";
479
+ interface MarginMarkupInput {
480
+ cost?: number | null;
481
+ price?: number | null;
482
+ marginPercent?: number | null;
483
+ markupPercent?: number | null;
484
+ }
485
+ interface MarginMarkupResult {
486
+ cost: number;
487
+ price: number;
488
+ profit: number;
489
+ marginPercent: number;
490
+ markupPercent: number;
491
+ given: MarginMarkupField[];
492
+ solvedFor: MarginMarkupField[];
493
+ }
494
+ /**
495
+ * Solve a pricing triangle: given exactly two of cost, price, gross margin
496
+ * percent, and markup percent, derive the other two. Margin is profit as a
497
+ * share of the selling price (profit / price) while markup is profit as a
498
+ * share of the cost (profit / cost), so a 20% margin is the same deal as a
499
+ * 25% markup — conflating them is the classic mistake this exists to avoid.
500
+ * Margin plus markup alone cannot be solved, since neither carries an
501
+ * absolute amount. Pure closed-form arithmetic, no live price feed.
502
+ */
503
+ declare function calculateMarginMarkup(input: MarginMarkupInput): MarginMarkupResult | {
504
+ error: string;
505
+ };
506
+ /** Markup percent that produces a given gross margin percent (margin < 100). */
507
+ declare function marginToMarkup(marginPercent: number): number | {
508
+ error: string;
509
+ };
510
+ /** Gross margin percent that results from a given markup percent (markup > -100). */
511
+ declare function markupToMargin(markupPercent: number): number | {
512
+ error: string;
513
+ };
451
514
 
452
515
  type units_AmortizationRow = AmortizationRow;
516
+ type units_AprApyDirection = AprApyDirection;
517
+ type units_AprApyResult = AprApyResult;
453
518
  type units_AspectRatioResult = AspectRatioResult;
454
519
  declare const units_BASE_LABELS: typeof BASE_LABELS;
455
520
  declare const units_BASE_PREFIXES: typeof BASE_PREFIXES;
@@ -478,6 +543,9 @@ type units_IpConversion = IpConversion;
478
543
  type units_IsbnFormat = IsbnFormat;
479
544
  type units_IsbnResult = IsbnResult;
480
545
  type units_LoanResult = LoanResult;
546
+ type units_MarginMarkupField = MarginMarkupField;
547
+ type units_MarginMarkupInput = MarginMarkupInput;
548
+ type units_MarginMarkupResult = MarginMarkupResult;
481
549
  type units_NotationStyle = NotationStyle;
482
550
  type units_NumberBase = NumberBase;
483
551
  type units_PercentChangeDirection = PercentChangeDirection;
@@ -499,6 +567,7 @@ declare const units_calcAspectRatio: typeof calcAspectRatio;
499
567
  declare const units_calcSubnet: typeof calcSubnet;
500
568
  declare const units_calculateCompoundInterest: typeof calculateCompoundInterest;
501
569
  declare const units_calculateLoan: typeof calculateLoan;
570
+ declare const units_calculateMarginMarkup: typeof calculateMarginMarkup;
502
571
  declare const units_calculatePercentageChange: typeof calculatePercentageChange;
503
572
  declare const units_calculateSimpleInterest: typeof calculateSimpleInterest;
504
573
  declare const units_calculateTax: typeof calculateTax;
@@ -506,6 +575,7 @@ declare const units_calculateTimeValue: typeof calculateTimeValue;
506
575
  declare const units_calculateTipSplit: typeof calculateTipSplit;
507
576
  declare const units_compareSemver: typeof compareSemver;
508
577
  declare const units_convert: typeof convert;
578
+ declare const units_convertAprApy: typeof convertAprApy;
509
579
  declare const units_convertBytes: typeof convertBytes;
510
580
  declare const units_convertIp: typeof convertIp;
511
581
  declare const units_coverBox: typeof coverBox;
@@ -530,6 +600,8 @@ declare const units_isValid: typeof isValid;
530
600
  declare const units_isValidCidr: typeof isValidCidr;
531
601
  declare const units_isValidIp: typeof isValidIp;
532
602
  declare const units_isValidIpv4: typeof isValidIpv4;
603
+ declare const units_marginToMarkup: typeof marginToMarkup;
604
+ declare const units_markupToMargin: typeof markupToMargin;
533
605
  declare const units_octalToPermissions: typeof octalToPermissions;
534
606
  declare const units_parseFileSize: typeof parseFileSize;
535
607
  declare const units_parseInput: typeof parseInput;
@@ -554,7 +626,7 @@ declare const units_validateIban: typeof validateIban;
554
626
  declare const units_validateIsbn: typeof validateIsbn;
555
627
  declare const units_viewportToPx: typeof viewportToPx;
556
628
  declare namespace units {
557
- export { type units_AmortizationRow as AmortizationRow, type units_AspectRatioResult as AspectRatioResult, units_BASE_LABELS as BASE_LABELS, units_BASE_PREFIXES as BASE_PREFIXES, units_BYTE_UNITS as BYTE_UNITS, type units_BarcodeFormat as BarcodeFormat, type units_BarcodeValidationResult as BarcodeValidationResult, type units_BaseConvertResult as BaseConvertResult, type units_ByteConvertResult as ByteConvertResult, type units_ByteUnit as ByteUnit, units_COMMON_CURRENCIES as COMMON_CURRENCIES, units_COMMON_LOCALES as COMMON_LOCALES, units_COMMON_PERMISSIONS as COMMON_PERMISSIONS, units_COMMON_RATIOS as COMMON_RATIOS, units_COMMON_SIZES as COMMON_SIZES, units_COMMON_TAX_RATES as COMMON_TAX_RATES, units_COMMON_TIP_PERCENTAGES as COMMON_TIP_PERCENTAGES, units_COMMON_VIEWPORTS as COMMON_VIEWPORTS, type units_CardValidationResult as CardValidationResult, type units_CompoundInterestResult as CompoundInterestResult, type units_CompoundYearRow as CompoundYearRow, type units_Dimensions as Dimensions, type units_FilePermissions as FilePermissions, type units_FormatOptions as FormatOptions, type units_IbanValidationResult as IbanValidationResult, type units_IpConversion as IpConversion, type units_IsbnFormat as IsbnFormat, type units_IsbnResult as IsbnResult, type units_LoanResult as LoanResult, type units_NotationStyle as NotationStyle, type units_NumberBase as NumberBase, type units_PercentChangeDirection as PercentChangeDirection, type units_PercentageChangeResult as PercentageChangeResult, type units_Permission as Permission, type units_PxConvertResult as PxConvertResult, type units_SemverVersion as SemverVersion, type units_SimpleInterestResult as SimpleInterestResult, type units_SubnetInfo as SubnetInfo, type units_TaxDirection as TaxDirection, type units_TaxResult as TaxResult, type units_TimeValueDirection as TimeValueDirection, type units_TimeValueResult as TimeValueResult, type units_TipSplitResult as TipSplitResult, type units_ViewportConvertResult as ViewportConvertResult, units_autoFormat as autoFormat, units_bumpVersion as bumpVersion, units_calcAspectRatio as calcAspectRatio, units_calcSubnet as calcSubnet, units_calculateCompoundInterest as calculateCompoundInterest, units_calculateLoan as calculateLoan, units_calculatePercentageChange as calculatePercentageChange, units_calculateSimpleInterest as calculateSimpleInterest, units_calculateTax as calculateTax, units_calculateTimeValue as calculateTimeValue, units_calculateTipSplit as calculateTipSplit, units_compareSemver as compareSemver, units_convert as convert, units_convertBytes as convertBytes, units_convertIp as convertIp, units_coverBox as coverBox, units_decimalToIp as decimalToIp, units_decimalToIpCidr as decimalToIpCidr, units_describePermissions as describePermissions, units_fitIntoBox as fitIntoBox, units_formatNumber as formatNumber, units_formatValue as formatValue, units_formatVwValue as formatVwValue, units_formatWithSeparator as formatWithSeparator, units_gcd as gcd, units_ipFromBinary as ipFromBinary, units_ipFromDecimal as ipFromDecimal, units_ipFromHex as ipFromHex, units_ipToBinary as ipToBinary, units_ipToDecimal as ipToDecimal, units_ipToDecimalCidr as ipToDecimalCidr, units_ipToHex as ipToHex, units_ipToOctal as ipToOctal, units_isValid as isValid, units_isValidCidr as isValidCidr, units_isValidIp as isValidIp, units_isValidIpv4 as isValidIpv4, units_octalToPermissions as octalToPermissions, units_parseFileSize as parseFileSize, units_parseInput as parseInput, units_parseNumberString as parseNumberString, units_parseSemver as parseSemver, units_permissionsToChmod as permissionsToChmod, units_permissionsToOctal as permissionsToOctal, units_permissionsToSymbolic as permissionsToSymbolic, units_ptToPx as ptToPx, units_pxToAll as pxToAll, units_pxToViewport as pxToViewport, units_remToPx as remToPx, units_satisfiesRange as satisfiesRange, units_scaleByHeight as scaleByHeight, units_scaleByWidth as scaleByWidth, units_sortVersions as sortVersions, units_splitSubnet as splitSubnet, units_symbolicToPermissions as symbolicToPermissions, units_validateBarcode as validateBarcode, units_validateCardNumber as validateCardNumber, units_validateIban as validateIban, units_validateIsbn as validateIsbn, units_viewportToPx as viewportToPx };
629
+ export { type units_AmortizationRow as AmortizationRow, type units_AprApyDirection as AprApyDirection, type units_AprApyResult as AprApyResult, type units_AspectRatioResult as AspectRatioResult, units_BASE_LABELS as BASE_LABELS, units_BASE_PREFIXES as BASE_PREFIXES, units_BYTE_UNITS as BYTE_UNITS, type units_BarcodeFormat as BarcodeFormat, type units_BarcodeValidationResult as BarcodeValidationResult, type units_BaseConvertResult as BaseConvertResult, type units_ByteConvertResult as ByteConvertResult, type units_ByteUnit as ByteUnit, units_COMMON_CURRENCIES as COMMON_CURRENCIES, units_COMMON_LOCALES as COMMON_LOCALES, units_COMMON_PERMISSIONS as COMMON_PERMISSIONS, units_COMMON_RATIOS as COMMON_RATIOS, units_COMMON_SIZES as COMMON_SIZES, units_COMMON_TAX_RATES as COMMON_TAX_RATES, units_COMMON_TIP_PERCENTAGES as COMMON_TIP_PERCENTAGES, units_COMMON_VIEWPORTS as COMMON_VIEWPORTS, type units_CardValidationResult as CardValidationResult, type units_CompoundInterestResult as CompoundInterestResult, type units_CompoundYearRow as CompoundYearRow, type units_Dimensions as Dimensions, type units_FilePermissions as FilePermissions, type units_FormatOptions as FormatOptions, type units_IbanValidationResult as IbanValidationResult, type units_IpConversion as IpConversion, type units_IsbnFormat as IsbnFormat, type units_IsbnResult as IsbnResult, type units_LoanResult as LoanResult, type units_MarginMarkupField as MarginMarkupField, type units_MarginMarkupInput as MarginMarkupInput, type units_MarginMarkupResult as MarginMarkupResult, type units_NotationStyle as NotationStyle, type units_NumberBase as NumberBase, type units_PercentChangeDirection as PercentChangeDirection, type units_PercentageChangeResult as PercentageChangeResult, type units_Permission as Permission, type units_PxConvertResult as PxConvertResult, type units_SemverVersion as SemverVersion, type units_SimpleInterestResult as SimpleInterestResult, type units_SubnetInfo as SubnetInfo, type units_TaxDirection as TaxDirection, type units_TaxResult as TaxResult, type units_TimeValueDirection as TimeValueDirection, type units_TimeValueResult as TimeValueResult, type units_TipSplitResult as TipSplitResult, type units_ViewportConvertResult as ViewportConvertResult, units_autoFormat as autoFormat, units_bumpVersion as bumpVersion, units_calcAspectRatio as calcAspectRatio, units_calcSubnet as calcSubnet, units_calculateCompoundInterest as calculateCompoundInterest, units_calculateLoan as calculateLoan, units_calculateMarginMarkup as calculateMarginMarkup, units_calculatePercentageChange as calculatePercentageChange, units_calculateSimpleInterest as calculateSimpleInterest, units_calculateTax as calculateTax, units_calculateTimeValue as calculateTimeValue, units_calculateTipSplit as calculateTipSplit, units_compareSemver as compareSemver, units_convert as convert, units_convertAprApy as convertAprApy, units_convertBytes as convertBytes, units_convertIp as convertIp, units_coverBox as coverBox, units_decimalToIp as decimalToIp, units_decimalToIpCidr as decimalToIpCidr, units_describePermissions as describePermissions, units_fitIntoBox as fitIntoBox, units_formatNumber as formatNumber, units_formatValue as formatValue, units_formatVwValue as formatVwValue, units_formatWithSeparator as formatWithSeparator, units_gcd as gcd, units_ipFromBinary as ipFromBinary, units_ipFromDecimal as ipFromDecimal, units_ipFromHex as ipFromHex, units_ipToBinary as ipToBinary, units_ipToDecimal as ipToDecimal, units_ipToDecimalCidr as ipToDecimalCidr, units_ipToHex as ipToHex, units_ipToOctal as ipToOctal, units_isValid as isValid, units_isValidCidr as isValidCidr, units_isValidIp as isValidIp, units_isValidIpv4 as isValidIpv4, units_marginToMarkup as marginToMarkup, units_markupToMargin as markupToMargin, units_octalToPermissions as octalToPermissions, units_parseFileSize as parseFileSize, units_parseInput as parseInput, units_parseNumberString as parseNumberString, units_parseSemver as parseSemver, units_permissionsToChmod as permissionsToChmod, units_permissionsToOctal as permissionsToOctal, units_permissionsToSymbolic as permissionsToSymbolic, units_ptToPx as ptToPx, units_pxToAll as pxToAll, units_pxToViewport as pxToViewport, units_remToPx as remToPx, units_satisfiesRange as satisfiesRange, units_scaleByHeight as scaleByHeight, units_scaleByWidth as scaleByWidth, units_sortVersions as sortVersions, units_splitSubnet as splitSubnet, units_symbolicToPermissions as symbolicToPermissions, units_validateBarcode as validateBarcode, units_validateCardNumber as validateCardNumber, units_validateIban as validateIban, units_validateIsbn as validateIsbn, units_viewportToPx as viewportToPx };
558
630
  }
559
631
 
560
- export { calculateTax as $, type AmortizationRow as A, BASE_LABELS as B, COMMON_CURRENCIES as C, type Dimensions as D, type PxConvertResult as E, type FilePermissions as F, type SimpleInterestResult as G, type SubnetInfo as H, type IbanValidationResult as I, type TaxResult as J, type TimeValueDirection as K, type LoanResult as L, type TimeValueResult as M, type NotationStyle as N, type TipSplitResult as O, type PercentChangeDirection as P, autoFormat as Q, bumpVersion as R, type SemverVersion as S, type TaxDirection as T, calcAspectRatio as U, type ViewportConvertResult as V, calcSubnet as W, calculateCompoundInterest as X, calculateLoan as Y, calculatePercentageChange as Z, calculateSimpleInterest as _, type AspectRatioResult as a, calculateTimeValue as a0, calculateTipSplit as a1, compareSemver as a2, convert as a3, convertBytes as a4, convertIp as a5, coverBox as a6, decimalToIp as a7, decimalToIpCidr as a8, describePermissions as a9, ptToPx as aA, pxToAll as aB, pxToViewport as aC, remToPx as aD, satisfiesRange as aE, scaleByHeight as aF, scaleByWidth as aG, sortVersions as aH, splitSubnet as aI, symbolicToPermissions as aJ, validateBarcode as aK, validateCardNumber as aL, validateIban as aM, validateIsbn as aN, viewportToPx as aO, fitIntoBox as aa, formatNumber as ab, formatValue as ac, formatVwValue as ad, formatWithSeparator as ae, gcd as af, ipFromBinary as ag, ipFromDecimal as ah, ipFromHex as ai, ipToBinary as aj, ipToDecimal as ak, ipToDecimalCidr as al, ipToHex as am, ipToOctal as an, isValid as ao, isValidCidr as ap, isValidIp as aq, isValidIpv4 as ar, octalToPermissions as as, parseFileSize as at, parseInput as au, parseNumberString as av, parseSemver as aw, permissionsToChmod as ax, permissionsToOctal as ay, permissionsToSymbolic as az, BASE_PREFIXES as b, BYTE_UNITS as c, type BarcodeFormat as d, type BarcodeValidationResult as e, type BaseConvertResult as f, type ByteConvertResult as g, type ByteUnit as h, COMMON_LOCALES as i, COMMON_PERMISSIONS as j, COMMON_RATIOS as k, COMMON_SIZES as l, COMMON_TAX_RATES as m, COMMON_TIP_PERCENTAGES as n, COMMON_VIEWPORTS as o, type CardValidationResult as p, type CompoundInterestResult as q, type CompoundYearRow as r, type FormatOptions as s, type IpConversion as t, units as u, type IsbnFormat as v, type IsbnResult as w, type NumberBase as x, type PercentageChangeResult as y, type Permission as z };
632
+ export { calcSubnet as $, type AmortizationRow as A, BASE_LABELS as B, COMMON_CURRENCIES as C, type Dimensions as D, type MarginMarkupResult as E, type FilePermissions as F, type NumberBase as G, type PercentageChangeResult as H, type IbanValidationResult as I, type Permission as J, type PxConvertResult as K, type LoanResult as L, type MarginMarkupField as M, type NotationStyle as N, type SimpleInterestResult as O, type PercentChangeDirection as P, type SubnetInfo as Q, type TaxResult as R, type SemverVersion as S, type TaxDirection as T, type TimeValueDirection as U, type TimeValueResult as V, type TipSplitResult as W, type ViewportConvertResult as X, autoFormat as Y, bumpVersion as Z, calcAspectRatio as _, type AprApyDirection as a, calculateCompoundInterest as a0, calculateLoan as a1, calculateMarginMarkup as a2, calculatePercentageChange as a3, calculateSimpleInterest as a4, calculateTax as a5, calculateTimeValue as a6, calculateTipSplit as a7, compareSemver as a8, convert as a9, markupToMargin as aA, octalToPermissions as aB, parseFileSize as aC, parseInput as aD, parseNumberString as aE, parseSemver as aF, permissionsToChmod as aG, permissionsToOctal as aH, permissionsToSymbolic as aI, ptToPx as aJ, pxToAll as aK, pxToViewport as aL, remToPx as aM, satisfiesRange as aN, scaleByHeight as aO, scaleByWidth as aP, sortVersions as aQ, splitSubnet as aR, symbolicToPermissions as aS, validateBarcode as aT, validateCardNumber as aU, validateIban as aV, validateIsbn as aW, viewportToPx as aX, convertAprApy as aa, convertBytes as ab, convertIp as ac, coverBox as ad, decimalToIp as ae, decimalToIpCidr as af, describePermissions as ag, fitIntoBox as ah, formatNumber as ai, formatValue as aj, formatVwValue as ak, formatWithSeparator as al, gcd as am, ipFromBinary as an, ipFromDecimal as ao, ipFromHex as ap, ipToBinary as aq, ipToDecimal as ar, ipToDecimalCidr as as, ipToHex as at, ipToOctal as au, isValid as av, isValidCidr as aw, isValidIp as ax, isValidIpv4 as ay, marginToMarkup as az, type AprApyResult as b, type AspectRatioResult as c, BASE_PREFIXES as d, BYTE_UNITS as e, type BarcodeFormat as f, type BarcodeValidationResult as g, type BaseConvertResult as h, type ByteConvertResult as i, type ByteUnit as j, COMMON_LOCALES as k, COMMON_PERMISSIONS as l, COMMON_RATIOS as m, COMMON_SIZES as n, COMMON_TAX_RATES as o, COMMON_TIP_PERCENTAGES as p, COMMON_VIEWPORTS as q, type CardValidationResult as r, type CompoundInterestResult as s, type CompoundYearRow as t, units as u, type FormatOptions as v, type IpConversion as w, type IsbnFormat as x, type IsbnResult as y, type MarginMarkupInput as z };