turkish-harmony-suffixes
v1.0.2
Published
A package for Turkish suffixes, using the harmony of the Turkish language
Downloads
133
Readme
Turkish Suffix Library
A TypeScript library for handling Turkish language suffixes with proper vowel harmony and consonant softening rules.
Features
- ✅ Full support for Turkish vowel harmony (2-way and 4-way)
- ✅ Automatic consonant softening (yumuşama)
- ✅ Proper noun handling with apostrophes
- ✅ Foreign word support
- ✅ Abbreviation handling
- ✅ TypeScript support with full type safety
- ✅ Zero dependencies
- ✅ Comprehensive test coverage
Installation
npm install turkish-suffixesor with Yarn:
yarn add turkish-suffixesor with Bun:
bun add turkish-suffixesUsage
import { withTurkishSuffix, TurkishCase } from 'turkish-suffixes';
// Plural
withTurkishSuffix('ev', TurkishCase.PLURAL); // 'evler'
withTurkishSuffix('araba', TurkishCase.PLURAL); // 'arabalar'
// Possessive
withTurkishSuffix('ev', TurkishCase.POSSESSIVE); // 'evin'
withTurkishSuffix('araba', TurkishCase.POSSESSIVE); // 'arabanın'
// Dative (to/for)
withTurkishSuffix('ev', TurkishCase.DATIVE); // 'eve'
withTurkishSuffix('okul', TurkishCase.DATIVE); // 'okula'
// Accusative (direct object)
withTurkishSuffix('ev', TurkishCase.ACCUSATIVE); // 'evi'
withTurkishSuffix('araba', TurkishCase.ACCUSATIVE); // 'arabayı'
// Locative (at/in/on)
withTurkishSuffix('ev', TurkishCase.LOCATIVE); // 'evde'
withTurkishSuffix('masa', TurkishCase.LOCATIVE); // 'masada'
// Ablative (from)
withTurkishSuffix('ev', TurkishCase.ABLATIVE); // 'evden'
withTurkishSuffix('okul', TurkishCase.ABLATIVE); // 'okuldan'API Reference
withTurkishSuffix(text: string, suffix: TurkishCase): string
Applies a Turkish suffix to the given text with proper vowel harmony.
Parameters
text: The word to apply the suffix tosuffix: The type of suffix to apply (fromTurkishCaseenum)
TurkishCase Enum
enum TurkishCase {
PLURAL = 'PLURAL', // -lar/-ler
POSSESSIVE = 'POSSESSIVE', // -(n)ın/-(n)in/-(n)un/-(n)ün
DATIVE = 'DATIVE', // -(y)a/-(y)e
ACCUSATIVE = 'ACCUSATIVE', // -(y)ı/-(y)i/-(y)u/-(y)ü
LOCATIVE = 'LOCATIVE', // -da/-de/-ta/-te
ABLATIVE = 'ABLATIVE', // -dan/-den/-tan/-ten
KI = 'ki' // -ki (unchanging)
}Special Features
Proper Nouns
Proper nouns are automatically detected and handled with apostrophes:
withTurkishSuffix('Ali', TurkishCase.DATIVE); // "Ali'ye"
withTurkishSuffix('İstanbul', TurkishCase.LOCATIVE); // "İstanbul'da"
withTurkishSuffix('Ankara', TurkishCase.ABLATIVE); // "Ankara'dan"Foreign Words
Mark foreign words with |y flag to prevent consonant softening:
withTurkishSuffix('computer|y', TurkishCase.POSSESSIVE); // "computer'ın"
withTurkishSuffix('laptop|y', TurkishCase.ACCUSATIVE); // "laptop'u"Consonant Softening
The library automatically applies consonant softening rules:
withTurkishSuffix('kitap', TurkishCase.POSSESSIVE); // "kitabın" (p → b)
withTurkishSuffix('ağaç', TurkishCase.DATIVE); // "ağaca" (ç → c)
withTurkishSuffix('renk', TurkishCase.POSSESSIVE); // "rengin" (k → g)Numbers and Abbreviations
withTurkishSuffix('2024', TurkishCase.LOCATIVE); // "2024'te"
withTurkishSuffix('TV', TurkishCase.DATIVE); // "TV'ye"
withTurkishSuffix('GPS', TurkishCase.ABLATIVE); // "GPS'den"Vowel Harmony Rules
The library automatically applies Turkish vowel harmony rules:
2-Way Harmony (a/e)
- Back vowels (a, ı, o, u) → -a
- Front vowels (e, i, ö, ü) → -e
4-Way Harmony (ı/i/u/ü)
- Back unrounded (a, ı) → -ı
- Back rounded (o, u) → -u
- Front unrounded (e, i) → -i
- Front rounded (ö, ü) → -ü
Examples
Complete Example
import { withTurkishSuffix, TurkishCase } from 'turkish-suffixes';
const word = 'ev';
console.log(`${word}'in halleri:`);
console.log(`Çoğul: ${withTurkishSuffix(word, TurkishCase.PLURAL)}`); // evler
console.log(`İyelik: ${withTurkishSuffix(word, TurkishCase.POSSESSIVE)}`); // evin
console.log(`Yönelme: ${withTurkishSuffix(word, TurkishCase.DATIVE)}`); // eve
console.log(`Belirtme: ${withTurkishSuffix(word, TurkishCase.ACCUSATIVE)}`); // evi
console.log(`Bulunma: ${withTurkishSuffix(word, TurkishCase.LOCATIVE)}`); // evde
console.log(`Ayrılma: ${withTurkishSuffix(word, TurkishCase.ABLATIVE)}`); // evdenReal-world Usage
// Building sentences
const city = 'İstanbul';
const person = 'Ahmet';
console.log(`${withTurkishSuffix(person, TurkishCase.POSSESSIVE)} arabası`); // Ahmet'in arabası
console.log(`${withTurkishSuffix(city, TurkishCase.LOCATIVE)} yaşıyor`); // İstanbul'da yaşıyor
console.log(`${withTurkishSuffix(city, TurkishCase.ABLATIVE)} geliyor`); // İstanbul'dan geliyorDevelopment
Building
bun run buildTesting
bun testRunning Examples
bun run examples/usage.tsContributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Semih Ayhan - @smhayhan
Acknowledgments
- Thanks to all contributors who have helped improve this library
- Inspired by the beauty and complexity of the Turkish language
