@thi.ng/checks

  • Version 3.9.1
  • Published
  • 54.1 kB
  • No dependencies
  • Apache-2.0 license

Install

npm i @thi.ng/checks
yarn add @thi.ng/checks
pnpm add @thi.ng/checks

Overview

Collection of 70+ type, feature & value checks

Index

Functions

function exists

exists: <T>(t: T) => t is T;

    function existsAndNotNull

    existsAndNotNull: <T>(x: T) => x is T;

      function hasBigInt

      hasBigInt: () => boolean;

        function hasCrypto

        hasCrypto: () => boolean;

          function hasMaxLength

          hasMaxLength: (len: number, x: ArrayLike<any>) => boolean;

            function hasMinLength

            hasMinLength: (len: number, x: ArrayLike<any>) => boolean;

              function hasPerformance

              hasPerformance: () => boolean;

                function hasWASM

                hasWASM: () => boolean;

                  function hasWebGL

                  hasWebGL: () => boolean;

                    function hasWebSocket

                    hasWebSocket: () => boolean;

                      function implementsFunction

                      implementsFunction: <T = any, K extends keyof T = any>(
                      x: any,
                      fn: K
                      ) => x is Pick<T, K>;

                        function isAlpha

                        isAlpha: (x: string) => boolean;

                          function isAlphaNum

                          isAlphaNum: (x: string) => boolean;

                            function isArray

                            isArray: (arg: any) => arg is any[];

                              function isArrayBufferLike

                              isArrayBufferLike: (x: any) => x is ArrayBufferLike;

                                function isArrayBufferView

                                isArrayBufferView: (x: any) => x is ArrayBufferView;

                                  function isArrayLike

                                  isArrayLike: <T = any>(x: any) => x is ArrayLike<T>;

                                    function isArrayOf

                                    isArrayOf: <T>(pred: (x: any) => boolean) => (x: any) => x is T[];
                                    • Higher order predicate to check if a given value is an array of T. Takes pred to check single array items.

                                      Parameter pred

                                      Remarks

                                      Uses Array.prototype.every() with additional pre-check.

                                      Also see isObjectOf, isSetOf.

                                    function isASCII

                                    isASCII: (x: string) => boolean;
                                    • Returns true iff all chars are in ASCII range [0x00,0x7f]

                                      Parameter x

                                    function isAsyncIterable

                                    isAsyncIterable: <T = any>(x: any) => x is AsyncIterable<T>;

                                      function isBigInt

                                      isBigInt: (x: any) => x is bigint;

                                        function isBlob

                                        isBlob: (x: any) => x is Blob;

                                          function isBoolean

                                          isBoolean: (x: any) => x is boolean;

                                            function isBooleanArray

                                            isBooleanArray: (x: any) => x is unknown[];

                                              function isChrome

                                              isChrome: () => boolean;

                                                function isDarkMode

                                                isDarkMode: () => boolean;
                                                • Browser only. Returns true if client has currently dark mode enabled. Always returns false if no global window object is available.

                                                function isDataURL

                                                isDataURL: (x: string) => boolean;

                                                  function isDate

                                                  isDate: (x: any) => x is Date;

                                                    function isEven

                                                    isEven: (x: number) => boolean;

                                                      function isFalse

                                                      isFalse: (x: any) => x is false;

                                                        function isFile

                                                        isFile: (x: any) => x is File;

                                                          function isFirefox

                                                          isFirefox: () => boolean;

                                                            function isFloatArray

                                                            isFloatArray: (x: any) => x is FloatArray;

                                                              function isFloatString

                                                              isFloatString: (x: string) => boolean;

                                                                function isFunction

                                                                isFunction: <T extends Function>(x: any) => x is T;

                                                                  function isGenerator

                                                                  isGenerator: <T = any>(x: any) => x is Generator<T, any, unknown>;

                                                                  function isHex

                                                                  isHex: (x: string) => boolean;

                                                                    function isHexColor

                                                                    isHexColor: (x: any) => x is string;

                                                                      function isIE

                                                                      isIE: () => boolean;

                                                                        function isIllegalKey

                                                                        isIllegalKey: (x: any) => boolean;
                                                                        • Returns true, if given x is an illegal object key as per ILLEGAL_KEYS.

                                                                          Parameter x

                                                                          Remarks

                                                                          Also see isProtoPath for more details

                                                                        function isInRange

                                                                        isInRange: (min: number, max: number, x: number) => boolean;

                                                                          function isInt32

                                                                          isInt32: (x: any) => x is number;

                                                                            function isIntArray

                                                                            isIntArray: (x: any) => x is IntArray;

                                                                              function isIntString

                                                                              isIntString: (x: string) => boolean;

                                                                                function isIterable

                                                                                isIterable: <T = any>(x: any) => x is Iterable<T>;

                                                                                  function isMap

                                                                                  isMap: <K = any, V = any>(x: any) => x is Map<K, V>;

                                                                                    function isMobile

                                                                                    isMobile: () => boolean;

                                                                                      function isNaN

                                                                                      isNaN: (x: any) => boolean;

                                                                                        function isNegative

                                                                                        isNegative: (x: any) => x is number;

                                                                                          function isNegativeInt

                                                                                          isNegativeInt: (x: any) => x is number;

                                                                                            function isNil

                                                                                            isNil: (x: any) => x is null;
                                                                                            • Checks if x is null or undefined.

                                                                                            function isNode

                                                                                            isNode: () => boolean;

                                                                                              function isNonNegativeInt

                                                                                              isNonNegativeInt: (x: any) => x is number;

                                                                                                function isNonPositiveInt

                                                                                                isNonPositiveInt: (x: any) => x is number;

                                                                                                  function isNotStringAndIterable

                                                                                                  isNotStringAndIterable: <T = any>(x: any) => x is Iterable<T>;

                                                                                                    function isNull

                                                                                                    isNull: (x: any) => x is null;

                                                                                                      function isNumber

                                                                                                      isNumber: (x: any) => x is number;

                                                                                                        function isNumberArray

                                                                                                        isNumberArray: (x: any) => x is unknown[];

                                                                                                          function isNumeric

                                                                                                          isNumeric: (x: string) => boolean;

                                                                                                            function isNumericArray

                                                                                                            isNumericArray: (x: any) => x is unknown[] | TypedArray;
                                                                                                            • Returns true if x is a JS array of numbers or a typed array.

                                                                                                              Parameter x

                                                                                                            function isNumericFloat

                                                                                                            isNumericFloat: (x: string) => boolean;
                                                                                                            • Returns true if given string only contains an integer or floating point number, optionally in scientific notiation (e.g. -123.45e-6).

                                                                                                              Parameter x

                                                                                                            function isNumericInt

                                                                                                            isNumericInt: (x: string) => boolean;
                                                                                                            • Returns true if given string contains only digits, and optionally, a sign prefix.

                                                                                                              Parameter x

                                                                                                            function isObject

                                                                                                            isObject: (x: any) => x is Object;

                                                                                                              function isObjectOf

                                                                                                              isObjectOf: <T>(
                                                                                                              pred: (x: any) => boolean
                                                                                                              ) => (x: any) => x is Record<PropertyKey, T>;
                                                                                                              • Higher order predicate to check if a given value is an object with all values of type T. Takes pred to check single array items.

                                                                                                                Parameter pred

                                                                                                                Remarks

                                                                                                                Uses Object.values().every() with additional pre-check.

                                                                                                                Also see isArrayOf, isSetOf.

                                                                                                              function isOdd

                                                                                                              isOdd: (x: number) => boolean;

                                                                                                                function isPlainObject

                                                                                                                isPlainObject: (x: any) => x is Record<string, any>;
                                                                                                                • Similar to isObject, but also checks if prototype is that of Object (or null).

                                                                                                                  Parameter x

                                                                                                                function isPlainObjectArray

                                                                                                                isPlainObjectArray: (x: any) => x is unknown[];

                                                                                                                  function isPositive

                                                                                                                  isPositive: (x: any) => x is number;

                                                                                                                    function isPositiveInt

                                                                                                                    isPositiveInt: (x: any) => x is number;

                                                                                                                      function isPrimitive

                                                                                                                      isPrimitive: (x: any) => x is string | number | boolean;
                                                                                                                      • Returns true if x is a string, number or boolean.

                                                                                                                        Parameter x

                                                                                                                      function isPrintableASCII

                                                                                                                      isPrintableASCII: (x: string) => boolean;
                                                                                                                      • Returns true iff all chars are in printable ASCII range [0x20,0x7e]

                                                                                                                        Parameter x

                                                                                                                      function isPromise

                                                                                                                      isPromise: <T = any>(x: any) => x is Promise<T>;

                                                                                                                        function isPromiseLike

                                                                                                                        isPromiseLike: <T = any>(x: any) => x is Promise<T>;

                                                                                                                          function isProtoPath

                                                                                                                          isProtoPath: (path: string | number | readonly (string | number)[]) => boolean;
                                                                                                                          • Returns true if given path contains any ILLEGAL_KEYS, i.e. could be used to poison the prototype chain of an object.

                                                                                                                            Parameter path

                                                                                                                            Remarks

                                                                                                                            If given an array, each item is considered a single sub-path property and will be checked as is. If given a string it will be split using "." as delimiter and each item checked as is (same way array paths are handled).

                                                                                                                            Original discussion here, implementation updated to be more encompassing: https://codeberg.org/thi.ng/umbrella/pulls/273

                                                                                                                            Also see isIllegalKey.

                                                                                                                          function isRegExp

                                                                                                                          isRegExp: (x: any) => x is RegExp;

                                                                                                                            function isSafari

                                                                                                                            isSafari: () => boolean;

                                                                                                                              function isSet

                                                                                                                              isSet: <T = any>(x: any) => x is Set<T>;

                                                                                                                                function isSetOf

                                                                                                                                isSetOf: <T>(pred: (x: any) => boolean) => (x: any) => x is Set<T>;
                                                                                                                                • Higher order predicate to check if a given value is a Set of T. Takes pred to check single items.

                                                                                                                                  Parameter pred

                                                                                                                                  Remarks

                                                                                                                                  Uses same semantics as Array.prototype.every(), i.e. also returns true if given an empty set.

                                                                                                                                  Also see isArrayOf, isObjectOf.

                                                                                                                                function isString

                                                                                                                                isString: (x: any) => x is string;

                                                                                                                                  function isStringArray

                                                                                                                                  isStringArray: (x: any) => x is unknown[];

                                                                                                                                    function isSymbol

                                                                                                                                    isSymbol: (x: any) => x is Symbol;

                                                                                                                                      function isTouchEvent

                                                                                                                                      isTouchEvent: (e: Event) => e is TouchEvent;
                                                                                                                                      • On Firefox TouchEvent is undefined if the hardware doesn't support touch. Therefore this predicate checks for that first before verifying if e is indeed a TouchEvent.

                                                                                                                                        Parameter e

                                                                                                                                      function isTransferable

                                                                                                                                      isTransferable: (x: any) => boolean;

                                                                                                                                        function isTrue

                                                                                                                                        isTrue: (x: any) => x is boolean;

                                                                                                                                          function isTypedArray

                                                                                                                                          isTypedArray: (x: any) => x is TypedArray;

                                                                                                                                            function isUint32

                                                                                                                                            isUint32: (x: any) => x is number;

                                                                                                                                              function isUintArray

                                                                                                                                              isUintArray: (x: any) => x is UintArray;

                                                                                                                                                function isUndefined

                                                                                                                                                isUndefined: (x: any) => x is undefined;

                                                                                                                                                  function isUUID

                                                                                                                                                  isUUID: (x: string) => boolean;

                                                                                                                                                    function isUUIDv4

                                                                                                                                                    isUUIDv4: (x: string) => boolean;

                                                                                                                                                      function isZero

                                                                                                                                                      isZero: (x: any) => x is 0;

                                                                                                                                                        Type Aliases

                                                                                                                                                        type FloatArray

                                                                                                                                                        type FloatArray = Float32Array | Float64Array;

                                                                                                                                                          type IntArray

                                                                                                                                                          type IntArray = Int8Array | Int16Array | Int32Array;

                                                                                                                                                            type TypedArray

                                                                                                                                                            type TypedArray = IntArray | UintArray | FloatArray;

                                                                                                                                                              type UintArray

                                                                                                                                                              type UintArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;

                                                                                                                                                                Package Files (80)

                                                                                                                                                                Dependencies (0)

                                                                                                                                                                No dependencies.

                                                                                                                                                                Dev Dependencies (4)

                                                                                                                                                                Peer Dependencies (0)

                                                                                                                                                                No peer dependencies.

                                                                                                                                                                Badge

                                                                                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@thi.ng/checks.

                                                                                                                                                                • Markdown
                                                                                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@thi.ng/checks)
                                                                                                                                                                • HTML
                                                                                                                                                                  <a href="https://www.jsdocs.io/package/@thi.ng/checks"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>