extract-string

1.0.2 • Public • Published
Build Status Pull Requests stats NPM Downloads NPM Version

Extract-String

Extracts the given pattern variables from the given string. You can use it to extract url params and strings without using regex.

Installation

npm install extract-string --save

Then, in your app:

var extract = require('extract-string');

Example 1

var test = extract('Hello my friends of the world.\nHello my dear friends of this world.')
            .pattern('{hi} my {type} of {where}.');
 
/*
returns:
[{
    hi : 'Hello',
    type : 'friends',
    where : 'the world'
},
{
    hi : 'Hello',
    type : 'dear friends',
    where : 'this world'
}
]
*/

Example 2

var test = extract('/users/12345/friends/6789/picture')
            .pattern('/users/{userid}/friends/{friendid}/picture');
/*
returns:
[{
    userid : 12345,
    friendid : 6789
}]
*/

License

MIT

Package Sidebar

Install

npm i extract-string

Weekly Downloads

94

Version

1.0.2

License

MIT

Last publish

Collaborators

  • npm.creador