update deno-commons-mod.ts
This commit is contained in:
@@ -597,6 +597,25 @@ export function getCurrentScriptDirectory(): string {
|
|||||||
return dirname(getCurrentScriptFile());
|
return dirname(getCurrentScriptFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function stringifySorted<T extends Record<string, any>>(
|
||||||
|
record: T,
|
||||||
|
space?: string | number,
|
||||||
|
): string {
|
||||||
|
return JSON.stringify(record, (key, value) => {
|
||||||
|
if (
|
||||||
|
value !== null && typeof value === "object" && !Array.isArray(value)
|
||||||
|
) {
|
||||||
|
const sortedKeys = Object.keys(value).sort();
|
||||||
|
const sortedObj: Record<string, any> = {};
|
||||||
|
for (const k of sortedKeys) {
|
||||||
|
sortedObj[k] = value[k];
|
||||||
|
}
|
||||||
|
return sortedObj;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}, space);
|
||||||
|
}
|
||||||
|
|
||||||
Deno.test("isOn", () => {
|
Deno.test("isOn", () => {
|
||||||
assertEquals(false, isOn(undefined));
|
assertEquals(false, isOn(undefined));
|
||||||
assertEquals(false, isOn(""));
|
assertEquals(false, isOn(""));
|
||||||
|
|||||||
Reference in New Issue
Block a user