fb3ec979524e668bfc5b85dded22a42c56117f41
3 const path
= require('path');
4 const { randomBytes
} = require('crypto');
5 const { promisify
} = require('util');
6 const randomBytesAsync
= promisify(randomBytes
);
10 * Return a function which combines a part of the filename with a scope, for use in logging.
11 * @param {string} filename
13 const fileScope
= (filename
) => {
14 let fScope
= path
.basename(filename
, '.js');
15 if (fScope
=== 'index') {
16 fScope
= path
.basename(path
.dirname(filename
));
18 return (scope
) => `${fScope}:${scope}`;
23 * Convert Base64 to Base64URL.
24 * @param {String} input
27 const base64ToBase64URL
= (input
) => {
36 * Convert Base64URL to normal Base64.
37 * @param {String} input
40 const base64URLToBase64
= (input
) => {
41 return base64RePad(input
)
48 * Add any missing trailing padding which may have been removed from Base64URL encoding.
49 * @param {String} input
51 const base64RePad
= (input
) => {
53 const lastBlockSize
= input
.length
% blockSize
;
55 const missing
= blockSize
- lastBlockSize
;
56 return input
+ '='.repeat(missing
);