UNPKG

3.9 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.unreachable = exports.nullToUndefined = exports.isStringArray = exports.isArray = exports.isUndefined = exports.isObject = exports.isFunction = exports.isErrorLike = exports.isError = exports.isNumber = exports.isString = exports.isBoolean = exports.Prioritizeable = exports.ArrayUtils = void 0;
19var array_utils_1 = require("./array-utils");
20Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return array_utils_1.ArrayUtils; } });
21var prioritizeable_1 = require("./prioritizeable");
22Object.defineProperty(exports, "Prioritizeable", { enumerable: true, get: function () { return prioritizeable_1.Prioritizeable; } });
23function isBoolean(value) {
24 return value === true || value === false;
25}
26exports.isBoolean = isBoolean;
27function isString(value) {
28 return typeof value === 'string' || value instanceof String;
29}
30exports.isString = isString;
31function isNumber(value) {
32 return typeof value === 'number' || value instanceof Number;
33}
34exports.isNumber = isNumber;
35function isError(value) {
36 return value instanceof Error;
37}
38exports.isError = isError;
39function isErrorLike(value) {
40 return isObject(value) && isString(value.name) && isString(value.message) && (isUndefined(value.stack) || isString(value.stack));
41}
42exports.isErrorLike = isErrorLike;
43// eslint-disable-next-line space-before-function-paren
44function isFunction(value) {
45 return typeof value === 'function';
46}
47exports.isFunction = isFunction;
48function isObject(value) {
49 // eslint-disable-next-line no-null/no-null
50 return typeof value === 'object' && value !== null;
51}
52exports.isObject = isObject;
53function isUndefined(value) {
54 return typeof value === 'undefined';
55}
56exports.isUndefined = isUndefined;
57/**
58 * @param value value to check.
59 * @param every optional predicate ran on every element of the array.
60 * @param thisArg value to substitute `this` with when invoking in the predicate.
61 * @returns whether or not `value` is an array.
62 */
63function isArray(value, every, thisArg) {
64 return Array.isArray(value) && (!isFunction(every) || value.every(every, thisArg));
65}
66exports.isArray = isArray;
67function isStringArray(value) {
68 return isArray(value, isString);
69}
70exports.isStringArray = isStringArray;
71/**
72 * Creates a shallow copy with all ownkeys of the original object that are `null` made `undefined`
73 */
74function nullToUndefined(nullable) {
75 const undefinable = Object.assign({}, nullable);
76 for (const key in nullable) {
77 // eslint-disable-next-line no-null/no-null
78 if (nullable[key] === null && Object.prototype.hasOwnProperty.call(nullable, key)) {
79 undefinable[key] = undefined;
80 }
81 }
82 return undefinable;
83}
84exports.nullToUndefined = nullToUndefined;
85/**
86 * Throws when called and statically makes sure that all variants of a type were consumed.
87 */
88function unreachable(_never, message = 'unhandled case') {
89 throw new Error(message);
90}
91exports.unreachable = unreachable;
92//# sourceMappingURL=types.js.map
\No newline at end of file