@synstack/str 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -1
- package/dist/str.index.cjs +305 -44
- package/dist/str.index.cjs.map +1 -1
- package/dist/str.index.d.cts +528 -72
- package/dist/str.index.d.ts +528 -72
- package/dist/str.index.js +303 -44
- package/dist/str.index.js.map +1 -1
- package/package.json +4 -4
- package/src/str.chainable.ts +325 -44
- package/src/str.lib.ts +230 -27
package/README.md
CHANGED
@@ -1 +1,142 @@
|
|
1
|
-
# @synstack/
|
1
|
+
# @synstack/str
|
2
|
+
|
3
|
+
> Advanced chainable string manipulation utilities for TypeScript
|
4
|
+
|
5
|
+
This package provides a strongly-typed, chainable API for string manipulation with support for multiple case conversions and advanced text formatting operations.
|
6
|
+
|
7
|
+
> [!WARNING]
|
8
|
+
> This package is included in the [@synstack/synscript](https://github.com/pAIrprogio/synscript) package. It is not recommended to install both packages at the same time.
|
9
|
+
|
10
|
+
## What is it for?
|
11
|
+
|
12
|
+
Working with strings should be simple and type-safe. This package turns verbose string operations into chainable, strongly-typed commands:
|
13
|
+
|
14
|
+
```typescript
|
15
|
+
import { str } from '@synstack/str'
|
16
|
+
|
17
|
+
// Basic chaining
|
18
|
+
const result = str(' Hello World ')
|
19
|
+
.trim()
|
20
|
+
.split(' ')
|
21
|
+
.at(0)
|
22
|
+
.$
|
23
|
+
|
24
|
+
// Case conversion
|
25
|
+
const camelCase = str('hello-world').camelCase().$
|
26
|
+
console.log(camelCase) // 'helloWorld'
|
27
|
+
|
28
|
+
// Advanced manipulation
|
29
|
+
const formatted = str(' some\n indented\n text')
|
30
|
+
.trimEmptyLines()
|
31
|
+
.dedent()
|
32
|
+
.$
|
33
|
+
|
34
|
+
// Line manipulation
|
35
|
+
const lines = str('line1\n\n\n\nline2')
|
36
|
+
.chopRepeatNewlines(1)
|
37
|
+
.split('\n')
|
38
|
+
console.log(lines) // ['line1', 'line2']
|
39
|
+
```
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
```bash
|
44
|
+
npm install @synstack/str
|
45
|
+
# or
|
46
|
+
yarn add @synstack/str
|
47
|
+
# or
|
48
|
+
pnpm add @synstack/str
|
49
|
+
```
|
50
|
+
|
51
|
+
## Features
|
52
|
+
|
53
|
+
- 🔗 Chainable API for fluent string manipulation
|
54
|
+
- 📝 Rich set of string utilities (trim, chop, indent, etc.)
|
55
|
+
- 🔄 Case conversion utilities (camel, pascal, snake, etc.)
|
56
|
+
- 🎯 TypeScript-first with full type safety
|
57
|
+
- ⚡ Zero dependencies (except change-case)
|
58
|
+
|
59
|
+
## API Reference
|
60
|
+
|
61
|
+
### Str Class
|
62
|
+
|
63
|
+
The main class providing chainable string operations. Extends `Pipeable` from `@synstack/pipe`.
|
64
|
+
|
65
|
+
#### Chaining Methods
|
66
|
+
|
67
|
+
- `_((str) => result)`: Chain operations on the Str instance
|
68
|
+
- `_$((value) => result)`: Chain operations on the string value
|
69
|
+
- `$`: Get the underlying string value
|
70
|
+
|
71
|
+
#### String Operations
|
72
|
+
|
73
|
+
##### Trimming
|
74
|
+
- `trim()`: Remove leading and trailing whitespace
|
75
|
+
- `trimStart()`: Remove leading whitespace
|
76
|
+
- `trimEnd()`: Remove trailing whitespace
|
77
|
+
- `trimEmptyLines()`: Remove whitespace from empty lines
|
78
|
+
- `trimLinesTrailingSpaces()`: Remove trailing spaces from all lines
|
79
|
+
|
80
|
+
##### Line Manipulation
|
81
|
+
- `chopEmptyLinesStart()`: Remove empty lines at start
|
82
|
+
- `chopEmptyLinesEnd()`: Remove empty lines at end
|
83
|
+
- `chopRepeatNewlines(max: number)`: Limit consecutive newlines
|
84
|
+
- `addLineNumbers(separator?: string)`: Add line numbers to each line
|
85
|
+
|
86
|
+
##### Indentation
|
87
|
+
- `indent(size: number, char?: string)`: Indent all lines
|
88
|
+
- `dedent(size?: number)`: Remove indentation
|
89
|
+
- `indentation()`: Get the minimum indentation level
|
90
|
+
- `leadingSpacesCount()`: Count leading spaces
|
91
|
+
|
92
|
+
##### String Extraction
|
93
|
+
- `split(separator: string | RegExp)`: Split string into array
|
94
|
+
- `takeStart(count: number)`: Take first n characters
|
95
|
+
- `takeEnd(count: number)`: Take last n characters
|
96
|
+
- `firstLine()`: Get the first line
|
97
|
+
- `lastLine()`: Get the last line
|
98
|
+
|
99
|
+
##### Case Conversion
|
100
|
+
- `camelCase()`: Convert to camelCase
|
101
|
+
- `capitalCase()`: Convert to Capital Case
|
102
|
+
- `constantCase()`: Convert to CONSTANT_CASE
|
103
|
+
- `dotCase()`: Convert to dot.case
|
104
|
+
- `kebabCase()`: Convert to kebab-case
|
105
|
+
- `noCase()`: Convert to no case
|
106
|
+
- `pascalCase()`: Convert to PascalCase
|
107
|
+
- `pascalSnakeCase()`: Convert to Pascal_Snake_Case
|
108
|
+
- `pathCase()`: Convert to path/case
|
109
|
+
- `sentenceCase()`: Convert to Sentence case
|
110
|
+
- `snakeCase()`: Convert to snake_case
|
111
|
+
- `trainCase()`: Convert to Train-Case
|
112
|
+
|
113
|
+
### Utility Functions
|
114
|
+
|
115
|
+
All methods from the Str class are also available as standalone functions:
|
116
|
+
|
117
|
+
```typescript
|
118
|
+
import { trim, dedent, chopEmptyLinesStart } from '@synstack/str'
|
119
|
+
|
120
|
+
const result = trim(' hello ') // 'hello'
|
121
|
+
```
|
122
|
+
|
123
|
+
## TypeScript Support
|
124
|
+
|
125
|
+
Full TypeScript support with generics and type inference. The library is written in TypeScript and provides type definitions out of the box.
|
126
|
+
|
127
|
+
```typescript
|
128
|
+
import { str } from '@synstack/str'
|
129
|
+
|
130
|
+
// Type inference works automatically
|
131
|
+
const result = str('hello')
|
132
|
+
.trim()
|
133
|
+
.split('')
|
134
|
+
.at(0)
|
135
|
+
.$
|
136
|
+
|
137
|
+
// result is inferred as string
|
138
|
+
```
|
139
|
+
|
140
|
+
## License
|
141
|
+
|
142
|
+
Apache-2.0
|