diff --git a/snippets/toCurrency.md b/snippets/toCurrency.md new file mode 100644 index 000000000..bc690aa68 --- /dev/null +++ b/snippets/toCurrency.md @@ -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 +``` diff --git a/tag_database b/tag_database index f95213c09..4a5a0f084 100644 --- a/tag_database +++ b/tag_database @@ -236,6 +236,7 @@ throttle:function times:function timeTaken:utility toCamelCase:string,regexp +toCurrency:utility toDecimalMark:utility,math toggleClass:browser toKebabCase:string,regexp diff --git a/test/arrayToHtmlList/arrayToHtmlList.test.js b/test/arrayToHtmlList/arrayToHtmlList.test.js index 45caf046c..1f8885778 100644 --- a/test/arrayToHtmlList/arrayToHtmlList.test.js +++ b/test/arrayToHtmlList/arrayToHtmlList.test.js @@ -1,22 +1,13 @@ const test = require('tape'); -//const arrayToHtmlList = require('./arrayToHtmlList.js'); -const jsdom = require('jsdom'); -const { JSDOM } = jsdom; -const listID = 'myListID'; -const dom = new JSDOM(`
Some text
- `); - t.true(hasClass(dom.window.document.querySelector('p'), className), 'element has the specified class'); - //t.deepEqual(hasClass(args..), 'Expected'); - //t.equal(hasClass(args..), 'Expected'); - //t.false(hasClass(args..), 'Expected'); - //t.throws(hasClass(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof hasClass === 'function', 'hasClass is a Function'); + //t.deepEqual(hasClass(args..), 'Expected'); + //t.equal(hasClass(args..), 'Expected'); + //t.false(hasClass(args..), 'Expected'); + //t.throws(hasClass(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/toCurrency/toCurrency.js b/test/toCurrency/toCurrency.js new file mode 100644 index 000000000..796e42ae4 --- /dev/null +++ b/test/toCurrency/toCurrency.js @@ -0,0 +1,2 @@ +const toCurrency = (n, curr, LanguageFormat = undefined) => new Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n); +module.exports = toCurrency \ No newline at end of file diff --git a/test/toCurrency/toCurrency.test.js b/test/toCurrency/toCurrency.test.js new file mode 100644 index 000000000..5da0952c0 --- /dev/null +++ b/test/toCurrency/toCurrency.test.js @@ -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(); +}); \ No newline at end of file