New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

broccoli-replace

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-replace

Replace text patterns with applause.

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.9K
increased by4.75%
Maintainers
1
Weekly downloads
 
Created
Source

broccoli-replace

Build Status Version Prerequisite License: MIT Twitter: outa7iME

Replace text patterns with applause.

Install

From NPM:

npm install broccoli-replace --save-dev

Usage

Assuming installation via NPM, you can use broccoli-replace in your Brocfile.js like this:

var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    '**/*.html'
  ],
  patterns: [
    {
      match: 'foo',
      replacement: 'bar'
    }
  ]
});

Options

Supports all the applause options.

Examples

Basic

File src/manifest.appcache:

CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*

Brocfile.js:

var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    'manifest.appcache'
  ],
  patterns: [
    {
      match: 'timestamp',
      replacement: Date.now()
    }
  ]
});

Multiple matching

File src/manifest.appcache:

CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*

File src/humans.txt:

              __     _
   _    _/__  /./|,//_`
  /_//_// /_|///  //_, outaTiME v.@@version

/* TEAM */
  Web Developer / Graphic Designer: Ariel Oscar Falduto
  Site: https://www.outa.im
  Twitter: @outa7iME
  Contact: afalduto at gmail dot com
  From: Buenos Aires, Argentina

/* SITE */
  Last update: @@timestamp
  Standards: HTML5, CSS3, robotstxt.org, humanstxt.org
  Components: H5BP, Modernizr, jQuery, Bootstrap, LESS, Jade, Grunt
  Software: Sublime Text, Photoshop, LiveReload

Brocfile.js:

var BroccoliReplace = require('broccoli-replace');
var pkg = require('./package.json');

module.exports = new BroccoliReplace('src', {
  files: [
    'manifest.appcache',
    'humans.txt'
  ],
  patterns: [
    {
      match: 'version',
      replacement: pkg.version
    },
    {
      match: 'timestamp',
      replacement: Date.now()
    }
  ]
});

Cache busting

File src/index.html:

<head>
  <link rel="stylesheet" href="/css/style.css?rel=@@timestamp">
  <script src="/js/app.js?rel=@@timestamp"></script>
</head>

Brocfile.js:

var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    'index.html'
  ],
  patterns: [
    {
      match: 'timestamp',
      replacement: Date.now()
    }
  ]
});

Include file

File src/index.html:

<body>
  @@include
</body>

Brocfile.js:

var BroccoliReplace = require('broccoli-replace');
var fs = require('fs');

module.exports = new BroccoliReplace('src', {
  files: [
    'index.html'
  ],
  patterns: [
    {
      match: 'include',
      replacement: fs.readFileSync('./includes/content.html', 'utf8')
    }
  ]
});

Regular expression

File src/username.txt:

John Smith

Brocfile.js:

var BroccoliReplace = require('broccoli-replace');

module.exports = new BroccoliReplace('src', {
  files: [
    'username.txt'
  ],
  patterns: [
    {
      match: /(\w+)\s(\w+)/,
      replacement: '$2, $1' // Replaces "John Smith" with "Smith, John"
    }
  ]
});

Lookup for foo instead of @@foo

Brocfile.js:

var BroccoliMergeTrees = require('broccoli-merge-trees');
var BroccoliReplace = require('broccoli-replace');

var inputNodes = [
  new BroccoliReplace('src', {
    files: [
      'foo.txt'
    ],
    patterns: [
      {
        match: /foo/g, // Explicitly using a regexp
        replacement: 'bar'
      }
    ]
  }),
  new BroccoliReplace('src', {
    files: [
      'foo.txt'
    ],
    patterns: [
      {
        match: 'foo',
        replacement: 'bar'
      }
    ],
    usePrefix: false // Using the option provided
  }),
  new BroccoliReplace('src', {
    files: [
      'foo.txt'
    ],
    patterns: [
      {
        match: 'foo',
        replacement: 'bar'
      }
    ],
    prefix: '' // Removing the prefix manually
  })
];

module.exports = new BroccoliMergeTrees(nodes);
  • applause - Human-friendly replacements

License

MIT © outaTiME

Keywords

FAQs

Package last updated on 04 Mar 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc