@synstack/str 1.2.1 → 1.2.3
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 +103 -142
- package/package.json +4 -4
package/README.md
CHANGED
@@ -1,142 +1,103 @@
|
|
1
|
-
# @synstack/str
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
1
|
+
# @synstack/str
|
2
|
+
|
3
|
+
Advanced chainable string manipulation utilities
|
4
|
+
|
5
|
+
> [!WARNING]
|
6
|
+
> This package is included in the [@synstack/synscript](../synscript/README.md) package. It is not recommended to install both packages at the same time.
|
7
|
+
|
8
|
+
## What is it for?
|
9
|
+
|
10
|
+
When working with strings in TypeScript, you often need to chain multiple operations like trimming, splitting, case conversion, and indentation management. This package provides a fluent, chainable API for string manipulation with full type safety:
|
11
|
+
|
12
|
+
```typescript
|
13
|
+
import { str } from "@synstack/str";
|
14
|
+
|
15
|
+
// Basic chaining
|
16
|
+
const result = str(" Hello World ").trim().split(" ").at(0).$;
|
17
|
+
|
18
|
+
// Case conversion
|
19
|
+
const camelCase = str("hello-world").camelCase().$;
|
20
|
+
console.log(camelCase); // 'helloWorld'
|
21
|
+
|
22
|
+
// Advanced manipulation
|
23
|
+
const formatted = str(" some\n indented\n text")
|
24
|
+
.trimEmptyLines()
|
25
|
+
.dedent().$;
|
26
|
+
|
27
|
+
// Line manipulation
|
28
|
+
const lines = str("line1\n\n\n\nline2").chopRepeatNewlines(1).split("\n");
|
29
|
+
console.log(lines); // ['line1', 'line2']
|
30
|
+
```
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
```bash
|
35
|
+
npm install @synstack/str
|
36
|
+
# or
|
37
|
+
yarn add @synstack/str
|
38
|
+
# or
|
39
|
+
pnpm add @synstack/str
|
40
|
+
```
|
41
|
+
|
42
|
+
## Features
|
43
|
+
|
44
|
+
### Chainable Operations
|
45
|
+
|
46
|
+
All string operations are chainable and maintain type safety:
|
47
|
+
|
48
|
+
```typescript
|
49
|
+
const result = str(" Hello World ").trim().split(" ").at(0).camelCase().$;
|
50
|
+
```
|
51
|
+
|
52
|
+
### Line Manipulation
|
53
|
+
|
54
|
+
Handle multi-line strings with precision:
|
55
|
+
|
56
|
+
```typescript
|
57
|
+
// Remove empty lines
|
58
|
+
str("Hello\n\n\nWorld").chopRepeatNewlines(1).$; // "Hello\nWorld"
|
59
|
+
|
60
|
+
// Add line numbers
|
61
|
+
str("A\nB\nC").addLineNumbers().$; // "0:A\n1:B\n2:C"
|
62
|
+
|
63
|
+
// Trim empty lines and spaces
|
64
|
+
str(" \n Hello \n ").trimEmptyLines().$; // "\nHello\n"
|
65
|
+
```
|
66
|
+
|
67
|
+
### Indentation Control
|
68
|
+
|
69
|
+
Manage text indentation with ease:
|
70
|
+
|
71
|
+
```typescript
|
72
|
+
// Add indentation
|
73
|
+
str("Hello\nWorld").indent(2).$; // " Hello\n World"
|
74
|
+
|
75
|
+
// Remove indentation
|
76
|
+
str(" Hello\n World").dedent().$; // "Hello\n World"
|
77
|
+
|
78
|
+
// Get indentation level
|
79
|
+
str(" Hello\n World").indentation(); // 2
|
80
|
+
```
|
81
|
+
|
82
|
+
### Case Conversion
|
83
|
+
|
84
|
+
Convert between different case styles:
|
85
|
+
|
86
|
+
```typescript
|
87
|
+
str("hello-world").camelCase().$; // "helloWorld"
|
88
|
+
str("hello-world").pascalCase().$; // "HelloWorld"
|
89
|
+
str("hello-world").snakeCase().$; // "hello_world"
|
90
|
+
str("hello-world").constantCase().$; // "HELLO_WORLD"
|
91
|
+
str("hello-world").dotCase().$; // "hello.world"
|
92
|
+
str("hello-world").pathCase().$; // "hello/world"
|
93
|
+
```
|
94
|
+
|
95
|
+
### Utility Functions
|
96
|
+
|
97
|
+
All methods from the Str class are also available as standalone functions:
|
98
|
+
|
99
|
+
```typescript
|
100
|
+
import { trim, dedent, chopEmptyLinesStart } from "@synstack/str";
|
101
|
+
|
102
|
+
const result = trim(" hello "); // 'hello'
|
103
|
+
```
|
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.3",
|
8
8
|
"description": "Advanced chainable string manipulation",
|
9
9
|
"keywords": [
|
10
10
|
"string",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"homepage": "https://github.com/pAIrprogio/synscript/tree/main/packages/str",
|
21
21
|
"repository": {
|
22
22
|
"type": "git",
|
23
|
-
"url": "https://github.com/pAIrprogio/
|
23
|
+
"url": "https://github.com/pAIrprogio/synscript.git",
|
24
24
|
"directory": "packages/str"
|
25
25
|
},
|
26
26
|
"license": "Apache-2.0",
|
@@ -46,7 +46,7 @@
|
|
46
46
|
}
|
47
47
|
},
|
48
48
|
"dependencies": {
|
49
|
-
"@synstack/pipe": "1.1.
|
49
|
+
"@synstack/pipe": "1.1.6",
|
50
50
|
"change-case": "^5.4.4"
|
51
51
|
},
|
52
52
|
"devDependencies": {
|
@@ -59,5 +59,5 @@
|
|
59
59
|
"!src/**/*.test.ts",
|
60
60
|
"dist/**/*"
|
61
61
|
],
|
62
|
-
"gitHead": "
|
62
|
+
"gitHead": "886036553ab02c6c1b98289b1de64240de866521"
|
63
63
|
}
|