File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,20 +75,12 @@ export function toPascalCase(str: string): string {
7575 * @returns {string } The snake_cased string.
7676 */
7777export 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/**
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments