File tree Expand file tree Collapse file tree 4 files changed +45
-83
lines changed Expand file tree Collapse file tree 4 files changed +45
-83
lines changed Original file line number Diff line number Diff line change 18
18
"homepage" : " https://github.com/joedelia/ajax2#readme" ,
19
19
"dependencies" : {
20
20
"babel-runtime" : " ^6.26.0" ,
21
- "camelcase-keys" : " ^7.0.0" ,
22
- "snakecase-keys" : " ^4.0.2" ,
21
+ "lodash" : " ^4.17.21" ,
23
22
"whatwg-fetch" : " ^2.0.4"
24
23
},
25
24
"devDependencies" : {
Original file line number Diff line number Diff line change
1
+ import camelCaseConverter from 'lodash/camelCase' ;
2
+ import snakeCaseConverter from 'lodash/snakeCase' ;
3
+
4
+ export function toCamelCase ( obj ) {
5
+ return deepMapKeys ( obj , camelCaseConverter ) ;
6
+ }
7
+ export function toSnakeCase ( obj ) {
8
+ return deepMapKeys ( obj , snakeCaseConverter ) ;
9
+ }
10
+
11
+ function deepMapKeys ( obj , mod ) {
12
+ if ( ( obj === null || typeof obj !== 'object' ) && ! Array . isArray ( obj ) )
13
+ throw new Error ( 'You must provide initial argument as an object' ) ;
14
+
15
+ if ( ! mod || typeof mod !== 'function' )
16
+ throw new Error ( 'You must provide a modifier by which your keys will be changed' ) ;
17
+
18
+ function innerRoutine ( obj , mod ) {
19
+ if ( Array . isArray ( obj ) )
20
+ return obj . map ( val => innerRoutine ( val , mod ) ) ;
21
+
22
+ if ( obj !== null && typeof obj === 'object' ) {
23
+ return Object . keys ( obj ) . reduce ( ( accum , key ) => {
24
+ accum [ mod ( key ) ] = innerRoutine ( obj [ key ] , mod ) ;
25
+ return accum ;
26
+ } , { } ) ;
27
+ }
28
+ return obj ;
29
+ }
30
+
31
+ return innerRoutine ( obj , mod ) ;
32
+ }
Original file line number Diff line number Diff line change 1
1
import 'whatwg-fetch' ; // eslint-disable-line import/no-unassigned-import
2
- import toCamelCase from 'camelcase-keys' ;
3
- import toSnakeCase from 'snakecase-keys' ;
2
+ import { toCamelCase , toSnakeCase } from './case-convert' ;
4
3
import EventDispatcher from './events' ;
5
4
6
5
let defaultConvertRequest = null ,
You can’t perform that action at this time.
0 commit comments