@@ -5,9 +5,9 @@ const makeString = (value, option) => {
5
5
return null ;
6
6
}
7
7
option = option || { } ;
8
- option . assignment = option . assignment || '=' ;
8
+
9
9
option . braces = option . braces || "true" ;
10
- option . quotes = option . quotes === 'double' ? 'double' : 'single ';
10
+ option . quotes = option . quotes || 'double' ;
11
11
12
12
//stringBasedOnType();
13
13
if ( isString ( value ) ) {
@@ -33,17 +33,24 @@ const makeString = (value, option) => {
33
33
34
34
if ( isObject ( value ) ) {
35
35
option . seperator = option . seperator || ',' ;
36
- Object . keys ( value ) . map ( ( ) => {
36
+ option . assignment = option . assignment || ':' ;
37
+ return option . braces === "true" ? '{' + iterateObj ( value , option ) + '}' : '' + iterateObj ( value , option ) + '' ;
38
+ } ;
37
39
38
- } ) ;
39
- }
40
40
41
41
42
42
return option . quotes === 'double' ? "" : '' ;
43
43
44
44
45
45
}
46
46
47
+ const iterateObj = ( value , option ) => {
48
+ return Object . keys ( value ) . map ( ( key ) => {
49
+ const modKey = ( option . quotes === 'double' ) ? '"' + key + '"' : "'" + key + "'" ;
50
+ return ( typeof value [ key ] === 'function' ) ? null : modKey + option . assignment + makeString ( value [ key ] , option ) ;
51
+ } ) . filter ( function ( i ) { return i ; } ) ;
52
+ }
53
+
47
54
const isString = ( value ) => {
48
55
return ( value != undefined && typeof value === 'string' ) ;
49
56
}
@@ -59,15 +66,15 @@ const isObject = (value) => {
59
66
const isDate = ( value ) => {
60
67
return ( value != undefined && typeof value === 'object' && Object . prototype . toString . call ( value ) === '[object Date]' )
61
68
}
62
-
63
- console . log ( makeString ( [ "ajay" , "prajoth" , new Date ( ) ] , { quotes : 'single' , braces : "false" } ) ) ;
64
-
65
- console . log ( typeof JSON . stringify ( [ 1 , 2 , "ajay" ] ) ) ;
66
-
67
69
var ajay = {
68
70
name : "Ajay" ,
69
- college : "UNCC "
71
+ college : "uncc "
70
72
}
71
- console . log ( JSON . stringify ( ajay ) ) ;
73
+ console . log ( makeString ( ajay , { braces : "false" } ) ) ;
74
+
75
+ //console.log(typeof JSON.stringify([1, 2, "ajay"]));
76
+
77
+
78
+ //console.log(JSON.stringify(ajay));
72
79
console . log ( isDate ( new Date ( ) ) ) ;
73
80
0 commit comments