-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (41 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var R = require ( 'ramda' );
module.exports = function ( func, obj ) {
return R.mapObj ( function ( value ) {
var o;
if ( R.type ( value ) === 'Object' ) {
return module.exports ( func, value );
}
if ( R.type ( value ) === 'Array' ) {
o = module.exports ( func, value );
return Object.keys ( o ).map ( function ( key ) { return o[ key ] } );
}
return func ( value );
}, obj );
};
if ( ! module.parent ) {
( function ( testData ) {
console.log ( module.exports ( function ( value ) {
var global = {
captured: 'replacement'
};
var regex = /%%(.*)%%/;
var match = regex.exec ( value );
if ( match ) {
return R.replace ( regex, global[match[1]], value );
}
return value;
}, testData ) );
} )( {
hallo: 'bye',
bye: '%%captured%%',
array: [
'hallo',
'bye',
'%%captured%%'
],
object: {
hallo: 'bye',
bye: '%%captured%%'
}
} );
}