lookingglass/hyperglass/ui/hooks/useStrf.ts
2021-09-08 01:02:25 -07:00

14 lines
407 B
TypeScript

import { useCallback } from 'react';
import format from 'string-format';
import type { UseStrfArgs } from './types';
/**
* Format a string with variables, like Python's string.format()
*/
export function useStrf(): (str: string, fmt: UseStrfArgs, fallback?: string) => string {
return useCallback(
(str: string, fmt: UseStrfArgs, fallback?: string) => format(str, fmt) ?? fallback,
[],
);
}