Giter VIP home page Giter VIP logo

preslovljivac-js's Introduction

preslovljivac-js

A simple transliteration library for Serbian language, written in Javascript and using ES Modules.

Usage

import preslovi from '@pionir/preslovljivac-js'; //loading the package  
console.log(preslovi("text",'','n')); /*using it to write "text" to console in cyrillic, the output will be "текст" */  
console.log(preslovi("текст",'','Cyrl')); //output will be "text"  

You can also give it a second parameter, in case you want something to remain unchanged.
For example, I want 'Microsoft' and 'Google' to remain the same:

import preslovi from '@pionir/preslovljivac-js';
console.log(preslovi("neki tekst, Google Microsoft", "Google, Microsoft",'a'));  
//the expected output is "неки текст, Google Microsoft"  

Do note though that you need to write it as a string, with each entry divided by commas (,).

You can also pass a third parameter.
If the third parameter is a 'falsy' value, it will use the auto-detector that i built: https://www.npmjs.com/package/@pionir/detektor-js.
It only counts through the first 512 characters, so if you have some massive strings it won't count through the entire string, so it may not be 100% accurate if both are abundant throughout the text. It will convert every character no matter the length of the string, though.
If you want to avoid this, you can give it a parameter 'Cyrl' for cyrillic, a non-empty string for latin.
For example:

import preslovi from '@pionir/preslovljivac-js';
console.log(preslovi("text in latin",'','t')); //i passed t as the third parameter so that it isn't a 'falsy' value  
//expected output is "текст ин латин"  
console.log(preslovi("текст на ћирилици",'','Cyrl')); /*i passed 'Cyrl' as the third parameter, so now it will treat it as cyrillic text and the output will be "tekst na ćirilici"*/  
//alternatively you can just let it use the auto-detect  
console.log(preslovi("text text and more text")); //the output here will be "текст текст анд море текст"  

./tests/main.js is a test file used with ava. Feel free to configure it as you wish.

Note: A few letters that exist in English latin don't exist in Serbian cyrillic, those are:
Q (translated as "ку"),
X (translated as "кс"),
Y (translated as "иј"),
W (translated as "в").

Here's a link to the npm page: https://www.npmjs.com/package/@pionir/preslovljivac-js
If you have any suggestions, feel free to send them to me. I'm always open for improvement.

preslovljivac-js's People

Contributors

njolf avatar marxo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.