make-it-rain 1.1.1 β 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +72 -71
- package/index.js +68 -68
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Alvian Zachry Faturrahman
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alvian Zachry Faturrahman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,71 +1,72 @@
|
|
|
1
|
-
# πΈ make-it-rain πΈ
|
|
2
|
-
[](https://npmjs.com/package/make-it-rain) [](https://nodejs.org/) [](https://opensource.org/licenses/MIT)
|
|
3
|
-
|
|
4
|
-
### The Only Money Formatter You'll Ever Need (Probably)
|
|
5
|
-
|
|
6
|
-
So, you've finally decided that numbers should look nice? **Wow, groundbreaking.**
|
|
7
|
-
Instead of manually adding commas and dots like a caveman, let **`make-it-rain`** handle the **tough** job of making your numbers **actually readable**.
|
|
8
|
-
|
|
9
|
-
## π Why Use This?
|
|
10
|
-
Because:
|
|
11
|
-
β
You want your app to look like it knows what money is.
|
|
12
|
-
β
You're too lazy to format numbers manually (same).
|
|
13
|
-
β
You finally realized not everyone uses the same thousands separator.
|
|
14
|
-
β
You enjoy writing `toLocaleString()` 50 times per project? No? Didnβt think so.
|
|
15
|
-
|
|
16
|
-
## π¦ Installation
|
|
17
|
-
Oh no, another package to install? **Deal with it.**
|
|
18
|
-
```sh
|
|
19
|
-
npm install make-it-rain
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
or if you're feeling edgy:
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
yarn add make-it-rain
|
|
26
|
-
```
|
|
27
|
-
## π οΈ Usage
|
|
28
|
-
Initialize this life-changing formatter once, then flex on your ugly numbers forever.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.log(money.makeItPretty(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
| `
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
# πΈ make-it-rain πΈ
|
|
2
|
+
[](https://npmjs.com/package/make-it-rain) [](https://nodejs.org/) [](https://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
### The Only Money Formatter You'll Ever Need (Probably)
|
|
5
|
+
|
|
6
|
+
So, you've finally decided that numbers should look nice? **Wow, groundbreaking.**
|
|
7
|
+
Instead of manually adding commas and dots like a caveman, let **`make-it-rain`** handle the **tough** job of making your numbers **actually readable**.
|
|
8
|
+
|
|
9
|
+
## π Why Use This?
|
|
10
|
+
Because:
|
|
11
|
+
β
You want your app to look like it knows what money is.
|
|
12
|
+
β
You're too lazy to format numbers manually (same).
|
|
13
|
+
β
You finally realized not everyone uses the same thousands separator.
|
|
14
|
+
β
You enjoy writing `toLocaleString()` 50 times per project? No? Didnβt think so.
|
|
15
|
+
|
|
16
|
+
## π¦ Installation
|
|
17
|
+
Oh no, another package to install? **Deal with it.**
|
|
18
|
+
```sh
|
|
19
|
+
npm install make-it-rain
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
or if you're feeling edgy:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
yarn add make-it-rain
|
|
26
|
+
```
|
|
27
|
+
## π οΈ Usage
|
|
28
|
+
Initialize this life-changing formatter once, then flex on your ugly numbers forever.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const makeItRain = require("make-it-rain");
|
|
33
|
+
|
|
34
|
+
const money = makeItRain("EUR", ".", true); // Set it and forget it
|
|
35
|
+
|
|
36
|
+
console.log(money.makeItPretty(1234567.89)); // β¬1.234.567,89
|
|
37
|
+
money.useWhat(false); // Switch to ISO code mode
|
|
38
|
+
console.log(money.makeItPretty(1234567.89)); // EUR 1.234.567,89
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
| Method | Description |
|
|
43
|
+
|--------|-------------|
|
|
44
|
+
|`makeItRain(currency, separator, useSymbol)` | Initializes the formatter once. Currency = any ISO currency code, separator = `,` or .`,` useSymbol = `true` for symbols (`$`), `false` for codes (`USD`). |
|
|
45
|
+
| `makeItPretty(amount)` | Takes a number and makes it visually acceptable.|
|
|
46
|
+
| `swapMoney(newCurrency)` | Change the currency to something else, because why not? |
|
|
47
|
+
| `useWhat(symbol)` | Toggle between using currency symbols (`$`) or ISO codes (`USD`). |
|
|
48
|
+
| `whatNow()` | Returns the current currency, in case you forgot. |
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## π© Features (That Should Have Existed in JavaScript Already)
|
|
52
|
+
- One-time setup: Set currency & separator once, use it everywhere.
|
|
53
|
+
- Formats numbers beautifully: Because nobody likes reading 1000000.00.
|
|
54
|
+
- Handles separators like a champ: Pick , or ., because the world can't agree.
|
|
55
|
+
- Errors when you mess up: Because I'm not letting you pass "lol" as a number.
|
|
56
|
+
|
|
57
|
+
## β What This Wonβt Do
|
|
58
|
+
- Convert currency: This isn't a forex exchange, buddy.
|
|
59
|
+
- Fix your bad financial decisions: Your debt is still your problem.
|
|
60
|
+
- Magically make you rich: But hey, your numbers will look expensive.
|
|
61
|
+
|
|
62
|
+
## π Contributing
|
|
63
|
+
Want to contribute? Cool. Fork it, break it, fix it, and submit a PR.
|
|
64
|
+
|
|
65
|
+
## π License
|
|
66
|
+
MIT β Because I'm not here to sue you.
|
|
67
|
+
|
|
68
|
+
## β Pro Tip
|
|
69
|
+
Use this package and pretend youβre rich. Youβre welcome.
|
|
70
|
+
|
|
71
|
+
This README will **ensure** your package is taken *seriously* while also making people question their life choices.
|
|
72
|
+
|
package/index.js
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
const currencySymbols = require("currency-symbol-map");
|
|
2
|
-
|
|
3
|
-
class MoneyFormatter {
|
|
4
|
-
constructor(currency = "USD", separator = ",", useSymbol = true) {
|
|
5
|
-
if (![".", ","].includes(separator)) {
|
|
6
|
-
throw new Error("Separator must be either ',' or '.' β not whatever creative mess you just passed.");
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
this.currency = currency;
|
|
10
|
-
this.separator = separator;
|
|
11
|
-
this.useSymbol = useSymbol;
|
|
12
|
-
this.fixIt();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
fixIt() {
|
|
16
|
-
this.formatter = new Intl.NumberFormat("en-US", {
|
|
17
|
-
style: "currency",
|
|
18
|
-
currency: this.currency,
|
|
19
|
-
minimumFractionDigits: 2,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
swapMoney(newCurrency) {
|
|
24
|
-
if (typeof newCurrency !== "string" || newCurrency.length !== 3) {
|
|
25
|
-
throw new Error("Nice try. Use a real 3-letter currency code.");
|
|
26
|
-
}
|
|
27
|
-
this.currency = newCurrency.toUpperCase();
|
|
28
|
-
this.fixIt();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
useWhat(symbol = true) {
|
|
32
|
-
this.useSymbol = symbol;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
makeItPretty(amount) {
|
|
36
|
-
if (typeof amount !== "number") {
|
|
37
|
-
throw new Error("Oh, so now we're formatting non-numbers? Genius.");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let formatted = this.formatter.format(amount);
|
|
41
|
-
|
|
42
|
-
if (this.separator === ".") {
|
|
43
|
-
formatted = formatted.replace(
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!this.useSymbol) {
|
|
47
|
-
let symbol = currencySymbols.getSymbol(this.currency) || "";
|
|
48
|
-
formatted = formatted.replace(symbol, this.currency);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return formatted;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
whatNow() {
|
|
55
|
-
return this.currency;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let instance = null;
|
|
60
|
-
|
|
61
|
-
function makeItRain(currency = "USD", separator = ",", useSymbol = true) {
|
|
62
|
-
if (!instance) {
|
|
63
|
-
instance = new MoneyFormatter(currency, separator, useSymbol);
|
|
64
|
-
}
|
|
65
|
-
return instance;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
module.exports = makeItRain;
|
|
1
|
+
const currencySymbols = require("currency-symbol-map");
|
|
2
|
+
|
|
3
|
+
class MoneyFormatter {
|
|
4
|
+
constructor(currency = "USD", separator = ",", useSymbol = true) {
|
|
5
|
+
if (![".", ","].includes(separator)) {
|
|
6
|
+
throw new Error("Separator must be either ',' or '.' β not whatever creative mess you just passed.");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
this.currency = currency;
|
|
10
|
+
this.separator = separator;
|
|
11
|
+
this.useSymbol = useSymbol;
|
|
12
|
+
this.fixIt();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fixIt() {
|
|
16
|
+
this.formatter = new Intl.NumberFormat("en-US", {
|
|
17
|
+
style: "currency",
|
|
18
|
+
currency: this.currency,
|
|
19
|
+
minimumFractionDigits: 2,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
swapMoney(newCurrency) {
|
|
24
|
+
if (typeof newCurrency !== "string" || newCurrency.length !== 3) {
|
|
25
|
+
throw new Error("Nice try. Use a real 3-letter currency code.");
|
|
26
|
+
}
|
|
27
|
+
this.currency = newCurrency.toUpperCase();
|
|
28
|
+
this.fixIt();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
useWhat(symbol = true) {
|
|
32
|
+
this.useSymbol = symbol;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
makeItPretty(amount) {
|
|
36
|
+
if (typeof amount !== "number") {
|
|
37
|
+
throw new Error("Oh, so now we're formatting non-numbers? Genius.");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let formatted = this.formatter.format(amount);
|
|
41
|
+
|
|
42
|
+
if (this.separator === ".") {
|
|
43
|
+
formatted = formatted.replace(/[,.]/g, c => (c === "," ? "." : ","));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!this.useSymbol) {
|
|
47
|
+
let symbol = currencySymbols.getSymbol(this.currency) || "";
|
|
48
|
+
formatted = formatted.replace(symbol, this.currency);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return formatted;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
whatNow() {
|
|
55
|
+
return this.currency;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let instance = null;
|
|
60
|
+
|
|
61
|
+
function makeItRain(currency = "USD", separator = ",", useSymbol = true) {
|
|
62
|
+
if (!instance) {
|
|
63
|
+
instance = new MoneyFormatter(currency, separator, useSymbol);
|
|
64
|
+
}
|
|
65
|
+
return instance;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = makeItRain;
|