@synstack/str 1.2.1 → 1.2.2

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.
Files changed (2) hide show
  1. package/README.md +103 -142
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,142 +1,103 @@
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
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.1",
7
+ "version": "1.2.2",
8
8
  "description": "Advanced chainable string manipulation",
9
9
  "keywords": [
10
10
  "string",
@@ -46,7 +46,7 @@
46
46
  }
47
47
  },
48
48
  "dependencies": {
49
- "@synstack/pipe": "1.1.4",
49
+ "@synstack/pipe": "1.1.5",
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": "348d1987aba7aee8fbc5469d071e3c71663fc775"
62
+ "gitHead": "2868de5f8935b959b5b5faa6606a2fa9fcad27ab"
63
63
  }