Registry / serialization / typescript-string-operations

typescript-string-operations

JSON →
library1.6.1jsnpmunverified

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.

npm install typescript-string-operations
INSTALL
IMPORT
SIG · TYPESCRIPT-STRING-
T
typescript-string-operations
serializationjavascriptv1.6.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StringBuilder
import { StringBuilder, formatString, isNullOrWhiteSpace, joinString, emptyString } from 'typescript-string-operations';
const StringBuilder = require('typescript-string-operations').StringBuilder;
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.
String (deprecated class)
import { String } from 'typescript-string-operations';
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.
formatString
import { formatString } from 'typescript-string-operations';
import { String } from 'typescript-string-operations'; String.format(...);
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.

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.

import { StringBuilder, emptyString, joinString, formatString, isNullOrWhiteSpace } from 'typescript-string-operations'; // 1. Using emptyString console.log('Empty String:', emptyString); // Output: Empty String: // 2. Using isNullOrWhiteSpace const value1 = null; const value2 = ''; const value3 = ' '; const value4 = 'Hello'; console.log(`isNullOrWhiteSpace(${JSON.stringify(value1)}):`, isNullOrWhiteSpace(value1)); // Output: true console.log(`isNullOrWhiteSpace(${JSON.stringify(value2)}):`, isNullOrWhiteSpace(value2)); // Output: true console.log(`isNullOrWhiteSpace(${JSON.stringify(value3)}):`, isNullOrWhiteSpace(value3)); // Output: true console.log(`isNullOrWhiteSpace(${JSON.stringify(value4)}):`, isNullOrWhiteSpace(value4)); // Output: false // 3. Using formatString with indexed arguments const userId = '2db5da20-1c5d-4f1a-8fd4-b41e34c8c5b5'; const formattedImageName = formatString("image_{0}.jpg", userId); console.log('Formatted Image Name:', formattedImageName); // Output: image_2db5da20-1c5d-4f1a-8fd4-b41e34c8c5b5.jpg // 4. Using formatString with specifiers and objects interface Fruit { type: string; color: string; shippingDate: Date; amount: number; } const fruit: Fruit = { type: "apple", color: "RED", shippingDate: new Date(2018, 1, 1), amount: 10000 }; const fruitDescription = formatString("The {type:U} is {color:L} shipped on {shippingDate:s} with an amount of {amount:n}", fruit); console.log('Fruit Description:', fruitDescription); // Output: The APPLE is red shipped on 2018-01-01T00:00:00 with an amount of 10.000 // 5. Using joinString const joinedFruits = joinString("; ", "Apple", "Banana", "Orange"); console.log('Joined Fruits (args):', joinedFruits); // Output: Apple; Banana; Orange const fruitArray = ['Mango', 'Pineapple']; const joinedFruitArray = joinString(", ", fruitArray); console.log('Joined Fruits (array):', joinedFruitArray); // Output: Mango, Pineapple const objectToJoin = { Name: "Foo", Value: "Bar", ID: "123" }; const joinedObject = joinString('.', objectToJoin); console.log('Joined Object:', joinedObject); // Output: Foo.Bar.123 // 6. Using StringBuilder const sb = new StringBuilder(); sb.Append('Hello').Append(' ').AppendLine('World!'); sb.AppendFormat('The answer is {0}.', 42); console.log('StringBuilder Output:\n', sb.ToString()); /* Expected Output: Hello World! The answer is 42. */
Debug
Known issues
breakingMethods 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.
fix
Migrate to the new lowercase-prefixed named function exports like `formatString`, `joinString`, `isNullOrWhiteSpace`, and `emptyString`.
affects: >=1.5.0
breakingThe `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.
fix
Avoid importing `String` (e.g., `import { String } from 'typescript-string-operations'`). Instead, use direct named imports for individual utility functions and constants.
affects: >=1.5.0
gotchaVersion 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.
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.
affects: >=1.5.0
gotchaPrior 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.
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.
affects: <1.5.0
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources