@pcg/text-kit 1.0.0-alpha.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.
@@ -0,0 +1,15 @@
1
+
2
+ 
3
+ > @pcg/text-kit@1.0.0-alpha.0 build /Users/serg_sadovyi/prj/deepvisionsoftware.github/pcg/packages/text-kit
4
+ > tsdown
5
+
6
+ ℹ tsdown v0.15.12 powered by rolldown v1.0.0-beta.45
7
+ ℹ Using tsdown config: /Users/serg_sadovyi/prj/deepvisionsoftware.github/pcg/packages/text-kit/tsdown.config.ts
8
+ ℹ entry: src/index.ts
9
+ ℹ tsconfig: ../../tsconfig.build.json
10
+ ℹ Build start
11
+ ℹ dist/index.js  9.79 kB │ gzip: 2.42 kB
12
+ ℹ dist/index.js.map 14.23 kB │ gzip: 3.60 kB
13
+ ℹ dist/index.d.ts  8.15 kB │ gzip: 1.67 kB
14
+ ℹ 3 files, total: 32.17 kB
15
+ ✔ Build complete in 580ms
package/README.md ADDED
@@ -0,0 +1,243 @@
1
+ # @deeepvision/textkit
2
+
3
+ `@deeepvision/textkit` is a text transformation and manipulation library that provides a collection of utility functions to help you work with strings effortlessly. This package is designed to simplify the process of changing cases, declination, pluralization, and more.
4
+
5
+ ## Features
6
+
7
+ * Case conversion (PascalCase, camelCase, param-case, snake_case, CONSTANT_CASE)
8
+ * Sentence transformation (to sentence, upper cased sentence, lower cased sentence)
9
+ * Abbreviation generation
10
+ * Declination based on number
11
+ * Pluralization and singularization
12
+
13
+ ## Installation
14
+
15
+ Install the package using npm or yarn:
16
+
17
+ ```bash
18
+ npm install @deeepvision/textkit
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Import and use the desired functions from the package:
24
+
25
+ ```ts
26
+ import {
27
+ ucfirst,
28
+ pascalCase,
29
+ camelCase,
30
+ // ...
31
+ decline,
32
+ singularToPlural,
33
+ pluralToSingular,
34
+ } from '@deeepvision/textkit';
35
+
36
+ // Change cases
37
+ const upperFirstChar = ucfirst('hello');
38
+ const pascal = pascalCase('hello world');
39
+ const camel = camelCase('hello world');
40
+ // ...
41
+
42
+ // Declination
43
+ const declinedNoun = decline('apple', 3);
44
+
45
+ // Pluralization
46
+ const plural = singularToPlural('cat');
47
+ const singular = pluralToSingular('cats');
48
+ ```
49
+
50
+ For a comprehensive list of available functions, please refer to the feature list provided in the package description.
51
+
52
+ ## API
53
+
54
+ ### Case conversion
55
+
56
+ #### `ucfirst(string: string): string`
57
+
58
+ Convert a string to string with the first character in uppercase.
59
+
60
+ ```ts
61
+ ucfirst('hello world'); // Hello world
62
+ ucfirst('HELLO WORLD'); // Hello world
63
+ ```
64
+
65
+ #### `lcfirst(string: string): string`
66
+
67
+ Convert a string to string with the first character in lower case.
68
+
69
+ ```ts
70
+ lcfirst('Hello world'); // hello world
71
+ ```
72
+
73
+ #### `pascalCase(string: string): string`
74
+
75
+ Convert a string to `PascalCase`.
76
+
77
+ ```ts
78
+ pascalCase('simple') //=> "Simple"
79
+ pascalCase('some.dot.case') //=> "SomeDotCase"
80
+ pascalCase('some-param-case') //=> "SomeParamCase"
81
+ pascalCase('some spaced case') //=> "SomeSpacedCase"
82
+ pascalCase('someCamelCase')) //=> "SomeCamelCase"
83
+ pascalCase('SomePascalCase') //=> "SomePascalCase"
84
+ ```
85
+
86
+ #### `camelCase(string: string): string`
87
+
88
+ Convert a string to camelCase.
89
+
90
+ ```ts
91
+ camelCase('simple') //=> "simple"
92
+ camelCase('some.dot.case') //=> "someDotCase"
93
+ camelCase('some-param-case') //=> "someParamCase"
94
+ camelCase('some spaced case') //=> "someSpacedCase"
95
+ camelCase('someCamelCase')) //=> "someCamelCase"
96
+ camelCase('SomePascalCase') //=> "somePascalCase"
97
+ ```
98
+
99
+ #### `paramCase(string: string): string` - Convert a string to param-case.
100
+
101
+ ```ts
102
+ paramCase('simple') //=> "simple"
103
+ paramCase('some.dot.case') //=> "some-dot-case"
104
+ paramCase('some-param-case') //=> "some-param-case"
105
+ paramCase('some spaced case') //=> "some-spaced-case"
106
+ paramCase('someCamelCase')) //=> "some-camel-case"
107
+ paramCase('SomePascalCase') //=> "some-pascal-case"
108
+ ```
109
+
110
+ #### `snakeCase(string: string): string`
111
+
112
+ Convert a string to snake_case.
113
+
114
+ ```ts
115
+ camelCase('simple') //=> "simple"
116
+ camelCase('some.dot.case') //=> "some_dot_case"
117
+ camelCase('some-param-case') //=> "some_param_case"
118
+ camelCase('some spaced case') //=> "some_spaced_case"
119
+ camelCase('someCamelCase')) //=> "some_camel_case"
120
+ camelCase('SomePascalCase') //=> "some_pascal_case"
121
+ ```
122
+
123
+ #### `constantCase(string: string): string`
124
+
125
+ Convert a string to CONSTANT_CASE.
126
+
127
+ ```ts
128
+ constantCase('foo bar'); //=> 'FOO_BAR'
129
+ constantCase('foo_bar'); //=> 'FOO_BAR'
130
+ constantCase('foo-bar'); //=> 'FOO_BAR'
131
+ constantCase('foo.bar'); //=> 'FOO_BAR'
132
+ constantCase('fooBar'); //=> 'FOO_BAR'
133
+ constantCase('FooBar'); //=> 'FOO_BAR'
134
+ ```
135
+
136
+ ### Sentence transformation
137
+
138
+ #### `toSentence(string: string): string`
139
+
140
+ Convert a string to sentence.
141
+
142
+ ```ts
143
+ toSentence('foo bar'); //=> 'Foo bar'
144
+ toSentence('foo_bar'); //=> 'Foo bar'
145
+ toSentence('foo-bar'); //=> 'Foo bar'
146
+ toSentence('foo.bar'); //=> 'Foo bar'
147
+ toSentence('fooBar'); //=> 'Foo bar'
148
+ toSentence('FooBar'); //=> 'Foo bar'
149
+ toSentence('foo bar baz'); //=> 'Foo bar baz'
150
+ ```
151
+
152
+ #### `toUcSentence(string: string): string`
153
+
154
+ Convert a string to upper cased sentence.
155
+
156
+ ```ts
157
+ toUcSentence('foo bar'); //=> 'Foo Bar'
158
+ toUcSentence('foo_bar'); //=> 'Foo Bar'
159
+ toUcSentence('foo-bar'); //=> 'Foo Bar'
160
+ toUcSentence('foo.bar'); //=> 'Foo Bar'
161
+ toUcSentence('fooBar'); //=> 'Foo Bar'
162
+ toUcSentence('FooBar'); //=> 'Foo Bar'
163
+ toUcSentence('foo bar baz'); //=> 'Foo Bar Baz'
164
+ ```
165
+
166
+ #### `toLcSentence(string: string): string`
167
+
168
+ Convert a string to lower cased sentence.
169
+
170
+ ```ts
171
+ toLcSentence('foo bar'); //=> 'foo bar'
172
+ toLcSentence('foo_bar'); //=> 'foo bar'
173
+ toLcSentence('foo-bar'); //=> 'foo bar'
174
+ toLcSentence('foo.bar'); //=> 'foo bar'
175
+ toLcSentence('fooBar'); //=> 'foo bar'
176
+ toLcSentence('FooBar'); //=> 'foo bar'
177
+ toLcSentence('Foo bar baz'); //=> 'foo bar baz'
178
+ ```
179
+
180
+ ### SQL alias and abbreviation
181
+
182
+ #### `toSqlAlias(string: string): string`
183
+
184
+ Convert a table name to SQL alias.
185
+
186
+ ```ts
187
+ toSqlAlias('foo bar'); //=> 'fb'
188
+ toSqlAlias('book'); //=> 'b'
189
+ toSqlAlias('article-category'); //=> 'ac'
190
+ ```
191
+
192
+ #### `toAbbreviation(string: string): string`
193
+
194
+ Convert a string to abbreviation.
195
+
196
+ ```ts
197
+ toAbbreviation('Deep Vision'); //=> 'DV'
198
+ toAbbreviation('Рожеві окуляри', {
199
+ lang: 'uk',
200
+ }); //=> 'RO'
201
+ toAbbreviation('Удивительные факты', {
202
+ lang: 'ru'
203
+ }); //=> 'UF'
204
+ toAbbreviation('The very long title that can be shorter but I love long titles', {
205
+ maxLength: 3
206
+ }); //=> 'TVL'
207
+ toAbbreviation('Vision'); //=> 'VSN'
208
+ toAbbreviation('Deep Vision', {
209
+ iteration: 1,
210
+ }); //=> 'DV1'
211
+ ```
212
+
213
+ ### Declination
214
+
215
+ #### `decline(noun: string, number: number): string`
216
+
217
+ Decline a noun based on a number.
218
+
219
+ ```ts
220
+ const words = ['элемент', 'элемента', 'элементов'];
221
+
222
+ decline(0, words, false) // => 'элементов'
223
+ decline(24, words, false) // => 'элемента'
224
+ decline(21, words, false) // => 'элемент'
225
+ ```
226
+
227
+ ### Pluralization
228
+
229
+ #### `singularToPlural(singular: string): string`
230
+
231
+ Change the plural form of a word to its singular form.
232
+
233
+ ```ts
234
+ singularToPlural('book'); //=> 'books'
235
+ ```
236
+
237
+ #### `pluralToSingular(plural: string): string`
238
+
239
+ Change the singular form of a word to its plural form.
240
+
241
+ ```ts
242
+ pluralToSingular('books'); //=> 'book'
243
+ ```
@@ -0,0 +1,243 @@
1
+ //#region src/cases.d.ts
2
+ /**
3
+ * Convert a string to string with the first character in uppercase.
4
+ * @example
5
+ * ucfirst('hello world'); // Hello world
6
+ **/
7
+ declare const ucfirst: (input: string) => string;
8
+ /**
9
+ * Convert a string to string with the first character in lower case.
10
+ * @example
11
+ * lcfirst('Hello world'); // hello world
12
+ **/
13
+ declare const lcfirst: (input: string) => string;
14
+ /**
15
+ * Convert a string to PascalCase.
16
+ * @example
17
+ * pascalCase('foo bar'); //=> 'FooBar'
18
+ * pascalCase('foo_bar'); //=> 'FooBar'
19
+ * pascalCase('foo-bar'); //=> 'FooBar'
20
+ * pascalCase('foo.bar'); //=> 'FooBar'
21
+ * pascalCase('fooBar'); //=> 'FooBar'
22
+ **/
23
+ declare const pascalCase: (input: string) => string;
24
+ /**
25
+ * Convert a string to camelCase.
26
+ * @example
27
+ * camelCase('foo bar'); //=> 'fooBar'
28
+ * camelCase('foo_bar'); //=> 'fooBar'
29
+ * camelCase('foo-bar'); //=> 'fooBar'
30
+ * camelCase('foo.bar'); //=> 'fooBar'
31
+ * camelCase('fooBar'); //=> 'fooBar'
32
+ * camelCase('FooBar'); //=> 'fooBar'
33
+ **/
34
+ declare const camelCase: (input: string) => string;
35
+ /**
36
+ * Convert a string to param-case.
37
+ * @example
38
+ * paramCase('foo bar'); //=> 'foo-bar'
39
+ * paramCase('foo_bar'); //=> 'foo-bar'
40
+ * paramCase('foo-bar'); //=> 'foo-bar'
41
+ * paramCase('foo.bar'); //=> 'foo-bar'
42
+ * paramCase('fooBar'); //=> 'foo-bar'
43
+ * paramCase('FooBar'); //=> 'foo-bar'
44
+ **/
45
+ declare const paramCase: (input: string) => string;
46
+ /**
47
+ * Convert a string to "dot.case".
48
+ * @example
49
+ * dotCase('foo bar'); //=> 'foo.bar'
50
+ * dotCase('foo_bar'); //=> 'foo.bar'
51
+ * dotCase('foo-bar'); //=> 'foo.bar'
52
+ * dotCase('foo.bar'); //=> 'foo.bar'
53
+ * dotCase('fooBar'); //=> 'foo.bar'
54
+ * dotCase('FooBar'); //=> 'foo.bar'
55
+ **/
56
+ declare const dotCase: (input: string) => string;
57
+ /**
58
+ * Convert a string to snake_case.
59
+ * @example
60
+ * snakeCase('foo bar'); //=> 'foo_bar'
61
+ * snakeCase('foo_bar'); //=> 'foo_bar'
62
+ * snakeCase('foo-bar'); //=> 'foo_bar'
63
+ * snakeCase('foo.bar'); //=> 'foo_bar'
64
+ * snakeCase('fooBar'); //=> 'foo_bar'
65
+ * snakeCase('FooBar'); //=> 'foo_bar'
66
+ **/
67
+ declare const snakeCase: (input: string) => string;
68
+ /**
69
+ * Convert a string to CONSTANT_CASE.
70
+ * @example
71
+ * constantCase('foo bar'); //=> 'FOO_BAR'
72
+ * constantCase('foo_bar'); //=> 'FOO_BAR'
73
+ * constantCase('foo-bar'); //=> 'FOO_BAR'
74
+ * constantCase('foo.bar'); //=> 'FOO_BAR'
75
+ * constantCase('fooBar'); //=> 'FOO_BAR'
76
+ * constantCase('FooBar'); //=> 'FOO_BAR'
77
+ **/
78
+ declare const constantCase: (input: string) => string;
79
+ /**
80
+ * Convert a string to sentence.
81
+ * @deprecated use sentenceCase instead
82
+ * @example
83
+ * toSentence('foo bar'); //=> 'Foo bar'
84
+ * toSentence('foo_bar'); //=> 'Foo bar'
85
+ * toSentence('foo-bar'); //=> 'Foo bar'
86
+ * toSentence('foo.bar'); //=> 'Foo bar'
87
+ * toSentence('fooBar'); //=> 'Foo bar'
88
+ * toSentence('FooBar'); //=> 'Foo bar'
89
+ * toSentence('foo bar baz'); //=> 'Foo bar baz'
90
+ **/
91
+ declare const toSentence: (input: string) => string;
92
+ /**
93
+ * Convert a string to sentence.
94
+ * @example
95
+ * sentenceCase('foo bar'); //=> 'Foo bar'
96
+ * sentenceCase('foo_bar'); //=> 'Foo bar'
97
+ * sentenceCase('foo-bar'); //=> 'Foo bar'
98
+ * sentenceCase('foo.bar'); //=> 'Foo bar'
99
+ * sentenceCase('fooBar'); //=> 'Foo bar'
100
+ * sentenceCase('FooBar'); //=> 'Foo bar'
101
+ * sentenceCase('foo bar baz'); //=> 'Foo bar baz'
102
+ **/
103
+ declare const sentenceCase: (input: string) => string;
104
+ /**
105
+ * Convert a string to upper cased sentence.
106
+ * @deprecated use capitalCase instead
107
+ * @example
108
+ * toUcSentence('foo bar'); //=> 'Foo Bar'
109
+ * toUcSentence('foo_bar'); //=> 'Foo Bar'
110
+ * toUcSentence('foo-bar'); //=> 'Foo Bar'
111
+ * toUcSentence('foo.bar'); //=> 'Foo Bar'
112
+ * toUcSentence('fooBar'); //=> 'Foo Bar'
113
+ * toUcSentence('FooBar'); //=> 'Foo Bar'
114
+ * toUcSentence('foo bar baz'); //=> 'Foo Bar Baz'
115
+ **/
116
+ declare const toUcSentence: (input: string) => string;
117
+ /**
118
+ * Convert a string to upper cased sentence.
119
+ * @example
120
+ * capitalCase('foo bar'); //=> 'Foo Bar'
121
+ * capitalCase('foo_bar'); //=> 'Foo Bar'
122
+ * capitalCase('foo-bar'); //=> 'Foo Bar'
123
+ * capitalCase('foo.bar'); //=> 'Foo Bar'
124
+ * capitalCase('fooBar'); //=> 'Foo Bar'
125
+ * capitalCase('FooBar'); //=> 'Foo Bar'
126
+ * capitalCase('foo bar baz'); //=> 'Foo Bar Baz'
127
+ **/
128
+ declare const capitalCase: (input: string) => string;
129
+ /**
130
+ * Alias to "toUcSentence"
131
+ * @deprecated use capitalCase instead
132
+ **/
133
+ declare const capitalize: (input: string) => string;
134
+ /**
135
+ * Convert a string to lower cased sentence.
136
+ * @deprecated use lowerSentenceCase instead
137
+ * @example
138
+ * toLcSentence('foo bar'); //=> 'foo bar'
139
+ * toLcSentence('foo_bar'); //=> 'foo bar'
140
+ * toLcSentence('foo-bar'); //=> 'foo bar'
141
+ * toLcSentence('foo.bar'); //=> 'foo bar'
142
+ * toLcSentence('fooBar'); //=> 'foo bar'
143
+ * toLcSentence('FooBar'); //=> 'foo bar'
144
+ * toLcSentence('Foo bar baz'); //=> 'foo bar baz'
145
+ **/
146
+ declare const toLcSentence: (input: string) => string;
147
+ /**
148
+ * Convert a string to lower cased sentence.
149
+ * @example
150
+ * lowerSentenceCase('foo bar'); //=> 'foo bar'
151
+ * lowerSentenceCase('foo_bar'); //=> 'foo bar'
152
+ * lowerSentenceCase('foo-bar'); //=> 'foo bar'
153
+ * lowerSentenceCase('foo.bar'); //=> 'foo bar'
154
+ * lowerSentenceCase('fooBar'); //=> 'foo bar'
155
+ * lowerSentenceCase('FooBar'); //=> 'foo bar'
156
+ * lowerSentenceCase('Foo bar baz'); //=> 'foo bar baz'
157
+ **/
158
+ declare const lowerSentenceCase: (input: string) => string;
159
+ /**
160
+ * Convert a table name to sql alias.
161
+ * @example
162
+ * toSqlAlias('foo bar'); //=> 'fb'
163
+ * toSqlAlias('book'); //=> 'b'
164
+ * toSqlAlias('article-category'); //=> 'ac'
165
+ **/
166
+ declare const toSqlAlias: (input: string) => string;
167
+ interface ToAbbreviationOptions {
168
+ maxLength?: number;
169
+ minLength?: number;
170
+ lang?: 'uk' | 'ru' | 'mn';
171
+ iteration?: number;
172
+ }
173
+ /**
174
+ * Remove vowels from a word.
175
+ * @param word - word to remove vowels from
176
+ * @returns word without vowels
177
+ * @example
178
+ * removeVowels('foo'); //=> 'f'
179
+ */
180
+ declare const removeVowels: (word: string) => string;
181
+ /**
182
+ * Convert a string to abbreviation.
183
+ * @example
184
+ * toAbbreviation('Sabbath Schook'); //=> 'SB'
185
+ * toAbbreviation('Рожеві окуляри', {
186
+ * lang: 'uk',
187
+ * }); //=> 'RO'
188
+ * toAbbreviation('Удивительные факты', {
189
+ * lang: 'ru',
190
+ * }); //=> 'UF'
191
+ */
192
+ declare const toAbbreviation: (input: string, opts?: ToAbbreviationOptions) => string;
193
+ //#endregion
194
+ //#region src/declination.d.ts
195
+ /**
196
+ * Decline a noun based on a number.
197
+ * @example
198
+ * const words = ['элемент', 'элемента', 'элементов'];
199
+ *
200
+ * decline(0, words, false) // => 'элементов'
201
+ * decline(24, words, false) // => 'элемента'
202
+ * decline(21, words, false) // => 'элемент'
203
+ *
204
+ * decline(0, words) // => '0 элементов'
205
+ * decline(24, words) // => '24 элемента'
206
+ * decline(21, words) // => '21 элемент'
207
+ */
208
+ declare const decline: (n: number, words: string[], concat?: boolean) => string;
209
+ //#endregion
210
+ //#region src/generators.d.ts
211
+ declare const createRandomString: (size?: number) => string;
212
+ declare const createRandomAbbreviationString: (size?: number) => string;
213
+ declare const createNumericCode: (num: number, length: number) => string;
214
+ //#endregion
215
+ //#region src/pluralize.d.ts
216
+ /**
217
+ * Change the plural form of a word to its singular form.
218
+ * @example
219
+ * pluralToSingular('books'); //=> 'book'
220
+ */
221
+ declare const singularToPlural: (input: string) => string;
222
+ /**
223
+ * Change the singular form of a word to its plural form.
224
+ * @example
225
+ * singularToPlural('book'); //=> 'books'
226
+ */
227
+ declare const pluralToSingular: (input: string) => string;
228
+ /**
229
+ * Checks if a given word is in its plural form.
230
+ *
231
+ * @param word - The word to check for plural form
232
+ * @returns `true` if the word is plural, `false` if it's singular
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * isPlural("cats"); // true
237
+ * isPlural("cat"); // false
238
+ * ```
239
+ */
240
+ declare const isPlural: (word: string) => boolean;
241
+ //#endregion
242
+ export { ToAbbreviationOptions, camelCase, capitalCase, capitalize, constantCase, createNumericCode, createRandomAbbreviationString, createRandomString, decline, dotCase, isPlural, lcfirst, lowerSentenceCase, paramCase, pascalCase, pluralToSingular, removeVowels, sentenceCase, singularToPlural, snakeCase, toAbbreviation, toLcSentence, toSentence, toSqlAlias, toUcSentence, ucfirst };
243
+ //# sourceMappingURL=index.d.ts.map