Extrapolate from a string using a given template
Using npm:
$ npm i --save string-extrapolate
Using yarn:
$ yarn add string-extrapolate
import extrapolate from 'string-extrapolate'
If any parameter isn't correct (i.e no placeholders, input that doesn't match), the function will return an empty object so the responsibility of handling is transferred to the user, and no need for error handling when using the function
extrapolate(undefined, undefined)
// => {}
extrapolate('asd', 'asd')
// => {}
extrapolate('a{asd}', 'dsa')
// => {}
extrapolate('This is a {something}', 'This is a draft')
// => { something: 'draft' }
extrapolate('{one} with {two} and {three}', 'first with second and third')
// => { one: 'first', two: 'second', three: 'third' }
extrapolate('a{{asd}}', 'azxc')
// => { '{asd}': 'zxc' }
extrapolate('http://something.com/{id}', 'http://something.com/123123')
// => { id: 123123 }
extrapolate('Test [test]', 'Test one', { opener: '[', closer: ']' })
// => { 'test': 'one' }
extrapolate('Test %(test)s', 'Test second', { opener: '%(', closer: ')s' })
// => { 'test': 'second' }