#article #noun #grammar #an #a

indefinite

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

10 releases

0.1.9 Dec 16, 2024
0.1.8 Jun 14, 2024
0.1.7 Oct 1, 2023
0.1.6 Jan 2, 2023
0.1.5 Dec 22, 2022

#217 in Text processing

Download history 91/week @ 2024-12-07 532/week @ 2024-12-14 39/week @ 2024-12-21 60/week @ 2024-12-28 338/week @ 2025-01-04 521/week @ 2025-01-11 721/week @ 2025-01-18 816/week @ 2025-01-25 923/week @ 2025-02-01 740/week @ 2025-02-08

3,344 downloads per month
Used in archival

MIT license

26KB
555 lines

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"]);
}

Dependencies

~2.2–3MB
~54K SLoC