sitespeed.io/lib/support/tsdbUtil.js

41 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const get = require('lodash.get');
const flatten = require('./flattenMessage');
module.exports = {
toSafeKey(key, safeChar = '_') {
return key.replace(/[.~ /+|,:?&%]|%7C/g, safeChar);
},
getConnectivity(options) {
// if we have a friendly name for your connectivity, use that!
let connectivity = get(options, 'browsertime.connectivity.alias');
if (connectivity) {
// If the alias is a number, it is converted to a Number by get.
return this.toSafeKey(connectivity.toString());
} else {
return get(options, 'browsertime.connectivity.profile', 'unknown');
}
},
getURLAndGroup(options, group, url, includeQueryParams, alias) {
if (
group &&
options.urlsMetaData &&
options.urlsMetaData[url] &&
options.urlsMetaData[url].alias
) {
let alias = options.urlsMetaData[url].alias;
return this.toSafeKey(group) + '.' + this.toSafeKey(alias);
} else if (alias && alias[url]) {
return this.toSafeKey(group) + '.' + this.toSafeKey(alias[url]);
} else {
return flatten.keypathFromUrl(
url,
includeQueryParams,
options.useHash,
group
);
}
}
};