--- /dev/null
+Creative Commons Legal Code
+
+CC0 1.0 Universal
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+ HEREUNDER.
+
+Statement of Purpose
+
+The laws of most jurisdictions throughout the world automatically confer
+exclusive Copyright and Related Rights (defined below) upon the creator
+and subsequent owner(s) (each and all, an "owner") of an original work of
+authorship and/or a database (each, a "Work").
+
+Certain owners wish to permanently relinquish those rights to a Work for
+the purpose of contributing to a commons of creative, cultural and
+scientific works ("Commons") that the public can reliably and without fear
+of later claims of infringement build upon, modify, incorporate in other
+works, reuse and redistribute as freely as possible in any form whatsoever
+and for any purposes, including without limitation commercial purposes.
+These owners may contribute to the Commons to promote the ideal of a free
+culture and the further production of creative, cultural and scientific
+works, or to gain reputation or greater distribution for their Work in
+part through the use and efforts of others.
+
+For these and/or other purposes and motivations, and without any
+expectation of additional consideration or compensation, the person
+associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+is an owner of Copyright and Related Rights in the Work, voluntarily
+elects to apply CC0 to the Work and publicly distribute the Work under its
+terms, with knowledge of his or her Copyright and Related Rights in the
+Work and the meaning and intended legal effect of CC0 on those rights.
+
+1. Copyright and Related Rights. A Work made available under CC0 may be
+protected by copyright and related or neighboring rights ("Copyright and
+Related Rights"). Copyright and Related Rights include, but are not
+limited to, the following:
+
+ i. the right to reproduce, adapt, distribute, perform, display,
+ communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+iii. publicity and privacy rights pertaining to a person's image or
+ likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+ subject to the limitations in paragraph 4(a), below;
+ v. rights protecting the extraction, dissemination, use and reuse of data
+ in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+ European Parliament and of the Council of 11 March 1996 on the legal
+ protection of databases, and under any national implementation
+ thereof, including any amended or successor version of such
+ directive); and
+vii. other similar, equivalent or corresponding rights throughout the
+ world based on applicable law or treaty, and any national
+ implementations thereof.
+
+2. Waiver. To the greatest extent permitted by, but not in contravention
+of, applicable law, Affirmer hereby overtly, fully, permanently,
+irrevocably and unconditionally waives, abandons, and surrenders all of
+Affirmer's Copyright and Related Rights and associated claims and causes
+of action, whether now known or unknown (including existing as well as
+future claims and causes of action), in the Work (i) in all territories
+worldwide, (ii) for the maximum duration provided by applicable law or
+treaty (including future time extensions), (iii) in any current or future
+medium and for any number of copies, and (iv) for any purpose whatsoever,
+including without limitation commercial, advertising or promotional
+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+member of the public at large and to the detriment of Affirmer's heirs and
+successors, fully intending that such Waiver shall not be subject to
+revocation, rescission, cancellation, termination, or any other legal or
+equitable action to disrupt the quiet enjoyment of the Work by the public
+as contemplated by Affirmer's express Statement of Purpose.
+
+3. Public License Fallback. Should any part of the Waiver for any reason
+be judged legally invalid or ineffective under applicable law, then the
+Waiver shall be preserved to the maximum extent permitted taking into
+account Affirmer's express Statement of Purpose. In addition, to the
+extent the Waiver is so judged Affirmer hereby grants to each affected
+person a royalty-free, non transferable, non sublicensable, non exclusive,
+irrevocable and unconditional license to exercise Affirmer's Copyright and
+Related Rights in the Work (i) in all territories worldwide, (ii) for the
+maximum duration provided by applicable law or treaty (including future
+time extensions), (iii) in any current or future medium and for any number
+of copies, and (iv) for any purpose whatsoever, including without
+limitation commercial, advertising or promotional purposes (the
+"License"). The License shall be deemed effective as of the date CC0 was
+applied by Affirmer to the Work. Should any part of the License for any
+reason be judged legally invalid or ineffective under applicable law, such
+partial invalidity or ineffectiveness shall not invalidate the remainder
+of the License, and in such case Affirmer hereby affirms that he or she
+will not (i) exercise any of his or her remaining Copyright and Related
+Rights in the Work or (ii) assert any associated claims and causes of
+action with respect to the Work, in either case contrary to Affirmer's
+express Statement of Purpose.
+
+4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+ surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+ warranties of any kind concerning the Work, express, implied,
+ statutory or otherwise, including without limitation warranties of
+ title, merchantability, fitness for a particular purpose, non
+ infringement, or the absence of latent or other defects, accuracy, or
+ the present or absence of errors, whether or not discoverable, all to
+ the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+ that may apply to the Work or any use thereof, including without
+ limitation any person's Copyright and Related Rights in the Work.
+ Further, Affirmer disclaims responsibility for obtaining any necessary
+ consents, permissions or other rights required for any use of the
+ Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+ party to this document and has no duty or obligation with respect to
+ this CC0 or use of the Work.
-{
- "fmt": { "lineWidth": 71 },
- "lint": { "rules": { "exclude": ["constructor-super"] } },
- "lock": false
-}
+{ "fmt":
+ { "exclude":
+ [ "deno.json" ]
+ , "lineWidth": 71
+ , "operatorPosition": "nextLine"
+ , "useBraces": "always" }
+, "lint":
+ { "rules":
+ { "exclude":
+ [ "constructor-super" ] } }
+, "lock": false }
--- /dev/null
+SPDX-FileCopyrightText: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+SPDX-License-Identifier: CC0-1.0
-// ♓🌟 Piscēs ∷ dev-deps.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
-
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🌟 Piscēs ∷ dev-deps.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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/>.
+ */
export {
assert,
assertEquals,
assertNotStrictEquals,
assertStrictEquals,
assertThrows,
-} from "https://deno.land/std@0.208.0/testing/asserts.ts";
-export {
- describe,
- it,
-} from "https://deno.land/std@0.208.0/testing/bdd.ts";
+} from "jsr:@std/assert@1.0.13";
+export { describe, it } from "jsr:@std/testing@1.0.15/bdd";
export {
assertSpyCall,
assertSpyCalls,
spy,
-} from "https://deno.land/std@0.208.0/testing/mock.ts";
+} from "jsr:@std/testing@1.0.15/mock";
-// ♓🌟 Piscēs ∷ function.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ function.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
ITERATOR,
defineOwnProperty,
getOwnPropertyDescriptor,
getPrototype,
+ hasOwnProperty,
objectCreate,
setPropertyValues,
setPrototype,
} from "./object.js";
+const PISCĒS = "♓🧩 Piscēs";
+
export const {
/**
* Creates a bound function from the provided function using the
* provided this value and arguments list.
*
- * ☡ As with `call` and `construct`, the arguments must be passed as
+ * ☡ As with `call´ and `construct´, the arguments must be passed as
* an array.
*/
bind,
/**
- * Returns a new function which calls the provided function with its
- * first argument as the `this` value and the remaining arguments
- * passed through.
+ * Returns a new arrow function function which wraps the provided
+ * function and passes its arguments thru.
*
- * The `length`, `name`, and prototype of the provided function will
+ * The `length´, `name´, and prototype of the provided function will
* be preserved in the new one. A second argument may be used to
- * override `length` and `name`.
+ * override `length´ and `name´.
*/
createArrowFunction,
/**
- * Returns a new function which calls the provided function with its
- * first argument as the `this` value and the remaining arguments
- * passed through.
+ * Returns a new arrow function which wraps the provided function,
+ * using its first argument as the this value when calling the
+ * provided function and passing the remainder thru.
*
- * The `length`, `name`, and prototype of the provided function will
+ * The `length´, `name´, and prototype of the provided function will
* be preserved in the new one. A second argument may be used to
- * override `length` and `name`.
+ * override `length´ and `name´.
*
- * ※ This is effectively an alias for `Function::call.bind`.
+ * ※ This is effectively an alias for `Function::call.bind´.
*/
createCallableFunction,
/**
* Returns a constructor which throws whenever it is called but has
- * the same `.name` and `.prototype` as the provided value.
+ * the same `.length´, `.name´, and `.prototype´ as the provided
+ * value.
*
- * The `length`, `name`, `prototype`, and prototype of the provided
+ * The `length´, `name´, `prototype´, and prototype of the provided
* function will be preserved in the new one. A second argument may
- * be used to override `length`, `name`, and `prototype`.
+ * be used to override `length´, `name´, and `prototype´.
*/
createIllegalConstructor,
/**
- * Returns a constructor which produces a new constructor which wraps
+ * Returns a constructor which produces a new constructor that wraps
* the provided constructor, but returns a proxy of the result using
* the provided handler.
*
* The resulting constructor inherits from, and has the same basic
- * shape as, `Proxy`.
+ * shape as, `Proxy´.
*
- * If a base constructor is not provided, `Object` will be used.
+ * If a base constructor is not provided, `Object´ will be used.
*
* If a third argument is provided, it is used as the target for the
* provided constructor when it is constructed. This can be used to
* prevent leakage of the provided constructor to superclasses
- * through `new.target`.
+ * through `new.target´.
*
- * The `length` of the provided function will be preserved in the new
- * one. A fourth argument may be used to override `length` and
- * `name`.
+ * The `length´ of the provided function will be preserved in the new
+ * one. A fourth argument may be used to override `length´ and
+ * `name´.
*
- * ※ `.prototype` will be present, but undefined, on the resulting
- * constructor. This differs from the behaviour of `Proxy`, for which
- * `.prototype` is not present at all. It is not presently possible
- * to create a constructor with no `.prototype` property in
+ * ※ `.prototype´ will be present, but undefined, on the resulting
+ * constructor. This differs from the behaviour of `Proxy´, for which
+ * `.prototype´ is not present at all. It is not presently possible
+ * to create a constructor with no `.prototype´ property in
* Ecmascript code.
*/
createProxyConstructor,
},
next: callBind(
arrayIteratorNext,
- call(arrayIterator, this.args, []),
+ reflectApply(arrayIterator, this.args, []),
),
};
},
constructor,
]);
if (existing) {
+ // There is an existing values set for this constructor.
+ //
+ // It is returned.
return existing;
} else {
+ // There is no existing values set for this constructor so one
+ // must be created.
const result = new wsConstructor();
reflectApply(wmSet, proxyConstructorValuesMap, [
constructor,
// No base function was provided to apply.
return $;
} else {
- // A base function was provided; apply it.
- const { length, name, prototype } = base;
+ // A base function was provided.
+ //
+ // Apply it.
+ const overrides = objectCreate(null);
+ overrides.length = +base.length + lengthDelta;
+ overrides.name = base.name;
if (getPrototype($) === functionPrototype) {
+ // The provided function has the function prototype.
+ //
+ // Change it to match the base function.
setPrototype($, getPrototype(base));
} else {
+ // The provided function already does not have the function
+ // prototype, so its prototype is not changed.
/* do nothing */
}
- return applyProperties($, {
- length: +length + lengthDelta,
- name,
- prototype,
- });
+ if (hasOwnProperty($, "prototype") && "prototype" in base) {
+ // The provided function has a `.prototype´ property, and one
+ // was provided in the base function as well.
+ try {
+ // If this does not throw, the provided function is a
+ // constructor. Its `.prototype´ property is set alongside
+ // the others.
+ reflectConstruct(function () {}, [], $);
+ overrides.prototype = base.prototype;
+ } catch {
+ // The provided function is not a constructor.
+ /* do nothing */
+ }
+ } else {
+ // The provided function does not have a `.prototype´ property,
+ // or the base function did not have one.
+ /* do nothing */
+ }
+ return applyProperties($, overrides);
}
};
const applyProperties = ($, override) => {
// No properties were provided to apply.
return $;
} else {
- // Properties were provided; apply them.
- const { length, name, prototype } = override;
+ // Properties were provided.
+ //
+ // Apply them.
+ const { length, name } = override;
if (
- prototype === UNDEFINED ||
- !getOwnPropertyDescriptor($, "prototype")?.writable
+ !("prototype" in override)
+ || !getOwnPropertyDescriptor($, "prototype")?.writable
) {
- // The provided function has no `.prototype`, its prototype is
+ // The provided function has no `.prototype´, its prototype is
// not writable, or no prototype value was provided.
//
// Do not modify the prototype property of the provided
// function.
/* do nothing */
} else {
- // The provided function is a constructor and a prototype value
- // was provided.
+ // The provided function has a writable `.prototype´ and a
+ // prototype value was provided.
//
// Change the prototype property of the provided function to
// match.
defineOwnDataProperty(
objectCreate(null),
"value",
- prototype,
+ override.prototype,
),
);
}
if (!(type(handler) === "object")) {
// The provided handler is not an object; this is an error.
throw new TypeError(
- `Piscēs: Proxy handler must be an object, but got: ${handler}.`,
+ `${PISCĒS}: Proxy handler must be an object, but got: ${handler}.`,
);
} else if (!isConstructor(constructor)) {
// The provided constructor is not a constructor; this is an
// error.
throw new TypeError(
- "Piscēs: Cannot create proxy constructor from nonconstructible value.",
+ `${PISCĒS}: Cannot create proxy constructor from nonconstructible value.`,
);
} else if (!isConstructor(target)) {
// The provided new target is not a constructor; this is an
// error.
throw new TypeError(
- "Piscēs: New target must be a constructor.",
+ `${PISCĒS}: New target must be a constructor.`,
);
} else {
// The arguments are acceptable.
setPrototype(
function (...$s) {
if (new.target === UNDEFINED) {
- // The constructor was not called with new; this is an
- // error.
+ // The constructor was not called with new; this is
+ // an error.
throw new TypeError(
- `Piscēs: ${
+ `${PISCĒS}: ${
C.name ?? "Proxy"
} must be called with new.`,
);
} else {
- // The constructor was called with new; return the
- // appropriate proxy.
+ // The constructor was called with new.
+ //
+ // Return the appropriate proxy.
const O = reflectConstruct(
constructor,
$s,
return false;
} else {
// One or more values has been registered for the
- // current constructor; return whether the provided
- // argument is one.
+ // current constructor.
+ //
+ // Return whether the provided argument is one.
return reflectApply(wsHas, values, [$]);
}
},
* Calls the provided function with the provided this value and
* arguments list.
*
- * ☡ This is effectively an alias for `Reflect.apply`—the arguments
+ * ☡ This is effectively an alias for `Reflect.apply´—the arguments
* must be passed as an arraylike.
*/
export const call = createArrowFunction(Reflect.apply, {
});
/**
- * Returns whether calling the provided function with no `this` value
+ * Returns whether calling the provided function with no this value
* or arguments completes normally; that is, does not throw an error.
*
* ☡ This function will throw an error if the provided argument is not
if (!isCallable($)) {
// The provided value is not callable; this is an error.
throw new TypeError(
- `Piscēs: Cannot determine completion of noncallable value: ${$}`,
+ `${PISCĒS}: Cannot determine completion of noncallable value: ${$}.`,
);
} else {
// The provided value is callable.
try {
- // Attempt to call the function and return true if this succeeds.
+ // This will throw if calling the function throws.
+ //
+ // Otherwise, return true.
$();
return true;
} catch {
- // Calling the function did not succeed; return false.
+ // Calling the function did not succeed.
+ //
+ // Return false.
return false;
}
}
* Constructs the provided function with the provided arguments list
* and new target.
*
- * ☡ This is effectively an alias for `Reflect.construct`—the
+ * ☡ This is effectively an alias for `Reflect.construct´—the
* arguments must be passed as an arraylike.
*/
export const construct = createArrowFunction(Reflect.construct);
* Returns the provided value.
*
* ※ This function can be called as a constructor. When used in an
- * `extends` clause and called via `super`, it will set the value of
- * `this` to the provided value, enabling it to be extended with
+ * `extends´ clause and called via `super´, it will set the value of
+ * `this´ to the provided value, enabling it to be extended with
* private class features.
*/
export const identity = function ($) {
/** Returns whether the provided value is a constructor. */
export const isConstructor = ($) =>
completesNormally(() =>
- // Try constructing a new object with the provided value as its
- // `new.target`. This will throw if the provided value is not a
- // constructor.
+ // Try constructing a new object using the provided value as
+ // `new.target´.
+ //
+ // ☡ This will throw if the provided value is not a constructor.
construct(function () {}, [], $)
);
-// ♓🌟 Piscēs ∷ function.test.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ function.test.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
assert,
it("[[Call]] returns a function with no prototype property", () => {
assert(
- !("prototype" in
- createArrowFunction(function () {}, { prototype: {} })),
+ !("prototype"
+ in createArrowFunction(function () {}, { prototype: {} })),
);
});
it("[[Call]] returns a function with no prototype property", () => {
assert(
- !("prototype" in
- createCallableFunction(function () {}, { prototype: {} })),
+ !("prototype"
+ in createCallableFunction(function () {}, { prototype: {} })),
);
});
-// ♓🌟 Piscēs ∷ iterable.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/>.
+// SPDX-FileCopyrightText: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ iterable.js
+ *
+ * Copyright © 2023, 2025 Lady [@ Ladys 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 { bind, call, identity } from "./function.js";
import {
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ This iterator function iterates over characters; use
- * `arrayIteratorFunction` to iterate over code units.
+ * arrayIteratorFunction to iterate over code units.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* function which, when called with a string, returns an iterator.
* An iterator generated by an iterator function.
*
* This class provides the internal data structure of all the
- * iterator functions as well as the `::next` behaviour they all use.
+ * iterator functions as well as the `::next´ behaviour they all use.
*
* ※ This class extends the identity function to allow for arbitrary
* construction of its superclass instance based on the provided
*
* ☡ It is not possible to type·check the provided next method or
* generator function to ensure that they actually are correct and
- * appropriately callable; if they aren’t, an error will be thrown
+ * appropriately callable; if they aren¦t, an error will be thrown
* when attempting to yield the first value.
*/
constructor(
const baseIteratorNext = this.#baseIteratorNext;
const generateNext = this.#generateNext;
while (true) {
- // This function sometimes needs to repeat its processing steps
- // in the case that a generator function was provided.
+ // This function some·times needs to repeat its processing
+ // steps in the case that a generator function was provided.
//
// To avoid potentially large amounts of recursive calls, it is
// defined in a loop which will exit the first time a suitable
return { value: UNDEFINED, done: true };
} else if (nextIterator === null) {
// This iterator is not currently yielding values from the
- // provided generator function, either because it doesn’t
+ // provided generator function, either because it doesn¦t
// exist or because its values have been exhausted.
//
// Get the next value in the base iterator and either provide
continue;
} else {
// The current iterator of values has yielded another
- // value; reyield it.
+ // value.
+ //
+ // Reyield it.
return { value, done: false };
}
}
const iteratorFunction = (
makeBaseIterator,
baseIteratorNext,
+ iteratorFunctionName,
generateNext,
stringTag = "Iterator",
) => {
const prototype = makePrototype(stringTag); // intentionally cached
- return ($, thisArg = UNDEFINED) =>
- new Iterator(
- prototype,
- call(makeBaseIterator, $, []),
- baseIteratorNext,
- generateNext == null ? null : bind(generateNext, thisArg, []),
- );
+ return defineOwnProperty(
+ ($, thisArg = UNDEFINED) =>
+ new Iterator(
+ prototype,
+ call(makeBaseIterator, $, []),
+ baseIteratorNext,
+ generateNext == null
+ ? null
+ : bind(generateNext, thisArg, []),
+ ),
+ "name",
+ defineOwnDataProperty(
+ objectCreate(null),
+ "value",
+ iteratorFunctionName,
+ ),
+ );
};
return {
bind(
iteratorFunction,
UNDEFINED,
- [arrayIterator, arrayIteratorNext],
+ [arrayIterator, arrayIteratorNext, "values"],
),
"name",
defineOwnDataProperty(
return this();
},
generatorIteratorNext,
+ "yields",
],
),
"name",
bind(
iteratorFunction,
UNDEFINED,
- [mapIterator, mapIteratorNext],
+ [mapIterator, mapIteratorNext, "entries"],
),
"name",
defineOwnDataProperty(
bind(
iteratorFunction,
UNDEFINED,
- [setIterator, setIteratorNext],
+ [setIterator, setIteratorNext, "values"],
),
"name",
defineOwnDataProperty(
bind(
iteratorFunction,
UNDEFINED,
- [stringIterator, stringIteratorNext],
+ [stringIterator, stringIteratorNext, "characters"],
),
"name",
defineOwnDataProperty(
-// ♓🌟 Piscēs ∷ iterable.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/>.
+// SPDX-FileCopyrightText: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ iterable.test.js
+ *
+ * Copyright © 2023, 2025 Lady [@ Ladys 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 {
assertEquals,
});
});
+ it("[[Construct]] throws an error", () => {
+ const iterator = arrayIteratorFunction();
+ assertThrows(() => new iterator([]));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(arrayIteratorFunction().length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ arrayIteratorFunction().name,
+ "values",
+ );
+ });
+ });
+
describe("::next", () => {
it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
const iterator = arrayIteratorFunction(function () {});
});
});
+ it("[[Construct]] throws an error", () => {
+ const iterator = generatorIteratorFunction();
+ assertThrows(() => new iterator(function* () {}));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(generatorIteratorFunction().length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ generatorIteratorFunction().name,
+ "yields",
+ );
+ });
+ });
+
describe("::next", () => {
it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
const generator = function* () {
});
});
+ it("[[Construct]] throws an error", () => {
+ const iterator = mapIteratorFunction();
+ assertThrows(() => new iterator(new Map()));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(mapIteratorFunction().length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ mapIteratorFunction().name,
+ "entries",
+ );
+ });
+ });
+
describe("::next", () => {
it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
const iterator = mapIteratorFunction(function () {});
});
});
+ it("[[Construct]] throws an error", () => {
+ const iterator = setIteratorFunction();
+ assertThrows(() => new iterator(new Set()));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(setIteratorFunction().length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ setIteratorFunction().name,
+ "values",
+ );
+ });
+ });
+
describe("::next", () => {
it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
const iterator = setIteratorFunction(function () {});
});
});
+ it("[[Construct]] throws an error", () => {
+ const iterator = stringIteratorFunction();
+ assertThrows(() => new iterator(""));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(stringIteratorFunction().length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ stringIteratorFunction().name,
+ "characters",
+ );
+ });
+ });
+
describe("::next", () => {
it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
const iterator = stringIteratorFunction(function () {});
-// ♓🌟 Piscēs ∷ numeric.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ numeric.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 { call, createArrowFunction } from "./function.js";
import { defineOwnDataProperty } from "./object.js";
UNDEFINED,
} from "./value.js";
+const PISCĒS = "♓🧩 Piscēs";
+
/**
* Returns the magnitude (absolute value) of the provided value.
*
- * ※ Unlike `Math.abs`, this function can take big·int arguments.
+ * ※ Unlike `Math.abs´, this function can take big·int arguments.
*/
export const abs = ($) => {
const n = toNumeric($);
/**
* Returns the arccos of the provided value.
*
- * ※ This function is effectively an alias for `Math.acos`.
+ * ※ This function is effectively an alias for `Math.acos´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the arccosh of the provided value.
*
- * ※ This function is effectively an alias for `Math.acosh`.
+ * ※ This function is effectively an alias for `Math.acosh´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the arcsin of the provided value.
*
- * ※ This function is effectively an alias for `Math.asin`.
+ * ※ This function is effectively an alias for `Math.asin´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the arcsinh of the provided value.
*
- * ※ This function is effectively an alias for `Math.asinh`.
+ * ※ This function is effectively an alias for `Math.asinh´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the arctan of the provided value.
*
- * ※ This function is effectively an alias for `Math.atan`.
+ * ※ This function is effectively an alias for `Math.atan´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the arctangent of the dividend of the provided values.
*
- * ※ Unlike `Math.atan2`, this function can take big·int arguments.
+ * ※ Unlike `Math.atan2´, this function can take big·int arguments.
* However, the result will always be a number.
*/
arctan2,
* Returns the number of leading zeroes in the 32‐bit representation
* of the provided value.
*
- * ※ Unlike `Math.clz32`, this function accepts either number or
+ * ※ Unlike `Math.clz32´, this function accepts either number or
* big·int values.
*/
clz32,
* Returns the 32‐bit float which best approximate the provided
* value.
*
- * ※ Unlike `Math.fround`, this function can take big·int arguments.
+ * ※ Unlike `Math.fround´, this function can take big·int arguments.
* However, the result will always be a number.
*/
toFloat32,
/**
* Returns the arctanh of the provided value.
*
- * ※ This function is effectively an alias for `Math.atanh`.
+ * ※ This function is effectively an alias for `Math.atanh´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the cube root of the provided value.
*
- * ※ This function is effectively an alias for `Math.cbrt`.
+ * ※ This function is effectively an alias for `Math.cbrt´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the ceiling of the provided value.
*
- * ※ This function is effectively an alias for `Math.ceil`.
+ * ※ This function is effectively an alias for `Math.ceil´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the cos of the provided value.
*
- * ※ This function is effectively an alias for `Math.cos`.
+ * ※ This function is effectively an alias for `Math.cos´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the cosh of the provided value.
*
- * ※ This function is effectively an alias for `Math.cosh`.
+ * ※ This function is effectively an alias for `Math.cosh´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the Euler number raised to the provided value.
*
- * ※ This function is effectively an alias for `Math.exp`.
+ * ※ This function is effectively an alias for `Math.exp´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the Euler number raised to the provided value, minus one.
*
- * ※ This function is effectively an alias for `Math.expm1`.
+ * ※ This function is effectively an alias for `Math.expm1´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the floor of the provided value.
*
- * ※ This function is effectively an alias for `Math.floor`.
+ * ※ This function is effectively an alias for `Math.floor´.
*
* ☡ This function does not allow big·int arguments.
*/
* Returns the square root of the sum of the squares of the provided
* arguments.
*
- * ※ This function is effectively an alias for `Math.hypot`.
+ * ※ This function is effectively an alias for `Math.hypot´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns whether the provided value is a finite number.
*
- * ※ This function is effectively an alias for `Number.isFinite`.
+ * ※ This function is effectively an alias for `Number.isFinite´.
*/
export const isFiniteNumber = createArrowFunction(
Number.isFinite,
/**
* Returns whether the provided value is an integral number.
*
- * ※ This function is effectively an alias for `Number.isInteger`.
+ * ※ This function is effectively an alias for `Number.isInteger´.
*/
export const isIntegralNumber = createArrowFunction(
Number.isInteger,
/**
* Returns whether the provided value is nan.
*
- * ※ This function is effectively an alias for `Number.isNaN`.
+ * ※ This function is effectively an alias for `Number.isNaN´.
*/
export const isNan = createArrowFunction(
Number.isNaN,
/**
* Returns whether the provided value is a safe integral number.
*
- * ※ This function is effectively an alias for `Number.isSafeInteger`.
+ * ※ This function is effectively an alias for `Number.isSafeInteger´.
*/
export const isSafeIntegralNumber = createArrowFunction(
Number.isSafeInteger,
/**
* Returns the ln of the provided value.
*
- * ※ This function is effectively an alias for `Math.log`.
+ * ※ This function is effectively an alias for `Math.log´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the ln of one plus the provided value.
*
- * ※ This function is effectively an alias for `Math.log1p`.
+ * ※ This function is effectively an alias for `Math.log1p´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the log10 of the provided value.
*
- * ※ This function is effectively an alias for `Math.log10`.
+ * ※ This function is effectively an alias for `Math.log10´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the log2 of the provided value.
*
- * ※ This function is effectively an alias for `Math.log2`.
+ * ※ This function is effectively an alias for `Math.log2´.
*
* ☡ This function does not allow big·int arguments.
*/
* Returns the highest value of the provided arguments, or negative
* infinity if no argument is provided.
*
- * ※ Unlike `Math.max`, this function accepts either number or big·int
+ * ※ Unlike `Math.max´, this function accepts either number or big·int
* values. All values must be of the same type, or this function will
* throw an error.
*
}
} else {
if (typeof highest !== typeof number) {
- // The type of the current number and the lowest number don’t
+ // The type of the current number and the lowest number don¦t
// match.
- throw new TypeError("Piscēs: Type mismatch.");
+ throw new TypeError(`${PISCĒS}: Type mismatch.`);
} else if (isNan(number)) {
// The current number is nan.
return NAN;
* Returns the lowest value of the provided arguments, or positive
* infinity if no argument is provided.
*
- * ※ Unlike `Math.min`, this function accepts either number or big·int
+ * ※ Unlike `Math.min´, this function accepts either number or big·int
* values. All values must be of the same type, or this function will
* throw an error.
*
} else {
// The current number is not the first one.
if (typeof lowest !== typeof number) {
- // The type of the current number and the lowest number don’t
+ // The type of the current number and the lowest number don¦t
// match.
- throw new TypeError("Piscēs: Type mismatch.");
+ throw new TypeError(`${PISCĒS}: Type mismatch.`);
} else if (isNan(number)) {
// The current number is nan.
return NAN;
/**
* Returns a pseudo·random value in the range [0, 1).
*
- * ※ This function is effectively an alias for `Math.random`.
+ * ※ This function is effectively an alias for `Math.random´.
*/
export const rand = createArrowFunction(
Math.random,
/**
* Returns the round of the provided value.
*
- * ※ This function is effectively an alias for `Math.round`.
+ * ※ This function is effectively an alias for `Math.round´.
*
* ☡ This function does not allow big·int arguments.
*/
* that positive and negative infinity will return +1 and −1
* respectively.
*
- * ※ Unlike `Math.sign`, this function accepts either number or
+ * ※ Unlike `Math.sign´, this function accepts either number or
* big·int values.
*/
export const sgn = ($) => {
/**
* Returns the sin of the provided value.
*
- * ※ This function is effectively an alias for `Math.sin`.
+ * ※ This function is effectively an alias for `Math.sin´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the sinh of the provided value.
*
- * ※ This function is effectively an alias for `Math.sinh`.
+ * ※ This function is effectively an alias for `Math.sinh´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the square root of the provided value.
*
- * ※ This function is effectively an alias for `Math.sqrt`.
+ * ※ This function is effectively an alias for `Math.sqrt´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the tan of the provided value.
*
- * ※ This function is effectively an alias for `Math.tan`.
+ * ※ This function is effectively an alias for `Math.tan´.
*
* ☡ This function does not allow big·int arguments.
*/
/**
* Returns the tanh of the provided value.
*
- * ※ This function is effectively an alias for `Math.tanh`.
+ * ※ This function is effectively an alias for `Math.tanh´.
*
* ☡ This function does not allow big·int arguments.
*/
*
* ※ This method is safe to use with numbers.
*
- * ※ This is effectively an alias for `BigInt`.
+ * ※ This is effectively an alias for `BigInt´.
*/
export const { toBigInt } = (() => {
const makeBigInt = BigInt;
const f = toIntegralNumberOrInfinity(fractionDigits);
if (!isFiniteNumber(f) || f < 0 || f > 100) {
throw new RangeError(
- `Piscēs: The number of fractional digits must be a finite number between 0 and 100 inclusive; got: ${f}.`,
+ `${PISCĒS}: The number of fractional digits must be a finite number between 0 and 100 inclusive; got: ${f}.`,
);
} else {
if (typeof n === "number") {
const f = toIntegralNumberOrInfinity(fractionDigits);
if (!isFiniteNumber(f) || f < 0 || f > 100) {
throw new RangeError(
- `Piscēs: The number of fractional digits must be a finite number between 0 and 100 inclusive; got: ${f}.`,
+ `${PISCĒS}: The number of fractional digits must be a finite number between 0 and 100 inclusive; got: ${f}.`,
);
} else {
const n = toNumeric($);
*
* ※ This function is safe to use with big·ints.
*
- * ※ This is effectively a nonconstructible version of the `Number`
+ * ※ This is effectively a nonconstructible version of the `Number´
* constructor.
*/
-export const { toNumber } = (() => {
- const makeNumber = Number;
- return { toNumber: ($) => makeNumber($) };
-})();
+export const toNumber = createArrowFunction(
+ Number,
+ { name: "toNumber" },
+);
/**
* Returns the result of converting the provided value to a number or
* Returns the result of converting the provided value to fit within
* the provided number of bits as a signed integer.
*
- * ※ Unlike `BigInt.asIntN`, this function accepts both big·int and
+ * ※ Unlike `BigInt.asIntN´, this function accepts both big·int and
* number values.
*
* ☡ The first argument, the number of bits, must be a number.
* Returns the result of converting the provided value to fit within
* the provided number of bits as an unsigned integer.
*
- * ※ Unlike `BigInt.asUintN`, this function accepts both big·int and
+ * ※ Unlike `BigInt.asUintN´, this function accepts both big·int and
* number values.
*
* ☡ The first argument, the number of bits, must be a number.
/**
* Returns the trunc of the provided value.
*
- * ※ This function is effectively an alias for `Math.trunc`.
+ * ※ This function is effectively an alias for `Math.trunc´.
*
* ☡ This function does not allow big·int arguments.
*/
-// ♓🌟 Piscēs ∷ numeric.test.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ numeric.test.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
assert,
it("[[Call]] converts to a number", () => {
assertStrictEquals(toNumber(2n), 2);
});
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toNumber(1));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toNumber.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(toNumber.name, "toNumber");
+ });
+ });
});
describe("toNumeric", () => {
-// ♓🌟 Piscēs ∷ object.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ object.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
IS_CONCAT_SPREADABLE,
isAccessorDescriptor,
+ isDataDescriptor,
SPECIES,
toFunctionName,
toLength,
UNDEFINED,
} from "./value.js";
+const PISCĒS = "♓🧩 Piscēs";
+
+const createArray = Array;
const { isArray } = Array;
const object = Object;
const {
* Methods will be called with the resulting object as their this
* value.
*
- * `LazyLoader` objects have the same prototype as the passed methods
+ * `LazyLoader´ objects have the same prototype as the passed methods
* object.
*/
export class LazyLoader extends null {
/**
- * Constructs a new `LazyLoader` object.
+ * Constructs a new `LazyLoader´ object.
*
* ☡ This function throws if the provided value is not an object.
*/
constructor(loadMethods) {
if (type(loadMethods) !== "object") {
- // The provided value is not an object; throw an error.
+ // The provided value is not an object; this is an error.
throw new TypeError(
- `Piscēs: Cannot construct LazyLoader: Provided argument is not an object: ${loadMethods}.`,
+ `${PISCĒS}: Cannot construct LazyLoader: Provided argument is not an object: ${loadMethods}.`,
);
} else {
- // The provided value is an object; process it and build the
- // result.
+ // The provided value is an object.
+ //
+ // Process it and build the result.
const result = create(getPrototypeOf(loadMethods));
const methodKeys = ownKeys(loadMethods);
for (let index = 0; index < methodKeys.length; ++index) {
* Defines an own property on the provided object on the provided
* property key using the provided property descriptor.
*
- * ※ This is effectively an alias for `Object.defineProperty`.
+ * ※ This is effectively an alias for `Object.defineProperty´.
*/
export const defineOwnProperty = (O, P, Desc) =>
defineProperty(O, P, Desc);
* Defines own properties on the provided object using the descriptors
* on the enumerable own properties of the provided additional objects.
*
- * ※ This differs from `Object.defineProperties` in that it can take
- * multiple source objects.
+ * ※ This function differs from `Object.defineProperties´ in that it
+ * can take multiple source objects.
*/
export const defineOwnProperties = (O, ...sources) => {
const { length } = sources;
for (let k = 0; k < length; ++k) {
+ // Iterate over each source and define the appropriate properties
+ // on the provided object.
defineProperties(O, sources[k]);
}
return O;
* Removes the provided property key from the provided object and
* returns the object.
*
- * ※ This function differs from `Reflect.deleteProperty` and the
- * `delete` operator in that it throws if the deletion is
+ * ※ This function differs from `Reflect.deleteProperty´ and the
+ * `delete´ operator in that it throws if the deletion is
* unsuccessful.
*
* ☡ This function throws if the first argument is not an object.
*/
export const deleteOwnProperty = (O, P) => {
if (type(O) !== "object") {
+ // The provided value is not an object; this is an error.
throw new TypeError(
- `Piscēs: Tried to set property but provided value was not an object: ${V}`,
+ `${PISCĒS}: Tried to set property but provided value was not an object: ${V}`,
);
} else if (!deleteProperty(O, P)) {
+ // The provided property could not be deleted on the provided
+ // value; this is an error.
throw new TypeError(
- `Piscēs: Tried to delete property from object but [[Delete]] returned false: ${P}`,
+ `${PISCĒS}: Tried to delete property from object but [[Delete]] returned false: ${P}`,
);
} else {
+ // The provided property was successfully deleted.
+ //
+ // Return the provided value.
return O;
}
};
* properties as nonconfigurable and (if data properties) nonwritable,
* and returns the object.
*
- * ※ This is effectively an alias for `Object.freeze`.
+ * ※ This is effectively an alias for `Object.freeze´.
*/
export const freeze = (O) => objectFreeze(O);
* property with the same value.
*
* - For accessor properties, create a nonconfigurable accessor
- * property with the same getter *and* setter.
+ * property with the same getter ⹐and⹑ setter.
*
* The prototype for the resulting object will be taken from the
- * `.prototype` property of the provided constructor, or the
- * `.prototype` of the `.constructor` of the provided object if the
+ * `.prototype´ property of the provided constructor, or the
+ * `.prototype´ of the `.constructor´ of the provided object if the
* provided constructor is undefined. If the used constructor has a
- * nonnullish `.[Symbol.species]`, that will be used instead. If the
+ * nonnullish `.[Symbol.species]´, that will be used instead. If the
* used constructor or species is nullish or does not have a
- * `.prototype` property, the prototype is set to null.
+ * `.prototype´ property, the prototype is set to null.
*
* ※ The prototype of the provided object itself is ignored.
*/
if (O == null) {
// O is null or undefined.
throw new TypeError(
- "Piscēs: Cannot copy properties of null or undefined.",
+ `${PISCĒS}: Cannot copy properties of null or undefined.`,
);
} else {
// O is not null or undefined.
//
// (If not provided, the constructor will be the value of getting
- // the `.constructor` property of O.)
+ // the `.constructor´ property of O.)
const species = constructor?.[SPECIES] ?? constructor;
const copy = create(
species == null || !("prototype" in species)
);
const keys = ownKeys(O);
for (let k = 0; k < keys.length; ++k) {
+ // Iterate over each key and define the appropriate value on the
+ // result.
const P = keys[k];
const Desc = getOwnPropertyDescriptor(O, P);
if (Desc.enumerable) {
* key.
*
* ☡ This function throws if the provided property key does not have an
- * associated value which is callable.
+ * associated value which is either nullish or callable.
*/
export const getMethod = (V, P) => {
const func = V[P];
if (func == null) {
- return undefined;
+ // The value of the provided property is nullish.
+ //
+ // Return undefined.
+ return UNDEFINED;
} else if (typeof func !== "function") {
- throw new TypeError(`Piscēs: Method not callable: ${P}`);
+ // The value of the provided property is not callable; this is an
+ // error.
+ throw new TypeError(`${PISCĒS}: Method not callable: ${P}`);
} else {
+ // The value of the provided property is callable.
+ //
+ // Return it.
return func;
}
};
* provided property key on the provided value, or null if none exists.
*
* ※ This is effectively an alias for
- * `Object.getOwnPropertyDescriptor`, but the return value is a proxied
+ * `Object.getOwnPropertyDescriptor´, but the return value is a proxied
* object with null prototype.
*/
export const getOwnPropertyDescriptor = (O, P) => {
* provided value.
*
* ※ This is effectively an alias for
- * `Object.getOwnPropertyDescriptors`, but the values on the resulting
+ * `Object.getOwnPropertyDescriptors´, but the values on the resulting
* object are proxied objects with null prototypes.
*/
export const getOwnPropertyDescriptors = (O) => {
const keys = ownKeys(obj);
const descriptors = {};
for (let k = 0; k < keys.length; ++k) {
+ // Iterate over the keys of the provided object and collect its
+ // descriptors.
const key = keys[k];
defineOwnDataProperty(
descriptors,
};
/**
- * Returns an array of property keys on the provided value.
+ * Returns an array of own property entries on the provided value,
+ * using the provided receiver if given.
+ */
+export const getOwnPropertyEntries = (O, Receiver = O) => {
+ const obj = toObject(O);
+ const keys = ownKeys(obj);
+ const target = Receiver === UNDEFINED ? obj : toObject(Receiver);
+ const result = createArray(keys.length);
+ for (let k = 0; k < keys.length; ++k) {
+ // Iterate over each key and add the corresponding entry to the
+ // result.
+ const key = keys[k];
+ defineOwnDataProperty(
+ result,
+ k,
+ [key, getOwnPropertyValue(obj, keys[k], target)],
+ );
+ }
+ return result;
+};
+
+/**
+ * Returns an array of own property keys on the provided value.
*
- * ※ This is effectively an alias for `Reflect.ownKeys`, except that
+ * ※ This is effectively an alias for `Reflect.ownKeys´, except that
* it does not require that the argument be an object.
*/
export const getOwnPropertyKeys = (O) => ownKeys(toObject(O));
*
* ☡ This includes both enumerable and non·enumerable properties.
*
- * ※ This is effectively an alias for `Object.getOwnPropertyNames`.
+ * ※ This is effectively an alias for `Object.getOwnPropertyNames´.
*/
export const getOwnPropertyStrings = (O) => getOwnPropertyNames(O);
* ☡ This includes both enumerable and non·enumerable properties.
*
* ※ This is effectively an alias for
- * `Object.getOwnPropertySymbols`.
+ * `Object.getOwnPropertySymbols´.
*/
export const getOwnPropertySymbols = (O) =>
objectGetOwnPropertySymbols(O);
+/**
+ * Returns the value of the provided own property on the provided
+ * value using the provided receiver, or undefined if the provided
+ * property is not an own property on the provided value.
+ *
+ * ※ If the receiver is not provided, it defaults to the provided
+ * value.
+ */
+export const getOwnPropertyValue = (O, P, Receiver = UNDEFINED) => {
+ const obj = toObject(O);
+ const desc = getOwnPropertyDescriptor(O, P);
+ if (desc === UNDEFINED) {
+ // The provided property is not an own property on the provided
+ // value.
+ //
+ // Return undefined.
+ return UNDEFINED;
+ }
+ if (isDataDescriptor(desc)) {
+ // The provided property is a data property.
+ //
+ // Return its value.
+ return desc.value;
+ } else {
+ // The provided property is an accessor property.
+ //
+ // Get its value using the appropriate receiver.
+ const target = Receiver === UNDEFINED ? obj : toObject(Receiver);
+ return call(desc.get, target, []);
+ }
+};
+
+/**
+ * Returns an array of own property values on the provided value, using
+ * the provided receiver if given.
+ */
+export const getOwnPropertyValues = (O, Receiver = O) => {
+ const obj = toObject(O);
+ const keys = ownKeys(obj);
+ const target = Receiver === UNDEFINED ? obj : toObject(Receiver);
+ const result = createArray(keys.length);
+ for (let k = 0; k < keys.length; ++k) {
+ // Iterate over each key and collect the values.
+ defineOwnDataProperty(
+ result,
+ k,
+ getOwnPropertyValue(obj, keys[k], target),
+ );
+ }
+ return result;
+};
+
/**
* Returns the value of the provided property key on the provided
* value.
*
- * ※ This is effectively an alias for `Reflect.get`, except that it
+ * ※ This is effectively an alias for `Reflect.get´, except that it
* does not require that the argument be an object.
*/
export const getPropertyValue = (O, P, Receiver = O) =>
/**
* Returns the prototype of the provided value.
*
- * ※ This is effectively an alias for `Object.getPrototypeOf`.
+ * ※ This is effectively an alias for `Object.getPrototypeOf´.
*/
export const getPrototype = (O) => getPrototypeOf(O);
* Returns whether the provided value has an own property with the
* provided property key.
*
- * ※ This is effectively an alias for `Object.hasOwn`.
+ * ※ This is effectively an alias for `Object.hasOwn´.
*/
export const hasOwnProperty = (O, P) => hasOwn(O, P);
* Returns whether the provided property key exists on the provided
* value.
*
- * ※ This is effectively an alias for `Reflect.has`, except that it
+ * ※ This is effectively an alias for `Reflect.has´, except that it
* does not require that the argument be an object.
*
* ※ This includes properties present on the prototype chain.
/** Returns whether the provided value is an arraylike object. */
export const isArraylikeObject = ($) => {
if (type($) !== "object") {
+ // The provided value is not an object.
return false;
} else {
+ // The provided value is an object.
try {
- lengthOfArraylike($); // throws if not arraylike
+ // Try to get the length and return true.
+ //
+ // ※ If this throws, the object is not arraylike.
+ lengthOfArraylike($);
return true;
} catch {
+ // Getting the length failed; return false.
return false;
}
}
*
* ※ This function returns false for nonobjects.
*
- * ※ This is effectively an alias for `Object.isExtensible`.
+ * ※ This is effectively an alias for `Object.isExtensible´.
*/
export const isExtensibleObject = (O) => isExtensible(O);
export const {
/**
* Returns whether the provided value is a property descriptor record
- * as created by `toPropertyDescriptor`.
+ * as created by `toPropertyDescriptor´.
*
* ※ This function is provided to enable inspection of whether an
- * object uses the property descriptor record proxy implementation,
- * not as a general test of whether an object satisfies the
- * requirements for property descriptors. In most cases, a more
- * specific test, like `isAccessorDescriptor`, `isDataDescriptor`, or
- * `isGenericDescriptor`, is preferrable.
+ * object uses the ♓🧩 Piscēs property descriptor record proxy
+ * implementation, not as a general test of whether an object
+ * satisfies the requirements for property descriptors. In most
+ * cases, a more specific test, like `isAccessorDescriptor´,
+ * `isDataDescriptor´, or `isGenericDescriptor´, is preferrable.
*/
isPropertyDescriptorRecord,
/**
* Converts the provided value to a property descriptor record.
*
- * ※ The prototype of a property descriptor record is always `null`.
+ * ※ The prototype of a property descriptor record is always `null´.
*
* ※ Actually constructing a property descriptor object using this
* class is only necessary if you need strict guarantees about the
* types of its properties; the resulting object is proxied to ensure
* the types match what one would expect from composing
- * FromPropertyDescriptor and ToPropertyDescriptor in the Ecmascript
- * specification.
+ * `FromPropertyDescriptor´ and `ToPropertyDescriptor´ in the
+ * Ecmascript specification.
*/
toPropertyDescriptorRecord,
} = (() => {
case "value":
return V;
case "get":
- if (V !== undefined && typeof V !== "function") {
+ if (V !== UNDEFINED && typeof V !== "function") {
+ // The provided value is not callable; this is an error.
throw new TypeError(
- "Piscēs: Getters must be callable.",
+ `${PISCĒS}: Getters must be callable.`,
);
} else {
+ // The provided value is callable.
return V;
}
case "set":
- if (V !== undefined && typeof V !== "function") {
+ if (V !== UNDEFINED && typeof V !== "function") {
+ // The provided value is not callable; this is an error.
throw new TypeError(
- "Piscēs: Setters must be callable.",
+ `${PISCĒS}: Setters must be callable.`,
);
} else {
+ // The provided value is callable.
return V;
}
default:
{
defineProperty(O, P, Desc) {
if (
- P === "configurable" || P === "enumerable" ||
- P === "writable" || P === "value" ||
- P === "get" || P === "set"
+ P === "configurable" || P === "enumerable"
+ || P === "writable" || P === "value"
+ || P === "get" || P === "set"
) {
- // P is a property descriptor attribute.
+ // `P´ is a property descriptor attribute.
const desc = assign(objectCreate(null), Desc);
if ("get" in desc || "set" in desc) {
- // Desc is an accessor property descriptor.
+ // `Desc´ is an accessor property descriptor.
throw new TypeError(
- "Piscēs: Property descriptor attributes must be data properties.",
+ `${PISCĒS}: Property descriptor attributes must be data properties.`,
);
} else if ("value" in desc || !(P in O)) {
- // Desc has a value or P does not already exist on O.
+ // `Desc´ has a value or `P´ does not already exist on
+ // `O´.
desc.value = coercePropertyDescriptorValue(
P,
desc.value,
);
} else {
- // Desc is not an accessor property descriptor and has no
- // value, but an existing value is present on O.
+ // `Desc´ is not an accessor property descriptor and has
+ // no value, but an existing value is present on `O´.
/* do nothing */
}
- const isAccessorDescriptor = "get" === P || "set" === P ||
- "get" in O || "set" in O;
- const isDataDescriptor = "value" === P ||
- "writable" === P ||
- "value" in O || "writable" in O;
+ const isAccessorDescriptor = "get" === P || "set" === P
+ || "get" in O || "set" in O;
+ const isDataDescriptor = "value" === P
+ || "writable" === P
+ || "value" in O || "writable" in O;
if (isAccessorDescriptor && isDataDescriptor) {
- // Both accessor and data attributes will be present on O
- // after defining P.
+ // Both accessor and data attributes will be present on
+ // `O´ after defining `P´; this is an error.
throw new TypeError(
- "Piscēs: Property descriptors cannot specify both accessor and data attributes.",
+ `${PISCĒS}: Property descriptors cannot specify both accessor and data attributes.`,
);
} else {
- // P can be safely defined on O.
+ // `P´ can be safely defined on `O´.
return reflectDefineProperty(O, P, desc);
}
} else {
- // P is not a property descriptor attribute.
+ // `P´ is not a property descriptor attribute.
return reflectDefineProperty(O, P, Desc);
}
},
setPrototypeOf(O, V) {
if (V !== null) {
- // V is not the property descriptor prototype.
+ // `V´ is not the property descriptor prototype.
return false;
} else {
- // V is the property descriptor prototype.
+ // `V´ is the property descriptor prototype.
return reflectSetPrototypeOf(O, V);
}
},
call(weakSetHas, propertyDescriptorRecords, [$]),
toPropertyDescriptorRecord: (Obj) => {
if (type(Obj) !== "object") {
- // The provided value is not an object.
+ // The provided value is not an object; this is an error.
throw new TypeError(
- `Piscēs: Cannot convert primitive to property descriptor: ${O}.`,
+ `${PISCĒS}: Cannot convert primitive to property descriptor: ${O}.`,
);
} else {
// The provided value is an object.
// A get property is specified.
const getter = Obj.get;
if (getter !== UNDEFINED && typeof getter !== "function") {
- // The getter is not callable.
- throw new TypeError("Piscēs: Getters must be callable.");
+ // The getter is not callable; this is an error.
+ throw new TypeError(
+ `${PISCĒS}: Getters must be callable.`,
+ );
} else {
// The getter is callable.
defineOwnDataProperty(desc, "get", Obj.get);
// A set property is specified.
const setter = Obj.set;
if (setter !== UNDEFINED && typeof setter !== "function") {
- // The setter is not callable.
- throw new TypeError("Piscēs: Setters must be callable.");
+ // The setter is not callable; this is an error.
+ throw new TypeError(
+ `${PISCĒS}: Setters must be callable.`,
+ );
} else {
// The setter is callable.
defineOwnDataProperty(desc, "set", Obj.set);
/* do nothing */
}
if (
- ("get" in desc || "set" in desc) &&
- ("value" in desc || "writable" in desc)
+ ("get" in desc || "set" in desc)
+ && ("value" in desc || "writable" in desc)
) {
- // Both accessor and data attributes have been defined.
+ // Both accessor and data attributes have been defined; this
+ // is an error.
throw new TypeError(
- "Piscēs: Property descriptors cannot specify both accessor and data attributes.",
+ `${PISCĒS}: Property descriptors cannot specify both accessor and data attributes.`,
);
} else {
// The property descriptor is valid.
*
* ※ This function returns false for nonobjects.
*
- * ※ This is effectively an alias for `!Object.isFrozen`.
+ * ※ This is effectively an alias for `!Object.isFrozen´.
*/
export const isUnfrozenObject = (O) => !isFrozen(O);
*
* ※ This function returns false for nonobjects.
*
- * ※ This is effectively an alias for `!Object.isSealed`.
+ * ※ This is effectively an alias for `!Object.isSealed´.
*/
export const isUnsealedObject = (O) => !isSealed(O);
* Returns an array of key~value pairs for the enumerable,
* string‐valued property keys on the provided value.
*
- * ※ This is effectively an alias for `Object.entries`.
+ * ※ This is effectively an alias for `Object.entries´.
*/
export const namedEntries = (O) => entries(O);
* Returns an array of the enumerable, string‐valued property keys on
* the provided value.
*
- * ※ This is effectively an alias for `Object.keys`.
+ * ※ This is effectively an alias for `Object.keys´.
*/
export const namedKeys = (O) => keys(O);
* Returns an array of property values for the enumerable,
* string‐valued property keys on the provided value.
*
- * ※ This is effectively an alias for `Object.values`.
+ * ※ This is effectively an alias for `Object.values´.
*/
export const namedValues = (O) => values(O);
* Returns a new object with the provided prototype and property
* descriptors.
*
- * ※ This is effectively an alias for `Object.create`.
+ * ※ This is effectively an alias for `Object.create´.
*/
export const objectCreate = (O, Properties) => create(O, Properties);
* Returns a new object with property keys and values from the provided
* iterable value.
*
- * ※ This is effectively an alias for `Object.fromEntries`.
+ * ※ This is effectively an alias for `Object.fromEntries´.
*/
export const objectFromEntries = (iterable) => fromEntries(iterable);
* Marks the provided object as non·extensible, and returns the
* object.
*
- * ※ This is effectively an alias for `Object.preventExtensions`.
+ * ※ This is effectively an alias for `Object.preventExtensions´.
*/
export const preventExtensions = (O) => objectPreventExtensions(O);
* Marks the provided object as non·extensible and marks all its
* properties as nonconfigurable, and returns the object.
*
- * ※ This is effectively an alias for `Object.seal`.
+ * ※ This is effectively an alias for `Object.seal´.
*/
export const seal = (O) => objectSeal(O);
* Sets the provided property key to the provided value on the provided
* object and returns the object.
*
- * ※ This function differs from `Reflect.set` in that it throws if the
+ * ※ This function differs from `Reflect.set´ in that it throws if the
* setting is unsuccessful.
*
* ☡ This function throws if the first argument is not an object.
*/
export const setPropertyValue = (O, P, V, Receiver = O) => {
if (type(O) !== "object") {
+ // The provided value is not an object; this is an error.
throw new TypeError(
- `Piscēs: Tried to set property but provided value was not an object: ${V}`,
+ `${PISCĒS}: Tried to set property but provided value was not an object: ${V}`,
);
} else if (!set(O, P, V, Receiver)) {
+ // Setting the property fails; this is an error.
throw new TypeError(
- `Piscēs: Tried to set property on object but [[Set]] returned false: ${P}`,
+ `${PISCĒS}: Tried to set property on object but [[Set]] returned false: ${P}`,
);
} else {
+ // The property was successfully set.
+ //
+ // Return the provided object.
return O;
}
};
* Sets the values of the enumerable own properties of the provided
* additional objects on the provided values.
*
- * ※ This is effectively an alias for `Object.assign`.
+ * ※ This is effectively an alias for `Object.assign´.
*/
export const setPropertyValues = (target, source, ...sources) => {
const to = toObject(target);
// values.
const nextSource = i === -1 ? source : sources[i];
if (nextSource != null) {
- // The current source is not nullish; handle its own properties.
+ // The current source is not nullish.
+ //
+ // Handle its own properties.
const from = toObject(nextSource);
const keys = ownKeys(from);
for (let k = 0; k < keys.length; ++k) {
const nextKey = keys[k];
const desc = reflectGetOwnPropertyDescriptor(from, nextKey);
if (desc !== UNDEFINED && desc.enumerable) {
- // The current key is present and enumerable; set it to its
- // corresponding value.
+ // The current key is present and enumerable.
+ //
+ // Set it to its corresponding value.
const propValue = from[nextKey];
to[nextKey] = propValue;
} else {
* Sets the prototype of the provided object to the provided value and
* returns the object.
*
- * ※ This is effectively an alias for `Object.setPrototypeOf`, but it
- * won’t throw when setting the prototype of a primitive to its current
+ * ※ This is effectively an alias for `Object.setPrototypeOf´, but it
+ * won¦t throw when setting the prototype of a primitive to its current
* value.
*/
export const setPrototype = (O, proto) => {
const obj = toObject(O);
if (O === obj) {
- // The provided value is an object; set its prototype normally.
+ // The provided value is an object.
+ //
+ // Set its prototype normally.
return setPrototypeOf(O, proto);
} else {
- // The provided value is not an object; attempt to set the
- // prototype on a coerced version with extensions prevented, then
- // return the provided value.
+ // The provided value is not an object.
+ //
+ // Attempt to set the prototype on a coerced version with
+ // extensions prevented, then return the provided value.
//
- // This will throw if the given prototype does not match the
+ // ☡ This will throw if the given prototype does not match the
// existing one on the coerced object.
setPrototypeOf(objectPreventExtensions(obj), proto);
return O;
if ($ == null) {
// The provided value is nullish; this is an error.
throw new TypeError(
- `Piscēs: Cannot convert ${$} into an object.`,
+ `${PISCĒS}: Cannot convert ${$} into an object.`,
);
} else {
- // The provided value is not nullish; coerce it to an object.
+ // The provided value is not nullish.
+ //
+ // Coerce it to an object.
return object($);
}
};
-// ♓🌟 Piscēs ∷ object.test.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🌟 Piscēs ∷ object.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
assert,
getMethod,
getOwnPropertyDescriptor,
getOwnPropertyDescriptors,
+ getOwnPropertyEntries,
getOwnPropertyKeys,
getOwnPropertyStrings,
getOwnPropertySymbols,
+ getOwnPropertyValue,
+ getOwnPropertyValues,
getPropertyValue,
getPrototype,
hasOwnProperty,
it("[[Call]] does not copy properties on the prototype", () => {
assert(
- !("failure" in
- frozenCopy(Object.create({ failure: undefined }))),
+ !("failure"
+ in frozenCopy(Object.create({ failure: undefined }))),
);
});
});
});
+describe("getOwnPropertyEntries", () => {
+ it("[[Call]] gets own (but not inherited) property entries", () => {
+ assertEquals(
+ getOwnPropertyEntries({ success: true }),
+ [["success", true]],
+ );
+ });
+
+ it("[[Call]] works for values coercible to objects", () => {
+ assertEquals(
+ getOwnPropertyEntries("foo"),
+ [["0", "f"], ["1", "o"], ["2", "o"], ["length", 3]],
+ );
+ });
+
+ it("[[Call]] uses the provided receiver", () => {
+ const target = {};
+ assertEquals(
+ getOwnPropertyEntries({
+ get success() {
+ return this;
+ },
+ }, target),
+ [["success", target]],
+ );
+ });
+
+ it("[[Call]] throws for null and undefined", () => {
+ assertThrows(() => getOwnPropertyEntries(null));
+ assertThrows(() => getOwnPropertyEntries(undefined));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new getOwnPropertyEntries({}));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(getOwnPropertyEntries.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ getOwnPropertyEntries.name,
+ "getOwnPropertyEntries",
+ );
+ });
+ });
+});
+
describe("getOwnPropertyKeys", () => {
it("[[Call]] gets own (but not inherited) property keys", () => {
assertEquals(getOwnPropertyKeys({ success: true }), ["success"]);
});
});
+describe("getOwnPropertyValue", () => {
+ it("[[Call]] gets the own property value", () => {
+ assertStrictEquals(
+ getOwnPropertyValue({ success: true }, "success"),
+ true,
+ );
+ });
+
+ it("[[Call]] returns undefined for non‐own properties", () => {
+ assertStrictEquals(
+ getOwnPropertyValue(Object.create({ success: true }), "success"),
+ undefined,
+ );
+ });
+
+ it("[[Call]] works for values coercible to objects", () => {
+ assertStrictEquals(getOwnPropertyValue("foo", "length"), 3);
+ });
+
+ it("[[Call]] uses the provided receiver", () => {
+ const target = {};
+ assertStrictEquals(
+ getOwnPropertyValue(
+ {
+ get success() {
+ return this;
+ },
+ },
+ "success",
+ target,
+ ),
+ target,
+ );
+ });
+
+ it("[[Call]] throws for null and undefined", () => {
+ assertThrows(() => getOwnPropertyValue(null));
+ assertThrows(() => getOwnPropertyValue(undefined));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new getOwnPropertyValue({}));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(getOwnPropertyValue.length, 2);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ getOwnPropertyValue.name,
+ "getOwnPropertyValue",
+ );
+ });
+ });
+});
+
+describe("getOwnPropertyValues", () => {
+ it("[[Call]] gets own (but not inherited) property values", () => {
+ assertEquals(getOwnPropertyValues({ success: true }), [true]);
+ });
+
+ it("[[Call]] works for values coercible to objects", () => {
+ assertEquals(
+ getOwnPropertyValues("foo"),
+ ["f", "o", "o", 3],
+ );
+ });
+
+ it("[[Call]] uses the provided receiver", () => {
+ const target = {};
+ assertEquals(
+ getOwnPropertyValues({
+ get success() {
+ return this;
+ },
+ }, target),
+ [target],
+ );
+ });
+
+ it("[[Call]] throws for null and undefined", () => {
+ assertThrows(() => getOwnPropertyValues(null));
+ assertThrows(() => getOwnPropertyValues(undefined));
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new getOwnPropertyValues({}));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(getOwnPropertyValues.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ getOwnPropertyValues.name,
+ "getOwnPropertyValues",
+ );
+ });
+ });
+});
+
describe("getPropertyValue", () => {
it("[[Call]] gets property values on the provided object", () => {
assertStrictEquals(
-// ♓🌟 Piscēs ∷ string.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ string.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
bind,
call,
+ completesNormally,
createArrowFunction,
createCallableFunction,
identity,
} from "./object.js";
import { sameValue, toLength, UNDEFINED } from "./value.js";
+const PISCĒS = "♓🧩 Piscēs";
+
const RE = RegExp;
const { prototype: rePrototype } = RE;
const { prototype: arrayPrototype } = Array;
export const {
/**
- * A `RegExp`like object which only matches entire strings, and may
+ * A `RegExp´‐like object which only matches entire strings, and may
* have additional constraints specified.
*
* Matchers are callable objects and will return true if they are
* called with a string that they match, and false otherwise.
- * Matchers will always return false if called with nonstrings,
- * although other methods like `::exec` coerce their arguments and
- * may still return true.
+ * Matchers will always return false if called with nonstrings, altho
+ * other methods like `::exec´ coerce their arguments and may still
+ * return true.
*/
Matcher,
} = (() => {
Object.getOwnPropertyDescriptor(rePrototype, "sticky").get;
const getUnicode =
Object.getOwnPropertyDescriptor(rePrototype, "unicode").get;
+ const getUnicodeSets =
+ Object.getOwnPropertyDescriptor(rePrototype, "unicodeSets").get;
+ /**
+ * The internal implementation of `Matcher´.
+ *
+ * ※ This class extends the identity function to enable the addition
+ * of private fields to the callable matcher function it constructs.
+ *
+ * ※ This class is not exposed.
+ */
const Matcher = class extends identity {
#constraint;
#regExp;
/**
- * Constructs a new `Matcher` from the provided source.
+ * Constructs a new `Matcher´ from the provided source.
*
* If the provided source is a regular expression, then it must
- * have the unicode flag set. Otherwise, it is interpreted as the
- * string source of a regular expression with the unicode flag set.
+ * have either the unicode flag set or the unicode sets flag set.
+ * Otherwise, it is interpreted as the string source of a regular
+ * expression with the unicode flag set.
*
* Other flags are taken from the provided regular expression
* object, if any are present.
* third argument. If provided, it will be called with three
* arguments whenever a match appears successful: first, the string
* being matched, second, the match result, and third, the
- * `Matcher` object itself. If the return value of this call is
+ * `Matcher´ object itself. If the return value of this call is
* falsey, then the match will be considered a failure.
*
* ☡ If the provided source regular expression uses nongreedy
* quantifiers, it may not match the whole string even if a match
* with the whole string is possible. Surround the regular
- * expression with `^(?:` and `)$` if you don’t want nongreedy
+ * expression with `^(?:´ and `)$´ if you don¦t want nongreedy
* regular expressions to fail when shorter matches are possible.
*/
constructor(source, name = UNDEFINED, constraint = null) {
// The provided value is not a string.
return false;
} else {
- // The provided value is a string. Set the `.lastIndex` of
- // the regular expression to 0 and see if the first attempt
- // at a match matches the whole string and passes the
- // provided constraint (if present).
+ // The provided value is a string.
+ //
+ // Set the `.lastIndex´ of the regular expression to 0, and
+ // see if the first attempt at a match successfully matches
+ // the whole string and passes the provided constraint (if
+ // present).
regExp.lastIndex = 0;
const result = call(reExec, regExp, [$]);
- return result?.[0] === $ &&
- (constraint === null || constraint($, result, this));
+ return result?.[0] === $
+ && (constraint === null || constraint($, result, this));
}
},
);
const regExp = this.#regExp = (() => {
- try {
- call(reExec, source, [""]); // throws if source not a RegExp
- } catch {
- return new RE(`${source}`, "u");
- }
- const unicode = call(getUnicode, source, []);
- if (!unicode) {
- // The provided regular expression does not have a unicode
- // flag.
- throw new TypeError(
- `Piscēs: Cannot create Matcher from non‐Unicode RegExp: ${source}`,
- );
+ if (completesNormally(() => call(reExec, source, [""]))) {
+ // The provided source is a `RegExp´.
+ if (
+ !call(getUnicode, source, [])
+ && !call(getUnicodeSets, source, [])
+ ) {
+ // The provided regular expression does not have a unicode
+ // flag or unicode sets flag.
+ throw new TypeError(
+ `${PISCĒS}: Cannot create Matcher from non‐Unicode RegExp: ${source}`,
+ );
+ } else {
+ // The provided regular expression has a unicode flag or
+ // unicode sets flag.
+ return new RE(source);
+ }
} else {
- // The provided regular expression has a unicode flag.
- return new RE(source);
+ // The provided source is not a `RegExp´.
+ //
+ // Create one using it as the source string.
+ return new RE(`${source}`, "u");
}
})();
if (constraint !== null && typeof constraint !== "function") {
throw new TypeError(
- "Piscēs: Cannot construct Matcher: Constraint is not callable.",
+ `${PISCĒS}: Cannot construct Matcher: Constraint is not callable.`,
);
} else {
this.#constraint = constraint;
}
}
- /** Gets whether the dot‐all flag is present on this `Matcher`. */
+ /** Gets whether the dot‐all flag is present on this `Matcher´. */
get dotAll() {
return call(getDotAll, this.#regExp, []);
}
/**
- * Executes this `Matcher` on the provided value and returns the
+ * Executes this `Matcher´ on the provided value and returns the
* result if there is a match, or null otherwise.
*
* Matchers only match if they can match the entire value on the
regExp.lastIndex = 0;
const result = call(reExec, regExp, [string]);
if (
- result?.[0] === string &&
- (constraint === null || constraint(string, result, this))
+ result?.[0] === string
+ && (constraint === null || constraint(string, result, this))
) {
// The entire string was matched and the constraint, if
// present, returned a truthy value.
}
/**
- * Gets the flags present on this `Matcher`.
+ * Gets the flags present on this `Matcher´.
*
- * ※ This needs to be defined because the internal `RegExp` object
- * may have flags which are not yet recognized by ♓🌟 Piscēs.
+ * ※ This needs to be defined because the internal `RegExp´ object
+ * may have flags which are not yet recognized by ♓🧩 Piscēs.
*/
get flags() {
return call(getFlags, this.#regExp, []);
}
- /** Gets whether the global flag is present on this `Matcher`. */
+ /** Gets whether the global flag is present on this `Matcher´. */
get global() {
return call(getGlobal, this.#regExp, []);
}
/**
- * Gets whether the has‐indices flag is present on this `Matcher`.
+ * Gets whether the has‐indices flag is present on this `Matcher´.
*/
get hasIndices() {
return call(getHasIndices, this.#regExp, []);
}
/**
- * Gets whether the ignore‐case flag is present on this `Matcher`.
+ * Gets whether the ignore‐case flag is present on this `Matcher´.
*/
get ignoreCase() {
return call(getIgnoreCase, this.#regExp, []);
}
/**
- * Gets whether the multiline flag is present on this `Matcher`.
+ * Gets whether the multiline flag is present on this `Matcher´.
*/
get multiline() {
return call(getMultiline, this.#regExp, []);
}
- /** Gets the regular expression source for this `Matcher`. */
+ /** Gets the regular expression source for this `Matcher´. */
get source() {
return call(getSource, this.#regExp, []);
}
- /** Gets whether the sticky flag is present on this `Matcher`. */
+ /** Gets whether the sticky flag is present on this `Matcher´. */
get sticky() {
return call(getSticky, this.#regExp, []);
}
/**
- * Gets whether the unicode flag is present on this `Matcher`.
- *
- * ※ This will always be true.
+ * Gets whether the unicode flag is present on this `Matcher´.
*/
get unicode() {
return call(getUnicode, this.#regExp, []);
}
+
+ /**
+ * Gets whether the unicode sets flag is present on this `Matcher´.
+ */
+ get unicodeSets() {
+ return call(getUnicodeSets, this.#regExp, []);
+ }
};
const matcherConstructor = Object.defineProperties(
})();
/**
- * Returns −0 if the provided argument is "-0"; returns a number
+ * Returns −0 if the provided argument is `"-0"´; returns a number
* representing the index if the provided argument is a canonical
* numeric index string; otherwise, returns undefined.
*
/**
* Returns an iterator over the codepoints in the string representation
* of the provided value according to the algorithm of
- * `String::[Symbol.iterator]`.
+ * `String::[Symbol.iterator]´.
*/
characters,
/**
* Returns the character at the provided position in the string
* representation of the provided value according to the algorithm of
- * `String::codePointAt`.
+ * `String::codePointAt´.
*/
export const getCharacter = ($, pos) => {
const codepoint = getCodepoint($, pos);
/**
* Returns the code unit at the provided position in the string
* representation of the provided value according to the algorithm of
- * `String::charAt`, except that out‐of‐bounds values return undefined
- * in place of nan.
+ * `String::charAt´, except that out‐of‐bounds values return
+ * undefined in place of nan.
*/
getCodeUnit,
/**
* Returns a string created from the provided code units.
*
- * ※ This is effectively an alias for `String.fromCharCode`, but
- * with the same error behaviour as `String.fromCodePoint`.
+ * ※ This is effectively an alias for `String.fromCharCode´, but
+ * with the same error behaviour as `String.fromCodePoint´.
*
* ☡ This function throws an error if provided with an argument which
* is not an integral number from 0 to FFFF₁₆ inclusive.
/**
* Returns the result of catenating the string representations of the
* provided values, returning a new string according to the algorithm
- * of `String::concat`.
+ * of `String::concat´.
*
* ※ If no arguments are given, this function returns the empty
* string. This is different behaviour than if an explicit undefined
* first argument is given, in which case the resulting string will
- * begin with `"undefined"`.
+ * begin with `"undefined"´.
*/
stringCatenate,
} = (() => {
!isIntegralNumber(nextCU) || nextCU < 0 || nextCU > 0xFFFF
) {
// The code unit is not an integral number between 0 and
- // 0xFFFF.
+ // 0xFFFF; this is an error.
throw new RangeError(
- `Piscēs: Code unit out of range: ${nextCU}.`,
+ `${PISCĒS}: Code unit out of range: ${nextCU}.`,
);
} else {
// The code unit is acceptable.
/**
* Returns the codepoint at the provided position in the string
* representation of the provided value according to the algorithm of
- * `String::codePointAt`.
+ * `String::codePointAt´.
*/
export const getCodepoint = createCallableFunction(
stringPrototype.codePointAt,
/**
* Returns the index of the first occurrence of the search string in
* the string representation of the provided value according to the
- * algorithm of `String::indexOf`.
+ * algorithm of `String::indexOf´.
*/
export const getFirstSubstringIndex = createCallableFunction(
stringPrototype.indexOf,
/**
* Returns the index of the last occurrence of the search string in the
* string representation of the provided value according to the
- * algorithm of `String::lastIndexOf`.
+ * algorithm of `String::lastIndexOf´.
*/
export const getLastSubstringIndex = createCallableFunction(
stringPrototype.lastIndexOf,
export const isArrayIndexString = ($) => {
const value = canonicalNumericIndexString($);
if (value !== UNDEFINED) {
- // The provided value is a canonical numeric index string; return
- // whether it is in range for array indices.
- return sameValue(value, 0) ||
- value === toLength(value) && value > 0 && value < -1 >>> 0;
+ // The provided value is a canonical numeric index string.
+ //
+ // Return whether it is in range for array indices.
+ return sameValue(value, 0)
+ || value === toLength(value) && value > 0 && value < -1 >>> 0;
} else {
// The provided value is not a canonical numeric index string.
return false;
export const isIntegerIndexString = ($) => {
const value = canonicalNumericIndexString($);
if (value !== UNDEFINED) {
- // The provided value is a canonical numeric index string; return
- // whether it is in range for integer indices.
- return sameValue(value, 0) ||
- value === toLength(value) && value > 0;
+ // The provided value is a canonical numeric index string.
+ //
+ // Return whether it is in range for integer indices.
+ return sameValue(value, 0)
+ || value === toLength(value) && value > 0;
} else {
// The provided value is not a canonical numeric index string.
return false;
/**
* Returns the result of joining the provided iterable.
*
- * If no separator is provided, it defaults to ",".
+ * If no separator is provided, it defaults to `","´.
*
* If a value is nullish, it will be stringified as the empty string.
*/
* Returns a string created from the raw value of the tagged template
* literal.
*
- * ※ This is effectively an alias for `String.raw`.
+ * ※ This is effectively an alias for `String.raw´.
*/
export const rawString = createArrowFunction(String.raw, {
name: "rawString",
/**
* Returns a string created from the provided codepoints.
*
- * ※ This is effectively an alias for `String.fromCodePoint`.
+ * ※ This is effectively an alias for `String.fromCodePoint´.
*
* ☡ This function throws an error if provided with an argument which
* is not an integral number from 0 to 10FFFF₁₆ inclusive.
/**
* Returns whether the string representation of the provided value ends
* with the provided search string according to the algorithm of
- * `String::endsWith`.
+ * `String::endsWith´.
*/
export const stringEndsWith = createCallableFunction(
stringPrototype.endsWith,
/**
* Returns whether the string representation of the provided value
* contains the provided search string according to the algorithm of
- * `String::includes`.
+ * `String::includes´.
*/
export const stringIncludes = createCallableFunction(
stringPrototype.includes,
/**
* Returns the result of matching the string representation of the
* provided value with the provided matcher according to the algorithm
- * of `String::match`.
+ * of `String::match´.
*/
export const stringMatch = createCallableFunction(
stringPrototype.match,
/**
* Returns the result of matching the string representation of the
* provided value with the provided matcher according to the algorithm
- * of `String::matchAll`.
+ * of `String::matchAll´.
*/
export const stringMatchAll = createCallableFunction(
stringPrototype.matchAll,
/**
* Returns the normalized form of the string representation of the
- * provided value according to the algorithm of `String::normalize`.
+ * provided value according to the algorithm of `String::normalize´.
*/
export const stringNormalize = createCallableFunction(
stringPrototype.normalize,
/**
* Returns the result of padding the end of the string representation
* of the provided value padded until it is the desired length
- * according to the algorithm of `String::padEnd`.
+ * according to the algorithm of `String::padEnd´.
*/
export const stringPadEnd = createCallableFunction(
stringPrototype.padEnd,
/**
* Returns the result of padding the start of the string representation
* of the provided value padded until it is the desired length
- * according to the algorithm of `String::padStart`.
+ * according to the algorithm of `String::padStart´.
*/
export const stringPadStart = createCallableFunction(
stringPrototype.padStart,
/**
* Returns the result of repeating the string representation of the
* provided value the provided number of times according to the
- * algorithm of `String::repeat`.
+ * algorithm of `String::repeat´.
*/
export const stringRepeat = createCallableFunction(
stringPrototype.repeat,
/**
* Returns the result of replacing the string representation of the
* provided value with the provided replacement, using the provided
- * matcher and according to the algorithm of `String::replace`.
+ * matcher and according to the algorithm of `String::replace´.
*/
export const stringReplace = createCallableFunction(
stringPrototype.replace,
/**
* Returns the result of replacing the string representation of the
* provided value with the provided replacement, using the provided
- * matcher and according to the algorithm of `String::replaceAll`.
+ * matcher and according to the algorithm of `String::replaceAll´.
*/
export const stringReplaceAll = createCallableFunction(
stringPrototype.replaceAll,
/**
* Returns the result of searching the string representation of the
* provided value using the provided matcher and according to the
- * algorithm of `String::search`.
+ * algorithm of `String::search´.
*/
export const stringSearch = createCallableFunction(
stringPrototype.search,
/**
* Returns a slice of the string representation of the provided value
- * according to the algorithm of `String::slice`.
+ * according to the algorithm of `String::slice´.
*/
export const stringSlice = createCallableFunction(
stringPrototype.slice,
/**
* Returns the result of splitting of the string representation of the
* provided value on the provided separator according to the algorithm
- * of `String::split`.
+ * of `String::split´.
*/
export const stringSplit = createCallableFunction(
stringPrototype.split,
/**
* Returns whether the string representation of the provided value
* starts with the provided search string according to the algorithm of
- * `String::startsWith`.
+ * `String::startsWith´.
*/
export const stringStartsWith = createCallableFunction(
stringPrototype.startsWith,
/**
* Returns the value of the provided string.
*
- * ※ This is effectively an alias for the `String::valueOf`.
+ * ※ This is effectively an alias for the `String::valueOf´.
*
* ☡ This function throws if the provided argument is not a string and
- * does not have a `[[StringData]]` slot.
+ * does not have a `[[StringData]]´ slot.
*/
export const stringValue = createCallableFunction(
stringPrototype.valueOf,
/**
* Returns a substring of the string representation of the provided
- * value according to the algorithm of `String::substring`.
+ * value according to the algorithm of `String::substring´.
*/
export const substring = createCallableFunction(
stringPrototype.substring,
-// ♓🌟 Piscēs ∷ string.test.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ string.test.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
assert,
assert(new Matcher(/(?:)/u));
});
- it("[[Construct]] throws with a non·unicode regular expression first argument", () => {
+ it("[[Construct]] accepts a unicode sets regular expression first argument", () => {
+ assert(new Matcher(/(?:)/v));
+ });
+
+ it("[[Construct]] throws with a non·unicode·aware regular expression first argument", () => {
assertThrows(() => new Matcher(/(?:)/));
});
assertStrictEquals(new Matcher(/(?:)/u).dotAll, false);
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
);
});
+ it("[[Construct]] throws an error", () => {
+ const matcher = new Matcher("");
+ assertThrows(() => new matcher.exec());
+ });
+
describe(".length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(Matcher.prototype.exec.length, 1);
assertStrictEquals(new Matcher(/(?:)/u).global, false);
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
assertStrictEquals(new Matcher(/(?:)/u).hasIndices, false);
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
assertStrictEquals(new Matcher(/(?:)/u).ignoreCase, false);
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
assertStrictEquals(new Matcher(/(?:)/u).multiline, false);
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
assertStrictEquals(new Matcher(/.*/su).source, ".*");
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
assertStrictEquals(new Matcher(/(?:)/u).sticky, false);
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
it("[[Call]] returns the string source", () => {
assertStrictEquals(new Matcher(/(?:)/u).toString(), "/(?:)/u");
});
+
+ it("[[Construct]] throws an error", () => {
+ const matcher = new Matcher("");
+ assertThrows(() => new matcher.toString());
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(Matcher.prototype.toString.length, 0);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ Matcher.prototype.toString.name,
+ "toString",
+ );
+ });
+ });
});
describe("::unicode", () => {
assertStrictEquals(new Matcher(/(?:)/u).unicode, true);
});
- describe(".length", () => {
+ describe("[[GetOwnProperty]].get.length", () => {
it("[[Get]] returns the correct length", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
- describe(".name", () => {
+ describe("[[GetOwnProperty]].get.name", () => {
it("[[Get]] returns the correct name", () => {
assertStrictEquals(
Object.getOwnPropertyDescriptor(
});
});
+ describe("::unicodeSets", () => {
+ it("[[Get]] returns true when the unicode sets flag is present", () => {
+ assertStrictEquals(new Matcher(/(?:)/v).unicodeSets, true);
+ });
+
+ describe("[[GetOwnProperty]].get.length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(
+ Object.getOwnPropertyDescriptor(
+ Matcher.prototype,
+ "unicodeSets",
+ ).get.length,
+ 0,
+ );
+ });
+ });
+
+ describe("[[GetOwnProperty]].get.name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ Object.getOwnPropertyDescriptor(
+ Matcher.prototype,
+ "unicodeSets",
+ ).get.name,
+ "get unicodeSets",
+ );
+ });
+ });
+ });
+
describe("~", () => {
it("[[Call]] returns true for a complete match", () => {
assertStrictEquals(new Matcher("")(""), true);
false,
);
});
+
+ it("[[Construct]] throws an error", () => {
+ const matcher = new Matcher("");
+ assertThrows(() => new matcher(""));
+ });
});
describe("~lastIndex", () => {
"very success full",
/([sc]+)[ue]?/g,
(...$s) =>
- `${$s[0].length}`.repeat($s[1].length) +
- $s[0].substring($s[1].length),
+ `${$s[0].length}`.repeat($s[1].length)
+ + $s[0].substring($s[1].length),
),
"very 2u33e22 full",
);
"very success full",
/([sc]+)[ue]?/g,
(...$s) =>
- `${$s[0].length}`.repeat($s[1].length) +
- $s[0].substring($s[1].length),
+ `${$s[0].length}`.repeat($s[1].length)
+ + $s[0].substring($s[1].length),
),
"very 2u33e22 full",
);
-// ♓🌟 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/>.
+// SPDX-FileCopyrightText: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ symbol.js
+ *
+ * Copyright © 2023, 2025 Lady [@ Ladys 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 { createCallableFunction } from "./function.js";
+const PISCĒS = "♓🧩 Piscēs";
+
/**
* Returns the description for the provided symbol.
*
- * ※ This is effectively an alias for the `Symbol::description`
+ * ※ This is effectively an alias for the `Symbol::description´
* getter.
*
* ☡ This function throws if the provided argument is not a symbol.
/**
* Returns a string representation of the provided symbol.
*
- * ※ Use `getSymbolDescription` instead if you just want the text
+ * ※ Use `getSymbolDescription´ instead if you just want the text
* description of a symbol.
*
- * ※ This is effectively an alias for the `Symbol::toString`.
+ * ※ This is effectively an alias for the `Symbol::toString´.
*
* ☡ This function throws if the provided argument is not a symbol.
*/
/**
* Returns the value of the provided symbol.
*
- * ※ This is effectively an alias for the `Symbol::valueOf`.
+ * ※ This is effectively an alias for the `Symbol::valueOf´.
*
* ☡ This function throws if the provided argument is not a symbol and
- * does not have a `[[SymbolData]]` slot.
+ * does not have a `[[SymbolData]]´ slot.
*/
export const symbolValue = createCallableFunction(
Symbol.prototype.valueOf,
-// ♓🌟 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/>.
+// SPDX-FileCopyrightText: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ symbol.test.js
+ *
+ * Copyright © 2023, 2025 Lady [@ Ladys 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,
-// ♓🌟 Piscēs ∷ value.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ value.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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/>.
+ */
+
+const PISCĒS = "♓🧩 Piscēs";
export const {
- /** The welknown `@@asyncIterator` symbol. */
+ /** The welknown `@@asyncIterator´ symbol. */
asyncIterator: ASYNC_ITERATOR,
- /** The welknown `@@hasInstance` symbol. */
+ /** The welknown `@@hasInstance´ symbol. */
hasInstance: HAS_INSTANCE,
- /** The welknown `@@isConcatSpreadable` symbol. */
+ /** The welknown `@@isConcatSpreadable´ symbol. */
isConcatSpreadable: IS_CONCAT_SPREADABLE,
- /** The welknown `@@iterator` symbol. */
+ /** The welknown `@@iterator´ symbol. */
iterator: ITERATOR,
- /** The welknown `@@match` symbol. */
+ /** The welknown `@@match´ symbol. */
match: MATCH,
- /** The welknown `@@matchAll` symbol. */
+ /** The welknown `@@matchAll´ symbol. */
matchAll: MATCH_ALL,
- /** The welknown `@@replace` symbol. */
+ /** The welknown `@@replace´ symbol. */
replace: REPLACE,
- /** The welknown `@@species` symbol. */
+ /** The welknown `@@species´ symbol. */
species: SPECIES,
- /** The welknown `@@split` symbol. */
+ /** The welknown `@@split´ symbol. */
split: SPLIT,
- /** The welknown `@@toPrimitive` symbol. */
+ /** The welknown `@@toPrimitive´ symbol. */
toPrimitive: TO_PRIMITIVE,
- /** The welknown `@@toStringTag` symbol. */
+ /** The welknown `@@toStringTag´ symbol. */
toStringTag: TO_STRING_TAG,
- /** The welknown `@@unscopables` symbol. */
+ /** The welknown `@@unscopables´ symbol. */
unscopables: UNSCOPABLES,
} = Symbol;
/**
* ln(10).
*
- * ※ This is an alias for `Math.LN10`.
+ * ※ This is an alias for `Math.LN10´.
*/
- LN10,
+ LN10: LN_10,
/**
* ln(2).
*
- * ※ This is an alias for `Math.LN2`.
+ * ※ This is an alias for `Math.LN2´.
*/
- LN2,
+ LN2: LN_2,
/**
- * log10(ℇ).
+ * log10(e).
*
- * ※ This is an alias for `Math.LOG10E`.
+ * ※ This is an alias for `Math.LOG10E´.
*/
- LOG10E: LOG10ℇ,
+ LOG10E: LOG10_𝑒,
/**
- * log2(ℇ).
+ * log2(e).
*
- * ※ This is an alias for `Math.LOG2E`.
+ * ※ This is an alias for `Math.LOG2E´.
*/
- LOG2E: LOG2ℇ,
+ LOG2E: LOG2_𝑒,
/**
* sqrt(½).
*
- * ※ This is an alias for `Math.SQRT1_2`.
+ * ※ This is an alias for `Math.SQRT1_2´.
*/
- SQRT1_2: RECIPROCAL_SQRT2,
+ SQRT1_2: RECIPROCAL_SQRT_2,
/**
* sqrt(2).
*
- * ※ This is an alias for `Math.SQRT2`.
+ * ※ This is an alias for `Math.SQRT2´.
*/
- SQRT2,
+ SQRT2: SQRT_2,
/**
- * The mathematical constant π.
+ * The mathematical constant 𝑒.
*
- * ※ This is an alias for `Math.PI`.
+ * ※ This is an alias for `Math.E´.
*/
- PI: Π,
+ E: 𝑒,
/**
- * The Euler number.
+ * The mathematical constant 𝜋.
*
- * ※ This is an alias for `Math.E`.
+ * ※ This is an alias for `Math.PI´.
*/
- E: ℇ,
+ PI: 𝜋,
} = Math;
export const {
/**
* The largest number value less than infinity.
*
- * ※ This is an alias for `Number.MAX_VALUE`.
+ * ※ This is an alias for `Number.MAX_VALUE´.
*/
MAX_VALUE: MAXIMUM_NUMBER,
/**
- * 2**53 - 1.
+ * 2^53 - 1.
*
- * ※ This is an alias for `Number.MAX_SAFE_INTEGER`.
+ * ※ This is an alias for `Number.MAX_SAFE_INTEGER´.
*/
MAX_SAFE_INTEGER: MAXIMUM_SAFE_INTEGRAL_NUMBER,
/**
* The smallest number value greater than negative infinity.
*
- * ※ This is an alias for `Number.MIN_VALUE`.
+ * ※ This is an alias for `Number.MIN_VALUE´.
*/
MIN_VALUE: MINIMUM_NUMBER,
/**
- * -(2**53 - 1).
+ * -(2^53 - 1).
*
- * ※ This is an alias for `Number.MIN_SAFE_INTEGER`.
+ * ※ This is an alias for `Number.MIN_SAFE_INTEGER´.
*/
MIN_SAFE_INTEGER: MINIMUM_SAFE_INTEGRAL_NUMBER,
/**
* Negative infinity.
*
- * ※ This is an alias for `Number.NEGATIVE_INFINITY`.
+ * ※ This is an alias for `Number.NEGATIVE_INFINITY´.
*/
NEGATIVE_INFINITY,
/**
* Nan.
*
- * ※ This is an alias for `Number.NaN`.
+ * ※ This is an alias for `Number.NaN´.
*/
NaN: NAN,
/**
* Positive infinity.
*
- * ※ This is an alias for `Number.POSITIVE_INFINITY`.
+ * ※ This is an alias for `Number.POSITIVE_INFINITY´.
*/
POSITIVE_INFINITY,
/**
* The difference between 1 and the smallest number greater than 1.
*
- * ※ This is an alias for `Number.EPSILON`.
+ * ※ This is an alias for `Number.EPSILON´.
*/
- EPSILON: Ε,
+ EPSILON: 𝜀,
} = Number;
/** Negative zero. */
*/
export const completePropertyDescriptor = (Desc) => {
if (Desc === UNDEFINED) {
+ // A description was not provided; this is an error.
throw new TypeError(
- "Piscēs: Cannot complete undefined property descriptor.",
+ `${PISCĒS}: Cannot complete undefined property descriptor.`,
);
} else if (!("get" in Desc || "set" in Desc)) {
// This is a generic or data descriptor.
if (!("value" in Desc)) {
- // `value` is not defined on this.
+ // `value´ is not defined on this.
Desc.value = UNDEFINED;
} else {
- // `value` is already defined on this.
+ // `value´ is already defined on this.
/* do nothing */
}
if (!("writable" in Desc)) {
- // `writable` is not defined on this.
+ // `writable´ is not defined on this.
Desc.writable = false;
} else {
- // `writable` is already defined on this.
+ // `writable´ is already defined on this.
/* do nothing */
}
} else {
// This is not a generic or data descriptor.
if (!("get" in Desc)) {
- // `get` is not defined on this.
+ // `get´ is not defined on this.
Desc.get = UNDEFINED;
} else {
- // `get` is already defined on this.
+ // `get´ is already defined on this.
/* do nothing */
}
if (!("set" in Desc)) {
- // `set` is not defined on this.
+ // `set´ is not defined on this.
Desc.set = UNDEFINED;
} else {
- // `set` is already defined on this.
+ // `set´ is already defined on this.
/* do nothing */
}
}
if (!("enumerable" in Desc)) {
- // `enumerable` is not defined on this.
+ // `enumerable´ is not defined on this.
Desc.enumerable = false;
} else {
- // `enumerable` is already defined on this.
+ // `enumerable´ is already defined on this.
/* do nothing */
}
if (!("configurable" in Desc)) {
- // `configurable` is not defined on this.
+ // `configurable´ is not defined on this.
Desc.configurable = false;
} else {
- // `configurable` is already defined on this.
+ // `configurable´ is already defined on this.
/* do nothing */
}
};
* descriptor.
*/
export const isFullyPopulatedDescriptor = (Desc) =>
- Desc !== UNDEFINED &&
- ("value" in Desc && "writable" in Desc ||
- "get" in Desc && "set" in Desc) &&
- "enumerable" in Desc && "configurable" in Desc;
+ Desc !== UNDEFINED
+ && ("value" in Desc && "writable" in Desc
+ || "get" in Desc && "set" in Desc)
+ && "enumerable" in Desc && "configurable" in Desc;
/**
* Gets whether the provided value is a generic (not accessor or data)
* descrtiptor.
*/
export const isGenericDescriptor = (Desc) =>
- Desc !== UNDEFINED &&
- !("get" in Desc || "set" in Desc || "value" in Desc ||
- "writable" in Desc);
+ Desc !== UNDEFINED
+ && !("get" in Desc || "set" in Desc || "value" in Desc
+ || "writable" in Desc);
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.
*
* 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.
*/
? ["toString", "valueOf"]
: ["valueOf", "toString"];
for (let index = 0; index < methodNames.length; ++index) {
+ // Test the methods in the order determined above (based on the
+ // hint) and return the result if the method returns a
+ // primitive.
+ //
+ // ☡ If this loop exits with·out returning, it is an error.
const method = O[methodNames[index]];
if (typeof method === "function") {
// Method is callable.
}
}
throw new TypeError(
- "Piscēs: Unable to convert object to primitive",
+ `${PISCĒS}: Unable to convert object to primitive.`,
);
},
toFunctionName: ($, prefix = UNDEFINED) => {
const key = toPrimitive($, "string");
const name = (() => {
if (typeof key === "symbol") {
- // The provided value is a symbol; format its description.
+ // The provided value is a symbol.
+ //
+ // Format its description.
const description = call(getSymbolDescription, key, []);
return description === UNDEFINED ? "" : `[${description}]`;
} else {
- // The provided value not a symbol; convert it to a string
- // property key.
+ // The provided value not a symbol.
+ //
+ // Convert it to a string property key.
return `${key}`;
}
})();
toPrimitive: ($, preferredType = "default") => {
const hint = `${preferredType}`;
if (
- "default" !== hint && "string" !== hint &&
- "number" !== hint
+ "default" !== hint && "string" !== hint
+ && "number" !== hint
) {
// An invalid preferred type was specified.
throw new TypeError(
- `Piscēs: Invalid preferred type: ${preferredType}.`,
+ `${PISCĒS}: Invalid preferred type: ${preferredType}.`,
);
} else if (type($) === "object") {
// The provided value is an object.
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.
/**
* Returns whether the provided values are the same value.
*
- * ※ This differs from `===` in the cases of nan and zero.
+ * ※ 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).
*
- * ※ This differs from `===` in the case of nan.
+ * ※ This differs from `===´ in the case of nan.
*/
sameValueZero,
// The provided values are not of the same type.
return false;
} else if (type1 === "number") {
- // The provided values are numbers; check if they are nan and
- // use strict equality otherwise.
+ // The provided values are numbers.
+ //
+ // Check if they are nan and use strict equality otherwise.
return isNan($1) && isNan($2) || $1 === $2;
} else {
- // The provided values are not numbers; use strict equality.
+ // The provided values are not numbers.
+ //
+ // Use strict equality.
return $1 === $2;
}
},
const integer = floor($);
if (isNan(integer) || integer == 0) {
// The value is zero·like.
+ //
+ // Return positive zero.
return 0;
} else {
// The value is not zero·like.
const clamped = toLength(integer);
if (clamped !== integer) {
- // Clamping the value changes it.
- throw new RangeError(`Piscēs: Index out of range: ${$}.`);
+ // Clamping the value changes it; this is an error.
+ throw new RangeError(`${PISCĒS}: Index out of range: ${$}.`);
} else {
// The value is within appropriate bounds.
+ //
+ // Return it.
return integer;
}
}
* Returns a lowercase string identifying the type of the provided
* value.
*
- * This differs from the value of the `typeof` operator only in the
- * cases of objects and null.
+ * This differs from the value of the `typeof´ operator only in the
+ * cases of callable objects and null.
*/
export const type = ($) => {
if ($ === null) {
-// ♓🌟 Piscēs ∷ value.test.js
-// ====================================================================
-//
-// 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 <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🌟 Piscēs ∷ value.test.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys 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 {
assertEquals,
isFullyPopulatedDescriptor,
isGenericDescriptor,
ITERATOR,
- LN10,
- LN2,
- LOG10ℇ,
- LOG2ℇ,
+ LN_10,
+ LN_2,
+ LOG10_𝑒,
+ LOG2_𝑒,
MATCH,
MATCH_ALL,
MAXIMUM_NUMBER,
ordinaryToPrimitive,
POSITIVE_INFINITY,
POSITIVE_ZERO,
- RECIPROCAL_SQRT2,
+ RECIPROCAL_SQRT_2,
REPLACE,
sameValue,
sameValueZero,
SPECIES,
SPLIT,
- SQRT2,
+ SQRT_2,
TO_PRIMITIVE,
TO_STRING_TAG,
toFunctionName,
type,
UNDEFINED,
UNSCOPABLES,
- Ε,
- Π,
- ℇ,
+ 𝑒,
+ 𝜀,
+ 𝜋,
} from "./value.js";
describe("ASYNC_ITERATOR", () => {
});
});
-describe("LN10", () => {
+describe("LN_10", () => {
it("[[Get]] is ln(10)", () => {
- assertStrictEquals(LN10, Math.LN10);
+ assertStrictEquals(LN_10, Math.LN10);
});
});
-describe("LN2", () => {
+describe("LN_2", () => {
it("[[Get]] is ln(2)", () => {
- assertStrictEquals(LN2, Math.LN2);
+ assertStrictEquals(LN_2, Math.LN2);
});
});
-describe("LOG10ℇ", () => {
- it("[[Get]] is log10(ℇ)", () => {
- assertStrictEquals(LOG10ℇ, Math.LOG10E);
+describe("LOG10_𝑒", () => {
+ it("[[Get]] is log10(𝑒)", () => {
+ assertStrictEquals(LOG10_𝑒, Math.LOG10E);
});
});
-describe("LOG2ℇ", () => {
+describe("LOG2_𝑒", () => {
it("[[Get]] is log2(ℇ)", () => {
- assertStrictEquals(LOG2ℇ, Math.LOG2E);
+ assertStrictEquals(LOG2_𝑒, Math.LOG2E);
});
});
});
});
-describe("RECIPROCAL_SQRT2", () => {
+describe("RECIPROCAL_SQRT_2", () => {
it("[[Get]] is sqrt(½)", () => {
- assertStrictEquals(RECIPROCAL_SQRT2, Math.SQRT1_2);
+ assertStrictEquals(RECIPROCAL_SQRT_2, Math.SQRT1_2);
});
});
});
});
-describe("SQRT2", () => {
+describe("SQRT_2", () => {
it("[[Get]] is sqrt(2)", () => {
- assertStrictEquals(SQRT2, Math.SQRT2);
+ assertStrictEquals(SQRT_2, Math.SQRT2);
});
});
});
});
-describe("Ε", () => {
- it("[[Get]] is ε", () => {
- assertStrictEquals(Ε, Number.EPSILON);
+describe("𝑒", () => {
+ it("[[Get]] is 𝑒", () => {
+ assertStrictEquals(𝑒, Math.E);
});
});
-describe("Π", () => {
- it("[[Get]] is π", () => {
- assertStrictEquals(Π, Math.PI);
+describe("𝜀", () => {
+ it("[[Get]] is 𝜀", () => {
+ assertStrictEquals(𝜀, Number.EPSILON);
});
});
-describe("ℇ", () => {
- it("[[Get]] is ℇ", () => {
- assertStrictEquals(ℇ, Math.E);
+describe("𝜋", () => {
+ it("[[Get]] is 𝜋", () => {
+ assertStrictEquals(𝜋, Math.PI);
});
});