1.2.0 • Published 11 months ago

string-extrapolate v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

string-extrapolate

Extrapolate from a string using a given template

Installation

Using npm:

$ npm i --save string-extrapolate

Using yarn:

$ yarn add string-extrapolate

Usage

Import

import extrapolate from 'string-extrapolate'

Default behavior

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')
// => {}

Basic usage

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 }

Config usage

extrapolate('Test [test]', 'Test one', { opener: '[', closer: ']' })
// => { 'test': 'one' }

extrapolate('Test %(test)s', 'Test second', { opener: '%(', closer: ')s' })
// => { 'test': 'second' }
1.2.0

11 months ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago