Skip to content

Repository files navigation

shevchenko.js

JavaScript library for the declension of Ukrainian personal names.

NPM Version NPM Downloads Docker Pulls

Links

Extensions

User guide

Installation

Install the library with npm:

npm install shevchenko

Import

The library is available as a CommonJS module, an ECMAScript module and a minified UMD bundle.

CommonJS

const shevchenko = require('shevchenko');

ECMAScript module

import * as shevchenko from 'shevchenko';

UMD

Load the bundle with a <script> tag. It exposes the library as the global shevchenko variable.

<script type="text/javascript" src="https://unpkg.com/shevchenko"></script>

Use cases

Declining names

This example declines a full name in the vocative case.

const shevchenko = require('shevchenko');

async function main() {
  const name = {
    givenName: 'Тарас',
    patronymicName: 'Григорович',
    familyName: 'Шевченко'
  };

  const vocative = await shevchenko.inVocative({ ...name, gender: 'masculine' });

  console.log(vocative); // { givenName: "Тарасе", patronymicName: "Григоровичу", familyName: "Шевченку" }
}

main().catch((error) => console.error(error));

Detecting grammatical gender

This example detects the grammatical gender of a name before declining it.

const shevchenko = require('shevchenko');

async function main() {
  const name = {
    givenName: 'Лариса',
    patronymicName: 'Петрівна',
    familyName: 'Косач-Квітка'
  };

  const gender = await shevchenko.detectGender(name); // "feminine"
  if (gender == null) {
    throw new Error('Failed to detect grammatical gender.');
  }

  const vocative = await shevchenko.inVocative({ ...name, gender });

  console.log(vocative); // { givenName: "Ларисо", patronymicName: "Петрівно", familyName: "Косач-Квітко" }
}

main().catch((error) => console.error(error));

Using the HTTP API

The library is also available as an HTTP API. See the tooleks/shevchenko Docker image for setup instructions.