@luolapeikko/ts-common
    Preparing search index...

    Class UndefCore

    Core class for all nullish types.

    v0.5.0

    Index

    Methods

    • Asserts that the given value is NOT null.

      Type Parameters

      • T

      Parameters

      Returns asserts value is T

      function add(a: number, b: number): number {
      UndefCore.assertNotNull(a);
      UndefCore.assertNotNull(b);
      return a + b;
      }

      If the given value is null or undefined.

      v0.5.0

    • Asserts that the given value is NOT null or undefined.

      Parameters

      • value: unknown

        The value to assert.

      Returns asserts value is {}

      function add(a: number, b: number): number {
      UndefCore.assertNotNullish(a);
      UndefCore.assertNotNullish(b);
      return a + b;
      }

      If the given value is null or undefined.

      v0.5.0

    • Asserts that the given value is NOT undefined.

      Type Parameters

      • T

      Parameters

      • value: Undef<T>

        The value to assert.

      Returns asserts value is T

      function add(a: number, b: number): number {
      UndefCore.assertNotUndefined(a);
      UndefCore.assertNotUndefined(b);
      return a + b;
      }

      If the given value is undefined.

      v0.5.0

    • Asserts that the given value is null.

      Parameters

      • value: unknown

        The value to assert.

      Returns asserts value is null

      const res: null = someCall():
      UndefCore.assertNull(res);

      If the given value is not null or undefined.

      v0.5.0

    • Asserts that the given value is null or undefined.

      Parameters

      • value: unknown

        The value to assert.

      Returns asserts value is undefined | null

      const res: null | undefined = someCall():
      NullishCore.assertNullish(res);

      If the given value is not null or undefined.

      v0.5.0

    • Asserts that the given value is undefined.

      Parameters

      • value: unknown

        The value to assert.

      Returns asserts value is undefined

      const res: undefined = someCall():
      UndefCore.assertUndefined(res);

      If the given value is not undefined.

      v0.5.0

    • Builds an type error Value is ${JSON.stringify(value)}.

      Parameters

      • value: unknown

        The invalid value.

      Returns TypeError

      The created error.

      v0.5.0

    • Type guard check if the given value is NOT null.

      Type Parameters

      • T

        The type of the value

      Parameters

      Returns value is T

      True if the value is neither null nor undefined, otherwise false

      const data = ['demo', null, undefined, 'demo'];
      const output: (string | undefined)[] = data.filter(UndefCore.isNotNull);

      v0.5.0

    • Type guard check if the given value is NOT null or undefined.

      Type Parameters

      • T

        The type of the value

      Parameters

      Returns value is T

      True if the value is neither null nor undefined, otherwise false

      const data = ['demo', null, undefined, 'demo'];
      const output: string[] = data.filter(UndefCore.isNotNullish);

      v0.5.0

    • Type guard check if the given value is not undefined.

      Type Parameters

      • T

        The type of the value

      Parameters

      • value: Undef<T>

        The value to check

      Returns value is T

      True if the value is not undefined, otherwise false

      const data = ['demo', undefined, 'demo'];
      const output: string[] = data.filter(UndefCore.isNotUndefined);

      v0.5.0

    • Type guard check if the given value is null.

      Parameters

      • value: unknown

        The value to check

      Returns value is null

      True if the value is null or undefined, otherwise false

      const data = ['demo', null, undefined, 'demo'];
      const count = data.filter(UndefCore.isNull).length; // 1

      v0.5.0

    • Type guard check if the given value is null or undefined.

      Parameters

      • value: unknown

        The value to check

      Returns value is undefined | null

      True if the value is null or undefined, otherwise false

      const data = ['demo', null, undefined, 'demo'];
      const count = data.filter(UndefCore.isNullish).length; // 2

      v0.5.0

    • Type guard check if the given value is undefined.

      Parameters

      • value: unknown

        The value to check

      Returns value is undefined

      True if the value is undefined, otherwise false

      const data = ['demo', undefined, 'demo'];
      const count = data.filter(UndefCore.isUndefined).length; // 1

      v0.5.0