https://github.com/fakundo/excel-style-javascript-dataformatter
Excel-Style Dataformatter
https://github.com/fakundo/excel-style-javascript-dataformatter
Last synced: 8 months ago
JSON representation
Excel-Style Dataformatter
- Host: GitHub
- URL: https://github.com/fakundo/excel-style-javascript-dataformatter
- Owner: fakundo
- Created: 2013-10-14T19:10:59.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-12-25T12:30:35.000Z (over 8 years ago)
- Last Synced: 2025-06-22T04:12:39.570Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 386 KB
- Stars: 8
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Excel-Style Javascript Data Formatter
[](https://www.npmjs.org/package/excel-style-dataformatter)
## Current version supports
- Number formatting (decimal form, fractional form, percents, etc.)
- Date formatting (elapsed time, am/pm)
- Predefined excel formats (Fixed, Standard, etc.)
- Localization
# Install
```
npm install excel-style-dataformatter
```
```
bower install excel-style-dataformatter
```
# Usage
## CommonJS
```js
import DataFormatter from 'excel-style-dataformatter';
const dataFormatter = new DataFormatter();
const result = dataFormatter.format('99', 'Number', 'Currency');
```
#### With locales
```js
import DataFormatter from 'excel-style-dataformatter';
import ru from 'excel-style-dataformatter/lib/ru';
// Create instance with defined locales
const options = { locales: [ru] };
const dataFormatter = new DataFormatter(options);
// Switch locale
dataFormatter.setLocale('ru');
const result = dataFormatter.format('99', 'Number', 'Currency');
```
## Browser
```html
// Create instance
var dataFormatter = new window.DataFormatter({
locales: [window.DataFormatter_ru]
});
// Default locale
document.write(dataFormatter.format('123.44', 'Number', 'Currency').value);
// Switch to russian
dataFormatter.setLocale('ru');
document.write(dataFormatter.format('123.44', 'Number', 'Currency').value);
```
## AMD
```html
require(['excel-style-dataformatter/lib/index', 'excel-style-dataformatter/lib/locales/ru'], function() {
require(['DataFormatter', 'DataFormatter_ru'], function(DataFormatter, ru) {
// Create instance
var dataFormatter = new DataFormatter({
locales: [ru]
});
// Default locale
document.write(dataFormatter.format('99', 'Number', 'Currency').value);
// Switch to russian
dataFormatter.setLocale('ru');
document.write(dataFormatter.format('99', 'Number', 'Currency').value);
});
});
```
# Available options
```
locale {string} - default locale
locales {string} - defined locales
UTCOffset {number|null} - UTC offset for dates in minutes
transformCode {function}
debug {boolean}
```
# API
* `.format(value, type, format)`
* `.defineLocales(locales)`
* `.setLocale(locale)`
* `.setUTCOffset(offset)`