X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/7c3a2eda590637af9463e5a59ab798f802d274a9..8ae1056e7a8e0d348781ed6b5e8c3210eebea9df:/value.js diff --git a/value.js b/value.js index 77cb6b4..bda9180 100644 --- a/value.js +++ b/value.js @@ -1,13 +1,49 @@ // ♓🌟 Piscēs ∷ value.js // ==================================================================== // -// Copyright © 2022 Lady [@ Lady’s Computer]. +// Copyright © 2022‐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 . -import { call } from "./function.js"; +export const { + /** The welknown `@@asyncIterator` symbol. */ + asyncIterator: ASYNC_ITERATOR, + + /** The welknown `@@hasInstance` symbol. */ + hasInstance: HAS_INSTANCE, + + /** The welknown `@@isConcatSpreadable` symbol. */ + isConcatSpreadable: IS_CONCAT_SPREADABLE, + + /** The welknown `@@iterator` symbol. */ + iterator: ITERATOR, + + /** The welknown `@@match` symbol. */ + match: MATCH, + + /** The welknown `@@matchAll` symbol. */ + matchAll: MATCH_ALL, + + /** The welknown `@@replace` symbol. */ + replace: REPLACE, + + /** The welknown `@@species` symbol. */ + species: SPECIES, + + /** The welknown `@@split` symbol. */ + split: SPLIT, + + /** The welknown `@@toPrimitive` symbol. */ + toPrimitive: TO_PRIMITIVE, + + /** The welknown `@@toStringTag` symbol. */ + toStringTag: TO_STRING_TAG, + + /** The welknown `@@unscopables` symbol. */ + unscopables: UNSCOPABLES, +} = Symbol; /** The null primitive. */ export const NULL = null; @@ -18,10 +54,10 @@ export const UNDEFINED = undefined; export const { /** * Returns the primitive value of the provided object per its - * `toString` and `valueOf` methods. + * `.toString` and `.valueOf` methods. * - * If the provided hint is "string", then `toString` takes - * precedence; otherwise, `valueOf` does. + * If the provided hint is "string", then `.toString` takes + * precedence; otherwise, `.valueOf` does. * * Throws an error if both of these methods are not callable or do * not return a primitive. @@ -34,13 +70,13 @@ export const { * * The provided preferred type, if specified, should be "string", * "number", or "default". If the provided input has a - * `[Symbol.toPrimitive]` method, this function will throw rather + * `.[Symbol.toPrimitive]` method, this function will throw rather * than calling that method with a preferred type other than one of * the above. */ toPrimitive, } = (() => { - const { toPrimitive: toPrimitiveSymbol } = Symbol; + const { apply: call } = Reflect; return { ordinaryToPrimitive: (O, hint) => { @@ -80,14 +116,14 @@ export const { ); } else if (type($) === "object") { // The provided value is an object. - const exoticToPrim = $[toPrimitiveSymbol] ?? undefined; + const exoticToPrim = $[TO_PRIMITIVE] ?? undefined; if (exoticToPrim !== undefined) { // The provided value has an exotic primitive conversion // method. if (typeof exoticToPrim !== "function") { // The method is not callable. throw new TypeError( - "Piscēs: `[Symbol.toPrimitive]` was neither nullish nor callable.", + "Piscēs: `.[Symbol.toPrimitive]` was neither nullish nor callable.", ); } else { // The method is callable. @@ -105,14 +141,14 @@ export const { }; })(); -/** - * Returns whether the provided values are the same value. - * - * ※ This differs from `===` in the cases of nan and zero. - */ -export const sameValue = Object.is; - export const { + /** + * Returns whether the provided values are the same value. + * + * ※ This differs from `===` in the cases of nan and zero. + */ + sameValue, + /** * Returns whether the provided values are either the same value or * both zero (either positive or negative). @@ -122,7 +158,9 @@ export const { sameValueZero, } = (() => { const { isNaN: isNan } = Number; + const { is } = Object; return { + sameValue: (a, b) => is(a, b), sameValueZero: ($1, $2) => { const type1 = type($1); const type2 = type($2);