Permalink
Browse files

Added replace plugin

  • Loading branch information...
1 parent b66b65c commit b263ccee5739e943e0e4de3dabfd311c0f8b6812 @tj committed Mar 21, 2012
Showing with 24 additions and 0 deletions.
  1. +1 −0 lib/ejson.js
  2. +12 −0 lib/plugins/replace.js
  3. +11 −0 test/replace.js
View
@@ -23,4 +23,5 @@ exports.version = '0.0.1';
exports.ms = require('./plugins/ms');
exports.glob = require('./plugins/glob');
+exports.replace = require('./plugins/replace');
exports.dimensions = require('./plugins/dimensions');
View
@@ -0,0 +1,12 @@
+
+/**
+ * Perform a replacement of `str` with `sub`.
+ */
+
+module.exports = function(str, sub){
+ return function(key, val){
+ return 'string' == typeof val
+ ? val.replace(str, sub)
+ : val;
+ }
+}
View
@@ -0,0 +1,11 @@
+
+var Parser = require('../')
+ , replace = Parser.replace;
+
+describe('replace', function(){
+ it('should replace occurrences of a string', function(){
+ replace('{root}', '/my/path')
+ ('', '{root}/foo')
+ .should.equal('/my/path/foo');
+ })
+})

0 comments on commit b263cce

Please sign in to comment.