sindresorhus / Percentage
Licence: mit
A percentage type for Swift
Stars: ✭ 225
Labels
Projects that are alternatives of or similar to Percentage
Returns
Make your functions return something meaningful, typed, and safe!
Stars: ✭ 2,015 (+795.56%)
Mutual labels: type-safety
Orm Lite
Header-Only, Strong-Typed, Compile-time Object Relation Mapping (ORM) in Modern C++ :-)
Stars: ✭ 164 (-27.11%)
Mutual labels: type-safety
Swiftyfitsize
📱 Swifty screen adaptation solution (Support Objective-C and Swift)
Stars: ✭ 184 (-18.22%)
Mutual labels: number
React Native Input Spinner
An extensible input number spinner component for react-native highly customizable. This component enhance a text input for entering numeric values, with increase and decrease buttons.
Stars: ✭ 155 (-31.11%)
Mutual labels: number
Libphonenumber Js
A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
Stars: ✭ 2,233 (+892.44%)
Mutual labels: number
Javascript Number Formatter
Lightweight & Fast JavaScript Number Formatter
Stars: ✭ 119 (-47.11%)
Mutual labels: number
Vue Literal Compiler
A Vue Compiler that allows you compile your string literals to render functions at build time and write components in SFC paradigm
Stars: ✭ 158 (-29.78%)
Mutual labels: type-safety
Typestrict
ESLint config focused on maximizing type safety 💪
Stars: ✭ 182 (-19.11%)
Mutual labels: type-safety
Android Xnumberkeyboard
Android number keyboard view. Android自定义的数字键盘。
Stars: ✭ 149 (-33.78%)
Mutual labels: number
Is Number
JavaScript/Node.js utility. Returns `true` if the value is a number or string number. Useful for checking regex match results, user input, parsed strings, etc.
Stars: ✭ 176 (-21.78%)
Mutual labels: number
Typecov
Track missing type coverage to ensure type safety
Stars: ✭ 128 (-43.11%)
Mutual labels: type-safety
Squid
Squid – type-safe metaprogramming and compilation framework for Scala
Stars: ✭ 172 (-23.56%)
Mutual labels: type-safety
Ts Toolbelt
ts-toolbelt is the largest, and most tested type library available right
now, featuring +200 utilities. Our type collection packages some of the most
advanced mapped types, conditional types, and recursive types on the market.
Stars: ✭ 3,099 (+1277.33%)
Mutual labels: type-safety
Vntnumberpickerpreference
NumberPicker Preference for Android
Stars: ✭ 176 (-21.78%)
Mutual labels: number
Percentage
A percentage type for Swift
Makes percentages more readable and type-safe, for example, for APIs that currently accept a fraction Double
.
-.opacity(0.45)
+.opacity(45%)
Install
Add the following to Package.swift
:
.package(url: "https://github.com/sindresorhus/Percentage", from: "1.1.0")
Usage
See the source for docs.
import Percentage
10% + 5.5%
//=> 15.5%
-10% / 2
//=> -5%
(40% + 93%) * 3
//=> 399%
50% * 50%
//=> 25%
30% > 25%
//=> true
50%.of(200)
//=> 100
Percentage(50)
//=> 50%
Percentage(fraction: 0.5)
//=> 50%
50%.fraction
//=> 0.5
10%.rawValue
//=> 10
print("\(1%)")
//=> "1%"
Percent.random(in: 10%...20%)
//=> "14.3%"
The type conforms to Hashable
, Codable
, RawRepresentable
, Comparable
, ExpressibleByFloatLiteral
, ExpressibleByIntegerLiteral
, Numeric
, and supports all the arithmetic operators.
Codable
The percentage value is encoded as a single value:
struct Foo: Codable {
let alpha: Percentage
}
let foo = Foo(alpha: 1%)
let data = try! JSONEncoder().encode(foo)
let string = String(data: data, encoding: .utf8)!
print(string)
//=> "{\"alpha\":1}"
FAQ
Can you support Carthage and CocoaPods?
No, but you can still use Swift Package Manager for this package even though you mainly use Carthage or CocoaPods.
Related
- Defaults - Swifty and modern UserDefaults
- Preferences - Add a preferences window to your macOS app
- KeyboardShortcuts - Add user-customizable global keyboard shortcuts to your macOS app
- LaunchAtLogin - Add "Launch at Login" functionality to your macOS app
- DockProgress - Show progress in your app's Dock icon
- CircularProgress - Circular progress indicator for your macOS app
- More…
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].