@igor.dvlpr/extendable-string
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ExtendableString

🦀 ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. 🪀


💖 Support further development

Donate to igorskyflyer



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) // Outputs 'AAAA'

const example = new UpperCaseString('aaaa')
example.value = 'hello'
console.log(test.value) // Outputs 'HELLO'

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.

Package Sidebar

Install

npm i @igor.dvlpr/extendable-string

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

6.53 kB

Total Files

5

Last publish

Collaborators

  • igor.dvlpr