-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve an issue where the 'removeUnusedKeys' option may re-order key…
…s in the translation file (#64)
- Loading branch information
Showing
5 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import isPlainObject from 'lodash/isPlainObject'; | ||
|
||
// flattenObjectKeys({ | ||
// a: { | ||
// b: { | ||
// c: [], | ||
// d: { | ||
// e: [{ f: [] }, { b: 1 }], | ||
// g: {} | ||
// } | ||
// } | ||
// } | ||
// }); | ||
// | ||
// [ [ 'a', 'b', 'c' ], | ||
// [ 'a', 'b', 'd', 'e', '0', 'f' ], | ||
// [ 'a', 'b', 'd', 'e', '1', 'b' ], | ||
// [ 'a', 'b', 'd', 'g' ] ] | ||
// | ||
const flattenObjectKeys = (obj, keys = []) => { | ||
return Object.keys(obj).reduce((acc, key) => { | ||
const o = ((isPlainObject(obj[key]) && Object.keys(obj[key]).length > 0) || (Array.isArray(obj[key]) && obj[key].length > 0)) | ||
? flattenObjectKeys(obj[key], keys.concat(key)) | ||
: [keys.concat(key)]; | ||
return acc.concat(o); | ||
}, []); | ||
}; | ||
|
||
export default flattenObjectKeys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import isPlainObject from 'lodash/isPlainObject'; | ||
import cloneDeep from 'clone-deep'; | ||
|
||
// omitEmptyObject({ | ||
// a: { | ||
// b: { | ||
// c: 1, | ||
// d: { | ||
// e: { | ||
// } | ||
// } | ||
// } | ||
// } | ||
// }); | ||
// | ||
// { a: { b: { c: 1 } } } | ||
// | ||
const unsetEmptyObject = (obj) => { | ||
Object.keys(obj).forEach(key => { | ||
if (!isPlainObject(obj[key])) { | ||
return; | ||
} | ||
|
||
unsetEmptyObject(obj[key]); | ||
if (isPlainObject(obj[key]) && Object.keys(obj[key]).length === 0) { | ||
obj[key] = undefined; | ||
delete obj[key]; | ||
} | ||
}); | ||
|
||
return obj; | ||
}; | ||
|
||
const omitEmptyObject = (obj) => unsetEmptyObject(cloneDeep(obj)); | ||
|
||
export default omitEmptyObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters