Skip to content

v3.0.0

Latest

Choose a tag to compare

@sindresorhus sindresorhus released this 02 Feb 09:34

Breaking

  • Percentage * and / now support scalar overloads, so expressions like 50% * 2 and 100% / 2 change behavior from percent-to-percent math to scalar math.
  • Compound assignments with scalars change accordingly, for example value *= 2 now doubles the percent instead of treating 2 as 2%.
  • postfix % now accepts all BinaryFloatingPoint types, which can cause ambiguity if another module defines its own postfix % for Float or CGFloat.

Improvements

You can now use Percentage directly with common SwiftUI, UIKit, and AppKit APIs that accept a fraction Double:

Text("Hello")
	.opacity(45%)
	.brightness(20%)
	.contrast(80%)
	.saturation(50%)
	.grayscale(100%)

Color.red.opacity(50%)

UIColor.red.withAlphaComponent(50%)

NSColor.red.withAlphaComponent(50%)

v2.0.0...v3.0.0