String Extensions

v0.1.0

The String Extension methods extend the global String Object´s Prototype.

Usage

Import the extensions part as early as possible to make sure the global Object Prototypes are extended.
Your IDE might offer the typing without importing this init function as they are declared globally.

import { initStringExtensions } from '@oardi/ts-utils';
initStringExtensions();

Initialization is idempotent and keeps the installed methods unchanged. If String.prototype already has a foreign own property with one of the extension names, initialization throws before installing any String extensions instead of overwriting the existing property.

capitalize

const myText = 'my text';
myText.capitalize(); // 'My text'

isNumber

const myText = 'my text';
myText.isNumber(); // false

isEmpty

const myText = 'my text';
myText.isEmpty(); // false

stripTags

stripTags() uses the browser’s DOMParser so HTML entities are decoded according to the DOM. String extensions can still be initialized in Node and during SSR, but calling stripTags() there throws an explicit error because DOMParser is unavailable.

const myText = '<b>my text</b>';
myText.stripTags(); // my text

Previous:Extensions

← Date Extension