Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>string.plural

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function string.plural
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

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"

Parameters

singular: string
plural: string

Returns

(count: number) => string