Commit graph

11 commits

Author SHA1 Message Date
Sindre Sorhus
e12289964d use String constructor rather than + for coercion 2014-06-26 15:09:37 +02:00
Joshua Appelman
580fe4d718 Replaces Array.prototype.reduce with a for loop.
As this is possibly the hottest code path, this speeds up average total
execution time with about 25%, benchmarking shows.
2014-06-26 14:49:03 +02:00
Sindre Sorhus
135852fd92 Merge pull request #27 from jbnicolai/optimize
Performance optimizations (ca. Factor 75)
2014-06-26 00:05:05 +02:00
Joshua Appelman
b0523a4438 Performance optimizations (ca. Factor 75)
- Precomputed style function
- Skip arguments to array + join if there's only one argument (the
  common case)
- Merge multiple return statements to one

To calculate the performance benefit:

```javascript
var chalk = require('./index.js');
console.time('100000 iterations');
for (var i = 0; i < 100000; i++) {
	chalk.red('A string that is about 80 characters long (normal use I think?)');
}
console.timeEnd('100000 iterations');
```

Running this before this commit:
```shell
for i in {1..5}; do node time.js; done
100000 iterations: 19485ms
100000 iterations: 18933ms
100000 iterations: 19365ms
100000 iterations: 19332ms
100000 iterations: 18660ms
```

After:
```shell
100000 iterations: 268ms
100000 iterations: 261ms
100000 iterations: 264ms
100000 iterations: 259ms
100000 iterations: 254ms
```

Performance gain, taking the middle result of both:
```shell
19332 / 261 = 74.~
```

Closes #16
2014-06-26 00:01:20 +02:00
Sindre Sorhus
90bd6477d6 add .hasColor() method - fixes #23 2014-06-24 21:34:11 +02:00
Sindre Sorhus
763b167349 refactor and extract the RegExp escaping 2014-06-24 17:13:41 +02:00
Joshua Appelman
d16b0ce367 Adds support for nested chalk expressions.
green(a + blue(b) + c) will now look the same as green(a) +
blue(b) + green(c), as expected. In the previous implementation the
output would have been green(a) + blue(b) + c, because the reset code of
the second expression would close all expressions around it as well.

Now this reset code is replaced by a start code of the outer lying
expression, both stopping the inner and re-starting the outer.
2014-06-23 13:25:47 +02:00
Sindre Sorhus
144421dc16 has-color => supports-color 2014-06-14 03:49:42 +02:00
Sindre Sorhus
cf7eb2d0c7 various tweaks 2014-06-04 01:47:53 +02:00
Sindre Sorhus
b0addb86d6 Update index.js 2013-12-16 19:25:01 +01:00
Sindre Sorhus
d2a1052042 use index.js 2013-12-13 20:22:40 +01:00
Renamed from chalk.js (Browse further)