Standalone utility function for checking whether a value is classified as a String primitive or String object.
npx @tessl/cli install tessl/npm-lodash--isstring@3.0.0Lodash IsString provides a standalone utility function for checking whether a value is classified as a String primitive or String object. This is the modern build of lodash's _.isString exported as a standalone Node.js module, enabling string type checking without importing the entire lodash library.
npm install lodash.isstringconst isString = require('lodash.isstring');For ES modules:
import isString from 'lodash.isstring';For TypeScript:
import isString from 'lodash.isstring';
// Type guard usage
function processValue(value: unknown): string | null {
if (isString(value)) {
// TypeScript now knows value is string
return value.toUpperCase();
}
return null;
}const isString = require('lodash.isstring');
// Check string primitives
isString('hello'); // => true
isString(''); // => true
// Check String objects
isString(new String('hello')); // => true
// Check non-strings
isString(123); // => false
isString(true); // => false
isString(null); // => false
isString(undefined); // => false
isString([]); // => false
isString({}); // => falseChecks if a value is classified as a String primitive or String object. This function handles both JavaScript string primitives and String constructor objects correctly.
/**
* Checks if `value` is classified as a `String` primitive or object.
* @param {*} value The value to check
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`
*/
function isString(value);Implementation Details:
typeof value == 'string' to detect string primitivesObject.prototype.toString.call(value) == '[object String]' to detect String objectsfalse for null, undefined, numbers, booleans, arrays, objects, and other non-string typesUsage Examples:
const isString = require('lodash.isstring');
// String primitives
isString('abc'); // => true
isString(''); // => true
isString('123'); // => true
// String objects
isString(new String('abc')); // => true
isString(new String('')); // => true
// Non-string values
isString(123); // => false
isString(true); // => false
isString(false); // => false
isString(null); // => false
isString(undefined); // => false
isString([]); // => false
isString({}); // => false
isString(new Date()); // => false
isString(/regex/); // => false
isString(function() {}); // => false
// Edge cases
isString(String(123)); // => true (converts to primitive string)
isString(Object('abc')); // => true (creates String object)