File tree Expand file tree Collapse file tree 5 files changed +28
-18
lines changed Expand file tree Collapse file tree 5 files changed +28
-18
lines changed Original file line number Diff line number Diff line change
1
+ const applyParams = require ( '../applyParams' ) ;
2
+
1
3
module . exports = function makePackagePatch ( packageInstance , params ) {
2
- const processedInstance = packageInstance . replace (
3
- / \$ \{ ( \w + ) \} / g,
4
- ( pattern , paramName ) => params [ paramName ]
5
- ? `this.getResources().getString(R.strings.${ paramName } )`
6
- : null
7
- ) ;
4
+ const processedInstance = applyParams ( packageInstance , params ) ;
8
5
9
6
return {
10
7
pattern : '.addPackage(new MainReactPackage())' ,
Original file line number Diff line number Diff line change
1
+ const applyParams = require ( '../applyParams' ) ;
2
+
1
3
module . exports = function makePackagePatch ( packageInstance , params ) {
2
- const processedInstance = packageInstance . replace (
3
- / \$ \{ ( \w + ) \} / g,
4
- ( pattern , paramName ) => params [ paramName ]
5
- ? `this.getResources().getString(R.strings.${ paramName } )`
6
- : null
7
- ) ;
4
+ const processedInstance = applyParams ( packageInstance , params ) ;
8
5
9
6
return {
10
7
pattern : 'new MainReactPackage()' ,
Original file line number Diff line number Diff line change
1
+ const applyParams = require ( '../applyParams' ) ;
2
+
1
3
module . exports = function makePackagePatch ( packageInstance , params ) {
2
- const processedInstance = packageInstance . replace (
3
- / \$ \{ ( \w + ) \} / g,
4
- ( pattern , paramName ) => params [ paramName ]
5
- ? `this.getResources().getString(R.strings.${ paramName } )`
6
- : null
7
- ) ;
4
+ const processedInstance = applyParams ( packageInstance , params ) ;
8
5
9
6
return {
10
7
pattern : 'new MainReactPackage()' ,
Original file line number Diff line number Diff line change
1
+ module . exports = function applyParams ( str , params ) {
2
+ return str . replace (
3
+ / \$ \{ ( \w + ) \} / g,
4
+ ( pattern , paramName ) => params [ paramName ]
5
+ ? `this.getResources().getString(R.strings.${ paramName } )`
6
+ : null
7
+ ) ;
8
+ } ;
Original file line number Diff line number Diff line change
1
+ const chai = require ( 'chai' ) ;
2
+ const expect = chai . expect ;
3
+ const applyParams = require ( '../../../src/android/patches/applyParams' ) ;
4
+
5
+ describe ( 'applyParams' , ( ) => {
6
+ it ( 'apply params to the string' , ( ) => {
7
+ expect (
8
+ applyParams ( '${foo}' , { foo : 'foo' } )
9
+ ) . to . be . equal ( 'this.getResources().getString(R.strings.foo)' ) ;
10
+ } ) ;
11
+ } ) ;
You can’t perform that action at this time.
0 commit comments