Giter Club home page Giter Club logo

icelandic's Introduction

Icelandic

This is a collection of ES6 methods for dealthing with Icelandic language text.

Installing

It's available on NPM:

npm i --save icelandic

Usage

These are the methods available and what they do:

icelandic.decompose(word)

Replaces special Icelandic characters in a string with their ASCII equivalents.

const icelandic = require("icelandic");
icelandic.decompose("Sævör grét áðan því úlpan var ónýt.")
// = "Saevor gret adan thvi ulpan var onyt."

icelandic.slugify(word)

A variant of decompose that will also remove non-word characters and clean up spaces and punctuation into dashes:

const icelandic = require("icelandic");
icelandic.decompose("Sævör grét áðan því úlpan var ónýt.")
// = "Saevor-gret-adan-thvi-ulpan-var-onyt"

icelandic.alphabetical(word1, word2)

Collate function for sorting strings using Icelandic alphabetical rules.

const icelandic = require("icelandic");
["áríðandi", "ári", "árið", "Ári"].sort(icelandic.alphabetical)
// = [ "ári", "Ári", "árið", "áríðandi" ]

icelandic.isPlural(number)

Report whether an integer demands a plural or singular declension. Icelandic language has only a single plural form.

const icelandic = require("icelandic");
icelandic.isPlural(11)
// = false

icelandic.numerals(number [, gender] [, yearMode])

Encodes a number into word numbers. It supports a range up to 1021. Fractions are supported but limited to three decimals.

const icelandic = require("icelandic");
icelandic.numerals(123456789)
// = "hundrað tuttugu og þrjár milljónir fjögur hundruð fimmtíu og sex þúsund sjö hundruð áttatíu og níu"

The gender argument should be one of "kk" (masculine), "kvk" (feminine), "hvk" (neuter). Function will default to neuter if nothing is provided.

icelandic.numerals(53, "kk")
// = "fimmtíu og þrír"

icelandic.numerals(53, "kvk")
// = "fimmtíu og þrjár"

The yearMode argument can be made to get the less conventional teen form of hundreds for the range of numbers from 1000–2000.

icelandic.numerals(1985, "hvk", true)
// = "nítján hundruð áttatíu og fimm"

icelandic.syllableCount(word)

Count the number of syllables that make up an Icelandic word. This is basically as simple as counting the vowels, except Icelandic has cases of dipthongs that need to be counted specially:

const icelandic = require("icelandic");
icelandic.syllableCount("augasteinn")
// = 3

icelandic.rhymeEncode(word [, number])

Reduces a word into a simpler version that can be matched with other similar reductions to determine if the words rhyme.

const icelandic = require("icelandic");
icelandic.rhymeEncode("heimkynninu")
// = 'h1mkininu'

The function takes a second argument that will limit the output to a number of syllables. Rhymes in Icelandic generally only use the final 1-2 syllables, so a more realistic way of determining if words rhyme would be something like comparing the final 2 syllables:

const rhymeEncode = require("icelandic").rhymeEncode;
rhymeEncode( 'augljósa', 2 ) === rhymeEncode( 'laktósa', 2 );
// = true

Additionally, the collection provides some common strings useful for internationalization:

icelandic.i18n

Exists as an object which members are names of days and months in the Icelandic language:

console.log(icelandic.i18n);
// {
//   'decimal': ',',
//   'thousands': '.',
//   'days': ['Sunnudagur', 'Mánudagur', ... ],
//   'shortDays': ['Sun', 'Mon', ... ],
//   'months': ['Janúar', 'Febrúar', ... ],
//   'shortMonths': ['Jan', 'Feb', ... ]
// }

icelandic's People

Contributors

borgar 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.