File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 99
1010import isPlainObject from 'lodash/isPlainObject' ;
1111import { wasmLog as log } from './util/log' ;
12- import { isObject , snakeKeysToCamel } from './util/objects' ;
12+ import { isObject , camelKeysToSnake , snakeKeysToCamel } from './util/objects' ;
1313import { LndApi , LoopApi , PoolApi , FaradayApi } from './api' ;
1414import {
1515 createTestCipher ,
@@ -206,7 +206,7 @@ export default class LNC {
206206 clearStorage = ( ) =>
207207 Object . entries ( localStorage )
208208 . map ( ( x ) => x [ 0 ] )
209- . filter ( ( x ) => x . substring ( 0 , 8 ) == 'lnc-web:' )
209+ . filter ( ( x ) => x . substring ( 0 , 8 ) === 'lnc-web:' )
210210 . map ( ( x ) => localStorage . removeItem ( x ) ) ;
211211
212212 /**
@@ -528,7 +528,7 @@ export default class LNC {
528528 } else {
529529 updated [ key ] = value ;
530530 }
531- return updated ;
531+ return camelKeysToSnake ( updated ) ;
532532 } , o ) ;
533533 }
534534}
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ const toCamel = (text: string) => {
77 } ) ;
88} ;
99
10+ /**
11+ * Converts a string from camel-case to snake-case
12+ */
13+ const toSnake = ( str : string ) =>
14+ str . replace ( / [ A - Z ] / g, ( letter ) => `_${ letter . toLowerCase ( ) } ` ) ;
15+
1016/**
1117 * Returns true if the value provided is an array
1218 */
@@ -44,3 +50,26 @@ export const snakeKeysToCamel = <T>(o: any): T => {
4450
4551 return o ;
4652} ;
53+
54+ /**
55+ * Recursively converts the keys of a Javascript object from camel-case to snake-case
56+ * Ex: { someKey: 'foo' } becomes { some-key: 'foo' }
57+ * @param o any Javascript object
58+ */
59+ export const camelKeysToSnake = < T > ( o : any ) : T => {
60+ if ( isObject ( o ) ) {
61+ const n : Record < string , unknown > = { } ;
62+
63+ Object . keys ( o ) . forEach ( ( k ) => {
64+ n [ toSnake ( k ) ] = camelKeysToSnake ( o [ k ] ) ;
65+ } ) ;
66+
67+ return n as T ;
68+ } else if ( isArray ( o ) ) {
69+ return o . map ( ( i : any ) => {
70+ return camelKeysToSnake ( i ) ;
71+ } ) ;
72+ }
73+
74+ return o ;
75+ } ;
You can’t perform that action at this time.
0 commit comments