1.1.0 • Published 5 months ago

i18n-possessive v1.1.0

Weekly downloads
20
License
MIT
Repository
github
Last release
5 months ago

i18n-possessive

Convert a noun into its possessive form in any of the supported languages, such as John to John’s (English) or Bella to de Bella (French).

Given a noun {name}, the language support is as follows:

LanguageLocale CodePossessive Rule
EnglishenAdds ’s to the noun.
SpanishesUses de before the noun (e.g., "el libro de Juan").
FrenchfrUses d’ if the noun starts with a vowel, otherwise de (e.g., "le livre d’Anne", "le livre de Marc").
GermandeAdds if the noun ends in s/ß/x/z, otherwise adds s.
PortugueseptUses de before the noun.
ItalianitUses di before the noun.
RussianruUses ’s (basic handling, may need improvement).
HindihiUses का (masculine) or की (feminine, contextual).
ArabicarUses ل before the noun to indicate possession (e.g., "كتاب ل علي" for "Ali’s book").
Mandarin ChinesezhUses after the noun (e.g., "张的书" for "Zhang’s book").
JapanesejaUses after the noun (e.g., "田中の本" for "Tanaka’s book").
KoreankoUses after the noun (e.g., "철수의 책" for "Chulsoo’s book").
TurkishtrUses nın or ın based on vowel harmony.
DutchnlAdds if the noun ends in s/ß/x/z, otherwise adds s.

Examples

import { possessive } from "i18n-possessive";

possessive("John", "en"));     // John’s
possessive("Sebastián", "es"); // de Sebastián
possessive("Bella", "fr");     // de Bella
possessive("Adalene", "fr");   // d’Adalene
possessive("Leon", "de");      // Leons
possessive("Niklas", "de");    // Niklas’
possessive("はると", "ja");     // はるとの

Thanks to Scott from the Slack team for the guidance!