import {
defineOwnProperties,
getOwnPropertyDescriptors,
- getPrototype,
- objectCreate,
setPrototype,
} from "./object.js";
-import { ITERATOR } from "./value.js";
const RE = RegExp;
const { prototype: rePrototype } = RE;
* with U+FFFD.
*/
scalarValues,
-
- /**
- * Returns the result of converting the provided value to a string of
- * scalar values by replacing (unpaired) surrogate values with
- * U+FFFD.
- */
- scalarValueString,
} = (() => {
const generateCharacters = function* (character) {
yield character;
bind(generateCodepoints, { allowSurrogates: false }, []),
"String Scalar Value Iterator",
);
- const {
- next: scalarValuesNext,
- } = getPrototype(scalarValuesIterator(""));
- const scalarValueIterablePrototype = {
- [ITERATOR]() {
- return {
- next: bind(
- scalarValuesNext,
- scalarValuesIterator(this.source),
- [],
- ),
- };
- },
- };
return {
characters: ($) => charactersIterator(`${$}`),
codeUnits: ($) => codeUnitsIterator(`${$}`),
codepoints: ($) => codepointsIterator(`${$}`),
scalarValues: ($) => scalarValuesIterator(`${$}`),
- scalarValueString: ($) =>
- stringFromCodepoints(...objectCreate(
- scalarValueIterablePrototype,
- { source: { value: `${$}` } },
- )),
};
})();
stringPrototype.substring,
);
+/**
+ * Returns the result of converting the provided value to a string of
+ * scalar values by replacing (unpaired) surrogate values with
+ * U+FFFD.
+ */
+export const toScalarValueString = createCallableFunction(
+ String.prototype.toWellFormed,
+ { name: "toScalarValueString" },
+);
+
/**
* Returns the result of converting the provided value to a string.
*
Matcher,
rawString,
scalarValues,
- scalarValueString,
splitOnASCIIWhitespace,
splitOnCommas,
stringCatenate,
stripAndCollapseASCIIWhitespace,
stripLeadingAndTrailingASCIIWhitespace,
substring,
+ toScalarValueString,
toString,
} from "./string.js";
});
});
-describe("scalarValueString", () => {
- it("[[Call]] replaces invalid values", () => {
- assertStrictEquals(
- scalarValueString("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
- "Ii🎙\uFFFD\uFFFD\uFFFD\uFFFD🆗☺",
- );
- });
-
- it("[[Construct]] throws an error", () => {
- assertThrows(() => new scalarValueString(""));
- });
-
- describe(".length", () => {
- it("[[Get]] returns the correct length", () => {
- assertStrictEquals(scalarValueString.length, 1);
- });
- });
-
- describe(".name", () => {
- it("[[Get]] returns the correct name", () => {
- assertStrictEquals(scalarValueString.name, "scalarValueString");
- });
- });
-});
-
describe("scalarValues", () => {
it("[[Call]] returns an iterable", () => {
assertStrictEquals(
});
});
+describe("toScalarValueString", () => {
+ it("[[Call]] replaces invalid values", () => {
+ assertStrictEquals(
+ toScalarValueString("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
+ "Ii🎙\uFFFD\uFFFD\uFFFD\uFFFD🆗☺",
+ );
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toScalarValueString(""));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(toScalarValueString.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ toScalarValueString.name,
+ "toScalarValueString",
+ );
+ });
+ });
+});
+
describe("toString", () => {
it("[[Call]] converts to a string", () => {
assertStrictEquals(