mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
27 lines
783 B
TypeScript
27 lines
783 B
TypeScript
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||
|
// This module is browser compatible.
|
||
|
|
||
|
// This file is copied from `std/assert`.
|
||
|
|
||
|
/**
|
||
|
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
|
||
|
* make tests less flaky
|
||
|
* @param v Value to be formatted
|
||
|
*/
|
||
|
export function format(v: unknown): string {
|
||
|
// deno-lint-ignore no-explicit-any
|
||
|
const { Deno } = globalThis as any;
|
||
|
return typeof Deno?.inspect === "function"
|
||
|
? Deno.inspect(v, {
|
||
|
depth: Infinity,
|
||
|
sorted: true,
|
||
|
trailingComma: true,
|
||
|
compact: false,
|
||
|
iterableLimit: Infinity,
|
||
|
// getters should be true in assertEquals.
|
||
|
getters: true,
|
||
|
strAbbreviateSize: Infinity,
|
||
|
})
|
||
|
: `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
|
||
|
}
|