๐ฆ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐ช
- ๐ Instantly applies custom string transformations on creation
- ๐ Updates value with transformation applied automatically
- ๐ก๏ธ Validates transformation function before use
- ๐งฉ Designed for easy extension via sub-classing
- ๐ฆ Encapsulates logic with private fields for safety
- ๐ Provides clean string output through the
toString()method - โก Ensures consistent transformed state at all times
Install it by executing any of the following, depending on your preferred package manager:
pnpm add @igorskyflyer/extendable-stringyarn add @igorskyflyer/extendable-stringnpm i @igorskyflyer/extendable-stringDo NOT instantiate a new object from the
ExtendableStringclass, extend it instead.
Creates an ExtendableString instance.
raw - The string input to transform.
transformFn - The transformation function to apply to the string.
Will throw an error if the transformation function is not supplied.
Gets the transformed string or sets a new value that will be transformed automatically.
Gets the transformed string value.
Returns the transformed string.
UpperCaseString.ts
import { ExtendableString } from '@igorskyflyer/extendable-string'
export class UpperCaseString extends ExtendableString {
constructor(value: string) {
super(value, (str) => str.toUpperCase())
}
}example.ts
import { UpperCaseString } from './UpperCaseString.js'
const test = new UpperCaseString('aaaa')
console.log(test.value) // Outputs 'AAAA'
const example = new UpperCaseString('aaaa')
example.value = 'hello'
console.log(test.value) // Outputs 'HELLO'๐ The changelog is available here, CHANGELOG.md.
Licensed under the MIT license which is available here, MIT license.
Consider buying me a coffee. โ
Thank you for supporting my efforts! ๐๐
๐ก Parse, manage, compare and output SemVer-compatible version numbers. ๐ก
@igorskyflyer/astro-escaped-component
๐๐ปโโ๏ธโโก๏ธ An Astro component that holds only HTML-encoded content. ๐
@igorskyflyer/normalized-string
๐ NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐ฎ
๐ Provides ways of checking whether a path is a legacy Windows device. ๐พ
๐บ Zero-dependency Map and RegExp based string replacer with Unicode support. ๐
Created by Igor Dimitrijeviฤ (@igorskyflyer).
