3 const path
= require('path');
6 * Return a function which combines a part of the filename with a scope, for use in logging.
7 * @param {string} filename
9 const fileScope
= (filename
) => {
10 let fScope
= path
.basename(filename
, '.js');
11 if (fScope
=== 'index') {
12 fScope
= path
.basename(path
.dirname(filename
));
14 return (scope
) => `${fScope}:${scope}`;
19 * Pick out useful axios response fields.
23 const axiosResponseLogData
= (res
) => {
24 const data
= pick(res
, [
32 data
.data
= logTruncate(data
.data
, 100);
39 * Limit length of string to keep logs sane
44 const logTruncate
= (str
, len
) => {
45 if (typeof str
!== 'string' || str
.toString().length
<= len
) {
48 return str
.toString().slice(0, len
) + `... (${str.toString().length} bytes)`;
53 * Return a new object with selected props.
55 * @param {String[]} props
57 const pick
= (obj
, props
) => {
58 return props
.reduce((acc
, prop
) => {
60 acc
[prop
] = obj
[prop
]; // eslint-disable-line security/detect-object-injection