Skip to content

Commit 4919ec6

Browse files
committed
support seperator and assignment
1 parent 48182d5 commit 4919ec6

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# make-string [![Build Status](https://travis-ci.org/ajay2507/make-string.svg?branch=master)](https://travis-ci.org/ajay2507/make-string)
1+
# make-string [![Build Status](https://travis-ci.org/pajaydev/make-string.svg?branch=master)](https://travis-ci.org/pajaydev/make-string)
22

33
make-string converts all data types to string as JSON.toString.
44

@@ -14,7 +14,7 @@ const makeString = require('make-string');
1414
makeString(25); // '25'
1515
```
1616
## Why? ##
17-
I need to convert the object to string in configurable way like removing curly braces, with single quote, etc. So I created this module. If you face any issues with this module, Free feel to create the issues https://github.com/ajay2507/make-string/issues.
17+
I need to convert the object to string in configurable way like removing curly braces, with single quote, etc. So I created this module. If you face any issues with this module, Free feel to create the issues [here](https://github.com/pajaydev/make-string/issues).
1818

1919
## options ##
2020
Options can be passed as optional second param to makeString to configure few things.
@@ -34,4 +34,5 @@ makeString({package:"make-string"}); // '{"package":"make-string"}'
3434
makeString({package:"make-string"}, {braces: 'false'}); // '"package":"make-string"'
3535
makeString({package:"make-string"}, {assignment: '='}); // '{"package"="make-string"}'
3636
makeString({package:"make-string"}, {assignment: '=', quotes:'no'}); // '{package=make-string}'
37+
makeString({package:"make-string",author:"Ajay"}, {assignment: '=', quotes:'no', seperator:'&'}); // '{package=make-string&author=ajay}'
3738
```

index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,11 @@ const createString = (value, option) => {
3939
if (isObject(value)) {
4040
option.seperator = option.seperator || ',';
4141
option.assignment = option.assignment || ':';
42-
return option.braces === "true" ? '{' + iterateObj(value, option) + '}' : '' + iterateObj(value, option) + '';
42+
const createObjString = iterateObj(value, option).join(option.seperator);
43+
return option.braces === "true" ? '{' + createObjString + '}' : '' + createObjString + '';
4344
};
4445

45-
46-
4746
return option.quotes === 'double' ? "" : '';
48-
49-
5047
}
5148

5249
const iterateObj = (value, option) => {

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "make-string",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"description": "convert all data types to string in configurable way",
55
"main": "index.js",
66
"scripts": {
@@ -18,5 +18,9 @@
1818
"toString",
1919
"JSON.toString",
2020
"makeString"
21-
]
21+
],
22+
"repository": {
23+
"type": "git",
24+
"url": "https://github.com/pajaydev/make-string"
25+
}
2226
}

test.js

+10
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ describe("test toString method", () => {
100100
expect(str).to.equal('"name"="Ajay","city"="san jose"');
101101
});
102102

103+
it("test Object to string without braces and different seperator", () => {
104+
const sampleObject = {
105+
name: "Ajay",
106+
city: "san jose"
107+
}
108+
const str = makeString(sampleObject, { braces: 'false', assignment: '=', seperator: '&', quotes: 'no' });
109+
expect(str).to.be.a('string');
110+
expect(str).to.equal('name=Ajay&city=san jose');
111+
});
112+
103113
it("test Object to string with and without quotes", () => {
104114
const sampleObject = {
105115
name: "Ajay",

0 commit comments

Comments
 (0)