Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Latest commit

 

History

History
33 lines (23 loc) · 756 Bytes

string_interpolate.md

File metadata and controls

33 lines (23 loc) · 756 Bytes

strings/stringInterpolate

Interpolate placeholder values found in the given string.

The given string may contain placeholder values in the form of $placeholder$ which are replaced by the values found in the given object.

function stringInterpolate(str: string, values: object): string

Args

str:string
String which possibly contains placeholder values to be replaced.

values:object
Object where keys are placeholders.

Returns

The string with placeholders replaced by values.

Examples

import { stringInterpolate } from 'utils/strings';

const str = 'Press $key$ now';
const values = {
    key: 'ENTER'
};

console.log(stringInterpolate(str, values)); // Outputs: 'Press ENTER now'