https://github.com/elsehow/templateer
match and extract from template strings
https://github.com/elsehow/templateer
Last synced: about 1 year ago
JSON representation
match and extract from template strings
- Host: GitHub
- URL: https://github.com/elsehow/templateer
- Owner: elsehow
- License: bsd-3-clause
- Created: 2016-04-22T06:10:25.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-23T08:04:11.000Z (about 10 years ago)
- Last Synced: 2024-07-06T21:45:23.083Z (almost 2 years ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# templateer
extract text from strings that match templates or schema
based on [extractjs](https://www.npmjs.com/package/extractjs)
## install
```
npm install templateer
```
## use
```javascript
var templateer = require('templateer')
var matcher = templateer("hello my {adj}, {noun}")
matcher('hello fuzzy my friend')
// > false
matcher('hello my fuzzy, ')
// > false
matcher("hello my fuzzy, tree friends")
// { adj: 'fuzzy', noun: 'tree friends'}
```
if your template doesn't take arguments, this will still work for you.
in this case, matcher will just return `{}` (which is truthy)
```javascript
var matcher = templateer('/fall through the book')
matcher('/fall through the book')
// {}
```
## api
### var matcher = templateer('some cool {template}')
make a matcher for a template.
see [extractjs](https://www.npmjs.com/package/extractjs) for more on the template string format.
### matcher('some cool string')
if there is match to the template, returns an object of template parameters associated to corresponding values in the string. (see example)
returns `false` if there is no match to the template
if there is a match, but the template string takes no arguments, `matcher` will return `{}`
## license
BSD