const {
next: arrayIteratorNext,
} = Object.getPrototypeOf([][iteratorSymbol]());
+const argumentIterablePrototype = {
+ [iteratorSymbol]() {
+ return {
+ next: bind(
+ arrayIteratorNext,
+ call(arrayIterator, this.args, []),
+ [],
+ ),
+ };
+ },
+};
+const binaryCodeUnitIterablePrototype = {
+ [iteratorSymbol]() {
+ return {
+ next: bind(
+ arrayIteratorNext,
+ call(arrayIterator, this, []),
+ [],
+ ),
+ };
+ },
+};
+
const getBufferByteLength =
Object.getOwnPropertyDescriptor(bufferPrototype, "byteLength").get;
const getTypedArrayBuffer =
typeof $ == "string"
? $
: hasOwnProperty($, "raw")
- ? rawString($, ...$s)
+ ? rawString(
+ $,
+ ...objectCreate(argumentIterablePrototype, {
+ args: { value: $s },
+ }),
+ )
: `${$}`,
);
-const binaryCodeUnitIterablePrototype = {
- [iteratorSymbol]() {
- return {
- next: bind(
- arrayIteratorNext,
- call(arrayIterator, this, []),
- [],
- ),
- };
- },
-};
-
+/**
+ * Returns the result of decoding the provided base64 string into an
+ * ArrayBuffer.
+ *
+ * ※ This function is not exposed.
+ */
const decodeBase64 = (source, safe = false) => {
const u6s = map(
source.length % 4 == 0
return call(getViewBuffer, dataView, []);
};
+/**
+ * Returns the result of encoding the provided ArrayBuffer into a
+ * base64 string.
+ *
+ * ※ This function is not exposed.
+ */
const encodeBase64 = (buffer, safe = false) => {
const dataView = new View(buffer);
const byteLength = call(getBufferByteLength, buffer, []);
return stringFromCodeUnits(...resultingCodeUnits);
};
+/**
+ * Returns a source string generated from the arguments passed to a
+ * tag function.
+ *
+ * ※ This function is not exposed.
+ */
const sourceFromArgs = ($, $s) =>
stringReplace(
- typeof $ == "string"
- ? $
- : hasOwnProperty($, "raw")
- ? rawString($, ...$s)
+ typeof $ == "string" ? $ : hasOwnProperty($, "raw")
+ ? rawString(
+ $,
+ ...objectCreate(argumentIterablePrototype, {
+ args: { value: $s },
+ }),
+ )
: `${$}`,
/[\t\n\f\r ]+/gu,
"",
);
/**
- * Returns an ArrayBuffer generated from the provided Base64.
+ * Returns an ArrayBuffer generated from the provided base64 string.
*
* This function can also be used as a tag for a template literal. The
* literal will be interpreted akin to `String.raw`.
decodeBase64(sourceFromArgs($, $s));
/**
- * Returns a (big‐endian) base64 string created from a typed array,
- * buffer, or (16‐bit) string.
+ * Returns a (big‐endian) base64 string created from the provided typed
+ * array, buffer, or (16‐bit) string.
*
* This function can also be used as a tag for a template literal. The
* literal will be interpreted akin to `String.raw`.
/**
* Returns an ArrayBuffer generated from the provided filename‐safe
- * Base64.
+ * base64 string.
*
* This function can also be used as a tag for a template literal. The
* literal will be interpreted akin to `String.raw`.
decodeBase64(sourceFromArgs($, $s), true);
/**
- * Returns a (big‐endian) filename‐safe base64 string created from a
- * typed array, buffer, or (16‐bit) string.
+ * Returns a (big‐endian) filename‐safe base64 string created from the
+ * provided typed array, buffer, or (16‐bit) string.
*
* This function can also be used as a tag for a template literal. The
* literal will be interpreted akin to `String.raw`.
/**
* Returns whether the provided value is a Base64 string.
*
- * Returns false if the provided value is not a string primitive.
+ * ※ This function returns false if the provided value is not a string
+ * primitive.
*/
export const isBase64 = ($) => {
if (typeof $ !== "string") {
/**
* Returns whether the provided value is a filename‐safe base64 string.
*
- * Returns false if the provided value is not a string primitive.
+ * ※ This function returns false if the provided value is not a string
+ * primitive.
*/
export const isFilenameSafeBase64 = ($) => {
if (typeof $ !== "string") {