color-string
color-string copied to clipboard
move to TypeScript
Changes
- Rewrite with TypeScript
- Separate
getandtofunctions to support tree-shaking - Expose some useful utilities
- Use
c8&avafor testing - Use named capturing group for getting matched values
- Change all
nullreturn values toundefined(FYI https://github.com/sindresorhus/meta/discussions/7)
Some lines are theoretically unreachable (unless the regex pattern has a bug). For TypeScript to determine the type, I wrote a polite condition such as if (!r || !g || !b) return undefined and ignored its coverage.
Notable changes
- Now all
getandtofunction parameters will be clamped - Fix some issues with negative numbers
olorString.to.hex(255, 10, 35, -1) /=> FF0A23-FF oHex(255, 10, 35, -1) /=> FF0A2300 olorString.to.rgb(-255, -10, -35) /=> rgb(-255, -10, -35) oRgb(-255, -10, -35) /=> rgb(0, 0, 0)