@@ -5,9 +5,9 @@ const makeString = (value, option) => {
55 return null ;
66 }
77 option = option || { } ;
8- option . assignment = option . assignment || '=' ;
8+
99 option . braces = option . braces || "true" ;
10- option . quotes = option . quotes === 'double' ? 'double' : 'single ';
10+ option . quotes = option . quotes || 'double' ;
1111
1212 //stringBasedOnType();
1313 if ( isString ( value ) ) {
@@ -33,17 +33,24 @@ const makeString = (value, option) => {
3333
3434 if ( isObject ( value ) ) {
3535 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+ } ;
3739
38- } ) ;
39- }
4040
4141
4242 return option . quotes === 'double' ? "" : '' ;
4343
4444
4545}
4646
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+
4754const isString = ( value ) => {
4855 return ( value != undefined && typeof value === 'string' ) ;
4956}
@@ -59,15 +66,15 @@ const isObject = (value) => {
5966const isDate = ( value ) => {
6067 return ( value != undefined && typeof value === 'object' && Object . prototype . toString . call ( value ) === '[object Date]' )
6168}
62-
63- console . log ( makeString ( [ "ajay" , "prajoth" , new Date ( ) ] , { quotes : 'single' , braces : "false" } ) ) ;
64-
65- console . log ( typeof JSON . stringify ( [ 1 , 2 , "ajay" ] ) ) ;
66-
6769var ajay = {
6870 name : "Ajay" ,
69- college : "UNCC "
71+ college : "uncc "
7072}
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));
7279console . log ( isDate ( new Date ( ) ) ) ;
7380
0 commit comments