Socket
Book a DemoInstallSign in
Socket

diffex

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diffex

A tool to extract key-value pairs by comparing a template with an input string.

latest
Source
npmnpm
Version
1.0.0-beta.1
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

DiffEx

A tool to extract key-value pairs by comparing (diffing) a template with an input string.

Build Status npm version Dependency Status devDependency Status

Installation

npm install flowxo/diffex

Usage

diffex is initialised with a template, which is used as a base for the diffing.

A template is a simple string with {{placeholder}} values. These placeholders will be replaced with data when the template is applied to an input string.

You should define your template variables inside {{ and }} curly braces. Don't include any spaces inside the curlys, as this will prevent the extractor from working correctly.

For example, these template variables are ok:

{{name}}
{{first_name}}
{{last-name}}

whereas these are invalid:

{{ name }}
{{first name}}
{{ last name }}

Create the diffex object like so:

var do = diffex(template);

Once you have the diffex object, there are two methods available: placeholders() and parse(input).

.placeholders()

Parses the template and outputs all found placeholders.

Example:

var diffex = require('diffex');
var template = '{{customer}} owes £{{amount}}.';

diffex(template).placeholders();
// -> ['customer', 'amount']

.parse(input)

Compares the template with an input, extracting the differences and outputting as key-value pairs.

var diffex = require('diffex');
var template = '{{customer}} owes £{{amount}}.';
var input = 'Bob owes £19.'

diffex(template).parse(input);
// -> { customer: 'Bob', amount: '19' }

Credit

The core diff algorithm was implemented by Neil Fraser, originally found here. The library is reproduced here under the Apache 2.0 license.

License

Apache 2.0

Keywords

diff

FAQs

Package last updated on 19 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts