pravopis
v1.0.0
Published
Set of helper string manipulation functions for handling Serbian language orthography rules correctly
Downloads
2
Readme
pravopis
pravopis
is a Node.js module which implements a few string manipulation functions which are useful
when working with text in Serbian language as they handle Serbian language orthography rules correctly.
Goal of this project is to implement functions covering all Serbian language orthography rules. For now just the most basic ones are implemented.
Installation
You can get latest version of pravopis
by cloning this repository or by installing the module via Yarn:
yarn add pravopis
Or, if you are still stuck with NPM, via:
npm install --save pravopis
Usage
const pravopis = require('pravopis');
console.log(pravopis.toCyrillic('Pozdrav!')); // => Поздрав!
Usage in browser:
Use a module bundler like Webpack or Browserify which can bundle Node modules easily.
API
pravopis.toCyrillic(s)
Transliterates string s
from Serbian Latin to Serbian Cyrillic alphabet honoring orthography rules for transliterating nj
/lj
/dž
to њ
/љ
/џ
.
Examples:
pravopis.toCyrillic('pravopis'); // правопис
pravopis.toCyrillic('injekcija, njiva'); // инјекција, њива
pravopis.toCyrillic('patlidžan, nadživeti'); // патлиџан, надживети
pravopis.toLatin(s)
Transliterates string s
from Serbian Cyrillic to Serbian Latin alphabet.
Examples:
pravopis.toCyrillic('pravopis'); // правопис
pravopis.toCyrillic('injekcija, njiva'); // инјекција, њива
pravopis.toCyrillic('patlidžan, nadživeti'); // патлиџан, надживети
pravopis.toVocative(name)
Returns vocative form of string name
(which is nominative form of a person's given name). Preserves casing and alphabet of a given string.
Examples:
pravopis.toVocative('Ђура'); // Ђуро
pravopis.toVocative('ПЕТАР'); // ПЕТРЕ
pravopis.toVocative('milojica'); // milojice
pravopis.toVocative('Stanoje'); // Stanoje
pravopis.equals(a, b)
Compares strings a
and b
and returns true
if they are equal, ignoring difference in used alphabet.
Examples:
pravopis.equals('latinica', 'латиница'); // true
pravopis.equals('ćirilica', 'ћирилица'); // true
pravopis.equals('ćirilica', 'Ћирилица'); // false
pravopis.equalsIgnoreCase(a, b)
Compares strings a
and b
and returns true
if they are equal, ignoring difference in case and used alphabet.
Examples:
pravopis.equalsIgnoreCase('latinica', 'латиница'); // true
pravopis.equalsIgnoreCase('ćirilica', 'ћирилица'); // true
pravopis.equalsIgnoreCase('ćirilica', 'Ћирилица'); // true
pravopis.hasCyrillic(s)
Returns true
if string s
has at least one Serbian Cyrillic letter.
Examples:
pravopis.hasCyrillic('ћирилица'); // true
pravopis.hasCyrillic('ćirilica'); // false
pravopis.hasLatin(s)
Returns true
if string s
has at least one Serbian Latin letter.
Examples:
pravopis.hasLatin('ћирилица'); // false
pravopis.hasLatin('ćirilica'); // true
Is it any good?
Yes.
Credits
- transliteration rules borrowed from this vokabular.org discussion
- vocative dictionary and rules adapted from Vokativ project by Nemanja Avramović.
Licence
MIT