Skip to content

Commit

Permalink
Also sort the objects inside json object
Browse files Browse the repository at this point in the history
  • Loading branch information
huyphung1602 committed Jan 2, 2025
1 parent 4c46726 commit cb6af89
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/dbml-connector/__tests__/connector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { connector } from '../src/index.ts';

const sortKeys = (obj: any): any => {
if (Array.isArray(obj)) {
if (obj.length > 0 && typeof obj[0] === 'object' && obj[0] !== null && 'name' in obj[0]) {
return obj.map(sortKeys).sort((a, b) => (a.name > b.name ? 1 : -1));
}
return obj.map(sortKeys);
} else if (obj !== null && typeof obj === 'object') {
return Object.keys(obj).sort().reduce((result: any, key: string) => {
Expand Down

0 comments on commit cb6af89

Please sign in to comment.