1
1
'use strict' ;
2
2
3
- const makeString = ( value , option ) => {
3
+ const createString = ( value , option ) => {
4
4
if ( value === null ) {
5
- return null ;
5
+ return ' null' ;
6
6
}
7
7
option = option || { } ;
8
8
@@ -11,11 +11,12 @@ const makeString = (value, option) => {
11
11
12
12
//stringBasedOnType();
13
13
if ( isString ( value ) ) {
14
- return option . quotes === 'double' ? '"' + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + '"' : "'" + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + "'" ;
14
+ const quote = option . quotes === 'no' ? 'double' : option . quotes ;
15
+ return quote === 'double' ? '"' + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + '"' : "'" + value . replace ( / \\ / g, '\\\\' ) . replace ( '"' , '\\"' ) + "'" ;
15
16
}
16
17
17
18
if ( isBoolean ( value ) ) {
18
- return option . quotes === 'double' ? '"' + value + '"' : "'" + value + "'" ;
19
+ return '' + value ;
19
20
}
20
21
21
22
if ( Array . isArray ( value ) ) {
@@ -66,15 +67,12 @@ const isObject = (value) => {
66
67
const isDate = ( value ) => {
67
68
return ( value != undefined && typeof value === 'object' && Object . prototype . toString . call ( value ) === '[object Date]' )
68
69
}
69
- var ajay = {
70
- name : "Ajay" ,
71
- college : "uncc"
72
- }
73
- console . log ( makeString ( ajay , { braces : "false" } ) ) ;
74
-
75
- //console.log(typeof JSON.stringify([1, 2, "ajay"]));
76
-
77
70
78
- //console.log(JSON.stringify(ajay));
79
- console . log ( isDate ( new Date ( ) ) ) ;
71
+ const makeString = ( value , option ) => {
72
+ if ( option && option . quotes === 'no' ) {
73
+ return createString ( value , option ) . replace ( / [ " " ] / g, "" ) ;
74
+ }
75
+ return createString ( value , option ) ;
76
+ }
80
77
78
+ module . exports = makeString ;
0 commit comments