Skip to content

๐Ÿฆ€ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐Ÿช€

License

Notifications You must be signed in to change notification settings

igorskyflyer/npm-extendable-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

91 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Icon of ExtendableString

ExtendableString


๐Ÿฆ€ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐Ÿช€



๐Ÿ“ƒ Table of Contents



๐Ÿค– Features

  • ๐Ÿš€ 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


๐Ÿ•ต๐Ÿผ Usage

Install it by executing any of the following, depending on your preferred package manager:

pnpm add @igorskyflyer/extendable-string
yarn add @igorskyflyer/extendable-string
npm i @igorskyflyer/extendable-string


๐Ÿคน๐Ÿผ API

๐Ÿ’ก TIP

First Steps

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


๐Ÿ“ Changelog

๐Ÿ“‘ The changelog is available here, CHANGELOG.md.



๐Ÿชช License

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



๐Ÿ’– Support

I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. โ˜•

Donate to igorskyflyer

Thank you for supporting my efforts! ๐Ÿ™๐Ÿ˜Š


๐Ÿงฌ Related

@igorskyflyer/keppo

๐ŸŽก 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. ๐Ÿ“ฎ


@igorskyflyer/windev

๐Ÿƒ Provides ways of checking whether a path is a legacy Windows device. ๐Ÿ’พ


@igorskyflyer/mapped-replacer

๐Ÿ—บ Zero-dependency Map and RegExp based string replacer with Unicode support. ๐Ÿ




๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author

Created by Igor Dimitrijeviฤ‡ (@igorskyflyer).

About

๐Ÿฆ€ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐Ÿช€

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project