# extractjs

> Extract/interpolate string

Latest version **0.3.1** (published 2016-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install extractjs
pnpm add extractjs
yarn add extractjs
bun add extractjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2016-04-23 |
| First published | 2015-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | prince john wesley |
| Maintainers | princejwesley |
| Keywords | interpolate, extract, pattern matching, bind, capture, template |

## Links

- npm: https://www.npmjs.com/package/extractjs
- Repository: https://github.com/princejwesley/extractjs
- Homepage: https://github.com/princejwesley/extractjs#readme
- Issues: https://github.com/princejwesley/extractjs/issues
- npm.io page: https://npm.io/package/extractjs

## Recent versions

- 0.3.1 (latest) — 2016-04-23
- 0.3.0 — 2016-04-22
- 0.2.0 — 2015-08-05
- 0.1.9 — 2015-05-01
- 0.1.8 — 2015-04-29
- 0.1.7 — 2015-04-29
- 0.1.6 — 2015-04-28
- 0.1.5 — 2015-04-26
- 0.1.4 — 2015-04-26
- 0.1.3 — 2015-04-26
- 0.1.2 — 2015-04-26
- 0.1.1 — 2015-04-25
- 0.1.0 — 2015-04-25

## README

# extractjs

[![Build Status](https://travis-ci.org/princejwesley/extractjs.svg)](https://travis-ci.org/princejwesley/extractjs) [![npm version](https://badge.fury.io/js/extractjs.svg)](http://badge.fury.io/js/extractjs) [![Bower version](https://badge.fury.io/bo/extractjs.svg)](http://badge.fury.io/bo/extractjs) ![license](https://img.shields.io/badge/license-MIT-blue.svg)

Extract/interpolate strings.

##Usage

###Node.js and Browserify

Install from npm

> npm install extractjs

```javascript

var extractjs = require('extractjs'),
    extractor = extractjs();

var captured = extractor("This is a {name} library",
    "This is a extractjs library");
// > { name: 'extractjs'}

```

#### Template Settings
##### Default Settings
```javascript
    var defaults = {
        startExtract: '{',
        endExtract: '}',
        extractors: { /* capture functions */ }
        initValue: void 0
    }
```

Templates can be redefined as below:
```javascript
var extractjs = require('extractjs'),
    settings = { startExtract: '[[', endExtract: ']]'}
    extractor = extractjs(settings);

var captured = extractor("This is [[name]], [[age]] years old", 
    "This is John, 26 years old");
// > { name: 'John', age: 26 } <-- age is no longer string

// Settings can be overridden at the time of extraction
var date = extractor("Date is |date|/|month|/|year|", "Date is 26/04/2015",
    { startExtract: '|', endExtract: '|'})
// > { date: 26, month: 4, year: 2015 }
```

Its possible to build a pattern before extract/interpolate data.
```javascript
var extractjs = require('extractjs'),
    extractor = extractjs();

var loginPattern = extractor("You are logged in as {name}.");

var name = loginPattern.extract('You are logged in as John. Last login: Today')
    .name;
// > John

var output = loginPattern.interpolate({name: 'John'});
//> You are loggin in as John.
```

extractors are used to override or manipulate captured values.
```javascript
var extractjs = require('extractjs'),
    settings = {
        extractors: {
            name: function(value) {
                var names = value.split(' ');
                return {
                    firstName: names[0],
                    lastName: value.substring(names[0].length).trim(),
                    fullName: value
                };
            }
        }
    },
    extractor = extractjs(settings);

var captured = extractor("This is {name}, {age} years old",
    "This is John Wesley, 26 years old");
// > { name: {
//      firstName: 'John',
//      lastName: 'Wesley',
//      fullName: 'John Wesley'
//     }, age: 26 }
```

###Web page
Access from window/global as extractjs.

## License
This plugin is licensed under the [MIT license](https://github.com/princejwesley/extractjs/blob/master/LICENSE).

Copyright (c) 2015 [Prince John Wesley](http://www.toolitup.com)

---
_Source: https://npm.io/package/extractjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
