Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel
Find a file
Adrian Tombu 12ab7ccab9
All checks were successful
Publish / checks (push) Successful in 56s
Publish / publish (push) Successful in 42s
Move to codeberg
2024-12-16 17:54:57 00:00
.forgejo/workflows Move to codeberg 2024-12-16 17:54:57 00:00
src Add honoree to irregular words 2024-06-14 16:11:03 00:00
.gitignore Move to codeberg 2024-12-16 17:54:57 00:00
Cargo.lock Move to codeberg 2024-12-16 17:54:57 00:00
Cargo.toml Move to codeberg 2024-12-16 17:54:57 00:00
LICENSE.md 🚀 Add Github Actions 2022-12-22 22:46:11 01:00
README.md 📚 Update MIT license authors 2022-12-22 22:41:33 01:00

crates.io docs.rs

indefinite

This crate is a port of the JavaScript library indefinite, thanks to the original authors of this library!

Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel.

Installation

cargo add indefinite

Usage

use indefinite::*;

fn main () {
    assert_eq!(indefinite("honor"), "an honor");
    assert_eq!(indefinite("ouija board"), "a ouija board");

    assert_eq!(indefinite_capitalized("apple"), "An apple");
    assert_eq!(indefinite_capitalized("banana"), "A banana");    

    assert_eq!(indefinite_article_only("apple"), "an");
    assert_eq!(indefinite_article_only("pear"), "a");

    assert_eq!(indefinite_article_only_capitalized("apple"), "An");
    assert_eq!(indefinite_article_only_capitalized("pear"), "A");  
}

Macros

Macros are available as a feature. They are working the same as the functions, except they also accept a list of inputs.

indefinite = { version = "0.1", features = [ "macros" ] }
use indefinite::*;

fn main () {
    assert_eq!(indefinite!("honor"), "an honor");
    assert_eq!(indefinite!("honor", "euro"), ["an honor", "a euro"]);

    assert_eq!(indefinite_capitalized!("apple"), "An apple");
    assert_eq!(indefinite_capitalized!("banana", "pear"), ["A banana", "A pear"]); 

    assert_eq!(indefinite_article_only!("apple"), "an");
    assert_eq!(indefinite_article_only!("apple","pear"), ["an", "a"]);

    assert_eq!(indefinite_article_only_capitalized!("apple"), "An");
    assert_eq!(indefinite_article_only_capitalized!("apple", "pear"), ["An", "A"]);
}