#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

#211 in Text processing

Download history 14/week @ 2024-12-25 145/week @ 2025-01-01 427/week @ 2025-01-08 640/week @ 2025-01-15 708/week @ 2025-01-22 934/week @ 2025-01-29 844/week @ 2025-02-05 812/week @ 2025-02-12 818/week @ 2025-02-19 777/week @ 2025-02-26 630/week @ 2025-03-05 549/week @ 2025-03-12 673/week @ 2025-03-19 907/week @ 2025-03-26 1706/week @ 2025-04-02 2101/week @ 2025-04-09

5,574 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.1–3MB
~54K SLoC