topkat-utils
Version:
A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.
51 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerConfig = exports.configFn = void 0;
const is_nodejs_1 = require("./is-nodejs");
const object_utils_1 = require("./object-utils");
const isNode = (0, is_nodejs_1.isNodeJs)();
let config = {
// Also used as default config
env: 'development',
isProd: false,
nbOfLogsToKeep: 25,
customTypes: {},
terminal: {
noColor: !isNode,
theme: {
primary: [0, 149, 250],
shade1: [0, 90, 250],
shade2: [0, 208, 245],
pageWidth: 53,
debugModeColor: [201, 27, 169],
}
},
};
/** Allow dynamic changing of config */
function configFn() { return config; }
exports.configFn = configFn;
function registerConfig(customConfig) {
if ('terminal' in customConfig === false)
customConfig.terminal = {};
if (customConfig.terminal?.theme?.primary) {
const primary = customConfig.terminal.theme.primary;
customConfig.terminal.theme.shade1 ??= [primary[0] / 2.2, primary[1] / 2.2, primary[2] / 2.2];
customConfig.terminal.theme.shade2 ??= primary;
}
const newconfig = {
...config,
...customConfig
};
newconfig.terminal = {
...config?.terminal,
...customConfig?.terminal
};
newconfig.terminal.theme = {
...config?.terminal?.theme,
...(customConfig?.terminal?.theme || {})
};
config = (0, object_utils_1.mergeDeep)(config, customConfig);
config.isProd = config?.env ? config.env.includes('prod') : true; // preprod | production
}
exports.registerConfig = registerConfig;
//# sourceMappingURL=config.js.map