Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (config) {
var i, prefixCC, env, value, configuration, hierarchy = [];
var conf = {};
// Extend defaults with user configuration
conf.prefix = (config && config.prefix) ? config.prefix : defaults.prefix;
conf.arraySeparator = (config && config.arraySeparator) ? config.arraySeparator : defaults.arraySeparator;
conf.defaults = (config && config.defaults) ? config.defaults : defaults.defaults;
// Namespace (prefix) for config env variables
prefixCC = changeCase.constantCase(conf.prefix);
// Create config object
configuration = new Config(conf.defaults);
// Iterate over env vars
for (env in process.env) {
// if env is in app namespace
if (env.indexOf(prefixCC) === 0) {
// split each var using separator
hierarchy = env.replace(prefixCC !== '' ? prefixCC + '_' : prefixCC, '').split('_');
// Array property ?
if (conf.arraySeparator && process.env[env].indexOf(conf.arraySeparator) !== -1) {
value = process.env[env].split(conf.arraySeparator);
// Try to parse each element in array
for (i = 0; i < value.length; i = i + 1) {
try {
value[i] = JSON.parse(value[i]);
loadFromEnv (env?: NodeJS.ProcessEnv) {
if (!env) {
env = process.env
}
// Copy all env vars starting with ENV_PREFIX into a set so we can check off
// the ones we recognize and warn the user about any we don't recognize.
const unrecognizedEnvKeys = new Set(
Object.keys(env).filter(key => key.startsWith(ENV_PREFIX))
)
const config = {}
for (let key of Object.keys(configSchema.properties)) {
const envKey = ENV_PREFIX + constantCase(key)
const envValue = env[envKey]
unrecognizedEnvKeys.delete(envKey)
if (typeof envValue === 'string') {
switch (configSchema.properties[key].type) {
case 'string':
config[key] = envValue
break
case 'object':
case 'array':
try {
config[key] = JSON.parse(envValue)
} catch (err) {
logger.error('unable to parse config. key=%s' + envKey)
}
break
async function expand(responseBody, __, includeFullObject, prune) {
__ = __ || i18n.__;
let fieldConstantCase = changeCase.constantCase(responseBody.field);
// if enum then look up value
// else get item from API
if (!_.has(config.fields[fieldConstantCase], 'type')) {
// throw 'No such facet type configured';
// default to raw
config.fields[fieldConstantCase] = {type: config.type.RAW};
}
// Preprocess
// Notice that sorting makes little sense if the list isn't exhaustive
if (config.fields[fieldConstantCase].ordering === 'NUMERIC') {
responseBody.results = _.sortBy(responseBody.results, function(e) {
return _.toSafeInteger(e.name);
});
}
if (prune && config.fields[fieldConstantCase].prune) {
function getRanges(field, minMax, buckets) {
// based on the field type and minimum resolution and min max values returns an array with min max values
// let range = ['1900,1910', '1910,1920', '1920,1930', '1930,1940'];
let constantField = changeCase.constantCase(field);
let bucketSizeVaries = false;
let diff = minMax.max - minMax.min;
let bucketSize = diff / buckets;
// an attempt to set buckets size to nice values (0.1 instead of 0.1043429) whilst keeping bucket count to around 10;
if (diff > 0.0000001) {
let b = 10000;
while (diff <= b) {
b /= 10;
}
b /= 10;
if (diff / b > 20) b *= 5;
if (diff / b > 15) b *= 2;
if (diff / b < 3) b /= 5;
if (diff / b < 5) b /= 2;
function normalizeActionType(key) {
let regularKey = key;
if (!RE_IS_CONSTANT.test(key)) {
regularKey = changeCase.constantCase(key);
if (!RE_IS_CONSTANT.test(regularKey)) {
throw new Error(
`[redux-cube] action type "${key}" must be constant case ("TEST_STRING") or camel case ("testString").`,
);
}
}
return regularKey;
}
function prepareCases(key, value) {
return {
[camelCase(key)]: camelCase(value),
[pascalCase(key)]: pascalCase(value),
[snakeCase(key)]: snakeCase(value),
[paramCase(key)]: paramCase(value),
[constantCase(key)]: constantCase(value),
};
}
data.results.forEach(function(e, i) {
let results = secondDimensionData[i].results;
e.values = categories.map(function(c) {
return _.get(results[c.key], 'count', 0);
});
e.diff = e.count - _.sum(e.values);
});
categories.forEach(function(e) {
delete e.key;
});
data.max = max;
data.min = min;
let constantDimension = changeCase.constantCase(query.secondDimension);
if (!facetConfig.fields[constantDimension].isOverlapping) {
data.secondDiff = _.sumBy(data.results, 'diff');
}
data.secondField = query.secondDimension;
data.categories = categories;
return data;
}
.then((answers) => {
const tokens = {
'WP Emerge Starter Theme': answers.name,
'WP Emerge Starter Plugin': answers.name,
'MyApp': pascalCase(answers.namespace),
'MY_APP': constantCase(answers.namespace),
'my_app': snakeCase(answers.namespace),
};
log('');
log('The following changes will be applied:');
log('--------------------------------------');
log(`WP Emerge Starter Theme/Plugin => ${chalk.cyan(tokens['WP Emerge Starter Theme'])}`);
log(`MyApp => ${chalk.cyan(tokens['MyApp'])}`);
log(`MY_APP => ${chalk.cyan(tokens['MY_APP'])}`);
log(`my_app => ${chalk.cyan(tokens['my_app'])}`);
log('--------------------------------------');
log('');
log(chalk.yellow('WARNING: This is a one-time replacement only. Once applied it cannot be undone or updated automatically.'));
return inquirer
.prompt([
async function addSecondDimension(data, query) {
expect(query.secondDimension).to.be.a('string', 'Dimension must be a string');
let constantSecondDimension = changeCase.constantCase(query.secondDimension);
expect(facetConfig.fields[constantSecondDimension]).to.be.an('object', 'There must exist a configuration for the dimension');
let isTypeEnumOrRange = facetConfig.fields[constantSecondDimension].type === facetConfig.type.ENUM || !!facetConfig.fields[constantSecondDimension].range;
expect(isTypeEnumOrRange).to.equal(true, 'Second dimension must be an low cardinality enum');
query.buckets = query.buckets || 10;
if (query.secondDimension == 'month') {
query.fillEnums = true;
query.buckets = undefined;
}
if (query.secondDimension == 'decimalLatitude' || query.secondDimension == 'year' || query.secondDimension == 'elevation') {
query.fillEnums = false;
query.buckets = query.buckets || 10;
}
let dimensionPromises = data.results.map(function(e) {
let mergedQuery = _.assign({}, query, getCamelCasedObject(e.filter), {dimension: query.secondDimension, limit: 1000, offset: 0});