-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sort library and sub-app names to reduce git merge conflicts
- Loading branch information
Showing
5 changed files
with
46 additions
and
2 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 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 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 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,17 @@ | ||
/** | ||
* In-place sort object entities by their keys so that it can be serialized to json with sorted order. | ||
* @param object | ||
* @returns The original object with modified entities order. | ||
*/ | ||
export function inPlaceSortByKeys(object: Record<string, any>): Record<string, any> { | ||
const sorted: Record<string, any> = {}; | ||
|
||
const keys = Object.keys(object); | ||
keys.sort(); | ||
for (const key of keys) { | ||
sorted[key] = object[key]; | ||
delete object[key]; | ||
} | ||
|
||
return Object.assign(object, sorted); | ||
} |
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,14 @@ | ||
import { inPlaceSortByKeys } from '../../src/utils/object-sorting'; | ||
|
||
|
||
describe('inPlaceSortByKeys', () => { | ||
it('should in-place sort the entities by their keys', () => { | ||
const input = { z: 'z', b: 'b', c: 'c', a: 'a', }; | ||
expect(Object.keys(input)).toEqual(['z', 'b', 'c', 'a']); | ||
|
||
const got = inPlaceSortByKeys(input); | ||
|
||
expect(got).toBe(input); // Same object | ||
expect(Object.keys(got)).toEqual(['a', 'b', 'c', 'z']); | ||
}) | ||
}) |