]> Lady’s Gitweb - Pisces/blob - symbol.js
Add symbolToString and symbolValue to symbol.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 import { getOwnPropertyDescriptor } from "./object.js";
12
13 /**
14 * Returns the description for the provided symbol.
15 *
16 * ※ This is effectively an alias for the `Symbol::description`
17 * getter.
18 *
19 * ☡ This function throws if the provided argument is not a symbol.
20 */
21 export const getSymbolDescription = createCallableFunction(
22 getOwnPropertyDescriptor(Symbol.prototype, "description").get,
23 "getSymbolDescription",
24 );
25
26 /**
27 * Returns a string representation of the provided symbol.
28 *
29 * ※ Use `getSymbolDescription` instead if you just want the text
30 * description of a symbol.
31 *
32 * ※ This is effectively an alias for the `Symbol::toString`.
33 *
34 * ☡ This function throws if the provided argument is not a symbol.
35 */
36 export const symbolToString = createCallableFunction(
37 Symbol.prototype.toString,
38 "symbolToString",
39 );
40
41 /**
42 * Returns the value of the provided symbol.
43 *
44 * ※ This is effectively an alias for the `Symbol::valueOf`.
45 *
46 * ☡ This function throws if the provided argument is not a symbol and
47 * does not have a `[[SymbolData]]` slot.
48 */
49 export const symbolValue = createCallableFunction(
50 Symbol.prototype.valueOf,
51 "symbolValue",
52 );
This page took 0.087688 seconds and 5 git commands to generate.