projects
/
websub-hub
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
publish requests may now include multiple topic urls
[websub-hub]
/
src
/
common.js
diff --git
a/src/common.js
b/src/common.js
index 0cacc3bf086f2b57f0b10db1ef289c6be7961e15..55a0807b00757e2c2fa0fe8d50e7c22701b0bacf 100644
(file)
--- a/
src/common.js
+++ b/
src/common.js
@@
-26,6
+26,22
@@
const validHash = (algorithm) => getHashes()
.filter((h) => h.match(/^sha[0-9]+$/))
.includes(algorithm);
.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
/**
* Recursively freeze an object.
* @param {Object} o
@@
-140,6
+156,7
@@
module.exports = {
arrayChunk,
attemptRetrySeconds,
axiosResponseLogData,
arrayChunk,
attemptRetrySeconds,
axiosResponseLogData,
+ ensureArray,
freezeDeep,
logTruncate,
randomBytesAsync,
freezeDeep,
logTruncate,
randomBytesAsync,