summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/contributing/style_guide.md13
-rw-r--r--std/fmt/colors.ts9
-rw-r--r--std/testing/asserts.ts9
-rw-r--r--std/testing/asserts_test.ts2
-rw-r--r--std/testing/diff.ts2
5 files changed, 27 insertions, 8 deletions
diff --git a/docs/contributing/style_guide.md b/docs/contributing/style_guide.md
index ed23f31e1..0bd7c628f 100644
--- a/docs/contributing/style_guide.md
+++ b/docs/contributing/style_guide.md
@@ -314,3 +314,16 @@ export function foo(): string {
`https://deno.land/std/` is intended to be baseline functionality that all Deno
programs can rely on. We want to guarantee to users that this code does not
include potentially unreviewed third party code.
+
+#### Document and maintain browser compatiblity.
+
+If a module is browser compatible, include the following in the JSDoc at the top
+of the module:
+
+```ts
+/** This module is browser compatible. */
+```
+
+Maintain browser compatibility for such a module by either not using the global
+`Deno` namespace or feature-testing for it. Make sure any new dependencies are
+also browser compatible.
diff --git a/std/fmt/colors.ts b/std/fmt/colors.ts
index 6a06af20e..a020657d9 100644
--- a/std/fmt/colors.ts
+++ b/std/fmt/colors.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-/**
- * A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
+/** A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
* on npm.
*
* ```
@@ -10,8 +9,10 @@
*
* This module supports `NO_COLOR` environmental variable disabling any coloring
* if `NO_COLOR` is set.
- */
-const { noColor } = Deno;
+ *
+ * This module is browser compatible. */
+
+const noColor = globalThis.Deno?.noColor ?? true;
interface Code {
open: string;
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts
index d3f8bb678..ce7214998 100644
--- a/std/testing/asserts.ts
+++ b/std/testing/asserts.ts
@@ -1,4 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+/** This module is browser compatible. Do not rely on good formatting of values
+ * for AssertionError messages in browsers. */
+
import { red, green, white, gray, bold } from "../fmt/colors.ts";
import diff, { DiffType, DiffResult } from "./diff.ts";
@@ -17,7 +20,7 @@ export class AssertionError extends Error {
}
function format(v: unknown): string {
- let string = Deno.inspect(v);
+ let string = globalThis.Deno ? Deno.inspect(v) : String(v);
if (typeof v == "string") {
string = `"${string.replace(/(?=["\\])/g, "\\")}"`;
}
@@ -254,7 +257,7 @@ export function assertStrContains(
): void {
if (!actual.includes(expected)) {
if (!msg) {
- msg = `actual: "${actual}" expected to contains: "${expected}"`;
+ msg = `actual: "${actual}" expected to contain: "${expected}"`;
}
throw new AssertionError(msg);
}
@@ -286,7 +289,7 @@ export function assertArrayContains(
return;
}
if (!msg) {
- msg = `actual: "${actual}" expected to contains: "${expected}"`;
+ msg = `actual: "${actual}" expected to contain: "${expected}"`;
msg += "\n";
msg += `missing: ${missing}`;
}
diff --git a/std/testing/asserts_test.ts b/std/testing/asserts_test.ts
index 14eabca61..fb25d46cf 100644
--- a/std/testing/asserts_test.ts
+++ b/std/testing/asserts_test.ts
@@ -169,7 +169,7 @@ test("testingAssertStringContainsThrow", function (): void {
} catch (e) {
assert(
e.message ===
- `actual: "Denosaurus from Jurassic" expected to contains: "Raptor"`
+ `actual: "Denosaurus from Jurassic" expected to contain: "Raptor"`
);
assert(e instanceof AssertionError);
didThrow = true;
diff --git a/std/testing/diff.ts b/std/testing/diff.ts
index 97baa089f..da1e827ac 100644
--- a/std/testing/diff.ts
+++ b/std/testing/diff.ts
@@ -1,4 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+/** This module is browser compatible. */
+
interface FarthestPoint {
y: number;
id: number;