Skip to content

Commit ee4f161

Browse files
committed
Allowing multi colors params
1 parent c6f2cd9 commit ee4f161

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ You can configure the colors of the displayed json by changing the values of the
8282
}
8383
```
8484

85+
You can not only use the color value as string but also you can use an array to specify the background color or you can make things look bold ( [see colors package for more details](http://npmjs.org/package/colors) )
86+
87+
88+
```javascript
89+
jsome.colors.bool = ['green' , 'bgRed']
90+
jsome.colors.attr = ['green' , 'bold']
91+
jsome.colors.quot = ['yellow', 'bold']
92+
jsome.colors.punc = ['yellow', 'bold']
93+
jsome.colors.brack = ['yellow', 'bold']
94+
```
95+
![jsome](https://raw.githubusercontent.com/Javascipt/Jsome/master/examples/example3.png)
96+
97+
8598
When you have a json as a string, instead of passing by `JSON.parse` function, you can just call the parse function of jsome
8699

87100
```javascript

examples/example3.png

7.23 KB
Loading

generator.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ module.exports = (function () {
6969
}
7070

7171
function colorifySpec (char, type, level) {
72-
return generateLevel(level) + useColorProvider(char, options.colors[type]);
72+
return generateLevel(level) + useColorProvider('' + char, options.colors[type]);
7373
}
7474

7575
function useColorProvider (str, color) {
7676
/* preparing for the use of Chalk over Colors module */
7777
if(options.params.colored) {
78-
return str[color];
78+
if(!getType(color) && color.length > 1) {
79+
return useColorProvider(str[color[0]], color.slice(1))
80+
} else {
81+
return str[getType(color) ? color : color[0]];
82+
}
7983
} else {
8084
return str;
8185
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"homepage": "https://github.com/Javascipt/Jsome#readme",
2525
"dependencies": {
26+
"chalk": "^1.1.1",
2627
"colors": "^1.1.2"
2728
}
2829
}

0 commit comments

Comments
 (0)