ts-data-forge
    Preparing search index...
    • Type guard that checks if a string has at least minLength characters.

      The length is measured in UTF-16 code units (the same unit as String.prototype.length), so characters outside the Basic Multilingual Plane (e.g. emoji) count as 2.

      Type Narrowing Behavior:

      • Narrows the input to MinLengthString<MinLength> while preserving the original string type (e.g. literal types) via intersection.
      • The result participates in the length-constraint subtyping relation: for example, a value narrowed to MinLengthString<3> is assignable to MinLengthString<1> (= NonEmptyString).

      Type Parameters

      • S extends string

        The input string type (literal types are preserved).

      • MinLength extends ArgStr

        The minimum number of characters (inclusive).

      Parameters

      • s: S

        The string to check.

      • minLength: MinLength

        The minimum number of characters (inclusive).

      Returns s is string & Readonly<
          { MinLength: readonly [MakeTupleImpl<0, `${MinLength}`, []>, 0] },
      > & Readonly<
          {
              "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
          },
      > & S

      true if s.length >= minLength, false otherwise. When true, TypeScript narrows s to MinLengthString<MinLength> & S.

      const input: string = 'very-secret-password';

      assert.isTrue(isMinLengthString(input, 12));

      assert.isFalse(isMinLengthString('short', 12));

      if (isMinLengthString(input, 12)) {
      const password: MinLengthString<12> = input;

      const nonEmpty: NonEmptyString = input; // OK (12 >= 1)
      }