Commit graph

17 commits

Author SHA1 Message Date
Ayush Kumar
ff7b1f0d60
Fix security and performance issues across core, vendor, and examples
Security:
- S2: hexToRgb — explicit typeof branch + padStart(6) for numeric hex inputs;
  makes the numeric-input path intentional and preserves leading zeros
- S3: FORCE_COLOR parsing — guard against NaN propagation when env value is
  non-numeric (e.g. FORCE_COLOR=yes now correctly falls back to level 1)
- S4: _supportsColor — remove side-effecting mutation of module-level
  flagForceColor; effective value is now computed locally, eliminating
  cross-call state corruption in test environments
- S5: applyOptions — change `options.level &&` to `options.level !== undefined`
  so null and NaN are properly rejected instead of silently stored as the level
- S6: browser.js — explicit Number(brand.version) > 93 instead of implicit
  string-to-number coercion for Chromium UA version check

Performance / correctness:
- P1: rainbow.js — replace stateful global-regex test() in loop (which
  misclassified every other non-printable character due to lastIndex advancing)
  with a direct code-point comparison: character < '!' || character > '~'
- P4: stringEncaseCRLFWithFirstIndex — switch from += string concatenation in
  loop to array-of-parts + single join(), reducing intermediate allocations for
  multi-line strings
- P6: builder — detect tagged template literal calls via .raw property and route
  through String.raw(), so chalk.red`hello ${name}` now produces correct output

Tests:
- instance.js: new Chalk({level: null/NaN}) now throws (S5 regression test)
- chalk.js: numeric hex with leading zeros (S2), template literal interpolations
  (P6) covered by new tests; all 35 tests pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 17:21:53 +05:30
Sindre Sorhus
77126fba13 Meta tweaks 2024-08-08 00:00:20 +02:00
Richie Bendall
386909ee0b
Tweak example (#623) 2024-01-19 21:36:11 +07:00
Sindre Sorhus
a027e3c1e0 Minor tweaks 2022-11-28 14:15:46 +07:00
Sindre Sorhus
ba5c385ecf Update screenshot
Fixes #554
2022-07-03 00:36:34 +02:00
Richie Bendall
09fd5c4ba8
Re-export types from supports-color (#526) 2021-11-21 13:51:24 +07:00
Sindre Sorhus
625a285772 Add types field to package.json
Fixes #500
2021-07-30 17:35:30 +02:00
Richie Bendall
4cf2e40e07
Add overline style and remove keyword, hsl, hsv, hwb and ansi color spaces (#433) 2021-04-22 10:54:42 +07:00
Sindre Sorhus
fa16f4ec37 Require Node.js 12 and move to ESM 2021-04-16 16:22:53 +07:00
Richie Bendall
c0d8e7ed8a
Update test dependencies (#414) 2020-10-03 23:56:24 +02:00
Sindre Sorhus
61999a4e77 Require Node.js 10 2020-04-02 16:10:07 +08:00
Yanis Benson
c08417e88c Improve performance greatly (#337) 2019-07-12 13:40:23 +07:00
Sindre Sorhus
3ef170b457 Require Node.js 8 2019-03-12 20:15:36 +07:00
Atif Aziz
b827cb0817 Fix ignore chars regex flags in rainbow example (#306)
Use global matches rather than stopping after the first match.
2018-10-27 21:09:54 +07:00
Sindre Sorhus
3d10f8fad7 Code style tweaks 2017-06-30 12:42:24 +02:00
Josh Junon
23ef1c7ca2 fix linter errors 2017-06-29 16:05:28 -07:00
Josh Junon
c0155688cf add rainbow example 2017-06-29 16:00:51 -07:00