Skip to content

Commit

Permalink
Merge branch 'dev', v3.0.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Mar 15, 2023
2 parents ddfc32d + 5fefbb9 commit 7093887
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/locales/de-CH/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('../de/fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/de/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('./fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
// Don't import the fields as it's a 1:1 mapping anyway
// { fields: require('./fields.json') },
require('./texts.json'),
Expand Down
3 changes: 2 additions & 1 deletion src/locales/es/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('./fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/fr-CA/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('../fr/fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/fr-CH/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('../fr/fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/fr/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('./fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/it-CH/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('../it/fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/it/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('./fields.json'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/ro/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default Object.assign(
import Utils from '../../utils';
export default Utils.mergeDeep(
{
fields: require('./fields.json'),
},
Expand Down
27 changes: 27 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,31 @@ export default class Utils {
return Boolean(data['stac_extensions'].find(uri => regexp.test(uri)));
}

/**
* Deep merge two objects.
* @param target
* @param ...sources
*/
static mergeDeep(target, ...sources) {
if (!sources.length) {
return target;
}
const source = sources.shift();

if (Utils.isObject(target) && Utils.isObject(source)) {
for (const key in source) {
if (Utils.isObject(source[key])) {
if (!target[key]) {
Object.assign(target, { [key]: {} });
}
Utils.mergeDeep(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}

return Utils.mergeDeep(target, ...sources);
}

}

0 comments on commit 7093887

Please sign in to comment.