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

    Class StringCore

    The StringCore class provides utility functions for string type checks and assertions.

    v1.0.2

    Index

    Methods

    • Asserts that a given value is a string.

      Parameters

      • value: unknown

        Value to check.

      Returns asserts value is string

      If the value is not a string.

      v1.0.2

    • Asserts that a given value is not a string.

      Type Parameters

      • T

      Parameters

      • value: unknown

        Value to check.

      Returns asserts value is Exclude<T, string>

      If the value is a string.

      v1.0.2

    • Builds an type error Invalid string: ${JSON.stringify(value)}.

      Parameters

      • value: unknown

        The invalid value.

      Returns TypeError

      The created error.

      v1.0.2

    • Type guard to check if a value ends with the specified suffix.

      Type Parameters

      • S extends string

        The suffix to check.

      Parameters

      • value: unknown

        The value to check.

      • suffix: S

        The expected suffix.

      Returns value is `${string}${S}`

      true if the value ends with the suffix; otherwise, false.

      StringCore.endsWith('hello', 'lo'); // true
      StringCore.endsWith('hello', 'he'); // false
      StringCore.endsWith(123, 'lo'); // false (not a string)

      v1.0.2

    • Type guard to check if a value is a string.

      Parameters

      • value: unknown

        The value to check.

      Returns value is string

      true if the value is a string; otherwise, false.

      v1.0.2

    • Type guard to check if a value is an EmptyString.

      Parameters

      • value: unknown

        The value to check.

      Returns value is ""

      true if the value is an empty string; otherwise, false.

      StringCore.isEmpty(''); // true
      StringCore.isEmpty('hello'); // false
      StringCore.isEmpty(123); // false (not a string)

      v1.0.2

    • Type guard to check if a value is a Lowercase<string>.

      Parameters

      • value: unknown

        The value to check.

      Returns value is Lowercase<string>

      true if the value is a lowercase string; otherwise, false.

      StringCore.isLowerCase('hello'); // true
      StringCore.isLowerCase('HELLO'); // false
      StringCore.isLowerCase(123); // false (not a string)

      v1.0.2

    • Type guard to check if a value is not a string.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to check.

      Returns value is Exclude<T, string>

      true if the value is not a string; otherwise, false.

      v1.0.2

    • Type guard to check if a value is a NonEmptyString<T>.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to check.

      Returns value is NonEmptyString<T>

      true if the value is a not empty string; otherwise, false.

      StringCore.isNotEmpty('hello'); // true
      StringCore.isNotEmpty(''); // false
      StringCore.isNotEmpty(123); // false (not a string)

      v1.0.2

    • Type guard to check if a value is not a NumberString.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to check.

      Returns value is Exclude<T, `${number}`>

      true if the value is not a numeric string; otherwise, false.

      StringCore.isNotNumeric('abc'); // true
      StringCore.isNotNumeric('123'); // false
      StringCore.isNotNumeric(123); // true (not a string)

      v1.0.2

    • Type guard to check if a value is a NumberString.

      Parameters

      • value: unknown

        The value to check.

      Returns value is `${number}`

      true if the value is a numeric string; otherwise, false.

      StringCore.isNumeric('123'); // true
      StringCore.isNumeric('12.3'); // true
      StringCore.isNumeric('abc'); // false
      StringCore.isNumeric(123); // false (not a string)

      v1.0.2

    • Type guard to check if a value is an Uppercase<string>.

      Parameters

      • value: unknown

        The value to check.

      Returns value is Uppercase<string>

      true if the value is an uppercase string; otherwise, false.

      StringCore.isUpperCase('HELLO'); // true
      StringCore.isUpperCase('hello'); // false
      StringCore.isUpperCase(123); // false (not a string)

      v1.0.2

    • Type guard to check if a value starts with the specified prefix.

      Type Parameters

      • P extends string

        The prefix to check.

      Parameters

      • value: unknown

        The value to check.

      • prefix: P

        The expected prefix.

      Returns value is `${P}${string}`

      true if the value starts with the prefix; otherwise, false.

      StringCore.startsWith('hello', 'he'); // true
      StringCore.startsWith('hello', 'el'); // false
      StringCore.startsWith(123, 'he'); // false (not a string)

      v1.0.2