@trait/replacor

0.1.2 • Public • Published

replacor Build Status

small module to replace code blocks with custom code, like for css code generators for example.

(technically it's also a very tiny template engine haha)

npm i -S @trait/replacor
var rp = require('replacor')

// Replace from a string
var res1 = rp.generate('var {} = 1', 'test') // 'var test = 1'

// You can also replace multiple ones, just keep the order
var res2 = rp.generate('var {} = {}', 'test2', '/()/') // 'var test2 = /()/'

// If you have a lot of them and you don't want to remember the order, you
// can name them
var res3 = rp.generateNamed(
  'var {varName} = {varValue}\
   {functionName}()\
   object.{propertyName}',
   {
     varName: 'test',
     varValue: 'cool var',
     functionName: 'myCoolFunction',
     propertyName: 'generateSparkles'
   }
 ) // 'var test = "cool var" (and so on...)'

license

MIT

Package Sidebar

Install

npm i @trait/replacor

Weekly Downloads

2

Version

0.1.2

License

MIT

Last publish

Collaborators

  • trait