ExtendableString
🦀 ExtendableString
allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. 🪀
💖 Support further development
Table of Contents
Usage
Install it by executing:
npm i "@igor.dvlpr/extendable-string"
API
To actually use it, you should extend your own String class from it.
Example
UpperCaseString.mts
import { ExtendableString } from '@igor.dvlpr/extendable-string'
export class UpperCaseString extends ExtendableString {
constructor(value: string) {
super(value, (str) => str.toUpperCase())
}
}
example.mts
import { UpperCaseString } from './UpperCaseString'
const test = new UpperCaseString('aaaa')
console.log(test.value)
const example = new UpperCaseString('aaaa')
example.value = 'hello'
console.log(test.value)
Each time you create a new string or assign a new value to it, your string transformation function will fire.
❗ You do NOT instantiate a new object from the ExtendableString
class, you extend it instead.
Properties
value
The value property represents the current transformed value of the string.
Methods
toString()
The toString()
method returns the current transformed value of the string.
License
This project is licensed under the terms of the MIT license.