@fgiova/aws-signature
Version:
[](https://www.npmjs.com/package/@fgiova/aws-signature)  [ • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatDate = formatDate;
exports.escapeUri = escapeUri;
exports.isArrayBuffer = isArrayBuffer;
exports.fromUtf8 = fromUtf8;
exports.toUint8Array = toUint8Array;
const node_buffer_1 = require("node:buffer");
function formatDate(now) {
const longDate = now.toISOString().replace(/\.\d{3}Z$/, "Z").replace(/[\-:]/g, "");
return {
longDate,
shortDate: longDate.slice(0, 8),
};
}
/* c8 ignore next 3 */
function hexEncode(c) {
return `{%${c.charCodeAt(0).toString(16).toUpperCase()}`;
}
function escapeUri(uri) {
// AWS percent-encodes some extra non-standard characters in a URI
return encodeURIComponent(uri).replace(/[!'()*]/g, hexEncode);
}
function isArrayBuffer(arg) {
return (typeof ArrayBuffer === "function" && arg instanceof ArrayBuffer) ||
Object.prototype.toString.call(arg) === "[object ArrayBuffer]";
}
function fromUtf8(input) {
const buf = node_buffer_1.Buffer.from(input, "utf8");
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}
function toUint8Array(data) {
if (typeof data === "string") {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}
return new Uint8Array(data);
}