Skip to content

Commit c7b37c0

Browse files
author
Kureev Alexey
committed
Move applyParams to standalone file
1 parent ae8c06d commit c7b37c0

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

src/android/patches/0.17/makePackagePatch.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
const applyParams = require('../applyParams');
2+
13
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);
85

96
return {
107
pattern: '.addPackage(new MainReactPackage())',

src/android/patches/0.18/makePackagePatch.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
const applyParams = require('../applyParams');
2+
13
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);
85

96
return {
107
pattern: 'new MainReactPackage()',

src/android/patches/0.20/makePackagePatch.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
const applyParams = require('../applyParams');
2+
13
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);
85

96
return {
107
pattern: 'new MainReactPackage()',

src/android/patches/applyParams.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
};

test/android/patches/applyPatch.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy