UNPKG

2.56 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright (C) 2016-2020 Michael Kourlas
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 * http://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.stringify = exports.isMap = exports.isSet = exports.isFunction = exports.isArray = exports.isObject = exports.isNull = exports.isUndefined = void 0;
19function isUndefined(val) {
20 return Object.prototype.toString.call(val) === "[object Undefined]";
21}
22exports.isUndefined = isUndefined;
23function isNull(val) {
24 return Object.prototype.toString.call(val) === "[object Null]";
25}
26exports.isNull = isNull;
27function isObject(val) {
28 return Object.prototype.toString.call(val) === "[object Object]";
29}
30exports.isObject = isObject;
31function isArray(val) {
32 return Object.prototype.toString.call(val) === "[object Array]";
33}
34exports.isArray = isArray;
35// eslint-disable-next-line @typescript-eslint/ban-types
36function isFunction(val) {
37 return Object.prototype.toString.call(val) === "[object Function]";
38}
39exports.isFunction = isFunction;
40function isSet(val) {
41 return Object.prototype.toString.call(val) === "[object Set]";
42}
43exports.isSet = isSet;
44function isMap(val) {
45 return Object.prototype.toString.call(val) === "[object Map]";
46}
47exports.isMap = isMap;
48/**
49 * Returns a string representation of the specified value, as given by the
50 * value's toString() method (if it has one) or the global String() function
51 * (if it does not).
52 *
53 * @param value The value to convert to a string.
54 *
55 * @returns A string representation of the specified value.
56 */
57// eslint-disable-next-line max-len
58// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
59function stringify(value) {
60 if (!isUndefined(value) && !isNull(value)) {
61 if (isFunction(value === null || value === void 0 ? void 0 : value.toString)) {
62 value = value.toString();
63 }
64 }
65 return String(value);
66}
67exports.stringify = stringify;