]> Lady’s Gitweb - Pisces/commitdiff
Create symbol.js module with getSymbolDescription
authorLady <redacted>
Mon, 4 Sep 2023 20:57:00 +0000 (16:57 -0400)
committerLady <redacted>
Mon, 4 Sep 2023 21:35:46 +0000 (17:35 -0400)
mod.js
symbol.js [new file with mode: 0644]
symbol.test.js [new file with mode: 0644]

diff --git a/mod.js b/mod.js
index 41bce2763d43e5de10d920b9c5f5db198e2c46ff..600f6195700cc9b1715562e9dfefe6bd232b0e69 100644 (file)
--- a/mod.js
+++ b/mod.js
@@ -15,4 +15,5 @@ export * from "./iri.js";
 export * from "./numeric.js";
 export * from "./object.js";
 export * from "./string.js";
+export * from "./symbol.js";
 export * from "./value.js";
diff --git a/symbol.js b/symbol.js
new file mode 100644 (file)
index 0000000..514b526
--- /dev/null
+++ b/symbol.js
@@ -0,0 +1,22 @@
+// ♓🌟 Piscēs ∷ symbol.js
+// ====================================================================
+//
+// Copyright © 2023 Lady [@ Lady’s Computer].
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+
+import { makeCallable } from "./function.js";
+import { getOwnPropertyDescriptor } from "./object.js";
+
+/**
+ * Returns the description for the provided symbol.
+ *
+ * ※ This is effectively an alias for the `Symbol::description`
+ * getter.
+ */
+export const getSymbolDescription = makeCallable(
+  getOwnPropertyDescriptor(Symbol.prototype, "description").get,
+  "getSymbolDescription",
+);
diff --git a/symbol.test.js b/symbol.test.js
new file mode 100644 (file)
index 0000000..bedcc72
--- /dev/null
@@ -0,0 +1,50 @@
+// ♓🌟 Piscēs ∷ symbol.test.js
+// ====================================================================
+//
+// Copyright © 2023 Lady [@ Lady’s Computer].
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+
+import {
+  assertStrictEquals,
+  assertThrows,
+  describe,
+  it,
+} from "./dev-deps.js";
+import { getSymbolDescription } from "./symbol.js";
+
+describe("getSymbolDescription", () => {
+  it("[[Call]] returns undefined when the symbol has no description", () => {
+    assertStrictEquals(getSymbolDescription(Symbol()), undefined);
+  });
+
+  it("[[Call]] returns the empty string when the symbol has an empty description", () => {
+    assertStrictEquals(getSymbolDescription(Symbol("")), "");
+  });
+
+  it("[[Call]] returns the description", () => {
+    assertStrictEquals(
+      getSymbolDescription(Symbol("etaoin")),
+      "etaoin",
+    );
+  });
+
+  it("[[Call]] returns the empty string when the symbol has an empty description", () => {
+    assertStrictEquals(getSymbolDescription(Symbol("")), "");
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new getSymbolDescription(Symbol()));
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        getSymbolDescription.name,
+        "getSymbolDescription",
+      );
+    });
+  });
+});
This page took 0.024227 seconds and 4 git commands to generate.