@datadog/mobile-react-native
Version:
A client-side React Native module to interact with Datadog
41 lines (38 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateContext = void 0;
var _InternalLog = require("../InternalLog");
var _SdkVerbosity = require("../SdkVerbosity");
/* eslint-disable @typescript-eslint/ban-ts-comment */
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/
/**
* Validates the given context before passing it to the native SDKs.
* @param context the original context
* @returns the original context if it's a plain object, an object wrapping the context if it's an array,
* or an empty object if the context is of any other type.
*/
const validateContext = context => {
if (!context) {
return {};
}
// eslint-disable-next-line eqeqeq
if (context.constructor == Object) {
return context;
}
if (Array.isArray(context)) {
_InternalLog.InternalLog.log("The given context is an array, it will be nested in 'context' property inside a new object.", _SdkVerbosity.SdkVerbosity.WARN);
return {
context
};
}
_InternalLog.InternalLog.log(`The given context (${context}) is invalid - it must be an object. Context will be empty.`, _SdkVerbosity.SdkVerbosity.ERROR);
return {};
};
exports.validateContext = validateContext;
//# sourceMappingURL=argsUtils.js.map