@ix-xs/node-comfort 1.1.3 → 1.2.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,396 @@
1
+ export = SQLite;
2
+ declare class SQLite {
3
+ /**
4
+ * Creates a new SQLite database connection.
5
+ *
6
+ * The database file and its parent folders are created if necessary.
7
+ * WAL journal mode and foreign key support are enabled automatically.
8
+ *
9
+ * Pass `":memory:"` to create a transient in-memory database.
10
+ *
11
+ * @param {string} [path="db.sqlite"] - Path to the SQLite database file.
12
+ *
13
+ * @example
14
+ * const db = new SQLite();
15
+ *
16
+ * @example
17
+ * const db = new SQLite("data/my-app.sqlite");
18
+ *
19
+ * @example
20
+ * const db = new SQLite(":memory:");
21
+ */
22
+ constructor(path?: string);
23
+ /**
24
+ * Executes a raw SQL statement using `run()`.
25
+ *
26
+ * Use this for custom SQL that is not covered by the helper methods.
27
+ * This method is intended for statements such as:
28
+ * - `INSERT`
29
+ * - `UPDATE`
30
+ * - `DELETE`
31
+ * - `CREATE INDEX`
32
+ * - PRAGMA writes
33
+ *
34
+ * @param {string} sql - SQL statement.
35
+ * @param {any[]|any} [params=[]] - Parameters to bind.
36
+ * @returns {Promise<{ changes: number, lastInsertRowid: bigint|number } | { error: string }>}
37
+ */
38
+ exec(sql: string, params?: any[] | any): Promise<{
39
+ changes: number;
40
+ lastInsertRowid: bigint | number;
41
+ } | {
42
+ error: string;
43
+ }>;
44
+ /**
45
+ * Executes a raw SQL query and returns the first row.
46
+ *
47
+ * @param {string} sql - SQL query.
48
+ * @param {any[]|any} [params=[]] - Parameters to bind.
49
+ * @returns {Promise<object|undefined|{ error: string }>}
50
+ */
51
+ queryOne(sql: string, params?: any[] | any): Promise<object | undefined | {
52
+ error: string;
53
+ }>;
54
+ /**
55
+ * Executes a raw SQL query and returns all rows.
56
+ *
57
+ * @param {string} sql - SQL query.
58
+ * @param {any[]|any} [params=[]] - Parameters to bind.
59
+ * @returns {Promise<object[]|{ error: string }>}
60
+ */
61
+ queryAll(sql: string, params?: any[] | any): Promise<object[] | {
62
+ error: string;
63
+ }>;
64
+ /**
65
+ * Creates a table and stores its schema in memory.
66
+ *
67
+ * This method supports both the new `columns` property and the legacy
68
+ * `options` property for backward compatibility.
69
+ *
70
+ * @param {{
71
+ * name: string,
72
+ * columns?: Record<string, {
73
+ * type: "INTEGER"|"TEXT"|"REAL"|"BLOB"|"NUMERIC",
74
+ * primaryKey?: boolean,
75
+ * autoincrement?: boolean,
76
+ * notNull?: boolean,
77
+ * unique?: boolean,
78
+ * defaultValue?: any,
79
+ * values?: any[],
80
+ * references?: { table: string, column: string },
81
+ * onDelete?: string,
82
+ * onUpdate?: string
83
+ * }>,
84
+ * options?: Record<string, any>,
85
+ * constraints?: Array<
86
+ * | { type: "unique", columns: string[] }
87
+ * | { type: "primaryKey", columns: string[] }
88
+ * | { type: "check", expression: string }
89
+ * | {
90
+ * type: "foreignKey",
91
+ * columns: string[],
92
+ * references: { table: string, columns: string[] },
93
+ * onDelete?: string,
94
+ * onUpdate?: string
95
+ * }
96
+ * >,
97
+ * indexes?: Array<{
98
+ * name?: string,
99
+ * columns: string[],
100
+ * unique?: boolean
101
+ * }>
102
+ * }} table - Table definition.
103
+ * @returns {Promise<{ ok: true } | { error: string }>}
104
+ *
105
+ * @example
106
+ * await db.createTable({
107
+ * name: "Post",
108
+ * columns: {
109
+ * id: { type: "INTEGER", primaryKey: true, autoincrement: true },
110
+ * userId: {
111
+ * type: "INTEGER",
112
+ * notNull: true,
113
+ * references: { table: "User", column: "id" },
114
+ * onDelete: "CASCADE"
115
+ * },
116
+ * title: { type: "TEXT", notNull: true }
117
+ * },
118
+ * indexes: [{ columns: ["userId"] }]
119
+ * });
120
+ */
121
+ createTable(table: {
122
+ name: string;
123
+ columns?: Record<string, {
124
+ type: "INTEGER" | "TEXT" | "REAL" | "BLOB" | "NUMERIC";
125
+ primaryKey?: boolean;
126
+ autoincrement?: boolean;
127
+ notNull?: boolean;
128
+ unique?: boolean;
129
+ defaultValue?: any;
130
+ values?: any[];
131
+ references?: {
132
+ table: string;
133
+ column: string;
134
+ };
135
+ onDelete?: string;
136
+ onUpdate?: string;
137
+ }>;
138
+ options?: Record<string, any>;
139
+ constraints?: Array<{
140
+ type: "unique";
141
+ columns: string[];
142
+ } | {
143
+ type: "primaryKey";
144
+ columns: string[];
145
+ } | {
146
+ type: "check";
147
+ expression: string;
148
+ } | {
149
+ type: "foreignKey";
150
+ columns: string[];
151
+ references: {
152
+ table: string;
153
+ columns: string[];
154
+ };
155
+ onDelete?: string;
156
+ onUpdate?: string;
157
+ }>;
158
+ indexes?: Array<{
159
+ name?: string;
160
+ columns: string[];
161
+ unique?: boolean;
162
+ }>;
163
+ }): Promise<{
164
+ ok: true;
165
+ } | {
166
+ error: string;
167
+ }>;
168
+ /**
169
+ * Creates an index on an existing table.
170
+ *
171
+ * Composite indexes are supported by passing multiple columns.
172
+ *
173
+ * @param {string} tableName - Table name.
174
+ * @param {{
175
+ * name?: string,
176
+ * columns: string[],
177
+ * unique?: boolean
178
+ * }} index - Index definition.
179
+ * @returns {Promise<{ ok: true } | { error: string }>}
180
+ *
181
+ * @example
182
+ * await db.createIndex("UserAuthMethod", {
183
+ * columns: ["provider", "providerUserId"],
184
+ * unique: true
185
+ * });
186
+ */
187
+ createIndex(tableName: string, index: {
188
+ name?: string;
189
+ columns: string[];
190
+ unique?: boolean;
191
+ }): Promise<{
192
+ ok: true;
193
+ } | {
194
+ error: string;
195
+ }>;
196
+ /**
197
+ * Drops a table and removes its model definition.
198
+ *
199
+ * @param {string} tableName - Table name.
200
+ * @returns {Promise<{ ok: true } | { error: string }>}
201
+ */
202
+ deleteTable(tableName: string): Promise<{
203
+ ok: true;
204
+ } | {
205
+ error: string;
206
+ }>;
207
+ /**
208
+ * Deletes all rows from a table.
209
+ *
210
+ * @param {string} tableName - Table name.
211
+ * @returns {Promise<{ ok: true } | { error: string }>}
212
+ */
213
+ clearTable(tableName: string): Promise<{
214
+ ok: true;
215
+ } | {
216
+ error: string;
217
+ }>;
218
+ /**
219
+ * Returns a single row matching a plain-object WHERE clause.
220
+ *
221
+ * @param {string} tableName - Table name.
222
+ * @param {Record<string, any>} [where={}] - Conditions.
223
+ * @returns {Promise<object|undefined|{ error: string }>}
224
+ */
225
+ get(tableName: string, where?: Record<string, any>): Promise<object | undefined | {
226
+ error: string;
227
+ }>;
228
+ /**
229
+ * Returns multiple rows from a table.
230
+ *
231
+ * Supports:
232
+ * - exact-match filters via `where`
233
+ * - custom ordering
234
+ * - pagination via `limit` and `offset`
235
+ *
236
+ * @param {string} tableName - Table name.
237
+ * @param {Record<string, any>} [where={}] - Exact-match conditions.
238
+ * @param {{
239
+ * limit?: number,
240
+ * offset?: number,
241
+ * orderBy?: string,
242
+ * direction?: "ASC"|"DESC"
243
+ * }} [options={}] - Query options.
244
+ * @returns {Promise<object[] | { error: string }>}
245
+ *
246
+ * @example
247
+ * const posts = await db.getAll("Post", { userId: 1 }, {
248
+ * limit: 20,
249
+ * offset: 0,
250
+ * orderBy: "createdAt",
251
+ * direction: "DESC"
252
+ * });
253
+ */
254
+ getAll(tableName: string, where?: Record<string, any>, options?: {
255
+ limit?: number;
256
+ offset?: number;
257
+ orderBy?: string;
258
+ direction?: "ASC" | "DESC";
259
+ }): Promise<object[] | {
260
+ error: string;
261
+ }>;
262
+ /**
263
+ * Inserts a new row into a table.
264
+ *
265
+ * This method performs a plain `INSERT`.
266
+ * If a unique constraint is violated, SQLite will throw an error.
267
+ *
268
+ * @param {string} tableName - Table name.
269
+ * @param {Record<string, any>} data - Row to insert.
270
+ * @returns {Promise<{ ok: true, lastInsertRowid: bigint|number, changes: number } | { error: string }>}
271
+ */
272
+ insert(tableName: string, data: Record<string, any>): Promise<{
273
+ ok: true;
274
+ lastInsertRowid: bigint | number;
275
+ changes: number;
276
+ } | {
277
+ error: string;
278
+ }>;
279
+ /**
280
+ * Updates one or more rows matching a WHERE clause.
281
+ *
282
+ * This method performs a plain `UPDATE`.
283
+ *
284
+ * @param {string} tableName - Table name.
285
+ * @param {Record<string, any>} data - Fields to update.
286
+ * @param {Record<string, any>} where - Conditions used to select rows.
287
+ * @returns {Promise<{ ok: true, changes: number } | { error: string }>}
288
+ */
289
+ update(tableName: string, data: Record<string, any>, where: Record<string, any>): Promise<{
290
+ ok: true;
291
+ changes: number;
292
+ } | {
293
+ error: string;
294
+ }>;
295
+ /**
296
+ * Inserts or updates a row using SQLite `ON CONFLICT DO UPDATE`.
297
+ *
298
+ * This is safer than `INSERT OR REPLACE` because it does not delete
299
+ * and recreate the row.
300
+ *
301
+ * @param {string} tableName - Table name.
302
+ * @param {Record<string, any>} data - Row data.
303
+ * @param {string[]} conflict - Columns that define the conflict target.
304
+ * @returns {Promise<{ ok: true, changes: number, lastInsertRowid: bigint|number } | { error: string }>}
305
+ *
306
+ * @example
307
+ * await db.upsert("UserAuthMethod", {
308
+ * userId: 1,
309
+ * provider: "google",
310
+ * providerUserId: "123"
311
+ * }, ["provider", "providerUserId"]);
312
+ */
313
+ upsert(tableName: string, data: Record<string, any>, conflict?: string[]): Promise<{
314
+ ok: true;
315
+ changes: number;
316
+ lastInsertRowid: bigint | number;
317
+ } | {
318
+ error: string;
319
+ }>;
320
+ /**
321
+ * Backward-compatible helper that inserts or updates a row.
322
+ *
323
+ * Behavior:
324
+ * - If `where` is provided, the existing row is loaded and merged with `data`,
325
+ * then updated if found or inserted if not found.
326
+ * - If `where` is not provided but `data.id` exists, lookup is performed on `id`.
327
+ * - If no existing row is found, a new row is inserted.
328
+ *
329
+ * This method is intentionally simple, but for production-grade control,
330
+ * prefer using `insert()`, `update()`, or `upsert()`.
331
+ *
332
+ * @param {string} tableName - Table name.
333
+ * @param {Record<string, any>} data - Row data.
334
+ * @param {Record<string, any>|null} [where=null] - Lookup condition.
335
+ * @returns {Promise<{ ok: true } | { error: string }>}
336
+ */
337
+ set(tableName: string, data: Record<string, any>, where?: Record<string, any> | null): Promise<{
338
+ ok: true;
339
+ } | {
340
+ error: string;
341
+ }>;
342
+ /**
343
+ * Deletes rows matching a WHERE clause.
344
+ *
345
+ * @param {string} tableName - Table name.
346
+ * @param {Record<string, any>} where - Conditions.
347
+ * @returns {Promise<{ ok: true, changes: number } | { error: string }>}
348
+ */
349
+ delete(tableName: string, where: Record<string, any>): Promise<{
350
+ ok: true;
351
+ changes: number;
352
+ } | {
353
+ error: string;
354
+ }>;
355
+ /**
356
+ * Counts rows matching a WHERE clause.
357
+ *
358
+ * @param {string} tableName - Table name.
359
+ * @param {Record<string, any>} [where={}] - Conditions.
360
+ * @returns {Promise<number | { error: string }>}
361
+ */
362
+ count(tableName: string, where?: Record<string, any>): Promise<number | {
363
+ error: string;
364
+ }>;
365
+ /**
366
+ * Runs multiple operations inside a transaction.
367
+ *
368
+ * If the callback throws, the transaction is rolled back.
369
+ * If the callback completes successfully, the transaction is committed.
370
+ *
371
+ * The callback may be synchronous or asynchronous.
372
+ *
373
+ * @template T
374
+ * @param {() => T|Promise<T>} callback - Function to execute inside the transaction.
375
+ * @returns {Promise<T | { error: string }>}
376
+ *
377
+ * @example
378
+ * const result = await db.transaction(async () => {
379
+ * await db.insert("User", { email: "a@b.com", createdAt: Date.now() });
380
+ * await db.insert("Profile", { userId: 1, nickname: "John" });
381
+ * return { ok: true };
382
+ * });
383
+ */
384
+ transaction<T>(callback: () => T | Promise<T>): Promise<T | {
385
+ error: string;
386
+ }>;
387
+ /**
388
+ * Closes the underlying SQLite connection.
389
+ *
390
+ * @example
391
+ * db.close();
392
+ */
393
+ close(): void;
394
+ #private;
395
+ }
396
+ //# sourceMappingURL=SQLite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SQLite.d.ts","sourceRoot":"","sources":["../../src/SQLite.js"],"names":[],"mappings":";AA2DiB;IAef;;;;;;;;;;;;;;;;;;OAkBG;IACH,mBAXW,MAAM,EA2BhB;IA8TD;;;;;;;;;;;;;;OAcG;IACH,UAJW,MAAM,WACN,GAAG,EAAE,GAAC,G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AO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,GAAC,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CA2CtG;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,eALW,MAAM,QACN,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,UACnB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAC,IAAI,GACtB,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAiCrD;IAED;;;;;;OAMG;IACH,kBAJW,MAAM,SACN,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAsBtE;IAED;;;;;;OAMG;IACH,iBAJW,MAAM,UACN,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,OAAO,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAmB/C;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAXa,CAAC,YACH,MAAM,CAAC,GAAC,OAAO,CAAC,CAAC,CAAC,GAChB,OAAO,CAAC,CAAC,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAwB1C;IAED;;;;;OAKG;IACH,cAIC;;CACF"}
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Capitalizes the first character of a string and lowercases the rest.
3
+ *
4
+ * @example
5
+ * nodeComfort.str.capitalize("hELLO"); // "Hello"
6
+ *
7
+ * @param {string} str - Input string.
8
+ * @returns {string} The capitalized string.
9
+ */
10
+ export function capitalize(str: string): string;
11
+ /**
12
+ * Uppercases the first character of each word (Title Case), leaving the rest untouched.
13
+ *
14
+ * @example
15
+ * nodeComfort.str.titleCase("the quick brown fox"); // "The Quick Brown Fox"
16
+ *
17
+ * @param {string} str - Input string.
18
+ * @returns {string} The title-cased string.
19
+ */
20
+ export function titleCase(str: string): string;
21
+ /**
22
+ * Converts a string to `camelCase`.
23
+ *
24
+ * @example
25
+ * nodeComfort.str.camelCase("hello world"); // "helloWorld"
26
+ * nodeComfort.str.camelCase("foo-bar_baz"); // "fooBarBaz"
27
+ *
28
+ * @param {string} str - Input string.
29
+ * @returns {string} The camelCased string.
30
+ */
31
+ export function camelCase(str: string): string;
32
+ /**
33
+ * Converts a string to `PascalCase`.
34
+ *
35
+ * @example
36
+ * nodeComfort.str.pascalCase("hello world"); // "HelloWorld"
37
+ *
38
+ * @param {string} str - Input string.
39
+ * @returns {string} The PascalCased string.
40
+ */
41
+ export function pascalCase(str: string): string;
42
+ /**
43
+ * Converts a string to `snake_case`.
44
+ *
45
+ * @example
46
+ * nodeComfort.str.snakeCase("helloWorld"); // "hello_world"
47
+ *
48
+ * @param {string} str - Input string.
49
+ * @returns {string} The snake_cased string.
50
+ */
51
+ export function snakeCase(str: string): string;
52
+ /**
53
+ * Converts a string to `kebab-case`.
54
+ *
55
+ * @example
56
+ * nodeComfort.str.kebabCase("helloWorld"); // "hello-world"
57
+ *
58
+ * @param {string} str - Input string.
59
+ * @returns {string} The kebab-cased string.
60
+ */
61
+ export function kebabCase(str: string): string;
62
+ /**
63
+ * Converts a string to `CONSTANT_CASE`.
64
+ *
65
+ * @example
66
+ * nodeComfort.str.constantCase("helloWorld"); // "HELLO_WORLD"
67
+ *
68
+ * @param {string} str - Input string.
69
+ * @returns {string} The CONSTANT_CASED string.
70
+ */
71
+ export function constantCase(str: string): string;
72
+ /**
73
+ * Converts a string into a URL-friendly slug.
74
+ *
75
+ * Accents/diacritics are stripped, non-alphanumeric runs become the separator.
76
+ *
77
+ * @example
78
+ * nodeComfort.str.slugify("Héllo, World!"); // "hello-world"
79
+ * nodeComfort.str.slugify("A B C", { separator: "_" }); // "a_b_c"
80
+ *
81
+ * @param {string} str - Input string.
82
+ * @param {{ separator?: string, lower?: boolean }} [options] - Slug options.
83
+ * @returns {string} The slug.
84
+ */
85
+ export function slugify(str: string, options?: {
86
+ separator?: string;
87
+ lower?: boolean;
88
+ }): string;
89
+ /**
90
+ * Truncates a string to a maximum length, appending an ellipsis if cut.
91
+ *
92
+ * @example
93
+ * nodeComfort.str.truncate("Hello world", 8); // "Hello…"
94
+ * nodeComfort.str.truncate("Hello world", 8, { omission: "..." }); // "Hello..."
95
+ *
96
+ * @param {string} str - Input string.
97
+ * @param {number} length - Maximum length of the result (including the omission).
98
+ * @param {{ omission?: string, words?: boolean }} [options] - Truncation options.
99
+ * @returns {string} The truncated string.
100
+ */
101
+ export function truncate(str: string, length: number, options?: {
102
+ omission?: string;
103
+ words?: boolean;
104
+ }): string;
105
+ /**
106
+ * Pads a string on the left (start) to a target length.
107
+ *
108
+ * @param {string} str - Input string.
109
+ * @param {number} length - Target total length.
110
+ * @param {string} [char=" "] - Padding character(s).
111
+ * @returns {string} The padded string.
112
+ */
113
+ export function padStart(str: string, length: number, char?: string): string;
114
+ /**
115
+ * Pads a string on the right (end) to a target length.
116
+ *
117
+ * @param {string} str - Input string.
118
+ * @param {number} length - Target total length.
119
+ * @param {string} [char=" "] - Padding character(s).
120
+ * @returns {string} The padded string.
121
+ */
122
+ export function padEnd(str: string, length: number, char?: string): string;
123
+ /**
124
+ * Centers a string within a target length by padding both sides.
125
+ *
126
+ * @example
127
+ * nodeComfort.str.center("hi", 6); // " hi "
128
+ * nodeComfort.str.center("hi", 6, "*"); // "**hi**"
129
+ *
130
+ * @param {string} str - Input string.
131
+ * @param {number} length - Target total length.
132
+ * @param {string} [char=" "] - Padding character.
133
+ * @returns {string} The centered string.
134
+ */
135
+ export function center(str: string, length: number, char?: string): string;
136
+ /**
137
+ * Reverses a string (Unicode code-point aware, so emojis stay intact).
138
+ *
139
+ * @example
140
+ * nodeComfort.str.reverse("abc"); // "cba"
141
+ *
142
+ * @param {string} str - Input string.
143
+ * @returns {string} The reversed string.
144
+ */
145
+ export function reverse(str: string): string;
146
+ /**
147
+ * Collapses all runs of whitespace into single spaces and trims the ends.
148
+ *
149
+ * @example
150
+ * nodeComfort.str.squish(" hello world \n"); // "hello world"
151
+ *
152
+ * @param {string} str - Input string.
153
+ * @returns {string} The normalized string.
154
+ */
155
+ export function squish(str: string): string;
156
+ /**
157
+ * Removes all HTML tags from a string.
158
+ *
159
+ * @example
160
+ * nodeComfort.str.stripTags("<b>Hi</b> there"); // "Hi there"
161
+ *
162
+ * @param {string} str - Input string.
163
+ * @returns {string} The string with tags removed.
164
+ */
165
+ export function stripTags(str: string): string;
166
+ /**
167
+ * Escapes HTML-sensitive characters (`& < > " '`).
168
+ *
169
+ * @example
170
+ * nodeComfort.str.escapeHTML('<a href="x">'); // "&lt;a href=&quot;x&quot;&gt;"
171
+ *
172
+ * @param {string} str - Input string.
173
+ * @returns {string} The escaped string.
174
+ */
175
+ export function escapeHTML(str: string): string;
176
+ /**
177
+ * Reverses {@link escapeHTML}: turns HTML entities back into characters.
178
+ *
179
+ * @param {string} str - Input string.
180
+ * @returns {string} The unescaped string.
181
+ */
182
+ export function unescapeHTML(str: string): string;
183
+ /**
184
+ * Escapes a string for safe use inside a `RegExp`.
185
+ *
186
+ * @example
187
+ * new RegExp(nodeComfort.str.escapeRegExp("a.b")); // matches literal "a.b"
188
+ *
189
+ * @param {string} str - Input string.
190
+ * @returns {string} The escaped string.
191
+ */
192
+ export function escapeRegExp(str: string): string;
193
+ /**
194
+ * Counts the number of non-overlapping occurrences of a substring.
195
+ *
196
+ * @example
197
+ * nodeComfort.str.count("banana", "a"); // 3
198
+ *
199
+ * @param {string} str - Input string.
200
+ * @param {string} sub - Substring to count.
201
+ * @returns {number} Number of occurrences.
202
+ */
203
+ export function count(str: string, sub: string): number;
204
+ /**
205
+ * Ensures a string starts with a given prefix (adds it only if missing).
206
+ *
207
+ * @example
208
+ * nodeComfort.str.ensurePrefix("example.com", "https://"); // "https://example.com"
209
+ *
210
+ * @param {string} str - Input string.
211
+ * @param {string} prefix - Prefix to ensure.
212
+ * @returns {string} The string with the prefix guaranteed.
213
+ */
214
+ export function ensurePrefix(str: string, prefix: string): string;
215
+ /**
216
+ * Ensures a string ends with a given suffix (adds it only if missing).
217
+ *
218
+ * @example
219
+ * nodeComfort.str.ensureSuffix("path", "/"); // "path/"
220
+ *
221
+ * @param {string} str - Input string.
222
+ * @param {string} suffix - Suffix to ensure.
223
+ * @returns {string} The string with the suffix guaranteed.
224
+ */
225
+ export function ensureSuffix(str: string, suffix: string): string;
226
+ /**
227
+ * Removes a prefix from a string if present.
228
+ *
229
+ * @param {string} str - Input string.
230
+ * @param {string} prefix - Prefix to remove.
231
+ * @returns {string} The string without the prefix.
232
+ */
233
+ export function removePrefix(str: string, prefix: string): string;
234
+ /**
235
+ * Removes a suffix from a string if present.
236
+ *
237
+ * @param {string} str - Input string.
238
+ * @param {string} suffix - Suffix to remove.
239
+ * @returns {string} The string without the suffix.
240
+ */
241
+ export function removeSuffix(str: string, suffix: string): string;
242
+ /**
243
+ * Renders a template, replacing `{key}` placeholders with values from `data`.
244
+ *
245
+ * Missing keys are left as-is by default. Nested paths (`{user.name}`) are supported.
246
+ *
247
+ * @example
248
+ * nodeComfort.str.template("Hi {name}, you have {count} msgs", { name: "Jo", count: 3 });
249
+ * // "Hi Jo, you have 3 msgs"
250
+ *
251
+ * @param {string} str - Template string.
252
+ * @param {Record<string, any>} data - Replacement values.
253
+ * @param {{ open?: string, close?: string, fallback?: string }} [options] - Delimiters / fallback.
254
+ * @returns {string} The rendered string.
255
+ */
256
+ export function template(str: string, data: Record<string, any>, options?: {
257
+ open?: string;
258
+ close?: string;
259
+ fallback?: string;
260
+ }): string;
261
+ /**
262
+ * Splits a string into an array of "words" (camelCase / snake / kebab aware).
263
+ *
264
+ * @example
265
+ * nodeComfort.str.words("helloWorld-foo_bar"); // ["hello", "World", "foo", "bar"]
266
+ *
267
+ * @param {string} str - Input string.
268
+ * @returns {string[]} The words.
269
+ */
270
+ export function words(str: string): string[];
271
+ /**
272
+ * Returns the visible length of a string in code points (emoji-safe).
273
+ *
274
+ * @example
275
+ * "😀".length; // 2
276
+ * nodeComfort.str.length("😀"); // 1
277
+ *
278
+ * @param {string} str - Input string.
279
+ * @returns {number} The number of code points.
280
+ */
281
+ export function length(str: string): number;
282
+ /**
283
+ * Generates a random alphanumeric string of a given length.
284
+ *
285
+ * Note: uses `Math.random` and is **not** cryptographically secure.
286
+ * For tokens/IDs use `nodeComfort.id.token()` instead.
287
+ *
288
+ * @param {number} [length=16] - Desired length.
289
+ * @param {string} [charset] - Characters to pick from.
290
+ * @returns {string} The random string.
291
+ */
292
+ export function random(length?: number, charset?: string): string;
293
+ //# sourceMappingURL=Str.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Str.d.ts","sourceRoot":"","sources":["../../src/Str.js"],"names":[],"mappings":"AA2BE;;;;;;;;GAQG;AACH,gCAHW,MAAM,GACJ,MAAM,CAMlB;AAED;;;;;;;;GAQG;AACH,+BAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;;;;GASG;AACH,+BAHW,MAAM,GACJ,MAAM,CAUlB;AAED;;;;;;;;GAQG;AACH,gCAHW,MAAM,GACJ,MAAM,CAMlB;AAED;;;;;;;;GAQG;AACH,+BAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;;;GAQG;AACH,+BAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;;;GAQG;AACH,kCAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;;;;;;;GAYG;AACH,6BAJW,MAAM,YACN;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACrC,MAAM,CAYlB;AAED;;;;;;;;;;;GAWG;AACH,8BALW,MAAM,UACN,MAAM,YACN;IAAE,QA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