Merge pull request #575 from Chalarangelo/add-toCurrency
Add toCurrency
This commit is contained in:
17
snippets/toCurrency.md
Normal file
17
snippets/toCurrency.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
### toCurrency
|
||||||
|
|
||||||
|
Take a number and return specified currency formatting.
|
||||||
|
|
||||||
|
Use `Intl.NumberFormat` to enable country / currency sensitive formatting.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const toCurrency = (n, curr, LanguageFormat = undefined) => Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
toCurrency(123456.789, 'EUR') // €123,456.79 | currency: Euro | currencyLangFormat: Local
|
||||||
|
toCurrency(123456.789, 'USD', 'en-us') // €123,456.79 | currency: US Dollar | currencyLangFormat: English (United States)
|
||||||
|
toCurrency(123456.789, 'USD', 'fa') // ۱۲۳٬۴۵۶٫۷۹ $ | currency: US Dollar | currencyLangFormat: Farsi
|
||||||
|
toCurrency(322342436423.2435, 'JPY') // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local
|
||||||
|
toCurrency(322342436423.2435, 'JPY', 'fi') // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish
|
||||||
|
```
|
||||||
@ -236,6 +236,7 @@ throttle:function
|
|||||||
times:function
|
times:function
|
||||||
timeTaken:utility
|
timeTaken:utility
|
||||||
toCamelCase:string,regexp
|
toCamelCase:string,regexp
|
||||||
|
toCurrency:utility
|
||||||
toDecimalMark:utility,math
|
toDecimalMark:utility,math
|
||||||
toggleClass:browser
|
toggleClass:browser
|
||||||
toKebabCase:string,regexp
|
toKebabCase:string,regexp
|
||||||
|
|||||||
@ -1,22 +1,13 @@
|
|||||||
const test = require('tape');
|
const test = require('tape');
|
||||||
//const arrayToHtmlList = require('./arrayToHtmlList.js');
|
const arrayToHtmlList = require('./arrayToHtmlList.js');
|
||||||
const jsdom = require('jsdom');
|
|
||||||
const { JSDOM } = jsdom;
|
|
||||||
const listID = 'myListID';
|
|
||||||
const dom = new JSDOM(`<ul id="${listID}"></ul>`);
|
|
||||||
// Override snippet to use jsdom
|
|
||||||
const arrayToHtmlList = (arr, listID) =>
|
|
||||||
arr.map(item => (dom.window.document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
|
|
||||||
|
|
||||||
test('Testing arrayToHtmlList', (t) => {
|
test('Testing arrayToHtmlList', (t) => {
|
||||||
//For more information on all the methods supported by tape
|
//For more information on all the methods supported by tape
|
||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function');
|
t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function');
|
||||||
arrayToHtmlList(['item 1', 'item 2'], 'myListID');
|
|
||||||
t.equals(dom.window.document.querySelector(`ul#${listID}`).innerHTML, '<li>item 1</li><li>item 2</li>', 'Generates and fills a list element');
|
|
||||||
//t.deepEqual(arrayToHtmlList(args..), 'Expected');
|
//t.deepEqual(arrayToHtmlList(args..), 'Expected');
|
||||||
//t.equal(arrayToHtmlList(args..), 'Expected');
|
//t.equal(arrayToHtmlList(args..), 'Expected');
|
||||||
//t.false(arrayToHtmlList(args..), 'Expected');
|
//t.false(arrayToHtmlList(args..), 'Expected');
|
||||||
//t.throws(arrayToHtmlList(args..), 'Expected');
|
//t.throws(arrayToHtmlList(args..), 'Expected');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
@ -1,20 +1,13 @@
|
|||||||
const test = require('tape');
|
const test = require('tape');
|
||||||
const hasClass = require('./hasClass.js');
|
const hasClass = require('./hasClass.js');
|
||||||
const jsdom = require('jsdom');
|
|
||||||
const { JSDOM } = jsdom;
|
|
||||||
|
|
||||||
test('Testing hasClass', (t) => {
|
test('Testing hasClass', (t) => {
|
||||||
//For more information on all the methods supported by tape
|
//For more information on all the methods supported by tape
|
||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof hasClass === 'function', 'hasClass is a Function');
|
t.true(typeof hasClass === 'function', 'hasClass is a Function');
|
||||||
const className = 'container'
|
//t.deepEqual(hasClass(args..), 'Expected');
|
||||||
const dom = new JSDOM(`
|
//t.equal(hasClass(args..), 'Expected');
|
||||||
<p class="${className}">Some text</p>
|
//t.false(hasClass(args..), 'Expected');
|
||||||
`);
|
//t.throws(hasClass(args..), 'Expected');
|
||||||
t.true(hasClass(dom.window.document.querySelector('p'), className), 'element has the specified class');
|
t.end();
|
||||||
//t.deepEqual(hasClass(args..), 'Expected');
|
|
||||||
//t.equal(hasClass(args..), 'Expected');
|
|
||||||
//t.false(hasClass(args..), 'Expected');
|
|
||||||
//t.throws(hasClass(args..), 'Expected');
|
|
||||||
t.end();
|
|
||||||
});
|
});
|
||||||
2
test/toCurrency/toCurrency.js
Normal file
2
test/toCurrency/toCurrency.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
const toCurrency = (n, curr, LanguageFormat = undefined) => new Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
|
||||||
|
module.exports = toCurrency
|
||||||
13
test/toCurrency/toCurrency.test.js
Normal file
13
test/toCurrency/toCurrency.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const toCurrency = require('./toCurrency.js');
|
||||||
|
|
||||||
|
test('Testing toCurrency', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof toCurrency === 'function', 'toCurrency is a Function');
|
||||||
|
//t.deepEqual(toCurrency(args..), 'Expected');
|
||||||
|
//t.equal(toCurrency(args..), 'Expected');
|
||||||
|
//t.false(toCurrency(args..), 'Expected');
|
||||||
|
//t.throws(toCurrency(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user