MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / formatString

Function formatString

src/shared/utils/StringFormatter.ts:18–38  ·  view source on GitHub ↗
(str: string, ...args: T)

Source from the content-addressed store, hash-verified

16 * @param args Arguments to replace "{N}" instances with.
17 */
18export function formatString<T extends Arg[]>(str: string, ...args: T): any[] | string {
19 let onlyStrings = true;
20 const map = splitVariableString(str, opts).map((val, index) => {
21 if (index % 2 === 1) {
22 const i = parseInt(val, 10);
23 if (i >= 0 && i < args.length) {
24 const arg = args[i];
25 if (React.isValidElement(arg)) {
26 onlyStrings = false;
27 return React.Children.toArray(arg).map(component => Object.assign({ key: index.toString() }, component));
28 }
29 return arg;
30 } else { throw new Error(`Failed to format string. Index out of bounds (index: "${i}", string: "${str}").`); }
31 } else {
32 return val;
33 }
34 });
35 return onlyStrings
36 ? map.join('')
37 : map;
38}

Callers 15

renderMethod · 0.90
formatLastPlayedFunction · 0.90
formatPlaytimeFunction · 0.90
TagFilterGroupEditorFunction · 0.90
SearchableSelectDropdownFunction · 0.90
renderMethod · 0.90
renderMethod · 0.90
renderDeleteImageButtonFunction · 0.90
CuratePageFunction · 0.90
BrowsePageClass · 0.90
HomePageFunction · 0.90

Calls 3

splitVariableStringFunction · 0.90
mapMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected