Version: v0.5.1 - Beta.  We welcome contributors & feedback.  THanks!

String.fill

fill(value0, value1, ...)

Description

Fill in placeholders {...} with values.

'Hello, {0}'.fill('Deer');
//= 'Hello, Deer'

// Without numbers - in order of arguments
'{} eats {}'.fill('Monkey', 'banana');
//= 'Monkey eats banana'

// With numbers - in any order
'{1} eats {0}'.fill('banana', 'Monkey');
//= 'Monkey eats banana'

// With a List
let values = ['Bear', 'honey'];
'{0} eats {1}'.fill(values);
//= 'Bear eats honey'

// With a Map
let animal = { name: 'Snail', food: 'leaves' };
'{name} eats {food}'.fill(animal);
//= 'Snail eats leaves'