{"id":12256,"library":"typescript-string-operations","title":"TypeScript String Operations","description":"The `typescript-string-operations` library (current stable v1.6.1) provides a collection of lightweight, utility functions for common string manipulations in TypeScript, inspired by C# string operations. It includes robust `formatString` with specifiers (e.g., `{0:L}` for lowercase, `{0:d}` for short date), `joinString` for concatenating arrays or objects with a delimiter, `isNullOrWhiteSpace` for comprehensive empty/null/whitespace checks, and an `emptyString` constant. A `StringBuilder` class is also available for efficient, mutable string construction, mirroring its C# counterpart. The library is designed to be lightweight, has no jQuery dependency, and is unit-tested, making it suitable for modern web applications, including those built with Angular. Its release cadence is feature-driven, with notable breaking changes in version 1.5.0, where uppercase-prefixed methods and the `String` class were deprecated in favor of named function imports to avoid polluting the global `String` object.","status":"active","version":"1.6.1","language":"javascript","source_language":"en","source_url":"https://github.com/sevensc/typescript-string-operations","tags":["javascript","typescript","string format","string operations","stringbuilder","string builder","angular"],"install":[{"cmd":"npm install typescript-string-operations","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-string-operations","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-string-operations","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the primary ESM import pattern. Using `require()` for CommonJS might work in some transpiled environments but is not the idiomatic TypeScript approach for this library.","wrong":"const StringBuilder = require('typescript-string-operations').StringBuilder;","symbol":"StringBuilder","correct":"import { StringBuilder, formatString, isNullOrWhiteSpace, joinString, emptyString } from 'typescript-string-operations';"},{"note":"This import provides a class that overrides the native `String` object. It is deprecated since v1.5.0 and will be removed in the next major release. Usage is `String.format()`, `String.isNullOrWhiteSpace()`, etc.","symbol":"String (deprecated class)","correct":"import { String } from 'typescript-string-operations';"},{"note":"Since v1.5.0, individual named functions like `formatString` are the recommended way to use the library's features, moving away from the deprecated `String` class.","wrong":"import { String } from 'typescript-string-operations'; String.format(...);","symbol":"formatString","correct":"import { formatString } from 'typescript-string-operations';"}],"quickstart":{"code":"import { StringBuilder, emptyString, joinString, formatString, isNullOrWhiteSpace } from 'typescript-string-operations';\n\n// 1. Using emptyString\nconsole.log('Empty String:', emptyString); // Output: Empty String:\n\n// 2. Using isNullOrWhiteSpace\nconst value1 = null;\nconst value2 = '';\nconst value3 = '   ';\nconst value4 = 'Hello';\nconsole.log(`isNullOrWhiteSpace(${JSON.stringify(value1)}):`, isNullOrWhiteSpace(value1)); // Output: true\nconsole.log(`isNullOrWhiteSpace(${JSON.stringify(value2)}):`, isNullOrWhiteSpace(value2)); // Output: true\nconsole.log(`isNullOrWhiteSpace(${JSON.stringify(value3)}):`, isNullOrWhiteSpace(value3)); // Output: true\nconsole.log(`isNullOrWhiteSpace(${JSON.stringify(value4)}):`, isNullOrWhiteSpace(value4)); // Output: false\n\n// 3. Using formatString with indexed arguments\nconst userId = '2db5da20-1c5d-4f1a-8fd4-b41e34c8c5b5';\nconst formattedImageName = formatString(\"image_{0}.jpg\", userId);\nconsole.log('Formatted Image Name:', formattedImageName); // Output: image_2db5da20-1c5d-4f1a-8fd4-b41e34c8c5b5.jpg\n\n// 4. Using formatString with specifiers and objects\ninterface Fruit {\n    type: string;\n    color: string;\n    shippingDate: Date;\n    amount: number;\n}\n\nconst fruit: Fruit = {\n    type: \"apple\",\n    color: \"RED\",\n    shippingDate: new Date(2018, 1, 1),\n    amount: 10000\n};\n\nconst fruitDescription = formatString(\"The {type:U} is {color:L} shipped on {shippingDate:s} with an amount of {amount:n}\", fruit);\nconsole.log('Fruit Description:', fruitDescription); // Output: The APPLE is red shipped on 2018-01-01T00:00:00 with an amount of 10.000\n\n// 5. Using joinString\nconst joinedFruits = joinString(\"; \", \"Apple\", \"Banana\", \"Orange\");\nconsole.log('Joined Fruits (args):', joinedFruits); // Output: Apple; Banana; Orange\n\nconst fruitArray = ['Mango', 'Pineapple'];\nconst joinedFruitArray = joinString(\", \", fruitArray);\nconsole.log('Joined Fruits (array):', joinedFruitArray); // Output: Mango, Pineapple\n\nconst objectToJoin = { Name: \"Foo\", Value: \"Bar\", ID: \"123\" };\nconst joinedObject = joinString('.', objectToJoin);\nconsole.log('Joined Object:', joinedObject); // Output: Foo.Bar.123\n\n// 6. Using StringBuilder\nconst sb = new StringBuilder();\nsb.Append('Hello').Append(' ').AppendLine('World!');\nsb.AppendFormat('The answer is {0}.', 42);\nconsole.log('StringBuilder Output:\\n', sb.ToString());\n/* Expected Output:\nHello World!\nThe answer is 42.\n*/","lang":"typescript","description":"Demonstrates installation, importing key functions and the StringBuilder class, and basic usage of `emptyString`, `isNullOrWhiteSpace`, `formatString` (with indexed arguments and object specifiers), `joinString` (with variadic arguments, arrays, and objects), and `StringBuilder` methods."},"warnings":[{"fix":"Migrate to the new lowercase-prefixed named function exports like `formatString`, `joinString`, `isNullOrWhiteSpace`, and `emptyString`.","message":"Methods and properties starting with an uppercase letter (e.g., `String.Format`, `String.Join`) were marked as deprecated in v1.5.0 and are scheduled for removal in future versions.","severity":"breaking","affected_versions":">=1.5.0"},{"fix":"Avoid importing `String` (e.g., `import { String } from 'typescript-string-operations'`). Instead, use direct named imports for individual utility functions and constants.","message":"The `String` class, which overrides the native JavaScript `String` object when imported, was deprecated in v1.5.0 and will be removed in the next major release.","severity":"breaking","affected_versions":">=1.5.0"},{"fix":"Ensure your project's TypeScript version is compatible with the version used by `typescript-string-operations` v1.5.0 or newer. Review compiler options and update your `tsconfig.json` if necessary.","message":"Version 1.5.0 updated to use the latest TypeScript version, which might cause compatibility issues or require environment checks for projects using older TypeScript versions.","severity":"gotcha","affected_versions":">=1.5.0"},{"fix":"It is strongly recommended to use the individual named function exports (`formatString`, `isNullOrWhiteSpace`, etc.) even in older versions if possible, to avoid global object modification. If upgrading to v1.5.0+, ensure the `String` class import is removed.","message":"Prior to its deprecation, importing the `String` class (e.g., `import { String } from 'typescript-string-operations'`) would override the native `String` object, potentially leading to conflicts or unexpected behavior with other libraries or native string methods.","severity":"gotcha","affected_versions":"<1.5.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm"}