split b64u functions into separate package
[squeep-mystery-box] / lib / common.js
1 'use strict';
2
3 const path = require('path');
4 const { randomBytes } = require('crypto');
5 const { promisify } = require('util');
6 const randomBytesAsync = promisify(randomBytes);
7
8
9 /**
10 * Return a function which combines a part of the filename with a scope, for use in logging.
11 * @param {string} filename
12 */
13 const fileScope = (filename) => {
14 let fScope = path.basename(filename, '.js');
15 if (fScope === 'index') {
16 fScope = path.basename(path.dirname(filename));
17 }
18 return (scope) => `${fScope}:${scope}`;
19 }
20
21
22 module.exports = {
23 fileScope,
24 randomBytesAsync,
25 };