@nevware21/ts-utils
    Preparing search index...

    Function isStringObject

    • Checks if the value is a String object (a string wrapped in an object), eg. new String("abc") or Object("abc"), rather than a primitive string (see isString). A String object has the length, indexes and functions of its string, but it is an object, so typeof returns "object", it is truthy even when it is empty, and === (and Map / Set keys) compare the object rather than its value. Use isStringLike to check for either.

      Like isDate and isRegExp the check uses objToString, so a String object from another realm (eg. an iframe) is also identified, and on a runtime with Symbol.toStringTag an object can change the result.

      The value is narrowed to String & object rather than String, as TypeScript treats a primitive string as a String, so value is String would narrow a string | number value to string (and to number when it is false), while a primitive string is never a String object. A value declared as String (which may also be a primitive string) is never when this is false, so declare it as string | String (which is string when false) or use isStringLike.

      Parameters

      • value: any

        The value to check

      Returns value is String & object

      True if the value is a String object, otherwise false

      0.20.0

      isStringObject(new String(""));      // true
      isStringObject(new String("abc")); // true
      isStringObject(Object("abc")); // true

      isStringObject("abc"); // false (a primitive string, see isString)
      isStringObject(String("abc")); // false (String() without new returns a primitive string)
      isStringObject(null); // false
      isStringObject(undefined); // false
      isStringObject({}); // false
      isStringObject(["a", "b", "c"]); // false