]> Lady’s Gitweb - Pisces/blob - symbol.js
Add methods for own entries and values to object.js
[Pisces] / symbol.js
1 // ♓🌟 Piscēs ∷ symbol.js
2 // ====================================================================
3 //
4 // Copyright © 2023 Lady [@ Lady’s Computer].
5 //
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
9
10 import { createCallableFunction } from "./function.js";
11
12 /**
13 * Returns the description for the provided symbol.
14 *
15 * ※ This is effectively an alias for the `Symbol::description`
16 * getter.
17 *
18 * ☡ This function throws if the provided argument is not a symbol.
19 */
20 export const getSymbolDescription = createCallableFunction(
21 Object.getOwnPropertyDescriptor(Symbol.prototype, "description").get,
22 { name: "getSymbolDescription" },
23 );
24
25 /**
26 * Returns a string representation of the provided symbol.
27 *
28 * ※ Use `getSymbolDescription` instead if you just want the text
29 * description of a symbol.
30 *
31 * ※ This is effectively an alias for the `Symbol::toString`.
32 *
33 * ☡ This function throws if the provided argument is not a symbol.
34 */
35 export const symbolToString = createCallableFunction(
36 Symbol.prototype.toString,
37 { name: "symbolToString" },
38 );
39
40 /**
41 * Returns the value of the provided symbol.
42 *
43 * ※ This is effectively an alias for the `Symbol::valueOf`.
44 *
45 * ☡ This function throws if the provided argument is not a symbol and
46 * does not have a `[[SymbolData]]` slot.
47 */
48 export const symbolValue = createCallableFunction(
49 Symbol.prototype.valueOf,
50 { name: "symbolValue" },
51 );
This page took 0.054597 seconds and 5 git commands to generate.