From c49a2c366539b53ac557305a0131bca953a268ee Mon Sep 17 00:00:00 2001 From: lionel-rowe Date: Wed, 7 May 2025 18:41:05 +0800 Subject: [PATCH] Fix/update `uppercase` custom function example for latest messageformat@next --- docs/integration/js.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/integration/js.md b/docs/integration/js.md index 79fbc37..9dfef80 100644 --- a/docs/integration/js.md +++ b/docs/integration/js.md @@ -182,13 +182,15 @@ providing definitions for custom functions. To start with, let's write code for a simple custom function: ```js -/** - * @params {string[]} locales - * @params {Record} options - * @params {string} value - */ -function uppercase(locales, options, value) { - return { toString: () => value.toUpperCase() }; +import { DefaultFunctions, asString } from "messageformat@next/functions"; + +/** @type {typeof DefaultFunctions.string} */ +function uppercase(context, options, input) { + return DefaultFunctions.string( + context, + options, + asString(input).toLocaleUpperCase(context.locales), + ); } ``` @@ -196,6 +198,8 @@ Now that this function is defined, we can pass it to the `MessageFormat` constructor as part of the third argument: ```js +import { MessageFormat } from "messageformat@next"; + const mf = new MessageFormat( ["en"], "{messageformat :uppercase}",