forked from MapComplete/MapComplete
Scripts: automatically reorder layers and themes into the fixed order
This commit is contained in:
parent
40678a2eb3
commit
8761685fa6
4 changed files with 55 additions and 46 deletions
18
src/Utils.ts
18
src/Utils.ts
|
@ -1229,6 +1229,8 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
* @param x
|
||||
* @constructor
|
||||
*/
|
||||
static Clone<T>(x: Readonly<T>): T
|
||||
static Clone<T>(x: T): T
|
||||
static Clone<T>(x: T): T {
|
||||
if (x === undefined) {
|
||||
return undefined
|
||||
|
@ -1267,7 +1269,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
reference: string,
|
||||
ts: ReadonlyArray<T>,
|
||||
getName: (t: T) => string
|
||||
): string[]
|
||||
): T[]
|
||||
public static sortedByLevenshteinDistance<T>(
|
||||
reference: string,
|
||||
ts: ReadonlyArray<T>,
|
||||
|
@ -1841,4 +1843,18 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
public static concat<T>(param: T[][]): T[] {
|
||||
return [].concat(...param)
|
||||
}
|
||||
|
||||
|
||||
public static reorder<T extends object>(object: T, order: ReadonlyArray<string>): T {
|
||||
const allKeys = new Set<string>(Object.keys(object))
|
||||
const copy = {}
|
||||
for (const key of order) {
|
||||
copy[key] = object[key]
|
||||
allKeys.delete(key)
|
||||
}
|
||||
for (const key of allKeys) {
|
||||
copy[key] = object[key]
|
||||
}
|
||||
return <T> copy
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue