UNPKG

4.86 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright The OpenTelemetry Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.isPlainObject = void 0;
19/* eslint-disable @typescript-eslint/no-explicit-any */
20/**
21 * based on lodash in order to support esm builds without esModuleInterop.
22 * lodash is using MIT License.
23 **/
24const objectTag = '[object Object]';
25const nullTag = '[object Null]';
26const undefinedTag = '[object Undefined]';
27const funcProto = Function.prototype;
28const funcToString = funcProto.toString;
29const objectCtorString = funcToString.call(Object);
30const getPrototype = overArg(Object.getPrototypeOf, Object);
31const objectProto = Object.prototype;
32const hasOwnProperty = objectProto.hasOwnProperty;
33const symToStringTag = Symbol ? Symbol.toStringTag : undefined;
34const nativeObjectToString = objectProto.toString;
35/**
36 * Creates a unary function that invokes `func` with its argument transformed.
37 *
38 * @private
39 * @param {Function} func The function to wrap.
40 * @param {Function} transform The argument transform.
41 * @returns {Function} Returns the new function.
42 */
43function overArg(func, transform) {
44 return function (arg) {
45 return func(transform(arg));
46 };
47}
48/**
49 * Checks if `value` is a plain object, that is, an object created by the
50 * `Object` constructor or one with a `[[Prototype]]` of `null`.
51 *
52 * @static
53 * @memberOf _
54 * @since 0.8.0
55 * @category Lang
56 * @param {*} value The value to check.
57 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
58 * @example
59 *
60 * function Foo() {
61 * this.a = 1;
62 * }
63 *
64 * _.isPlainObject(new Foo);
65 * // => false
66 *
67 * _.isPlainObject([1, 2, 3]);
68 * // => false
69 *
70 * _.isPlainObject({ 'x': 0, 'y': 0 });
71 * // => true
72 *
73 * _.isPlainObject(Object.create(null));
74 * // => true
75 */
76function isPlainObject(value) {
77 if (!isObjectLike(value) || baseGetTag(value) !== objectTag) {
78 return false;
79 }
80 const proto = getPrototype(value);
81 if (proto === null) {
82 return true;
83 }
84 const Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
85 return (typeof Ctor == 'function' &&
86 Ctor instanceof Ctor &&
87 funcToString.call(Ctor) === objectCtorString);
88}
89exports.isPlainObject = isPlainObject;
90/**
91 * Checks if `value` is object-like. A value is object-like if it's not `null`
92 * and has a `typeof` result of "object".
93 *
94 * @static
95 * @memberOf _
96 * @since 4.0.0
97 * @category Lang
98 * @param {*} value The value to check.
99 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
100 * @example
101 *
102 * _.isObjectLike({});
103 * // => true
104 *
105 * _.isObjectLike([1, 2, 3]);
106 * // => true
107 *
108 * _.isObjectLike(_.noop);
109 * // => false
110 *
111 * _.isObjectLike(null);
112 * // => false
113 */
114function isObjectLike(value) {
115 return value != null && typeof value == 'object';
116}
117/**
118 * The base implementation of `getTag` without fallbacks for buggy environments.
119 *
120 * @private
121 * @param {*} value The value to query.
122 * @returns {string} Returns the `toStringTag`.
123 */
124function baseGetTag(value) {
125 if (value == null) {
126 return value === undefined ? undefinedTag : nullTag;
127 }
128 return symToStringTag && symToStringTag in Object(value)
129 ? getRawTag(value)
130 : objectToString(value);
131}
132/**
133 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
134 *
135 * @private
136 * @param {*} value The value to query.
137 * @returns {string} Returns the raw `toStringTag`.
138 */
139function getRawTag(value) {
140 const isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
141 let unmasked = false;
142 try {
143 value[symToStringTag] = undefined;
144 unmasked = true;
145 }
146 catch (e) {
147 // silence
148 }
149 const result = nativeObjectToString.call(value);
150 if (unmasked) {
151 if (isOwn) {
152 value[symToStringTag] = tag;
153 }
154 else {
155 delete value[symToStringTag];
156 }
157 }
158 return result;
159}
160/**
161 * Converts `value` to a string using `Object.prototype.toString`.
162 *
163 * @private
164 * @param {*} value The value to convert.
165 * @returns {string} Returns the converted string.
166 */
167function objectToString(value) {
168 return nativeObjectToString.call(value);
169}
170//# sourceMappingURL=lodash.merge.js.map
\No newline at end of file