Version: v0.7.0 - Beta.  We welcome contributors & feedback.

String.fill

fill($value0, $value1, ...) -> string

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
$values = ['Bear', 'honey']
'{0} eats {1}'.fill(values)
//= 'Bear eats honey'

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

See Also