string-extrapolate
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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' }

Readme

Keywords

Package Sidebar

Install

npm i string-extrapolate

Weekly Downloads

11

Version

1.2.0

License

ISC

Unpacked Size

35.2 kB

Total Files

9

Last publish

Collaborators

  • ruthenz