shevchenko
Version:
JavaScript library for declension of Ukrainian anthroponyms
40 lines (37 loc) • 1.53 kB
JavaScript
/**
* @file JavaScript library for declension of Ukrainian anthroponyms
* @module shevchenko
* @version 3.1.4
* @author Oleksandr Tolochko <shevchenko-js@tooleks.com>
* @license MIT
* @copyright 2017-2025 Oleksandr Tolochko <shevchenko-js@tooleks.com>
* @see {@link git+https://github.com/tooleks/shevchenko-js.git}
*/
import givenNameRules from './artifacts/given-name-rules.json.js';
import patronymicNameRules from './artifacts/patronymic-name-rules.json.js';
import { GrammaticalGenderDetector } from './grammatical-gender-detector.js';
const givenNameDetector = new GrammaticalGenderDetector({
masculinePattern: new RegExp(givenNameRules.masculine, 'i'),
femininePattern: new RegExp(givenNameRules.feminine, 'i'),
});
const patronymicNameDetector = new GrammaticalGenderDetector({
masculinePattern: new RegExp(patronymicNameRules.masculine, 'i'),
femininePattern: new RegExp(patronymicNameRules.feminine, 'i'),
});
/**
* Detects the grammatical gender of the anthroponym using
* patronymic name or given name endings.
*
* Returns the grammatical gender of the anthroponym.
* Returns null if the grammatical gender of the anthroponym cannot be detected.
*/
function detectGender(anthroponym) {
if (anthroponym.patronymicName) {
return patronymicNameDetector.detect(anthroponym.patronymicName.toLocaleLowerCase());
}
if (anthroponym.givenName) {
return givenNameDetector.detect(anthroponym.givenName.toLocaleLowerCase());
}
return null;
}
export { detectGender };