-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strings): add currency formatters
- Loading branch information
1 parent
112ba7e
commit 52b7340
Showing
6 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { memoizeJ } from "@thi.ng/memoize/memoizej"; | ||
import type { Stringer } from "./api.js"; | ||
|
||
export const currency = < | ||
(sym: string, pre?: boolean, prec?: number) => Stringer<number> | ||
>memoizeJ((sym: string, pre = true, prec = 2) => { | ||
const ff = (x: number) => x.toFixed(prec); | ||
return pre ? (x: number) => sym + ff(x) : (x: number) => ff(x) + sym; | ||
}); | ||
|
||
export const chf = currency("CHF "); | ||
|
||
export const eur = currency("€"); | ||
|
||
export const gbp = currency("£"); | ||
|
||
export const usd = currency("$"); | ||
|
||
export const yen = currency("¥"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters