UNPKG

@microsoft/applicationinsights-core-js

Version:

Microsoft Application Insights Core Javascript SDK

114 lines (112 loc) 4.12 kB
/* * Application Insights JavaScript SDK - Core, 3.3.6 * Copyright (c) Microsoft and contributors. All rights reserved. */ import { asString, isBoolean, isFunction, isNullOrUndefined, isString } from "@nevware21/ts-utils"; import { STR_EMPTY } from "../JavaScriptSDK/InternalConstants"; import { _DYN_TO_LOWER_CASE } from "../__DynamicConstants"; /** * @internal * @ignore * @param str * @param defaultValue * @returns */ function _stringToBoolOrDefault(theValue, defaultValue, theConfig) { if (!theValue && isNullOrUndefined(theValue)) { return defaultValue; } if (isBoolean(theValue)) { return theValue; } return asString(theValue)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() === "true"; } /** * Helper which returns an IConfigDefaultCheck instance with the field defined as an object * that should be merged * @param defaultValue - The default value to apply it not provided or it's not valid * @returns a new IConfigDefaultCheck structure */ export function cfgDfMerge(defaultValue) { return { mrg: true, v: defaultValue }; } /** * Helper which returns an IConfigDefaultCheck instance with the provided field set function * @param setter - The IConfigCheckFn function to validate the user provided value * @param defaultValue - The default value to apply it not provided or it's not valid * @returns a new IConfigDefaultCheck structure */ export function cfgDfSet(setter, defaultValue) { return { set: setter, v: defaultValue }; } /** * Helper which returns an IConfigDefaultCheck instance with the provided field validator * @param validator - The IConfigCheckFn function to validate the user provided value * @param defaultValue - The default value to apply it not provided or it's not valid * @param fallBackName - The fallback configuration name if the current value is not available * @returns a new IConfigDefaultCheck structure */ export function cfgDfValidate(validator, defaultValue, fallBackName) { return { fb: fallBackName, isVal: validator, v: defaultValue }; } /** * Helper which returns an IConfigDefaultCheck instance that will validate and convert the user * provided value to a boolean from a string or boolean value * @param defaultValue - The default value to apply it not provided or it's not valid * @param fallBackName - The fallback configuration name if the current value is not available * @returns a new IConfigDefaultCheck structure */ export function cfgDfBoolean(defaultValue, fallBackName) { return { fb: fallBackName, set: _stringToBoolOrDefault, v: !!defaultValue }; } /** * Helper which returns an IConfigDefaultCheck instance that will validate that the user * provided value is a function. * @param defaultValue - The default value to apply it not provided or it's not valid * @returns a new IConfigDefaultCheck structure */ export function cfgDfFunc(defaultValue) { return { isVal: isFunction, v: defaultValue || null }; } /** * Helper which returns an IConfigDefaultCheck instance that will validate that the user * provided value is a function. * @param defaultValue - The default string value to apply it not provided or it's not valid, defaults to an empty string * @returns a new IConfigDefaultCheck structure */ export function cfgDfString(defaultValue) { return { isVal: isString, v: asString(defaultValue || STR_EMPTY) }; } /** * Helper which returns an IConfigDefaultCheck instance identifying that value associated with this property * should not have it's properties converted into a dynamic config properties. * @param defaultValue - The default value to apply it not provided or it's not valid * @returns a new IConfigDefaultCheck structure */ export function cfgDfBlockPropValue(defaultValue) { return { blkVal: true, v: defaultValue }; } //# sourceMappingURL=ConfigDefaultHelpers.js.map