Skip to content

Commit

Permalink
Replace deprecated flatten w/ native flat method
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Dec 24, 2023
1 parent c4dbb3d commit 152a468
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
},
"dependencies": {
"@babel/runtime": "^7.22.15",
"@ultraq/array-utils": "^3.1.1",
"@ultraq/function-utils": "^0.5.1"
},
"devDependencies": {
Expand Down
21 changes: 10 additions & 11 deletions source/MessageFormatter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -16,7 +16,6 @@

import {findClosingBracket, splitFormattedArgument} from './utilities.js';

import {flatten} from '@ultraq/array-utils';
import {memoize} from '@ultraq/function-utils';

/**
Expand Down Expand Up @@ -49,15 +48,15 @@ import {memoize} from '@ultraq/function-utils';

/**
* The main class for formatting messages.
*
*
* @author Emanuel Rabina
*/
export default class MessageFormatter {

/**
* Creates a new formatter that can work using any of the custom type handlers
* you register.
*
*
* @param {string} locale
* @param {Record<string,TypeHandler>} [typeHandlers]
* Optional object where the keys are the names of the types to register,
Expand All @@ -73,12 +72,12 @@ export default class MessageFormatter {
/**
* Formats an ICU message syntax string using `values` for placeholder data
* and any currently-registered type handlers.
*
*
* @type {(message: string, values?: FormatValues) => string}
*/
format = memoize((message, values = {}) => {

return flatten(this.process(message, values)).join('');
return this.process(message, values).flat(Infinity).join('');
});

/**
Expand All @@ -88,10 +87,10 @@ export default class MessageFormatter {
* their own type handlers. This raw output is useful for other renderers,
* eg: React where components can be used instead of being forced to return
* raw strings.
*
*
* This method is used by {@link MessageFormatter#format} where it acts as a
* string renderer.
*
*
* @param {string} message
* @param {FormatValues} [values]
* @return {any[]}
Expand Down

0 comments on commit 152a468

Please sign in to comment.