1.0.0 • Published 12 months ago

@igor.dvlpr/extendable-string v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

ExtendableString

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

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.

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.