An open API service indexing awesome lists of open source software.

https://github.com/khonsulabs/nominals

Formatting of nominal identifiers in various languages (ordered list headings)
https://github.com/khonsulabs/nominals

formatting nominals rust

Last synced: 9 months ago
JSON representation

Formatting of nominal identifiers in various languages (ordered list headings)

Awesome Lists containing this project

README

          

# Nominals

![nominals is considered alpha](https://img.shields.io/badge/status-alpha-orange)
[![crate version](https://img.shields.io/crates/v/nominals.svg)](https://crates.io/crates/nominals)
[![Documentation for `main`](https://img.shields.io/badge/docs-main-informational)](https://khonsulabs.github.io/nominals/main/nominals/)

This type of formatting can be used for list identifiers when creating ordered
lists similar to HTML's `

    ` tag. The crate was written to power the
    `List` widget in [Cushy][cushy].

    This crate's original implementation was inspired by [Typst][typst]'s
    implementation of list numbering. However, this crate is a fresh implementation
    with newly-written implementations and types.

    ```rust
    use nominals::{Decimal, DigitCollection, Error, LetterLower, Nominal};

    fn main() {
    // Formatting a nominal is as easy as calling to_nominal with the desired
    // nominal system.
    assert_eq!(0_u32.to_nominal(&Decimal), "0");
    // By default, alphabet systems treat their first symbol as 0 in the ones
    // place, but treat the first symbol as 1 in every other digit place.
    assert_eq!(0_u32.to_nominal(&LetterLower), "a");
    assert_eq!(1_u32.to_nominal(&LetterLower), "b");
    assert_eq!(26_u32.to_nominal(&LetterLower), "aa");

    // This behavior can be changed by using the one_based helper:
    assert_eq!(1_u32.to_nominal(&LetterLower.one_based()), "a");
    assert_eq!(2_u32.to_nominal(&LetterLower.one_based()), "b");
    assert_eq!(27_u32.to_nominal(&LetterLower.one_based()), "aa");
    // When a nominal can't be formatted with `to_nominal`, it falls back to
    // Decimal.
    assert_eq!(0_u32.to_nominal(&LetterLower.one_based()), "0");
    assert_eq!(
    0_u32.try_to_nominal(&LetterLower.one_based()).unwrap_err(),
    Error::NoZeroSymbol
    );
    }
    ```

    ## `no_std` support

    This crate is `no_std` compatible, and can operate both with and without
    `alloc`.

    [cushy]: https://github.com/khonsulabs/cushy
    [typst]: https://github.com/typst/typst

    ## Supported Systems

    - [`Decimal`](https://khonsulabs.github.io/nominals/main/nominals/struct.Decimal.html): 0‎ 1‎ 2‎ 3‎ 4‎ …‎ 9‎ 10‎ 11‎ 12‎ …‎ 99‎ 100‎ 101‎ 102
    - [`LetterLower`](https://khonsulabs.github.io/nominals/main/nominals/struct.LetterLower.html): a‎ b‎ c‎ d‎ e‎ …‎ z‎ aa‎ ab‎ ac‎ …‎ yz‎ za‎ zb‎ zc
    - [`LetterUpper`](https://khonsulabs.github.io/nominals/main/nominals/struct.LetterUpper.html): A‎ B‎ C‎ D‎ E‎ …‎ Z‎ AA‎ AB‎ AC‎ …‎ YZ‎ ZA‎ ZB‎ ZC
    - [`RomanLower`](https://khonsulabs.github.io/nominals/main/nominals/struct.RomanLower.html): i‎ ii‎ iii‎ iv‎ v‎ vi‎ …‎ ix‎ x‎ xi‎ …‎ mmmcmxcix‎ i̅v̅‎ i̅v̅i‎ …‎ d̅m̅l̅c̅i̅x̅cmxcix‎ m̅‎ m̅i
    - [`RomanUpper`](https://khonsulabs.github.io/nominals/main/nominals/struct.RomanUpper.html): I‎ II‎ III‎ IV‎ V‎ VI‎ …‎ IX‎ X‎ XI‎ …‎ MMMCMXCIX‎ I̅V̅‎ I̅V̅I‎ …‎ D̅M̅L̅C̅I̅X̅CMXCIX‎ M̅‎ M̅I
    - [`CircledNumber`](https://khonsulabs.github.io/nominals/main/nominals/struct.CircledNumber.html): ⓪‎ ①‎ ②‎ ③‎ ④‎ …‎ ⑨‎ ⑩‎ ⑪‎ ⑫‎ …‎ ㊽‎ ㊾‎ ㊿
    - [`DoubleCircledNumber`](https://khonsulabs.github.io/nominals/main/nominals/struct.DoubleCircledNumber.html): ⓵‎ ⓶‎ ⓷‎ ⓸‎ ⓹‎ ⓺‎ ⓻‎ ⓼‎ ⓽‎ ⓾
    - [`ArmenianLower`](https://khonsulabs.github.io/nominals/main/nominals/struct.ArmenianLower.html): ա‎ բ‎ գ‎ …‎ թ‎ ժ‎ ժա‎ ժբ‎ …‎ ղթ‎ ճ‎ ճա
    - [`ArmenianUpper`](https://khonsulabs.github.io/nominals/main/nominals/struct.ArmenianUpper.html): Ա ‎ Բ‎ Գ‎ …‎ Թ‎ Ժ‎ ԺԱ ‎ ԺԲ‎ …‎ ՂԹ‎ Ճ‎ ՃԱ
    - [`Bengali`](https://khonsulabs.github.io/nominals/main/nominals/struct.Bengali.html): ০‎ ১‎ ২‎ ৩‎ ৪‎ …‎ ৯‎ ১০‎ ১১‎ ১২‎ …‎ ৯৯‎ ১০০‎ ১০১‎ ১০২
    - [`Cambodian`](https://khonsulabs.github.io/nominals/main/nominals/struct.Cambodian.html): ០‎ ១‎ ២‎ ៣‎ ៤‎ …‎ ៩‎ ១០‎ ១១‎ ១២‎ …‎ ៩៩‎ ១០០‎ ១០១‎ ១០២
    - [`SimplifiedChineseInformal`](https://khonsulabs.github.io/nominals/main/nominals/struct.SimplifiedChineseInformal.html): 零‎ 一‎ 二‎ …‎ 九‎ 十‎ 十一‎ …‎ 十九‎ 二十‎ 二十一‎ …‎ 九十九‎ 一百‎ 一百零一
    - [`TraditionalChineseInformal`](https://khonsulabs.github.io/nominals/main/nominals/struct.TraditionalChineseInformal.html): 零‎ 一‎ 二‎ …‎ 九‎ 十‎ 十一‎ …‎ 十九‎ 二十‎ 二十一‎ …‎ 九十九‎ 一百‎ 一百零一
    - [`SimplifiedChineseFormal`](https://khonsulabs.github.io/nominals/main/nominals/struct.SimplifiedChineseFormal.html): 零‎ 一‎ 二‎ …‎ 九‎ 一十‎ 一十一‎ …‎ 一十九‎ 二十‎ 二十一‎ …‎ 九十九‎ 一百‎ 一百零一
    - [`TraditionalChineseFormal`](https://khonsulabs.github.io/nominals/main/nominals/struct.TraditionalChineseFormal.html): 零‎ 一‎ 二‎ …‎ 九‎ 一十‎ 一十一‎ …‎ 一十九‎ 二十‎ 二十一‎ …‎ 九十九‎ 一百‎ 一百零一
    - [`CjkDecimal`](https://khonsulabs.github.io/nominals/main/nominals/struct.CjkDecimal.html): 〇‎ 一‎ 二‎ 三‎ 四‎ …‎ 九‎ 一〇‎ 一一‎ 一二‎ …‎ 九九‎ 一〇〇‎ 一〇一‎ 一〇二
    - [`CjkEarthlyBranch`](https://khonsulabs.github.io/nominals/main/nominals/struct.CjkEarthlyBranch.html): 子‎ 丑‎ 寅‎ 卯‎ 辰‎ …‎ 亥‎ 一三‎ 一四‎ 一五‎ …‎ 一四四‎ 一四五‎ 一四六‎ 一四七
    - [`CjkHeavenlyStem`](https://khonsulabs.github.io/nominals/main/nominals/struct.CjkHeavenlyStem.html): 甲‎ 乙‎ 丙‎ 丁‎ 戊‎ …‎ 癸‎ 一一‎ 一二‎ 一三‎ …‎ 一〇〇‎ 一〇一‎ 一〇二‎ 一〇三
    - [`Devanagari`](https://khonsulabs.github.io/nominals/main/nominals/struct.Devanagari.html): ०‎ १‎ २‎ ३‎ ४‎ …‎ ९‎ १०‎ ११‎ १२‎ …‎ ९९‎ १००‎ १०१‎ १०२
    - [`EasternArabic`](https://khonsulabs.github.io/nominals/main/nominals/struct.EasternArabic.html): ٠‎ ١‎ ٢‎ ٣‎ ٤‎ …‎ ٩‎ ١٠‎ ١١‎ ١٢‎ …‎ ٩٩‎ ١٠٠‎ ١٠١‎ ١٠٢
    - [`Ethiopic`](https://khonsulabs.github.io/nominals/main/nominals/struct.Ethiopic.html): ፩‎ ፪‎ ፫‎ …‎ ፲‎ ፲፩‎ ፲፪‎ …‎ ፺፱‎ ፻‎ ፻፩‎ …‎ ፱፻፺፱‎ ፲፻‎ ፲፻፩
    - [`Georgian`](https://khonsulabs.github.io/nominals/main/nominals/struct.Georgian.html): ა‎ ბ‎ გ‎ …‎ თ‎ ი‎ ია‎ იბ‎ …‎ ჟთ‎ რ‎ რა
    - [`GreekLower`](https://khonsulabs.github.io/nominals/main/nominals/struct.GreekLower.html): α‎ β‎ γ‎ δ‎ ε‎ …‎ ω‎ αα‎ αβ‎ αγ‎ …‎ ψω‎ ωα‎ ωβ‎ ωγ
    - [`GreekUpper`](https://khonsulabs.github.io/nominals/main/nominals/struct.GreekUpper.html): Α‎ Β‎ Γ‎ Δ‎ Ε‎ …‎ Ω‎ ΑΑ‎ ΑΒ‎ ΑΓ‎ …‎ ΨΩ‎ ΩΑ‎ ΩΒ‎ ΩΓ
    - [`Gujarati`](https://khonsulabs.github.io/nominals/main/nominals/struct.Gujarati.html): ૦‎ ૧‎ ૨‎ ૩‎ ૪‎ …‎ ૯‎ ૧૦‎ ૧૧‎ ૧૨‎ …‎ ૯૯‎ ૧૦૦‎ ૧૦૧‎ ૧૦૨
    - [`Gurmukhi`](https://khonsulabs.github.io/nominals/main/nominals/struct.Gurmukhi.html): ੦‎ ੧‎ ੨‎ ੩‎ ੪‎ …‎ ੯‎ ੧੦‎ ੧੧‎ ੧੨‎ …‎ ੯੯‎ ੧੦੦‎ ੧੦੧‎ ੧੦੨
    - [`HanjaInformal`](https://khonsulabs.github.io/nominals/main/nominals/struct.HanjaInformal.html): 零‎ 一‎ 二‎ …‎ 九‎ 十‎ 十一‎ …‎ 十九‎ 二十‎ 二十一‎ …‎ 九十九‎ 百‎ 百一
    - [`HangeulFormal`](https://khonsulabs.github.io/nominals/main/nominals/struct.HangeulFormal.html): 영‎ 일‎ 이‎ …‎ 구‎ 일십‎ 일십일‎ …‎ 일십구‎ 이십‎ 이십일‎ …‎ 구십구‎ 일백‎ 일백일
    - [`HangeulJamo`](https://khonsulabs.github.io/nominals/main/nominals/struct.HangeulJamo.html): ㄱ‎ ㄴ‎ ㄷ‎ ㄹ‎ ㅁ‎ …‎ ㅎ‎ ㄱㄱ‎ ㄱㄴ‎ ㄱㄷ‎ …‎ ㅍㅎ‎ ㅎㄱ‎ ㅎㄴ‎ ㅎㄷ
    - [`HangeulSyllable`](https://khonsulabs.github.io/nominals/main/nominals/struct.HangeulSyllable.html): 가‎ 나‎ 다‎ 라‎ 마‎ …‎ 하‎ 가가‎ 가나‎ 가다‎ …‎ 파하‎ 하가‎ 하나‎ 하다
    - [`HanjaFormal`](https://khonsulabs.github.io/nominals/main/nominals/struct.HanjaFormal.html): 零‎ 壹‎ 貳‎ …‎ 九‎ 壹拾‎ 壹拾壹‎ …‎ 壹拾九‎ 貳拾‎ 貳拾壹‎ …‎ 九拾九‎ 壹百‎ 壹百壹
    - [`Hebrew`](https://khonsulabs.github.io/nominals/main/nominals/struct.Hebrew.html): ׳א״‎ ׳ב״‎ ׳ג״‎ …‎ ׳ט״‎ ׳י״‎ …‎ יג‎ יד‎ ט״ו‎ ט״ז‎ יז‎ …‎ שצו‎ שצז‎ שצח‎ שצט‎ ׳ת״
    - [`HexLower`](https://khonsulabs.github.io/nominals/main/nominals/struct.HexLower.html): 0‎ 1‎ 2‎ 3‎ 4‎ …‎ f‎ 10‎ 11‎ 12‎ …‎ ff‎ 100‎ 101‎ 102
    - [`HexUpper`](https://khonsulabs.github.io/nominals/main/nominals/struct.HexUpper.html): 0‎ 1‎ 2‎ 3‎ 4‎ …‎ F‎ 10‎ 11‎ 12‎ …‎ FF‎ 100‎ 101‎ 102
    - [`Hiragana`](https://khonsulabs.github.io/nominals/main/nominals/struct.Hiragana.html): あ‎ い‎ う‎ え‎ お‎ …‎ ん‎ ああ‎ あい‎ あう‎ …‎ をん‎ んあ‎ んい‎ んう
    - [`HiraganaIroha`](https://khonsulabs.github.io/nominals/main/nominals/struct.HiraganaIroha.html): い‎ ろ‎ は‎ に‎ ほ‎ …‎ す‎ いい‎ いろ‎ いは‎ …‎ せす‎ すい‎ すろ‎ すは
    - [`JapaneseFormal`](https://khonsulabs.github.io/nominals/main/nominals/struct.JapaneseFormal.html): 零‎ 壱‎ 弐‎ …‎ 九‎ 壱拾‎ 壱拾壱‎ …‎ 壱拾九‎ 弐拾‎ 弐拾壱‎ …‎ 九拾九‎ 壱百‎ 壱百壱
    - [`JapaneseInformal`](https://khonsulabs.github.io/nominals/main/nominals/struct.JapaneseInformal.html): 〇‎ 一‎ 二‎ …‎ 九‎ 十‎ 十一‎ …‎ 十九‎ 二十‎ 二十一‎ …‎ 九十九‎ 百‎ 百一
    - [`Kannada`](https://khonsulabs.github.io/nominals/main/nominals/struct.Kannada.html): ೦‎ ೧‎ ೨‎ ೩‎ ೪‎ …‎ ೯‎ ೧೦‎ ೧೧‎ ೧೨‎ …‎ ೯೯‎ ೧೦೦‎ ೧೦೧‎ ೧೦೨
    - [`Katakana`](https://khonsulabs.github.io/nominals/main/nominals/struct.Katakana.html): ア‎ イ‎ ウ‎ エ‎ オ‎ …‎ ン‎ アア‎ アイ‎ アウ‎ …‎ ヲン‎ ンア‎ ンイ‎ ンウ
    - [`KatakanaIroha`](https://khonsulabs.github.io/nominals/main/nominals/struct.KatakanaIroha.html): イ‎ ロ‎ ハ‎ ニ‎ ホ‎ …‎ ス‎ イイ‎ イロ‎ イハ‎ …‎ セス‎ スイ‎ スロ‎ スハ
    - [`Lao`](https://khonsulabs.github.io/nominals/main/nominals/struct.Lao.html): ໐‎ ໑‎ ໒‎ ໓‎ ໔‎ …‎ ໙‎ ໑໐‎ ໑໑‎ ໑໒‎ …‎ ໙໙‎ ໑໐໐‎ ໑໐໑‎ ໑໐໒
    - [`Malayalam`](https://khonsulabs.github.io/nominals/main/nominals/struct.Malayalam.html): ൦‎ ൧‎ ൨‎ ൩‎ ൪‎ …‎ ൯‎ ൧൦‎ ൧൧‎ ൧൨‎ …‎ ൯൯‎ ൧൦൦‎ ൧൦൧‎ ൧൦൨
    - [`Mongolian`](https://khonsulabs.github.io/nominals/main/nominals/struct.Mongolian.html): ᠐‎ ᠑‎ ᠒‎ ᠓‎ ᠔‎ …‎ ᠙‎ ᠑᠐‎ ᠑᠑‎ ᠑᠒‎ …‎ ᠙᠙‎ ᠑᠐᠐‎ ᠑᠐᠑‎ ᠑᠐᠒
    - [`Myanmar`](https://khonsulabs.github.io/nominals/main/nominals/struct.Myanmar.html): ၀‎ ၁‎ ၂‎ ၃‎ ၄‎ …‎ ၉‎ ၁၀‎ ၁၁‎ ၁၂‎ …‎ ၉၉‎ ၁၀၀‎ ၁၀၁‎ ၁၀၂
    - [`Oriya`](https://khonsulabs.github.io/nominals/main/nominals/struct.Oriya.html): ୦‎ ୧‎ ୨‎ ୩‎ ୪‎ …‎ ୯‎ ୧୦‎ ୧୧‎ ୧୨‎ …‎ ୯୯‎ ୧୦୦‎ ୧୦୧‎ ୧୦୨
    - [`Persian`](https://khonsulabs.github.io/nominals/main/nominals/struct.Persian.html): ۰‎ ۱‎ ۲‎ ۳‎ ۴‎ …‎ ۹‎ ۱۰‎ ۱۱‎ ۱۲‎ …‎ ۹۹‎ ۱۰۰‎ ۱۰۱‎ ۱۰۲
    - [`Tamil`](https://khonsulabs.github.io/nominals/main/nominals/struct.Tamil.html): ௦‎ ௧‎ ௨‎ ௩‎ ௪‎ …‎ ௯‎ ௧௦‎ ௧௧‎ ௧௨‎ …‎ ௯௯‎ ௧௦௦‎ ௧௦௧‎ ௧௦௨
    - [`Telugu`](https://khonsulabs.github.io/nominals/main/nominals/struct.Telugu.html): ౦‎ ౧‎ ౨‎ ౩‎ ౪‎ …‎ ౯‎ ౧౦‎ ౧౧‎ ౧౨‎ …‎ ౯౯‎ ౧౦౦‎ ౧౦౧‎ ౧౦౨
    - [`Thai`](https://khonsulabs.github.io/nominals/main/nominals/struct.Thai.html): ๐‎ ๑‎ ๒‎ ๓‎ ๔‎ …‎ ๙‎ ๑๐‎ ๑๑‎ ๑๒‎ …‎ ๙๙‎ ๑๐๐‎ ๑๐๑‎ ๑๐๒
    - [`Tibetan`](https://khonsulabs.github.io/nominals/main/nominals/struct.Tibetan.html): ༠‎ ༡‎ ༢‎ ༣‎ ༤‎ …‎ ༩‎ ༡༠‎ ༡༡‎ ༡༢‎ …‎ ༩༩‎ ༡༠༠‎ ༡༠༡‎ ༡༠༢

    ## Open-source Licenses

    This project, like all projects from [Khonsu Labs](https://khonsulabs.com/), is open-source.
    This repository is available under the [MIT License](./LICENSE-MIT) or the
    [Apache License 2.0](./LICENSE-APACHE).

    To learn more about contributing, please see [CONTRIBUTING.md](./CONTRIBUTING.md).