Skip to content

Commit 0b9dc9d

Browse files
committed
fixup! feat: add more utility methods
1 parent 8d82841 commit 0b9dc9d

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

src/utils/string.utils.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,12 @@ export function toPascalCase(str: string): string {
7575
* @returns {string} The snake_cased string.
7676
*/
7777
export function toSnakeCase(str: string): string {
78-
// Count leading and trailing spaces
79-
const leadingSpaces = (str.match(/^(\s+)/) || [""])[0].length;
80-
const trailingSpaces = (str.match(/(\s+)$/) || [""])[0].length;
81-
// Remove leading/trailing spaces for main conversion
82-
const trimmed = str.trim();
83-
// Convert to snake_case
84-
let result = trimmed
85-
.replace(/([a-z])([A-Z])/g, "$1_$2")
86-
.replace(/\s+/g, "_")
87-
.replace(/-+/g, "_")
78+
return str
79+
.trim()
80+
.replace(/([a-z])([A-Z])/g, "$1_$2") // camelCase -> camel_Case
81+
.replace(/\s+/g, "_") // spaces to underscore
82+
.replace(/-+/g, "_") // dashes to underscore
8883
.toLowerCase();
89-
// Add underscores for each leading/trailing space (match test expectation)
90-
result = "_".repeat(leadingSpaces) + result + "_".repeat(trailingSpaces);
91-
return result;
9284
}
9385

9486
/**

src/utils/validate.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ export function isCreditCard(str: string): boolean {
238238
* @param {string} str - The input string.
239239
* @returns {boolean} True if valid JSON.
240240
*/
241-
export function isJSON(str: string): boolean {
241+
export function isValidJSON(str: string): boolean {
242242
try {
243-
const result = JSON.parse(str);
244-
return !!result && typeof result === "object";
243+
JSON.parse(str);
244+
return true;
245245
} catch {
246246
return false;
247247
}

0 commit comments

Comments
 (0)