@igor.dvlpr/magic-string
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "@igor.dvlpr/magic-string", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "๐งต An expressive and chainable library for advanced string manipulations. Supports appending, prepending, trimming, quoting, and path formatting with customizable whitespace handling. Makes advanced String manipulations a piece of cake. ๐ฆฅ", | ||
@@ -12,7 +12,7 @@ "sideEffects": false, | ||
"module": "./dist/index.mjs", | ||
"files": ["dist"], | ||
"files": ["dist/*.mjs", "dist/*.d.mts"], | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "vitest --run", | ||
"debug": "tsc --sourceMap --watch", | ||
"dev": "tsc --sourceMap --watch", | ||
"pub": "npm test && npm run build && npm publish --access public" | ||
@@ -45,3 +45,3 @@ }, | ||
"@igor.dvlpr/biome-config-igorskyflyer": "^1.0.3", | ||
"@types/node": "^20.14.13", | ||
"@types/node": "^20.14.14", | ||
"typescript": "^5.5.4", | ||
@@ -48,0 +48,0 @@ "vitest": "^2.0.5" |
181
README.md
@@ -48,20 +48,27 @@ <h1 align="center">MagicString</h1> | ||
- [Usage](#-usage) | ||
- [Features](#-features) | ||
- [API](#-api) | ||
- [StringValue](#type-stringvalue--string--string) | ||
- [constructor()](#constructor-magicstring) | ||
- [constructor()](#constructorinitialvalue-stringvalue) | ||
- [value](#value-string) | ||
- [length](#length-number) | ||
- [isEmpty()](#isempty-boolean) | ||
- [clear()](#clear-magicstring) | ||
- [append()](#appendvalue-stringvalue-magicstring) | ||
- [appendSingleQuoted()](#appendsinglequotedvalue-stringvalue-magicstring) | ||
- [appendQuoted()](#appendquotedvalue-stringvalue-magicstring) | ||
- [trimAll()](#trimall-magicstring) | ||
- [trim()](#trim-magicstring) | ||
- [trimOn()](#trimon-magicstring) | ||
- [trimOff()](#trimoff-magicstring) | ||
- [path()](#pathvalue-stringvalue-magicstring) | ||
- [prepend()](#prependvalue-stringvalue-magicstring) | ||
- [toLowerCase()](#tolowercase-magicstring) | ||
- [toUpperCase()](#touppercase-magicstring) | ||
- [clear()](#clear) | ||
- [append()](#appendvalue-stringvalue) | ||
- [appendIf()](#appendifvalue-stringvalue-rest-stringvalue) | ||
- [appendSingleQuoted()](#appendsinglequotedvalue-stringvalue) | ||
- [appendQuoted()](#appendquotedvalue-stringvalue) | ||
- [trimAll()](#trimall) | ||
- [trim()](#trim) | ||
- [trimOn()](#trimon) | ||
- [trimOff()](#trimoff) | ||
- [trimStart()](#trimstart) | ||
- [trimEnd()](#trimend) | ||
- [path()](#pathvalue-stringvalue) | ||
- [prepend()](#prependvalue-stringvalue) | ||
- [toLowerCase()](#tolowercase) | ||
- [toUpperCase()](#touppercase) | ||
- [replace()](#replacesearchvalue-string-replacevalue-string) | ||
- [insert()](#insertvalue-stringvalue-index-number) | ||
- [substring()](#substringstart-number-end-number) | ||
- [Examples](#-examples) | ||
@@ -76,2 +83,10 @@ - [Changelog](#-changelog) | ||
## ๐ค Features | ||
- ๐ฃ๏ธ expressive and chainable | ||
- ๐ with many string manipulation methods | ||
- ๐ฝ increases productiveness | ||
--- | ||
## ๐ต๐ผ Usage | ||
@@ -85,3 +100,3 @@ | ||
<br> | ||
--- | ||
@@ -96,6 +111,14 @@ ## ๐คน๐ผ API | ||
### `constructor(): MagicString` | ||
### `constructor(initialValue?: StringValue)` | ||
*Creates a new instance of MagicString.* | ||
`initialValue` - Optional, the initial value to assign to the accumulator. | ||
<br> | ||
> [!NOTE] | ||
> The value is assigned to the accumulator as-is, no processing is performed. | ||
> | ||
--- | ||
@@ -107,2 +130,4 @@ | ||
<br> | ||
Returns the accumulator as a string. | ||
@@ -112,2 +137,12 @@ | ||
### `length: number` | ||
*Gets the length of the accumulator.* | ||
<br> | ||
Returns the length of the accumulator. | ||
--- | ||
### `isEmpty(): boolean` | ||
@@ -121,3 +156,3 @@ | ||
### `clear(): MagicString` | ||
### `clear()` | ||
@@ -130,3 +165,3 @@ *Clears the accumulator.* | ||
### `append(value: StringValue): MagicString` | ||
### `append(value: StringValue)` | ||
@@ -143,4 +178,22 @@ *Appends a value to the accumulator.* | ||
### `appendSingleQuoted(value: StringValue): MagicString` | ||
### `appendIf(value: StringValue, ...rest: StringValue[])` | ||
*Conditionally appends values to the accumulator only if the primary value is followed by other non-empty values.* | ||
*This method checks if the provided rest values are non-empty before appending them.* | ||
*Supports passing multiple string values as rest parameters or a single array of strings.* | ||
`value` - The primary value to append. | ||
`rest` - Additional values to check and append. | ||
<br> | ||
Returns the current instance of `MagicString`. | ||
--- | ||
### `appendSingleQuoted(value: StringValue)` | ||
*Appends a single-quoted value to the accumulator.* | ||
@@ -156,3 +209,3 @@ | ||
### `appendQuoted(value: StringValue): MagicString` | ||
### `appendQuoted(value: StringValue)` | ||
@@ -169,3 +222,3 @@ *Appends a double-quoted value to the accumulator.* | ||
### `trimAll(): MagicString` | ||
### `trimAll()` | ||
@@ -180,3 +233,3 @@ *Trims all whitespace in the accumulator.* | ||
### `trim(): MagicString` | ||
### `trim()` | ||
@@ -191,3 +244,3 @@ *Trims only leading and trailing whitespace from the accumulator.* | ||
### `trimOn(): MagicString` | ||
### `trimOn()` | ||
@@ -202,3 +255,3 @@ *Enables trimming of values before adding them to the accumulator.* | ||
### `trimOff(): MagicString` | ||
### `trimOff()` | ||
@@ -213,4 +266,24 @@ *Disables trimming of values before adding them to the accumulator.* | ||
### `path(value: StringValue): MagicString` | ||
### `trimStart()` | ||
*Trims only leading whitespace from the accumulator.* | ||
<br> | ||
Returns the current instance of `MagicString`. | ||
--- | ||
### `trimEnd()` | ||
*Trims only trailing whitespace from the accumulator.* | ||
<br> | ||
Returns the current instance of `MagicString`. | ||
--- | ||
### `path(value: StringValue)` | ||
*Appends a value representing a path to the accumulator, wrapping it in double quotes if necessary.* | ||
@@ -226,3 +299,3 @@ | ||
### `prepend(value: StringValue): MagicString` | ||
### `prepend(value: StringValue)` | ||
@@ -239,3 +312,3 @@ *Prepends a value to the accumulator.* | ||
### `toLowerCase(): MagicString` | ||
### `toLowerCase()` | ||
@@ -250,3 +323,3 @@ *Converts the accumulator to lower case.* | ||
### `toUpperCase(): MagicString` | ||
### `toUpperCase()` | ||
@@ -261,5 +334,51 @@ *Converts the accumulator to upper case.* | ||
### `replace(searchValue: string, replaceValue: string)` | ||
*Replaces occurrences of a substring in the accumulator with a new substring.* | ||
`searchValue` - The substring to search for. | ||
`replaceValue` - The substring to replace with. | ||
<br> | ||
Returns the current instance of `MagicString`. | ||
--- | ||
### `insert(value: StringValue, index: number)` | ||
*Inserts a value at a specified index in the accumulator.* | ||
*If the `index` is negative or zero, the value is prepended.* | ||
*If the `index` is greater than or equal to the length of the current accumulator, the value is appended.* | ||
`value` - The value to insert. | ||
`index` - The position at which to insert the value. | ||
<br> | ||
Returns the current instance of `MagicString`. | ||
--- | ||
### `substring(start: number, end?: number)` | ||
*Extracts a substring from the accumulator between specified indices.* | ||
`start` - The starting index of the substring. | ||
`end` - The ending index of the substring (optional). | ||
<br> | ||
Returns the current instance of `MagicString`. | ||
--- | ||
## โจ Examples | ||
`example.ts` | ||
`example.mts` | ||
```ts | ||
@@ -337,5 +456,3 @@ import { MagicString } from '@igor.dvlpr/magic-string' | ||
<br> | ||
### ๐จ๐ปโ๐ป Author | ||
## ๐จ๐ปโ๐ป Author | ||
Created by **Igor Dimitrijeviฤ** ([*@igorskyflyer*](https://github.com/igorskyflyer/)). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27308
303
439