ratio
The ratio function converts a fraction string (Ratio) into an actual pixel/character count relative to a given total. It is used internally by Card widths but is also available for custom layout calculations.
Signature
function ratio(a: number, b: Ratio): number
Parameters
a: The total (e.g. terminal column count).b: ARatiofraction string —"1/2","1/3","2/3", or"full".
Return Value
A number equal to a × b. For "full" the original value is returned unchanged.
Usage
import { ratio, size } from "ts-better-console";
ratio(120, "1/2"); // 60
ratio(120, "1/3"); // 40
ratio(120, "2/3"); // 80
ratio(120, "full") // 120
// Combined with terminal size
const halfWidth = ratio(size.width.og, "1/2");
Want to support this project?
If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.
Want to contribute to this project?
Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!