@@ -6,10 +6,10 @@ const makeString = (value, option) => {
6
6
}
7
7
option = option || { } ;
8
8
option . assignment = option . assignment || '=' ;
9
- option . seperator = option . seperator || '=' ;
10
- option . curlyBraces = option . curlyBraces || true ;
9
+ option . braces = option . braces || "true" ;
11
10
option . quotes = option . quotes === 'double' ? 'double' : 'single' ;
12
11
12
+ //stringBasedOnType();
13
13
if ( isString ( value ) ) {
14
14
return option . quotes === 'double' ? '"' + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + '"' : "'" + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + "'" ;
15
15
}
@@ -19,13 +19,26 @@ const makeString = (value, option) => {
19
19
}
20
20
21
21
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 ) ;
23
28
}
24
29
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 ( ( ) => {
26
37
38
+ } ) ;
27
39
}
28
40
41
+
29
42
return option . quotes === 'double' ? "" : '' ;
30
43
31
44
@@ -40,9 +53,21 @@ const isBoolean = (value) => {
40
53
}
41
54
42
55
const 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]' )
44
61
}
45
62
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 ( ) ) ) ;
47
73
48
- console . log ( JSON . stringify ( [ 1 , 2 , "ajay" ] ) ) ;
0 commit comments