Skip to content

Commit 6055d99

Browse files
feat(mf2): Rename :math as :offset, make it default
1 parent 6f2e864 commit 6055d99

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

mf2/messageformat/src/functions/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type { MessageString } from './string.ts';
2525

2626
import { currency } from './currency.ts';
2727
import { date, datetime, time } from './datetime.ts';
28-
import { math } from './math.ts';
28+
import { offset } from './offset.ts';
2929
import { integer, number } from './number.ts';
3030
import { string } from './string.ts';
3131
import { unit } from './unit.ts';
@@ -53,6 +53,15 @@ export let DefaultFunctions = {
5353
*/
5454
number,
5555

56+
/**
57+
* Supports formatting and selection as defined in LDML 48 for the
58+
* {@link https://www.unicode.org/reports/tr35/tr35-76/tr35-messageFormat.html#the-offset-function | :offset function}.
59+
*
60+
* The `operand` must be a number, BigInt, or string representing a JSON number,
61+
* or an object wrapping such a value, with a `valueOf()` accessor and an optional `options` object.
62+
*/
63+
offset,
64+
5665
/**
5766
* Supports formatting and selection as defined in LDML 47 for the
5867
* {@link https://www.unicode.org/reports/tr35/tr35-75/tr35-messageFormat.html#the-string-function | :string function}.
@@ -111,15 +120,6 @@ export let DraftFunctions = {
111120
*/
112121
datetime,
113122

114-
/**
115-
* Supports formatting and selection as defined in LDML 47 for the
116-
* {@link https://www.unicode.org/reports/tr35/tr35-75/tr35-messageFormat.html#the-math-function | :math function}.
117-
*
118-
* The `operand` must be a number, BigInt, or string representing a JSON number,
119-
* or an object wrapping such a value, with a `valueOf()` accessor and an optional `options` object.
120-
*/
121-
math,
122-
123123
/**
124124
* Supports formatting as defined in LDML 47 for the
125125
* {@link https://www.unicode.org/reports/tr35/tr35-75/tr35-messageFormat.html#the-time-function | :time function}.

mf2/messageformat/src/functions/number.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import type { DefaultFunctions, DraftFunctions } from './index.ts';
88
import { asPositiveInteger, asString } from './utils.ts';
99

1010
/**
11-
* The resolved value of a {@link DraftFunctions.currency | :currency},
12-
* {@link DefaultFunctions.integer | :integer}, {@link DraftFunctions.math | :math},
13-
* {@link DefaultFunctions.number | :number}, or {@link DraftFunctions.unit | :unit} expression.
11+
* The resolved value of a
12+
* {@link DraftFunctions.currency | :currency},
13+
* {@link DefaultFunctions.integer | :integer},
14+
* {@link DefaultFunctions.number | :number},
15+
* {@link DefaultFunctions.offset | :offset},
16+
* or {@link DraftFunctions.unit | :unit} expression.
1417
*/
1518
export interface MessageNumber extends MessageValue<'number'> {
1619
readonly type: 'number';

mf2/messageformat/src/functions/math.ts renamed to mf2/messageformat/src/functions/offset.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { MessageNumber, number, readNumericOperand } from './number.ts';
44
import { asPositiveInteger } from './utils.ts';
55

66
/**
7-
* `math` accepts a numeric value as input and adds or subtracts an integer value from it
7+
* `offset` accepts a numeric value as input and adds or subtracts an integer value from it
88
*
99
* @beta
1010
*/
11-
export function math(
11+
export function offset(
1212
ctx: MessageFunctionContext,
1313
exprOpt: Record<string | symbol, unknown>,
1414
operand?: unknown
@@ -26,7 +26,7 @@ export function math(
2626
}
2727
if (add < 0 === sub < 0) {
2828
const msg =
29-
'Exactly one of "add" or "subtract" is required as a :math option';
29+
'Exactly one of "add" or "subtract" is required as an :offset option';
3030
throw new MessageFunctionError('bad-option', msg, source);
3131
}
3232
const delta = add < 0 ? -sub : add;

0 commit comments

Comments
 (0)