+export const {
+ /**
+ * 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.
+ */
+ 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 function throws an error if provided with an argument which
+ * is not an integral number from 0 to FFFF₁₆ inclusive.
+ */
+ stringFromCodeUnits,
+
+ /**
+ * Returns the result of catenating the string representations of the
+ * provided values, returning a new string according to the algorithm
+ * 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"`.
+ */
+ stringCatenate,
+} = (() => {
+ const { fromCharCode } = String;
+ const { charCodeAt, concat } = String.prototype;
+ const {
+ isInteger: isIntegralNumber,
+ isNaN: isNan,
+ } = Number;
+
+ return {
+ getCodeUnit: ($, n) => {
+ const codeUnit = call(charCodeAt, $, [n]);
+ return isNan(codeUnit) ? UNDEFINED : codeUnit;
+ },
+ stringCatenate: Object.defineProperties(
+ (...args) => call(concat, "", args),
+ { name: { value: "stringCatenate" }, length: { value: 2 } },
+ ),
+ stringFromCodeUnits: Object.defineProperties(
+ (...codeUnits) => {
+ for (let index = 0; index < codeUnits.length; ++index) {
+ // Iterate over each provided code unit and throw if it is
+ // out of range.
+ const nextCU = +codeUnits[index];
+ if (
+ !isIntegralNumber(nextCU) || nextCU < 0 || nextCU > 0xFFFF
+ ) {
+ // The code unit is not an integral number between 0 and
+ // 0xFFFF.
+ throw new RangeError(
+ `Piscēs: Code unit out of range: ${nextCU}.`,
+ );
+ } else {
+ // The code unit is acceptable.
+ /* do nothing */
+ }
+ }
+ return call(fromCharCode, UNDEFINED, codeUnits);
+ },
+ { name: { value: "stringFromCodeUnits" }, length: { value: 1 } },
+ ),
+ };
+})();