X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/8669d6cba4a0e88ba9fb0e4f9f025bcb417c3cbc..f1667ed7321c6802dc2e96532b0b96eabba4b929:/string.js diff --git a/string.js b/string.js index fb41e62..100f0bd 100644 --- a/string.js +++ b/string.js @@ -275,7 +275,8 @@ export const { * An iterator object for iterating over code values (either code * units or codepoints) in a string. * - * ※ This constructor is not exposed. + * ※ This class is not exposed, although its methods are (through + * the prototypes of string code value iterator objects). */ const StringCodeValueIterator = class extends identity { #allowSurrogates; @@ -380,21 +381,21 @@ export const { return { codeUnits: ($) => - new StringCodeValueIterator(call(arrayIterator, $, [])), + new StringCodeValueIterator(call(arrayIterator, `${$}`, [])), codepoints: ($) => new StringCodeValueIterator( - call(stringIterator, $, []), + call(stringIterator, `${$}`, []), true, ), scalarValues: ($) => new StringCodeValueIterator( - call(stringIterator, $, []), + call(stringIterator, `${$}`, []), false, ), scalarValueString: ($) => stringFromCodepoints(...objectCreate( scalarValueIterablePrototype, - { source: { value: $ } }, + { source: { value: `${$}` } }, )), }; })(); @@ -659,3 +660,11 @@ export const stripLeadingAndTrailingASCIIWhitespace = (() => { * value according to the algorithm of String::substring. */ export const substring = makeCallable(String.prototype.substring); + +/** + * Returns the result of converting the provided value to a string. + * + * ☡ This method throws for symbols and other objects without a string + * representation. + */ +export const toString = ($) => `${$}`;