.filter((h) => h.match(/^sha[0-9]+$/))
.includes(algorithm);
+
+/**
+ * Return an array containing x if x is not an array.
+ * @param {*} x
+ */
+const ensureArray = (x) => {
+ if (x === undefined) {
+ return [];
+ }
+ if (!Array.isArray(x)) {
+ return Array(x);
+ }
+ return x;
+};
+
+
/**
* Recursively freeze an object.
* @param {Object} o
* @param {Number} jitter
* @returns {Number}
*/
- const attemptRetrySeconds = (attempt, retryBackoffSeconds = [60, 120, 360, 1440, 7200, 43200, 86400], jitter = 0.618) => {
+const attemptRetrySeconds = (attempt, retryBackoffSeconds = [60, 120, 360, 1440, 7200, 43200, 86400], jitter = 0.618) => {
const maxAttempt = retryBackoffSeconds.length - 1;
if (typeof attempt !== 'number' || attempt < 0) {
attempt = 0;
* @param {Array} array
* @param {Number} per
*/
- const arrayChunk = (array, per = 1) => {
+const arrayChunk = (array, per = 1) => {
const nChunks = Math.ceil(array.length / per);
return Array.from(Array(nChunks), (_, i) => array.slice(i * per, (i + 1) * per));
}
* @param {Array} dst
* @param {Array} src
*/
- const stackSafePush = (dst, src) => {
+const stackSafePush = (dst, src) => {
const jsEngineMaxArguments = 2**16; // Current as of Node 12
arrayChunk(src, jsEngineMaxArguments).forEach((items) => {
Array.prototype.push.apply(dst, items);
arrayChunk,
attemptRetrySeconds,
axiosResponseLogData,
+ ensureArray,
freezeDeep,
logTruncate,
randomBytesAsync,