import { string } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { plural } = string;
A simple curried pluralizing function. Takes the singular and plural forms of a word and returns a function that takes a count and returns the correct word for the count.
Examples
Example 1
Example 1
import { plural } from "./string.ts";
const are = plural("is", "are");
const rabbits = plural("rabbit", "rabbits");
const sentence = (n: number) => `There ${are(n)} ${n} ${rabbits(n)}`;
const result1 = sentence(1); // "There is 1 rabbit"
const result2 = sentence(4); // "There are 4 rabbits"
const result3 = sentence(0); // "There are 0 rabbits"