@synstack/str 1.2.10 → 1.2.12
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 +87 -20
- package/package.json +3 -3
package/README.md
CHANGED
@@ -10,7 +10,7 @@ When working with strings in TypeScript, you often need to chain multiple operat
|
|
10
10
|
import { str } from "@synstack/str";
|
11
11
|
|
12
12
|
// Basic chaining
|
13
|
-
const result = str(" Hello World ").trim().split(" ")
|
13
|
+
const result = str(" Hello World ").trim().split(" ").$;
|
14
14
|
|
15
15
|
// Case conversion
|
16
16
|
const camelCase = str("hello-world").camelCase().$;
|
@@ -23,7 +23,7 @@ const formatted = str(" some\n indented\n text")
|
|
23
23
|
|
24
24
|
// Line manipulation
|
25
25
|
const lines = str("line1\n\n\n\nline2").chopRepeatNewlines(1).split("\n");
|
26
|
-
console.log(lines); // ['line1', 'line2']
|
26
|
+
console.log(lines); // [Str('line1'), Str('line2')]
|
27
27
|
```
|
28
28
|
|
29
29
|
## Installation
|
@@ -43,7 +43,37 @@ pnpm add @synstack/str
|
|
43
43
|
All string operations are chainable and maintain type safety:
|
44
44
|
|
45
45
|
```typescript
|
46
|
-
const result = str(" Hello World ").trim().split(" ")
|
46
|
+
const result = str(" Hello World ").trim().split(" ");
|
47
|
+
const firstWord = result.at(0)?.camelCase().$; // 'hello'
|
48
|
+
```
|
49
|
+
|
50
|
+
### Basic String Operations
|
51
|
+
|
52
|
+
Core string manipulation methods:
|
53
|
+
|
54
|
+
```typescript
|
55
|
+
// Trimming
|
56
|
+
str(" Hello ").trim().$; // "Hello"
|
57
|
+
str(" Hello ").trimStart().$; // "Hello "
|
58
|
+
str(" Hello ").trimEnd().$; // " Hello"
|
59
|
+
|
60
|
+
// Character access and length
|
61
|
+
str("Hello").at(0); // "H"
|
62
|
+
str("Hello").at(-1); // "o"
|
63
|
+
str("Hello").length(); // 5
|
64
|
+
|
65
|
+
// String extraction
|
66
|
+
str("Hello World").takeStart(5).$; // "Hello"
|
67
|
+
str("Hello World").takeEnd(5).$; // "World"
|
68
|
+
str("Hello World").chopStart(6).$; // "World"
|
69
|
+
str("Hello World").chopEnd(6).$; // "Hello"
|
70
|
+
|
71
|
+
// String replacement
|
72
|
+
str("Hello World").replace("o", "0").$; // "Hell0 World"
|
73
|
+
str("Hello World").replaceAll("o", "0").$; // "Hell0 W0rld"
|
74
|
+
|
75
|
+
// String splitting
|
76
|
+
str("a,b,c").split(","); // [Str("a"), Str("b"), Str("c")]
|
47
77
|
```
|
48
78
|
|
49
79
|
### Line Manipulation
|
@@ -54,11 +84,21 @@ Handle multi-line strings with precision:
|
|
54
84
|
// Remove empty lines
|
55
85
|
str("Hello\n\n\nWorld").chopRepeatNewlines(1).$; // "Hello\nWorld"
|
56
86
|
|
57
|
-
//
|
58
|
-
str("
|
87
|
+
// Remove empty lines from start/end
|
88
|
+
str("\n\n Hello").chopEmptyLinesStart().$; // " Hello"
|
89
|
+
str("Hello \n\n").chopEmptyLinesEnd().$; // "Hello "
|
90
|
+
|
91
|
+
// Clean up empty lines
|
92
|
+
str("Hello\n \nWorld").trimEmptyLines().$; // "Hello\n\nWorld"
|
93
|
+
str("Hello \nWorld ").trimLinesTrailingSpaces().$; // "Hello\nWorld"
|
94
|
+
|
95
|
+
// Line access
|
96
|
+
str("A\nB\nC").firstLine().$; // "A"
|
97
|
+
str("A\nB\nC").lastLine().$; // "C"
|
59
98
|
|
60
|
-
//
|
61
|
-
str("
|
99
|
+
// Add line numbers
|
100
|
+
str("A\nB\nC").addLineNumbers().$; // "0:A\n1:B\n2:C"
|
101
|
+
str("A\nB").addLineNumbers(" -> ").$; // "0 -> A\n1 -> B"
|
62
102
|
```
|
63
103
|
|
64
104
|
### Indentation Control
|
@@ -67,13 +107,16 @@ Manage text indentation with ease:
|
|
67
107
|
|
68
108
|
```typescript
|
69
109
|
// Add indentation
|
70
|
-
str("Hello\nWorld").indent(2).$;
|
110
|
+
str("Hello\nWorld").indent(2).$; // " Hello\n World"
|
111
|
+
str("A\nB").indent(3, "-").$; // "---A\n---B"
|
71
112
|
|
72
113
|
// Remove indentation
|
73
|
-
str(" Hello\n World").dedent().$;
|
114
|
+
str(" Hello\n World").dedent().$; // "Hello\n World"
|
115
|
+
str(" A\n B").dedent(2).$; // " A\nB"
|
74
116
|
|
75
|
-
// Get indentation
|
117
|
+
// Get indentation information
|
76
118
|
str(" Hello\n World").indentation(); // 2
|
119
|
+
str(" Hello").leadingSpacesCount(); // 2
|
77
120
|
```
|
78
121
|
|
79
122
|
### Case Conversion
|
@@ -81,20 +124,44 @@ str(" Hello\n World").indentation(); // 2
|
|
81
124
|
Convert between different case styles:
|
82
125
|
|
83
126
|
```typescript
|
84
|
-
str("hello-world").camelCase().$;
|
85
|
-
str("hello-world").pascalCase().$;
|
86
|
-
str("hello-world").snakeCase().$;
|
87
|
-
str("hello-world").constantCase().$;
|
88
|
-
str("hello-world").
|
89
|
-
str("hello-world").
|
127
|
+
str("hello-world").camelCase().$; // "helloWorld"
|
128
|
+
str("hello-world").pascalCase().$; // "HelloWorld"
|
129
|
+
str("hello-world").snakeCase().$; // "hello_world"
|
130
|
+
str("hello-world").constantCase().$; // "HELLO_WORLD"
|
131
|
+
str("hello-world").kebabCase().$; // "hello-world"
|
132
|
+
str("hello-world").dotCase().$; // "hello.world"
|
133
|
+
str("hello-world").pathCase().$; // "hello/world"
|
134
|
+
|
135
|
+
// Additional case styles
|
136
|
+
str("hello-world").capitalCase().$; // "Hello World"
|
137
|
+
str("hello-world").sentenceCase().$; // "Hello world"
|
138
|
+
str("hello-world").trainCase().$; // "Hello-World"
|
139
|
+
str("hello-world").pascalSnakeCase().$; // "Hello_World"
|
140
|
+
str("hello-world").noCase().$; // "hello world"
|
90
141
|
```
|
91
142
|
|
92
|
-
### Utility
|
143
|
+
### Utility Methods
|
93
144
|
|
94
|
-
|
145
|
+
Check string properties and states:
|
95
146
|
|
96
147
|
```typescript
|
97
|
-
|
148
|
+
// Check if empty
|
149
|
+
str("").isEmpty(); // true
|
150
|
+
str(" \n ").isEmpty(); // true
|
151
|
+
str("Hello").isEmpty(); // false
|
152
|
+
```
|
153
|
+
|
154
|
+
### Standalone Functions
|
98
155
|
|
99
|
-
|
156
|
+
All methods from the Str class are also available as standalone functions:
|
157
|
+
|
158
|
+
```typescript
|
159
|
+
import {
|
160
|
+
trim, dedent, chopEmptyLinesStart, addLineNumbers,
|
161
|
+
camelCase, pascalCase, snakeCase
|
162
|
+
} from "@synstack/str";
|
163
|
+
|
164
|
+
const result = trim(" hello "); // 'hello'
|
165
|
+
const indented = dedent(" A\n B"); // 'A\n B'
|
166
|
+
const camel = camelCase("hello-world"); // 'helloWorld'
|
100
167
|
```
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
7
|
-
"version": "1.2.
|
7
|
+
"version": "1.2.12",
|
8
8
|
"description": "Advanced chainable string manipulation",
|
9
9
|
"keywords": [
|
10
10
|
"string",
|
@@ -45,7 +45,7 @@
|
|
45
45
|
}
|
46
46
|
},
|
47
47
|
"dependencies": {
|
48
|
-
"@synstack/pipe": "^1.1.
|
48
|
+
"@synstack/pipe": "^1.1.14",
|
49
49
|
"change-case": "^5.4.4"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
@@ -58,5 +58,5 @@
|
|
58
58
|
"!src/**/*.test.ts",
|
59
59
|
"dist/**/*"
|
60
60
|
],
|
61
|
-
"gitHead": "
|
61
|
+
"gitHead": "330f6fbc8d1ae4fb300168db3e293db51a186ab2"
|
62
62
|
}
|