color-string icon indicating copy to clipboard operation
color-string copied to clipboard

move to TypeScript

Open LitoMore opened this issue 10 months ago • 0 comments

Changes

  • Rewrite with TypeScript
  • Separate get and to functions to support tree-shaking
  • Expose some useful utilities
  • Use c8 & ava for testing
  • Use named capturing group for getting matched values
  • Change all null return values to undefined (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 get and to function 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)
    

LitoMore avatar Feb 13 '25 00:02 LitoMore