@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.

      Type Parameters

      • T = unknown

      Parameters

      • value: T

        Value to check.

      Returns asserts value is IsGuard<T, string>

      If the value is not a string.

      v1.0.2

    • Asserts that a given value is not a string.

      Type Parameters

      • T = unknown

      Parameters

      • value: unknown

        Value to check.

      Returns asserts value is IsNotGuard<T, string>

      If the value is a string.

      v1.0.2

    • Builds value error.

      Parameters

      • value: unknown

        The invalid value.

      • typeName:
            | "String"
            | "EmptyString"
            | "LowerCaseString"
            | "UpperCaseString"
            | "NumberString"

        The expected type name.

      • OptionalisNot: boolean = false

        Whether the error should be for !${typeName}.

      Returns TypeError

      The created error.

      v1.1.2

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

      Type Parameters

      • T = unknown
      • S extends string = string

        The suffix to check.

      Parameters

      • value: T

        The value to check.

      • suffix: S

        The expected suffix.

      Returns value is IsGuard<T, `${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

    • Gets the article for the given word.

      Parameters

      • word: string

        Word to get the article for.

      Returns "a" | "an"

      The article for the word.

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

      Type Parameters

      • T = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsGuard<T, string>

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

      v1.0.2

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

      Type Parameters

      • T = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsGuard<T, "">

      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>.

      Type Parameters

      • T = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsGuard<T, 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 = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsNotGuard<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 = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsNotGuard<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 = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsNotGuard<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.

      Type Parameters

      • T = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsGuard<T, `${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>.

      Type Parameters

      • T = unknown

      Parameters

      • value: T

        The value to check.

      Returns value is IsGuard<T, 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

      • T = unknown
      • P extends string = string

        The prefix to check.

      Parameters

      • value: T

        The value to check.

      • prefix: P

        The expected prefix.

      Returns value is IsGuard<T, `${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