All Projects → klyrr → krokus

klyrr / krokus

Licence: MIT license
A library to format numbers and a collection for localization patterns.

Programming Languages

javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to krokus

logstash-laravel-logs
Process Laravel Log files on Logstash and forward to ElasticSearch
Stars: ✭ 35 (+118.75%)
Mutual labels:  parse
svg-quick-editor
SVG Quick Editor is a free and open-source SVG editing tool. It offers features such as editing SVG colors, viewing or deleting their paths.
Stars: ✭ 88 (+450%)
Mutual labels:  parse
abstract-syntax-tree
A library for working with abstract syntax trees.
Stars: ✭ 77 (+381.25%)
Mutual labels:  parse
rasn1
Ruby ASN.1 library
Stars: ✭ 14 (-12.5%)
Mutual labels:  parse
xml-spac
Handle streaming XML data with declarative, composable parsers
Stars: ✭ 39 (+143.75%)
Mutual labels:  parse
parse
Parse with an Eloquent-like interface for Laravel
Stars: ✭ 15 (-6.25%)
Mutual labels:  parse
rpgdice
A generic RPG dice roller syntax and library.
Stars: ✭ 24 (+50%)
Mutual labels:  parse
icc
JavaScript module to parse International Color Consortium (ICC) profiles
Stars: ✭ 37 (+131.25%)
Mutual labels:  parse
php-simple-request
php-simple-request is a request parser library designed to simplify requests validation and filtering using annotations, generating at the same time an object representation from the request data.
Stars: ✭ 15 (-6.25%)
Mutual labels:  parse
limelight
A php Japanese language text analyzer and parser.
Stars: ✭ 76 (+375%)
Mutual labels:  parse
color-math
Expressions to manipulate colors.
Stars: ✭ 18 (+12.5%)
Mutual labels:  parse
parse-csv
CSV parser for node.js
Stars: ✭ 15 (-6.25%)
Mutual labels:  parse
ParseCareKit
Securely synchronize any CareKit 2.1+ based app to a Parse Server Cloud. Compatible with parse-hipaa.
Stars: ✭ 28 (+75%)
Mutual labels:  parse
ujson drf
JSON Renderer and Parser for Django Rest Framework using the ultra fast json (in C).
Stars: ✭ 14 (-12.5%)
Mutual labels:  parse
android-tao-rest-data-processor
Android REST Data Processor library. Easy to build a REST request, to receive and processing data (XML, JSON, CSV and etc.) from REST requests, file system, assets.
Stars: ✭ 24 (+50%)
Mutual labels:  parse
BaaSDelphiSamples
💾 Code samples for BaaS and PaaS using Delphi
Stars: ✭ 30 (+87.5%)
Mutual labels:  parse
jgeXml
The Just-Good-Enough XML Toolkit
Stars: ✭ 20 (+25%)
Mutual labels:  parse
Astview
Astview is a graphical viewer for abstract syntax trees
Stars: ✭ 20 (+25%)
Mutual labels:  parse
xml-to-json
Simple API that converts dynamic XML feeds to JSON through a URL or pasting the raw XML data. Made 100% in PHP.
Stars: ✭ 38 (+137.5%)
Mutual labels:  parse
elm-html-parser
Parse HTML in Elm!
Stars: ✭ 44 (+175%)
Mutual labels:  parse

Krokus

Build Status Locales 703 Currencies 301

A provider for localization patterns and a number and currency formatter and parser.

In order to have the all currency and locale patterns in one place.

ISO 4217 is a standard to format currencies.

The data is generated from CLDR33.

Installation

npm

npm install --save krokus

yarn

yarn add krokus


Use the krokus formatter

import krokus from 'krokus';

const formatPattern = {
  pattern: '#,##0.00 ¤',
  decimal_sep: ',',
  group_sep: '.',
  symbol: '€',
};

> krokus.formatCurrency(10000, formatPattern);
10.000,00 

Use the krokus parser

import krokus from 'krokus';

const formatPattern = {
  pattern: '#,##0.00 ¤',
  decimal_sep: ',',
  group_sep: '.',
  symbol: '€',
};

> krokus.parseCurrency('10.000,00 €', formatPattern);
10000

Access the generated currency and locale settings

import krokus from 'krokus';

> krokus.locales.de_DE
{ decimal_sep: ',',
  group_sep: '.',
  number_pattern: '#,##0.###',
  currency_pattern: '#,##0.00 ¤' }

> krokus.currencies.EUR
{ symbol: '€', wideSymbol: '€', code: 'EUR' }

Real-life example

Use the krokus calls in your functions:

import krokus from 'krokus';

export const formatNumber = (amount, locale) => {
  const format = krokus.locales[locale];
  format.pattern = format.number_pattern;
  return krokus.formatNumber(amount, format);
};

export const formatCurrency = (amount, locale, currency) => {
  if (!currency) {
    return formatNumber(amount, locale);
  }

  const localeData = krokus.locales[locale];
  const currencyData = krokus.currencies[currency.code];

  return krokus.formatCurrency(amount, {
    pattern: localeData.currency_pattern,
    decimal_sep: localeData.decimal_sep,
    group_sep: localeData.group_sep,
    symbol: currencyData.wideSymbol
  });
};

Run the tests if the formats are still generating the expected formatted numbers in JS

yarn

yarn test

Generate the krokus number formatter from the es6 files

yarn

yarn run compile

Create the up-to-date version of the json files

bundle install

rake update
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].