3bf7e55cc7e85a4cd050fd2708dc2726fa9f9d94
3 const path
= require('path');
4 const { name: packageName
, version: packageVersion
} = require('../package');
6 const libraryIdentifier
= `${packageName}@${packageVersion}`;
9 * Return a function which combines a part of the filename with a scope, for use in logging.
10 * @param {string} filename
12 const fileScope
= (filename
) => {
13 const shortFilename
= path
.basename(filename
, '.js');
14 const fScope
= (shortFilename
=== 'index') ? path
.basename(path
.dirname(filename
)) : shortFilename
;
15 return (scope
) => [libraryIdentifier
, fScope
, scope
].join(':');
20 * Pick out useful axios response fields.
21 * @param {AxiosResponse} res
24 const axiosResponseLogData
= (res
) => {
25 const data
= pick(res
, [
33 data
.data
= logTruncate(data
.data
, 100);
40 * Limit length of string to keep logs sane
45 const logTruncate
= (str
, len
) => {
46 if (typeof str
!== 'string' || str
.toString().length
<= len
) {
49 return str
.toString().slice(0, len
) + `... (${str.toString().length} bytes)`;
54 * Return a new object with selected props.
56 * @param {String[]} props
58 const pick
= (obj
, props
) => {
59 return props
.reduce((acc
, prop
) => {
61 acc
[prop
] = obj
[prop
]; // eslint-disable-line security/detect-object-injection
69 * Return a set containing non-shared items between two sets.
74 const setSymmetricDifference
= (a
, b
) => {
88 * URL objects have weird names.
89 * @param {String} component
92 const properURLComponentName
= (component
) => {
93 // eslint-disable-next-line security/detect-object-injection
97 }[component
] || component
;
102 * Encodes single-level object as form data string.
103 * @param {Object} data
105 const formData
= (data
) => {
106 const formData
= new URLSearchParams();
107 Object
.entries(data
).forEach(([name
, value
]) => formData
.set(name
, value
));
108 return formData
.toString();
114 axiosResponseLogData
,
117 setSymmetricDifference
,
118 properURLComponentName
,