1.1.0 • Published 6 years ago

collectify v1.1.0

Weekly downloads
2
License
GPL-3.0
Repository
github
Last release
6 years ago

Collectify

Extract text by regular expression and collect it in a file.

Usage

Options

NameRequiredDefaultDescription
fileYesN/ACollect the extracted text in this file.
regexYesN/AExtract text matching this regular expression.
captureNo0Collect text from capture group instead of entire match.

Example

We could, for example, extract all style tags and collect the contents into an external css file allowing css to be defined directly in javascript.

var fs = require("fs");
var browserify = require("browserify");
browserify("./script.js")
  .plugin("collectify", {
    file: "./public/styles.css",
    regex: /<style>([\s\S]+?)<\/style>/g,
    capture: 1
  })
  .bundle()
  .pipe(fs.createWriteStream("./public/bundle.js"));