0.4.3 • Published 2 years ago

intl-io v0.4.3

Weekly downloads
279
License
MIT
Repository
github
Last release
2 years ago

Culture specific date/time and number formatting and parsing based on ECMAScript Internationalization API (Intl).

Used for localized calendars, date fields and number fields in CxJS.

This module is available in four formats:

  • CommonJS: dist/intl-io.js
  • ES Module: dist/intl-io.module.js
  • Modern ES Module: dist/intl-io.modern.js
  • UMD: dist/intl-io.umd.js

Install

$ npm install intl-io --save

Usage

import { DateTimeCulture, NumberCulture } from 'intl-io';

let dateCulture = new DateTimeCulture('es');
dateCulture.format(new Date(), 'yyyyMMdd'); //28/08/2019
dateCulture.format(new Date(), 'yyyyMMMdd'); //28 ago. 2019
dateCulture.format(new Date(), 'yyyyMMdd'); //28 de agosto de 2019
dateCulture.format(new Date(), 'yyyyMMddDDD'); //mié., 28 de agosto de 2019
let date = culture.parse('mié., 28 de agosto de 2019', { loose: true }); //Aug 28, 2019

let numberCulture = new NumberCulture('de');
let formatter = numberCulture.getFormatter({
    style: 'currency',
    currency: 'EUR',
});
let currency = formatter.format(5555.5); //5.555,50 €
let number = numberCulture.parse('5.555,5'); //5555.5

For number formatting options look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat.

Date time formatting

Some parts support different length. Four digits means full name, three digits is a long form, two digits is medium and one digit is short form.

  • YYYY - full year (e.g. 2019)
  • YY - short year (e.g. 19)
  • MMMM - long month name (e.g. August)
  • MMM - short month name (e.g. Aug)
  • MM - two digit month (e.g. 08)
  • M - numeric month (e.g. 8)
  • DDDD - full day name (e.g. Monday)
  • DDD - short day name (e.g. Mon)
  • DD - short day name (e.g. Mo)
  • D - short day name (e.g. M)

Examples

FormatDescriptionResult
yyyyMMddShort date09/07/2019
yyyyMMMddMedium dateSep 07, 2019
HHmmShort time09:35 PM
HHmmNShort time21:35
yyyyMMMddHHmmFull date timeSep 07, 2019 09:35 PM

Format Specifiers

SpecifierPart
y, Yyear
Mmonth
Dday name
dday
h, Hhours
m, iminutes
s, Sseconds
a, Ahour12 AM/PM
p, Phour12 AM/PM
n, Nhour24
t, Ttimezone
u, UUTC timezone
z, ZUTC timezone

For detailed date formatting options look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat.

License

MIT © Codaxy

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.0

7 years ago

0.2.12

7 years ago

0.2.11

8 years ago

0.2.10

8 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

1.0.0

10 years ago