Skip to content

Commit

Permalink
Resolve typescript:S2871 (provide compare function)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalre committed Jun 21, 2023
1 parent 773f311 commit ce460eb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/util/yaml-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,31 @@ const sortArrays = (obj: unknown) => {
if (!obj || typeof obj !== "object") {
return
} else if (Array.isArray(obj)) {
obj.sort()
obj.sort((a, b) => SortArrayUtil.compareObjects(a, b))
}
Object.keys(obj).forEach(key => {
const object = obj[key as keyof unknown]
if (typeof object === "object") {
if (Array.isArray(object)) {
Object.entries(object).sort()
Object.entries(object).sort((a, b) => SortArrayUtil.compareObjects(a, b))
}
sortArrays(object)
}
})
}

export class SortArrayUtil {
static compareObjects(a: object, b: object) {
if (a > b) {
return 1
}
if (a < b) {
return -1
}
return 0
}
}

export class YamlUtil {
settings: Settings
jsyamladapter: JsYamlAdapter
Expand Down

0 comments on commit ce460eb

Please sign in to comment.