No description, website, or topics provided.
Switch branches/tags
Nothing to show
Pull request Compare This branch is 2 commits behind dominictarr:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Setup a series of inserts on a string, but without altering it (yet) then apply all the inserts without them interfeering with each other.

this is very useful if you want to check multiple regexps against a string and wrap those words...

I intend to use this to implement Syntax Highlighting in Hipster


insert-queue can beused to insert multiple strings into another string,

var iq = require( 'insert-queue' )
var q = iq('a string to do insertions on')
q.wrap(/.*/, ['<p>', '</p>'])
q.wrap(/string/, ['<i>', '</i>'])

// '<p>a <i>string</i> to do insertions on</i>'


wrap (regexpy, around)

Wrap occurances of regexpy with around.

If around is a string, it will be inserted before and after matches of regexpy. If regexpy is global (/.../g) all matches will be replaced. Otherwise only the first occurance will be replaced.

Note: regexpy doesn't have to be a RegExp. It just needs a exec method, and to set global = true if it can produce multiple matches (and must use a lastIndex property like a regexp)

In this way you can implement your own ad-hock look behind, etc.

insertBefore(index, string)

Queue string to be inserted at index, ahead of anything currently queued at index.

insertAfter(index, string)

Queue string to be inserted at index, behind anything currently queued at index.