https://github.com/igorskyflyer/npm-extendable-string
๐ฆ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐ช
https://github.com/igorskyflyer/npm-extendable-string
back-end browser class extend extendable igorskyflyer javascript js node npm string text transform ts typescript utility vitest
Last synced: 5 months ago
JSON representation
๐ฆ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐ช
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-extendable-string
- Owner: igorskyflyer
- License: mit
- Created: 2023-05-29T15:20:32.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T20:43:59.000Z (almost 2 years ago)
- Last Synced: 2025-03-06T12:52:48.456Z (about 1 year ago)
- Topics: back-end, browser, class, extend, extendable, igorskyflyer, javascript, js, node, npm, string, text, transform, ts, typescript, utility, vitest
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@igor.dvlpr/extendable-string
- Size: 120 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
ExtendableString
๐ฆ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐ช
## ๐ Table of Contents
- [Features](#-features)
- [Usage](#-usage)
- [API](#-api)
- [constructor()](#constructorraw-transformfn)
- [value](#value-string)
- [toString()](#tostring-string)
- [Examples](#๏ธ-examples)
- [Changelog](#-changelog)
- [Support](#-support)
- [License](#-license)
- [Related](#-related)
- [Author](#-author)
## ๐ค 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:
```bash
pnpm add @igorskyflyer/extendable-string
```
```bash
yarn add @igorskyflyer/extendable-string
```
```bash
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`
```ts
import { ExtendableString } from '@igorskyflyer/extendable-string'
export class UpperCaseString extends ExtendableString {
constructor(value: string) {
super(value, (str) => str.toUpperCase())
}
}
```
`example.ts`
```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](https://github.com/igorskyflyer/npm-extendable-string/blob/main/CHANGELOG.md).
## ๐ชช License
Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-extendable-string/blob/main/LICENSE).
## ๐ Support
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! ๐๐
## ๐งฌ Related
[@igorskyflyer/keppo](https://www.npmjs.com/package/@igorskyflyer/keppo)
> _๐ก Parse, manage, compare and output SemVer-compatible version numbers. ๐ก_
[@igorskyflyer/astro-escaped-component](https://www.npmjs.com/package/@igorskyflyer/astro-escaped-component)
> _๐๐ปโโ๏ธโโก๏ธ An Astro component that holds only HTML-encoded content. ๐_
[@igorskyflyer/normalized-string](https://www.npmjs.com/package/@igorskyflyer/normalized-string)
> _๐ NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐ฎ_
[@igorskyflyer/windev](https://www.npmjs.com/package/@igorskyflyer/windev)
> _๐ Provides ways of checking whether a path is a legacy Windows device. ๐พ_
[@igorskyflyer/mapped-replacer](https://www.npmjs.com/package/@igorskyflyer/mapped-replacer)
> _๐บ Zero-dependency Map and RegExp based string replacer with Unicode support. ๐_
## ๐จ๐ปโ๐ป Author
Created by **Igor Dimitrijeviฤ** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).