@sylphx/flow 2.18.1 → 2.18.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.
@@ -1,281 +0,0 @@
1
- /**
2
- * Functional string utilities
3
- * Pure string transformation functions
4
- *
5
- * DESIGN RATIONALE:
6
- * - Pure functions for string operations
7
- * - Composable transformations
8
- * - Type-safe operations
9
- * - No side effects
10
- */
11
-
12
- /**
13
- * Trim whitespace from string
14
- */
15
- export const trim = (str: string): string => str.trim();
16
-
17
- /**
18
- * Trim start of string
19
- */
20
- export const trimStart = (str: string): string => str.trimStart();
21
-
22
- /**
23
- * Trim end of string
24
- */
25
- export const trimEnd = (str: string): string => str.trimEnd();
26
-
27
- /**
28
- * Convert to lowercase
29
- */
30
- export const toLowerCase = (str: string): string => str.toLowerCase();
31
-
32
- /**
33
- * Convert to uppercase
34
- */
35
- export const toUpperCase = (str: string): string => str.toUpperCase();
36
-
37
- /**
38
- * Split string by delimiter
39
- */
40
- export const split =
41
- (delimiter: string | RegExp) =>
42
- (str: string): string[] =>
43
- str.split(delimiter);
44
-
45
- /**
46
- * Join array of strings
47
- */
48
- export const join =
49
- (delimiter: string) =>
50
- (arr: string[]): string =>
51
- arr.join(delimiter);
52
-
53
- /**
54
- * Replace pattern in string
55
- */
56
- export const replace =
57
- (pattern: string | RegExp, replacement: string) =>
58
- (str: string): string =>
59
- str.replace(pattern, replacement);
60
-
61
- /**
62
- * Replace all occurrences
63
- */
64
- export const replaceAll =
65
- (pattern: string | RegExp, replacement: string) =>
66
- (str: string): string =>
67
- str.replaceAll(pattern, replacement);
68
-
69
- /**
70
- * Check if string starts with prefix
71
- */
72
- export const startsWith =
73
- (prefix: string) =>
74
- (str: string): boolean =>
75
- str.startsWith(prefix);
76
-
77
- /**
78
- * Check if string ends with suffix
79
- */
80
- export const endsWith =
81
- (suffix: string) =>
82
- (str: string): boolean =>
83
- str.endsWith(suffix);
84
-
85
- /**
86
- * Check if string includes substring
87
- */
88
- export const includes =
89
- (substring: string) =>
90
- (str: string): boolean =>
91
- str.includes(substring);
92
-
93
- /**
94
- * Test string against regex
95
- */
96
- export const test =
97
- (pattern: RegExp) =>
98
- (str: string): boolean =>
99
- pattern.test(str);
100
-
101
- /**
102
- * Match string against regex
103
- */
104
- export const match =
105
- (pattern: RegExp) =>
106
- (str: string): RegExpMatchArray | null =>
107
- str.match(pattern);
108
-
109
- /**
110
- * Slice string
111
- */
112
- export const slice =
113
- (start: number, end?: number) =>
114
- (str: string): string =>
115
- str.slice(start, end);
116
-
117
- /**
118
- * Substring
119
- */
120
- export const substring =
121
- (start: number, end?: number) =>
122
- (str: string): string =>
123
- str.substring(start, end);
124
-
125
- /**
126
- * Pad start of string
127
- */
128
- export const padStart =
129
- (length: number, fillString = ' ') =>
130
- (str: string): string =>
131
- str.padStart(length, fillString);
132
-
133
- /**
134
- * Pad end of string
135
- */
136
- export const padEnd =
137
- (length: number, fillString = ' ') =>
138
- (str: string): string =>
139
- str.padEnd(length, fillString);
140
-
141
- /**
142
- * Repeat string n times
143
- */
144
- export const repeat =
145
- (count: number) =>
146
- (str: string): string =>
147
- str.repeat(count);
148
-
149
- /**
150
- * Check if string is empty
151
- */
152
- export const isEmpty = (str: string): boolean => str.length === 0;
153
-
154
- /**
155
- * Check if string is blank (empty or whitespace)
156
- */
157
- export const isBlank = (str: string): boolean => str.trim().length === 0;
158
-
159
- /**
160
- * Check if string is not empty
161
- */
162
- export const isNotEmpty = (str: string): boolean => str.length > 0;
163
-
164
- /**
165
- * Check if string is not blank
166
- */
167
- export const isNotBlank = (str: string): boolean => str.trim().length > 0;
168
-
169
- /**
170
- * Capitalize first letter
171
- */
172
- export const capitalize = (str: string): string => {
173
- if (str.length === 0) {
174
- return str;
175
- }
176
- return str.charAt(0).toUpperCase() + str.slice(1);
177
- };
178
-
179
- /**
180
- * Capitalize all words
181
- */
182
- export const capitalizeWords = (str: string): string => {
183
- return str
184
- .split(' ')
185
- .map((word) => capitalize(word))
186
- .join(' ');
187
- };
188
-
189
- /**
190
- * Convert to camelCase
191
- */
192
- export const toCamelCase = (str: string): string => {
193
- return str
194
- .replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))
195
- .replace(/^[A-Z]/, (c) => c.toLowerCase());
196
- };
197
-
198
- /**
199
- * Convert to PascalCase
200
- */
201
- export const toPascalCase = (str: string): string => {
202
- const camel = toCamelCase(str);
203
- return capitalize(camel);
204
- };
205
-
206
- /**
207
- * Convert to kebab-case
208
- */
209
- export const toKebabCase = (str: string): string => {
210
- return str
211
- .replace(/([a-z])([A-Z])/g, '$1-$2')
212
- .replace(/[\s_]+/g, '-')
213
- .toLowerCase();
214
- };
215
-
216
- /**
217
- * Convert to snake_case
218
- */
219
- export const toSnakeCase = (str: string): string => {
220
- return str
221
- .replace(/([a-z])([A-Z])/g, '$1_$2')
222
- .replace(/[\s-]+/g, '_')
223
- .toLowerCase();
224
- };
225
-
226
- /**
227
- * Truncate string to max length
228
- */
229
- export const truncate =
230
- (maxLength: number, suffix = '...') =>
231
- (str: string): string => {
232
- if (str.length <= maxLength) {
233
- return str;
234
- }
235
- return str.slice(0, maxLength - suffix.length) + suffix;
236
- };
237
-
238
- /**
239
- * Extract lines from string
240
- */
241
- export const lines = (str: string): string[] => str.split(/\r?\n/);
242
-
243
- /**
244
- * Remove empty lines
245
- */
246
- export const removeEmptyLines = (str: string): string => {
247
- return lines(str).filter(isNotBlank).join('\n');
248
- };
249
-
250
- /**
251
- * Indent each line
252
- */
253
- export const indent =
254
- (spaces: number) =>
255
- (str: string): string => {
256
- const indentation = ' '.repeat(spaces);
257
- return lines(str)
258
- .map((line) => indentation + line)
259
- .join('\n');
260
- };
261
-
262
- /**
263
- * Remove indentation
264
- */
265
- export const dedent = (str: string): string => {
266
- const linesArray = lines(str);
267
-
268
- // Find minimum indentation
269
- const minIndent = linesArray.filter(isNotBlank).reduce((min, line) => {
270
- const match = line.match(/^(\s*)/);
271
- const indent = match ? match[1].length : 0;
272
- return Math.min(min, indent);
273
- }, Number.POSITIVE_INFINITY);
274
-
275
- if (minIndent === 0 || minIndent === Number.POSITIVE_INFINITY) {
276
- return str;
277
- }
278
-
279
- // Remove minimum indentation from each line
280
- return linesArray.map((line) => line.slice(minIndent)).join('\n');
281
- };