npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extractjs

v0.3.1

Published

Extract/interpolate string

Downloads

340

Readme

extractjs

Build Status npm version Bower version license

Extract/interpolate strings.

##Usage

###Node.js and Browserify

Install from npm

npm install extractjs


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
    var defaults = {
        startExtract: '{',
        endExtract: '}',
        extractors: { /* capture functions */ }
        initValue: void 0
    }

Templates can be redefined as below:

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.

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.

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.

Copyright (c) 2015 Prince John Wesley