try to fix this spaghetti of a code
This commit is contained in:
+7
-2
@@ -1,4 +1,4 @@
|
||||
const crypto = require('node:crypto');
|
||||
const crypto = require('node:crypto');
|
||||
class AppError extends Error {
|
||||
constructor(code, message, status = 400) { super(message); this.code = code; this.status = status; }
|
||||
}
|
||||
@@ -16,4 +16,9 @@ class KeyedQueue {
|
||||
async drain() { await Promise.all([...this.tails.values()]); }
|
||||
}
|
||||
const hash = value => crypto.createHash('sha256').update(value).digest('hex');
|
||||
module.exports = {AppError, KeyedQueue, hash};
|
||||
function canonical(value) {
|
||||
if (Array.isArray(value)) return value.map(canonical);
|
||||
if (value && typeof value === 'object') return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])]));
|
||||
return value;
|
||||
}
|
||||
module.exports = {AppError, KeyedQueue, hash, canonical};
|
||||
|
||||
Reference in New Issue
Block a user