@@ -6,10 +6,10 @@ const makeString = (value, option) => {
66 }
77 option = option || { } ;
88 option . assignment = option . assignment || '=' ;
9- option . seperator = option . seperator || '=' ;
10- option . curlyBraces = option . curlyBraces || true ;
9+ option . braces = option . braces || "true" ;
1110 option . quotes = option . quotes === 'double' ? 'double' : 'single' ;
1211
12+ //stringBasedOnType();
1313 if ( isString ( value ) ) {
1414 return option . quotes === 'double' ? '"' + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + '"' : "'" + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + "'" ;
1515 }
@@ -19,13 +19,26 @@ const makeString = (value, option) => {
1919 }
2020
2121 if ( Array . isArray ( value ) ) {
22- // return
22+ option . seperator = option . seperator || ',' ;
23+ return option . braces === "true" ? '[' + value . map ( ( val ) => {
24+ return makeString ( val , option ) ;
25+ } ) . join ( option . seperator ) + ']' : value . map ( ( val ) => {
26+ return makeString ( val , option ) ;
27+ } ) . join ( option . seperator ) ;
2328 }
2429
25- if ( ) {
30+ if ( isDate ( value ) ) {
31+ return option . quotes === 'double' ? '"' + value . toISOString ( ) + '"' : "'" + value . toISOString ( ) + "'" ;
32+ }
33+
34+ if ( isObject ( value ) ) {
35+ option . seperator = option . seperator || ',' ;
36+ Object . keys ( value ) . map ( ( ) => {
2637
38+ } ) ;
2739 }
2840
41+
2942 return option . quotes === 'double' ? "" : '' ;
3043
3144
@@ -40,9 +53,21 @@ const isBoolean = (value) => {
4053}
4154
4255const isObject = ( value ) => {
43- return ( value != undefined && ) ;
56+ return ( value !== undefined && typeof value === 'object' && Object . prototype . toString . call ( value ) === '[object Object]' ) ;
57+ }
58+
59+ const isDate = ( value ) => {
60+ return ( value != undefined && typeof value === 'object' && Object . prototype . toString . call ( value ) === '[object Date]' )
4461}
4562
46- console . log ( typeof makeString ( true , { quotes : 'single' } ) ) ;
63+ console . log ( makeString ( [ "ajay" , "prajoth" , new Date ( ) ] , { quotes : 'single' , braces : "false" } ) ) ;
64+
65+ console . log ( typeof JSON . stringify ( [ 1 , 2 , "ajay" ] ) ) ;
66+
67+ var ajay = {
68+ name : "Ajay" ,
69+ college : "UNCC"
70+ }
71+ console . log ( JSON . stringify ( ajay ) ) ;
72+ console . log ( isDate ( new Date ( ) ) ) ;
4773
48- console . log ( JSON . stringify ( [ 1 , 2 , "ajay" ] ) ) ;
0 commit comments