draftply Download

Cooking Units

← All samples

cooking-units.dplylibEditor
1---
2app_version: 0.5.0
3---
4# cooking-units.dplylib
5// Common kitchen-measure units, built exactly on draftply's built-in US
6// volume unit (floz) and metric volume unit (ml) — no independent rounding.
7//
8// Import this library and use the units inline (2 tbsp, 1.5 cup_us) or with
9// convert(): convert(1, "cup_us", "ml"), ...
10//
11// "Cup" is deliberately not a single unit here: the US cup (236.588 ml), the
12// metric cup (250 ml) and the UK/Imperial cup (284.131 ml) genuinely differ,
13// and a bare "cup" would silently pick one. Use cup_us or cup_metric by name
14// instead.
15
16# US customary spoons, exact from the built-in floz
17defunit("tbsp", 1 / 2, "floz") // 1 tbsp = 1/2 US fl oz = 14.7868 ml
18defunit("tsp", 1 / 3, "tbsp") // 1 tsp = 1/3 tbsp = 4.9289 ml
19
20# Cups — pick the one that matches your recipe's origin
21defunit("cup_us", 8, "floz") // US legal/customary cup = 236.588 ml
22defunit("cup_metric", 250, "ml") // metric cup, common outside the US
23
24# Quick examples (visible when you open this file directly)
25convert(1, "cup_us", "ml") // 236.588 ml
26convert(1, "cup_metric", "ml") // 250 ml
27convert(3, "tsp", "tbsp") // 1 tbsp
28convert(1, "cup_us", "tbsp") // 16 tbsp
29