Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Release 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Karamov authored Sep 8, 2019
2 parents 75f0f38 + b2b8860 commit 60e7d85
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 52 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A tiny currency formatting library for JavaScript.

- **Small.** Dependency-free. 469 bytes minified and gzipped. Controlled by [Size Limit](https://github.com/ai/size-limit).
- **Small.** Dependency-free. 559 bytes minified and gzipped. Controlled by [Size Limit](https://github.com/ai/size-limit).
- **Functional.** The function can be used traditionally or curried for later reuse.
- **Flexible.** The config can be tweaked to present any modern currency.

Expand All @@ -11,6 +11,8 @@ import prettyMoney from "pretty-money";
let price = prettyMoney({ currency: "EUR" }, 10000); //=> "10000 EUR"
```

### [Demo](https://os.karamoff.ru/pretty-money#demo)

Works everywhere where there is support for ES3.

----
Expand Down
8 changes: 1 addition & 7 deletions config/build/plugins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import rpBanner from 'rollup-plugin-banner';
import rpCleanup from 'rollup-plugin-cleanup';
import rpStrip from 'rollup-plugin-strip';
import { terser as rpTerser } from 'rollup-plugin-terser';
import rpTypescript2 from 'rollup-plugin-typescript2';
Expand All @@ -12,11 +11,6 @@ export const banner = () => rpBanner(
'@license MIT'
);

export const cleanup = () => rpCleanup({
comments: 'license',
extensions: ['.ts']
});

export const strip = () => rpStrip({
debugger: true,
functions: ['console.log', 'console.debug'],
Expand All @@ -25,4 +19,4 @@ export const strip = () => rpStrip({

export const terser = () => rpTerser();

export const typescript = () => rpTypescript2();
export const typescript = () => rpTypescript2();
8 changes: 5 additions & 3 deletions config/build/rollup.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultOutput, getFilename, input } from './defaults';
import { terser, typescript } from './plugins';
import { banner, strip, terser, typescript } from './plugins';

export default {
input,
Expand All @@ -17,6 +17,8 @@ export default {
],
plugins: [
typescript(),
terser()
terser(),
strip(),
banner()
]
}
}
10 changes: 9 additions & 1 deletion dist/pretty-money.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion dist/pretty-money.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2>

<p>
It can help you format financial values in any way you desire. While being highly customizable, <code>pretty-money</code>
is easy to use and extremely lightweight (469&nbsp;bytes minzipped).
is easy to use and extremely lightweight (559&nbsp;bytes minzipped).
</p>
<aside>
<p>
Expand Down
35 changes: 1 addition & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "pretty-money",
"version": "1.0.0",
"version": "1.0.1",
"description": "A tiny currency formatting library for JavaScript",
"license": "MIT",
"keywords": [
"money",
"currency",
"format"
],
"homepage": "https://github.com/NickKaramoff/pretty-money#readme",
"homepage": "https://os.karamoff.ru/pretty-money",
"repository": {
"type": "git",
"url": "git+https://github.com/NickKaramoff/pretty-money.git"
Expand Down Expand Up @@ -49,7 +49,6 @@
"npm-run-all": "^4.1.5",
"rollup": "^1.20.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
"rollup-plugin-strip": "^1.2.2",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-typescript2": "^0.24.0",
Expand Down
2 changes: 1 addition & 1 deletion src/pretty-money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const prettyMoney: prettifyFactory = (options: FormatOptions = {}, number?: numb
let decimalPart = number.slice(splitIdx);

if (_opts.decimals === "fluid" || (_opts.decimals === "minmax" && decimalPart.slice(_opts.minDecimal).match(/^0*$/))) {
decimalPart = decimalPart.replace(/0*$/, "");
decimalPart = decimalPart.slice(0, _opts.minDecimal) + decimalPart.slice(_opts.minDecimal).replace(/0*$/, "");
}

number = wholePart + (decimalPart === "" ? "" : _opts.decimalDelimiter) + decimalPart;
Expand Down
5 changes: 5 additions & 0 deletions test/decimals-fixed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ test("default config with fixed decimals and number with less decimals", () => {
.toBe("1234.50 RUB");
});

test("default config with fixed fluid from 1 to 2 and number with no decimals", () => {
expect(prettyMoney({ currency: "RUB", decimals: "fixed", minDecimal: 1 }, 1234))
.toBe("1234.00 RUB");
});

test("default config with fixed decimals and number with same amount of decimals", () => {
expect(prettyMoney({ currency: "RUB", decimals: "fixed" }, 1234.56))
.toBe("1234.56 RUB");
Expand Down
10 changes: 10 additions & 0 deletions test/decimals-fluid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ test("default config with fluid decimals and number with less decimals", () => {
.toBe("1234.5 RUB");
});

test("default config with fluid decimals from 1 to 2 and number with less decimals", () => {
expect(prettyMoney({ currency: "RUB", decimals: "fluid", minDecimal: 1 }, 1234.5))
.toBe("1234.5 RUB");
});

test("default config with fluid decimals from 1 to 2 and number with no decimals", () => {
expect(prettyMoney({ currency: "RUB", decimals: "fluid", minDecimal: 1 }, 1234))
.toBe("1234.0 RUB");
});

test("default config with fluid decimals and number with same amount of decimals", () => {
expect(prettyMoney({ currency: "RUB", decimals: "fluid" }, 1234.56))
.toBe("1234.56 RUB");
Expand Down
5 changes: 5 additions & 0 deletions test/decimals-minmax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ test("default config with minmax decimals from 1 to 2 and number with less decim
.toBe("1234.5 RUB");
});

test("default config with minmax decimals from 1 to 2 and number with no decimals", () => {
expect(prettyMoney({ currency: "RUB", minDecimal: 1 }, 1234))
.toBe("1234.0 RUB");
});

test("default config with minmax decimals and number with same amount of decimals", () => {
expect(prettyMoney({ currency: "RUB" }, 1234.56))
.toBe("1234.56 RUB");
Expand Down

0 comments on commit 60e7d85

Please sign in to comment.