Skip to content

Commit 0dc7d42

Browse files
committed
added support for number to string
1 parent 2078a45 commit 0dc7d42

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.npmignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# OS Generate Files #
2+
######################
3+
.DS_Store
4+
.DS_Store?
5+
.travis.yml
6+
7+
/node_modules

index.js

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const createString = (value, option) => {
1919
return '' + value;
2020
}
2121

22+
if (isNumber(value)) {
23+
return '' + value;
24+
}
25+
2226
if (Array.isArray(value)) {
2327
option.seperator = option.seperator || ',';
2428
return option.braces === "true" ? '[' + value.map((val) => {
@@ -68,6 +72,10 @@ const isDate = (value) => {
6872
return (value != undefined && typeof value === 'object' && Object.prototype.toString.call(value) === '[object Date]')
6973
}
7074

75+
const isNumber = (value) => {
76+
return (value != undefined && typeof value === 'number')
77+
}
78+
7179
const makeString = (value, option) => {
7280
if (option && option.quotes === 'no') {
7381
return createString(value, option).replace(/[""]/g, "");

test.js

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe("test toString method", () => {
3737

3838
it("test number to string", () => {
3939
const str = makeString(25);
40-
console.log(JSON.stringify(25));
4140
expect(str).to.be.a('string');
4241
expect(str).to.equal(JSON.stringify(25));
4342
});

0 commit comments

Comments
 (0)