npm.io
2.0.0 • Published 2 years ago

@igor.dvlpr/extendable-string

Licence
MIT
Version
2.0.0
Deps
0
Size
9 kB
Vulns
0
Weekly
0
Stars
1
DeprecatedThis package is deprecated

ExtendableString


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



Support further development

I work hard for every project, including this one
and your support means a lot to me!

Consider buying me a coffee.
Thank you for supporting my efforts!


Donate to igorskyflyer

@igorskyflyer




Table of contents



Usage

Install it by executing:

npm i '@igor.dvlpr/extendable-string'

API


Do NOT instantiate a new object from the ExtendableString class, extend it instead.


constructor(raw, transformFn)

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.


value: string

Gets the transformed string or sets a new value that will be transformed automatically.


toString(): string

Gets the transformed string value.

Returns the transformed string.


Examples

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.mjs'

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'

Changelog

The changelog is available here: CHANGELOG.md.


License

Licensed under the MIT license which is available here, MIT license.


@igor.dvlpr/keppo

Parse, manage, compare and output SemVer-compatible version numbers.


@igor.dvlpr/astro-escaped-component

An Astro component that holds only HTML-encoded content.


@aria-toolkit/shared

Shared resources between Aria modules.


@igor.dvlpr/windev

Provides ways of checking whether a path is a legacy Windows device.


@igor.dvlpr/mapped-replacer

Zero-dependency Map and RegExp based string replacer with Unicode support.



Author

Created by Igor Dimitrijević (@igorskyflyer).

Keywords