Use BigNumber for Money calculations
This commit is contained in:
parent
8c47573501
commit
33210c1871
6 changed files with 572 additions and 311 deletions
275
NOTICE-js
275
NOTICE-js
|
@ -5855,6 +5855,37 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
** bignumber.js; version 9.0.0 -- https://github.com/MikeMcl/bignumber.js#readme
|
||||||
|
Copyright (c) 2019 Michael Mclaughlin
|
||||||
|
Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
|
||||||
|
|
||||||
|
The MIT Licence.
|
||||||
|
|
||||||
|
Copyright (c) 2019 Michael Mclaughlin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
'Software'), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
** array.prototype.find; version 2.1.1 -- https://github.com/paulmillr/Array.prototype.find#readme
|
** array.prototype.find; version 2.1.1 -- https://github.com/paulmillr/Array.prototype.find#readme
|
||||||
|
@ -6715,36 +6746,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
------
|
|
||||||
|
|
||||||
** case-sensitive-paths-webpack-plugin; version 2.3.0 -- https://github.com/Urthen/case-sensitive-paths-webpack-plugin#readme
|
|
||||||
Copyright (c) 2016 Michael Pratt
|
|
||||||
Copyright (c) 2018 Michael Pratt
|
|
||||||
Copyright (c) 2015 Alexandre Kirszenberg
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2018 Michael Pratt
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
** @types/istanbul-reports; version 1.1.2 --
|
** @types/istanbul-reports; version 1.1.2 --
|
||||||
|
@ -12090,6 +12091,36 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
** case-sensitive-paths-webpack-plugin; version 2.3.0 -- https://github.com/Urthen/case-sensitive-paths-webpack-plugin#readme
|
||||||
|
Copyright (c) 2016 Michael Pratt
|
||||||
|
Copyright (c) 2018 Michael Pratt
|
||||||
|
Copyright (c) 2015 Alexandre Kirszenberg
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2018 Michael Pratt
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
** chokidar; version 2.1.8 -- https://github.com/paulmillr/chokidar
|
** chokidar; version 2.1.8 -- https://github.com/paulmillr/chokidar
|
||||||
|
@ -13485,32 +13516,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
OTHER DEALINGS IN THE SOFTWARE.
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
------
|
|
||||||
|
|
||||||
** extsprintf; version 1.3.0 -- https://github.com/davepacheco/node-extsprintf
|
|
||||||
Copyright (c) 2012, Joyent, Inc.
|
|
||||||
|
|
||||||
Copyright (c) 2012, Joyent, Inc. All rights reserved.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE
|
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
** deep-equal; version 1.1.1 -- https://github.com/substack/node-deep-equal#readme
|
** deep-equal; version 1.1.1 -- https://github.com/substack/node-deep-equal#readme
|
||||||
|
@ -14307,9 +14312,6 @@ Copyright 2012-2015, Yahoo Inc.
|
||||||
** istanbul-lib-instrument; version 4.0.3 -- https://istanbul.js.org/
|
** istanbul-lib-instrument; version 4.0.3 -- https://istanbul.js.org/
|
||||||
Copyright 2012-2015 Yahoo! Inc.
|
Copyright 2012-2015 Yahoo! Inc.
|
||||||
Copyright 2012-2015, Yahoo Inc.
|
Copyright 2012-2015, Yahoo Inc.
|
||||||
** istanbul-lib-report; version 3.0.0 -- https://istanbul.js.org/
|
|
||||||
Copyright 2012-2015 Yahoo! Inc.
|
|
||||||
Copyright 2012-2015, Yahoo Inc.
|
|
||||||
|
|
||||||
Copyright 2012-2015 Yahoo! Inc.
|
Copyright 2012-2015 Yahoo! Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
@ -17935,6 +17937,32 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
** extsprintf; version 1.3.0 -- https://github.com/davepacheco/node-extsprintf
|
||||||
|
Copyright (c) 2012, Joyent, Inc.
|
||||||
|
|
||||||
|
Copyright (c) 2012, Joyent, Inc. All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
** fast-json-parse; version 1.0.3 -- https://github.com/mcollina/fast-json-parse#readme
|
** fast-json-parse; version 1.0.3 -- https://github.com/mcollina/fast-json-parse#readme
|
||||||
|
@ -18775,6 +18803,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
** istanbul-lib-report; version 3.0.0 -- https://istanbul.js.org/
|
||||||
|
Copyright 2012-2015 Yahoo! Inc.
|
||||||
|
Copyright 2012-2015, Yahoo Inc.
|
||||||
** istanbul-reports; version 3.0.2 -- https://istanbul.js.org/
|
** istanbul-reports; version 3.0.2 -- https://istanbul.js.org/
|
||||||
(c) Sindre Sorhus
|
(c) Sindre Sorhus
|
||||||
Copyright 2012-2015 Yahoo! Inc.
|
Copyright 2012-2015 Yahoo! Inc.
|
||||||
|
@ -21694,6 +21725,7 @@ SOFTWARE.
|
||||||
** jest-environment-jsdom; version 24.9.0 --
|
** jest-environment-jsdom; version 24.9.0 --
|
||||||
Copyright (c) Facebook, Inc. and its affiliates.
|
Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
** jest-pnp-resolver; version 1.2.2 -- https://github.com/arcanis/jest-pnp-resolver
|
** jest-pnp-resolver; version 1.2.2 -- https://github.com/arcanis/jest-pnp-resolver
|
||||||
|
Copyright (c) 2016 Mael Nison
|
||||||
** jquery; version 1.11.1 -- http://jquery.com
|
** jquery; version 1.11.1 -- http://jquery.com
|
||||||
(c) 2013 jQuery Foundation, Inc.
|
(c) 2013 jQuery Foundation, Inc.
|
||||||
(c) 2005, 2014 jQuery Foundation, Inc.
|
(c) 2005, 2014 jQuery Foundation, Inc.
|
||||||
|
@ -21910,9 +21942,6 @@ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
(c) Sindre Sorhus
|
(c) Sindre Sorhus
|
||||||
(c) Sindre Sorhus (https://sindresorhus.com)
|
(c) Sindre Sorhus (https://sindresorhus.com)
|
||||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
** os-homedir; version 1.0.2 -- https://github.com/sindresorhus/os-homedir#readme
|
|
||||||
(c) Sindre Sorhus (https://sindresorhus.com)
|
|
||||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
@ -23430,67 +23459,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
|
||||||
** request; version 2.88.2 -- https://github.com/request/request#readme
|
|
||||||
Copyright 2010-2012 Mikeal Rogers
|
|
||||||
|
|
||||||
Apache License
|
|
||||||
|
|
||||||
Version 2.0, January 2004
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
||||||
|
|
||||||
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
||||||
|
|
||||||
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
||||||
|
|
||||||
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
------
|
|
||||||
|
|
||||||
** phantomjs-prebuilt; version 2.1.16 -- https://github.com/Medium/phantomjs
|
** phantomjs-prebuilt; version 2.1.16 -- https://github.com/Medium/phantomjs
|
||||||
Copyright 2012 The Obvious Corporation.
|
Copyright 2012 The Obvious Corporation.
|
||||||
Copyright 2013 The Obvious Corporation.
|
Copyright 2013 The Obvious Corporation.
|
||||||
|
@ -27329,6 +27297,9 @@ IN THE SOFTWARE.
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
** os-homedir; version 1.0.2 -- https://github.com/sindresorhus/os-homedir#readme
|
||||||
|
(c) Sindre Sorhus (https://sindresorhus.com)
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
** os-tmpdir; version 1.0.2 -- https://github.com/sindresorhus/os-tmpdir#readme
|
** os-tmpdir; version 1.0.2 -- https://github.com/sindresorhus/os-tmpdir#readme
|
||||||
(c) Sindre Sorhus (https://sindresorhus.com)
|
(c) Sindre Sorhus (https://sindresorhus.com)
|
||||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
@ -28717,6 +28688,8 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
** request; version 2.88.2 -- https://github.com/request/request#readme
|
||||||
|
Copyright 2010-2012 Mikeal Rogers
|
||||||
** tunnel-agent; version 0.6.0 -- https://github.com/mikeal/tunnel-agent#readme
|
** tunnel-agent; version 0.6.0 -- https://github.com/mikeal/tunnel-agent#readme
|
||||||
** typescript; version 4.0.2 -- https://www.typescriptlang.org/
|
** typescript; version 4.0.2 -- https://www.typescriptlang.org/
|
||||||
(c) by W3C
|
(c) by W3C
|
||||||
|
@ -31997,34 +31970,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
------
|
|
||||||
|
|
||||||
** v8-compile-cache; version 2.1.1 -- https://github.com/zertosh/v8-compile-cache#readme
|
|
||||||
Copyright (c) 2019 Andres Suarez
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2019 Andres Suarez
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
** upath; version 1.2.0 -- http://github.com/anodynos/upath/
|
** upath; version 1.2.0 -- http://github.com/anodynos/upath/
|
||||||
|
@ -35928,6 +35873,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
** v8-compile-cache; version 2.1.1 -- https://github.com/zertosh/v8-compile-cache#readme
|
||||||
|
Copyright (c) 2019 Andres Suarez
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2019 Andres Suarez
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
** vfile-message; version 2.0.4 -- https://github.com/vfile/vfile-message#readme
|
** vfile-message; version 2.0.4 -- https://github.com/vfile/vfile-message#readme
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
// License: LGPL-3.0-or-later
|
// License: LGPL-3.0-or-later
|
||||||
import { Money } from './money';
|
import { Money, Operand, RoundingMode } from './money';
|
||||||
|
|
||||||
describe("Money", () => {
|
describe("Money", () => {
|
||||||
describe('Money.fromCents', () => {
|
describe('Money.fromCents', () => {
|
||||||
|
@ -23,6 +24,17 @@ describe("Money", () => {
|
||||||
expect(result).toBeInstanceOf(Money);
|
expect(result).toBeInstanceOf(Money);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('succeeds from a stringy json', () => {
|
||||||
|
expect.hasAssertions();
|
||||||
|
const old = Money.fromCents(333, 'eur');
|
||||||
|
|
||||||
|
const result = Money.fromCents({ amount: '333', currency: 'eur' });
|
||||||
|
// eslint-disable-next-line jest/prefer-strict-equal
|
||||||
|
expect(result).toEqual(old);
|
||||||
|
|
||||||
|
expect(result).toBeInstanceOf(Money);
|
||||||
|
});
|
||||||
|
|
||||||
it('succeeds from function parameters', () => {
|
it('succeeds from function parameters', () => {
|
||||||
expect.hasAssertions();
|
expect.hasAssertions();
|
||||||
const result = Money.fromCents(333, 'eur');
|
const result = Money.fromCents(333, 'eur');
|
||||||
|
@ -31,5 +43,197 @@ describe("Money", () => {
|
||||||
|
|
||||||
expect(result).toBeInstanceOf(Money);
|
expect(result).toBeInstanceOf(Money);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('succeeds from BigNumber', () => {
|
||||||
|
expect.hasAssertions();
|
||||||
|
const result = Money.fromCents(new BigNumber(333), 'eur');
|
||||||
|
// eslint-disable-next-line jest/prefer-strict-equal
|
||||||
|
expect(result).toEqual({ amount: 333, currency: 'eur' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects if string is not an integer', () => {
|
||||||
|
expect.hasAssertions();
|
||||||
|
expect(() => {
|
||||||
|
Money.fromCents('3344.4', 'usd');
|
||||||
|
}).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects if BigNumber is not an integer', () => {
|
||||||
|
expect.hasAssertions();
|
||||||
|
expect(() => {
|
||||||
|
Money.fromCents(new BigNumber('3344.4'), 'usd');
|
||||||
|
}).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects if number is not an integer', () => {
|
||||||
|
expect.hasAssertions();
|
||||||
|
expect(() => {
|
||||||
|
Money.fromCents(444.333, 'usd');
|
||||||
|
}).toThrow(TypeError);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
const cents1000 = Money.fromCents(1000, 'usd');
|
||||||
|
const cents500 = Money.fromCents(500, 'usd');
|
||||||
|
|
||||||
|
const euCents1000 = Money.fromCents(1000, 'eur');
|
||||||
|
|
||||||
|
const negative1000 = Money.fromCents(-1000, 'usd');
|
||||||
|
|
||||||
|
function verifyCurrency(func:(m:Money, other:Money) => unknown){
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(() => func(cents1000, euCents1000)).toThrow(TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe.each([
|
||||||
|
['add', (m:Money, other:Money) => m.add(other)],
|
||||||
|
['compare', (m:Money, other:Money) => m.compare(other)],
|
||||||
|
['divide', (m:Money, other:Money) => m.divide(other)],
|
||||||
|
['greaterThan', (m:Money, other:Money) => m.greaterThan(other)],
|
||||||
|
['greaterThanOrEqual', (m:Money, other:Money) => m.greaterThanOrEqual(other)],
|
||||||
|
['lessThan', (m:Money, other:Money) => m.lessThan(other)],
|
||||||
|
['lessThanOrEqual', (m:Money, other:Money) => m.lessThanOrEqual(other)],
|
||||||
|
['multiply', (m:Money, other:Money) => m.multiply(other)],
|
||||||
|
['subtract', (m:Money, other:Money) => m.subtract(other)],
|
||||||
|
|
||||||
|
])('.%s with %s', (_name, func) => {
|
||||||
|
|
||||||
|
it(`throw when currency doesn't match`, () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(() => func(cents1000, euCents1000)).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe.each([
|
||||||
|
['add', (m:Money, other:Operand) => m.add(other)],
|
||||||
|
['subtract', (m:Money, other:Operand) => m.subtract(other)],
|
||||||
|
])('.%s with %s', (_name, func) => {
|
||||||
|
|
||||||
|
it(`throw when other is a decimal number`, () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(() => func(cents1000, 4.5)).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`throw when other is a decimal BigNumber`, () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(() => func(cents1000, new BigNumber('4.5'))).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('.isZero', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(cents1000.isZero()).toStrictEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('.isPositive', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(cents1000.isPositive()).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('.isNegative', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(negative1000.isNegative()).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.compare', () => {
|
||||||
|
describe('greater', () => {
|
||||||
|
describe('Money', () => {
|
||||||
|
it('same currency', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(cents1000.compare(cents500)).toStrictEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('different currency', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(() => {
|
||||||
|
cents1000.compare(euCents1000);
|
||||||
|
}).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('BigNumber', () => {
|
||||||
|
it('same currency', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(cents1000.compare(cents500)).toStrictEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('different currency', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(() => {
|
||||||
|
cents1000.compare(euCents1000);
|
||||||
|
}).toThrow(TypeError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.divide', () => {
|
||||||
|
it('divides 36 into 9', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents(36, 'usd').divide(9).toJSON()).toStrictEqual({amount: 4, currency: 'usd'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws if the currencies do not match', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
verifyCurrency((m, other) => m.divide(other));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('defaults to rounding to HalfUp', () => {
|
||||||
|
expect.assertions(3);
|
||||||
|
expect(Money.fromCents(40, 'usd').divide(Money.fromCents(9, 'usd')).toJSON()).toStrictEqual({amount: 4, currency: 'usd'});
|
||||||
|
|
||||||
|
expect(Money.fromCents(41, 'usd').divide(Money.fromCents(9, 'usd')).toJSON()).toStrictEqual({amount: 5, currency: 'usd'});
|
||||||
|
|
||||||
|
expect(Money.fromCents(7, 'usd').divide(Money.fromCents(2, 'usd')).toJSON()).toStrictEqual({amount: 4, currency: 'usd'});
|
||||||
|
});
|
||||||
|
it('rounds to floor if requested', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents(41, 'usd').divide(Money.fromCents(9, 'usd'), RoundingMode.Floor).toJSON()).toStrictEqual({amount: 4, currency: 'usd'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rounds to ceil if requested', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents(40, 'usd').divide(Money.fromCents(9, 'usd'), RoundingMode.Ceil).toJSON()).toStrictEqual({amount: 5, currency: 'usd'});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.multiply', () => {
|
||||||
|
it('multiply 9 x 4', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents(9, 'usd').multiply(4).toJSON()).toStrictEqual({amount: 36, currency: 'usd'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws if the currencies do not match', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
verifyCurrency((m, other) => m.multiply(other));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles multiplying by a decimal properly', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents('3', 'usd').multiply(new BigNumber('1.263')).toJSON()).toStrictEqual({amount: 4, currency: 'usd'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('defaults to rounding to HalfUp', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents(7, 'usd').multiply(new BigNumber('.5')).toJSON()).toStrictEqual({amount: 4, currency: 'usd'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rounds to floor if requested', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents('3', 'usd').multiply('1.263', RoundingMode.Floor).toJSON()).toStrictEqual({amount: 3, currency: 'usd'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rounds to ceil if requested', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(Money.fromCents('3', 'usd').multiply('1.263', RoundingMode.Ceil).toJSON()).toStrictEqual({amount: 4, currency: 'usd'});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.toBigNumber', () => {
|
||||||
|
it('doesnt round to nearest integer', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
expect(cents1000.toBigNumber().plus('1.2').toString()).toStrictEqual('1001.2');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
@ -1,33 +1,108 @@
|
||||||
// License: LGPL-3.0-or-later
|
// License: LGPL-3.0-or-later
|
||||||
// based upon https://github.com/davidkalosi/js-money
|
// based upon https://github.com/davidkalosi/js-money
|
||||||
import isFunction from 'lodash/isFunction';
|
import BigNumber from 'bignumber.js';
|
||||||
|
|
||||||
const assertSameCurrency = function (left: Money, right: Money) {
|
/**
|
||||||
if (left.currency !== right.currency)
|
* Forces BigNumber to throw an error if it receives an invalid numerical value.
|
||||||
throw new Error('Different currencies');
|
*/
|
||||||
};
|
function bigNumberDebug<T>(func: () => T):T {
|
||||||
|
const previousDebug = BigNumber.DEBUG;
|
||||||
|
try {
|
||||||
|
BigNumber.DEBUG = true;
|
||||||
|
return func();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
BigNumber.DEBUG = previousDebug;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const assertType = function (other: unknown) {
|
function assertSameCurrency(left: Money, right: Operand) {
|
||||||
if (!(other instanceof Money))
|
if (right instanceof Money && left.currency !== right.currency)
|
||||||
throw new TypeError('Instance of Money required');
|
throw new TypeError('Different currencies');
|
||||||
};
|
}
|
||||||
|
|
||||||
const assertOperand = function (operand: unknown) {
|
function coerceToBigNumber(operand:unknown, mustBeInteger=false): BigNumber {
|
||||||
if (typeof operand !== 'number' || isNaN(operand) && !isFinite(operand))
|
let bigNumber = null;
|
||||||
throw new TypeError('Operand must be a number');
|
if (operand instanceof Money) {
|
||||||
};
|
bigNumber = operand.toBigNumber();
|
||||||
|
}
|
||||||
|
else if (operand instanceof BigNumber) {
|
||||||
|
bigNumber = new BigNumber(operand);
|
||||||
|
}
|
||||||
|
else if (typeof operand === 'object') {
|
||||||
|
//it's MoneyAsJson
|
||||||
|
bigNumber = new BigNumber((operand as MoneyAsJson).amount);
|
||||||
|
}
|
||||||
|
else if(typeof operand === 'string') {
|
||||||
|
bigNumberDebug(() => {
|
||||||
|
bigNumber = new BigNumber(operand);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (typeof operand === 'number') {
|
||||||
|
bigNumberDebug(() => {
|
||||||
|
bigNumber = new BigNumber(operand);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new TypeError('Operand must be coercible to a BigNumber');
|
||||||
|
}
|
||||||
|
|
||||||
type MoneyAsJson = { amount: number, currency: string };
|
if (mustBeInteger && !bigNumber.isInteger()) {
|
||||||
|
throw new TypeError('Operand must be an integer');
|
||||||
|
}
|
||||||
|
|
||||||
|
return bigNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type MoneyAsJson = { amount: number, currency: string };
|
||||||
|
type StringyMoneyAsJson = {amount:string, currency: string};
|
||||||
|
|
||||||
|
export type Operand = number | Money | BigNumber | string;
|
||||||
|
|
||||||
|
export enum RoundingMode {
|
||||||
|
/** Rounds away from zero. */
|
||||||
|
Up = 0,
|
||||||
|
|
||||||
|
/** Rounds towards zero. */
|
||||||
|
Down,
|
||||||
|
|
||||||
|
/** Rounds towards Infinity. */
|
||||||
|
Ceil,
|
||||||
|
|
||||||
|
/** Rounds towards -Infinity. */
|
||||||
|
Floor,
|
||||||
|
|
||||||
|
/** Rounds towards nearest neighbour. If equidistant, rounds away from zero . */
|
||||||
|
HalfUp,
|
||||||
|
|
||||||
|
/** Rounds towards nearest neighbour. If equidistant, rounds towards zero. */
|
||||||
|
HalfDown,
|
||||||
|
|
||||||
|
/** Rounds towards nearest neighbour. If equidistant, rounds towards even neighbour. */
|
||||||
|
HalfEven,
|
||||||
|
|
||||||
|
/** Rounds towards nearest neighbour. If equidistant, rounds towards Infinity. */
|
||||||
|
HalfCeil,
|
||||||
|
|
||||||
|
/** Rounds towards nearest neighbour. If equidistant, rounds towards -Infinity. */
|
||||||
|
HalfFloor,
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a monetary amount. For safety, all Money objects are immutable. All of the functions in this class create a new Money object.
|
* Represents a monetary amount. For safety, all Money objects are immutable. All of the functions in this class create a new Money object.
|
||||||
*
|
*
|
||||||
|
* Money always represents a whole number of the smallest monetary unit. It can never be fractional. Multiplication and division always rounds to
|
||||||
|
* and integer (see the `RoundingMode` )
|
||||||
|
*
|
||||||
|
*
|
||||||
* To create a new Money object is to use the `fromCents` function.
|
* To create a new Money object is to use the `fromCents` function.
|
||||||
* @export
|
* @export
|
||||||
* @class Money
|
* @class Money
|
||||||
*/
|
*/
|
||||||
export class Money {
|
export class Money {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a `Money` object with the given number if smallest monetary units and the ISO currency. Another name for the `fromCents` function.
|
* Create a `Money` object with the given number if smallest monetary units and the ISO currency. Another name for the `fromCents` function.
|
||||||
* @static
|
* @static
|
||||||
|
@ -35,11 +110,14 @@ export class Money {
|
||||||
*/
|
*/
|
||||||
static fromSMU = Money.fromCents;
|
static fromSMU = Money.fromCents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The currency of the monetary value, always in lower case.
|
||||||
|
*/
|
||||||
readonly currency: string;
|
readonly currency: string;
|
||||||
|
|
||||||
protected constructor(readonly amount: number, currency: string) {
|
protected constructor(readonly amount: number, currency: string) {
|
||||||
this.currency = currency.toLowerCase();
|
this.currency = currency.toLowerCase();
|
||||||
const methodsToBind = [this.equals, this.add, this.subtract, this.multiply, this.divide, this.allocate,
|
const methodsToBind = [this.equals, this.add, this.subtract, this.multiply, this.divide,
|
||||||
this.compare, this.greaterThan, this.greaterThanOrEqual, this.lessThan,
|
this.compare, this.greaterThan, this.greaterThanOrEqual, this.lessThan,
|
||||||
this.lessThanOrEqual, this.isZero, this.isPositive, this.isNegative,
|
this.lessThanOrEqual, this.isZero, this.isPositive, this.isNegative,
|
||||||
this.toJSON];
|
this.toJSON];
|
||||||
|
@ -49,222 +127,210 @@ export class Money {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a `Money` object with the given number of cents and the ISO currency unit
|
* Create a new money object
|
||||||
* @static
|
* @param amount the value of Money as an object of type {amount:number, currency:string}. `amount` must be an integer
|
||||||
* @param {number} amount
|
* or `TypeError` will be thrown.
|
||||||
* @param {string} currency
|
|
||||||
* @return Money
|
|
||||||
* @memberof Money
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static fromCents(amount: MoneyAsJson): Money;
|
static fromCents(amount: MoneyAsJson): Money;
|
||||||
static fromCents(amount: Money): Money;
|
|
||||||
static fromCents(amount: number, currency: string): Money;
|
|
||||||
static fromCents(amount: number | Money | MoneyAsJson, currency?: string): Money {
|
|
||||||
|
|
||||||
if (typeof amount === 'number')
|
/**
|
||||||
return new Money(amount, currency);
|
* Create a new money object
|
||||||
if (amount instanceof Money)
|
* @param amount the value of Money as an object of type {amount:string, currency:string}. `amount` must contain an integer
|
||||||
return new Money(amount.amount, amount.currency);
|
* or `TypeError` will be thrown.
|
||||||
else
|
*/
|
||||||
return new Money(amount.amount, amount.currency);
|
static fromCents(amount: StringyMoneyAsJson): Money;
|
||||||
|
/**
|
||||||
|
* Create a new money object
|
||||||
|
* @param amount a Money object that will be replicated to create a new Money object
|
||||||
|
*/
|
||||||
|
static fromCents(amount: Money): Money;
|
||||||
|
/**
|
||||||
|
* Create a new money object.
|
||||||
|
* @param amount an integer representing the amount of the new Money object. If you pass a non-integer, `TypeError` will be thrown.
|
||||||
|
* @param currency the currency of the new Money object
|
||||||
|
*/
|
||||||
|
static fromCents(amount: number, currency: string): Money;
|
||||||
|
/**
|
||||||
|
* Create a new money object
|
||||||
|
* @param amount a string containing the integer of the amount of the new Money object. If you pass a non-integer, `TypeError` will be thrown.
|
||||||
|
* @param currency the currency of the new Money object
|
||||||
|
*/
|
||||||
|
static fromCents(amount: string, currency: string): Money;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param amount a BigNumber containing the integer of the amount of the new Money object. If you pass a non-integer, `TypeError` will be thrown.
|
||||||
|
* @param currency the currency of the new Money object
|
||||||
|
*/
|
||||||
|
static fromCents(amount: BigNumber, currency: string): Money;
|
||||||
|
/**
|
||||||
|
* The overloaded function that allows all of the previous constructors
|
||||||
|
*/
|
||||||
|
static fromCents(amount: number | BigNumber | Money | MoneyAsJson | string | StringyMoneyAsJson, currency?: string): Money {
|
||||||
|
|
||||||
|
if (!currency && typeof amount === 'object' && !(amount instanceof BigNumber)) {
|
||||||
|
currency = amount.currency;
|
||||||
|
}
|
||||||
|
return new Money(coerceToBigNumber(amount, true).toNumber(), currency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the two objects together creating a new Money instance that holds the result of the operation.
|
* Adds the two objects together creating a new Money instance that holds the result of the operation.
|
||||||
*
|
*
|
||||||
* @param {Money} other
|
* @param other an object represented an integer value to add the current Money object. If it's a Money object,
|
||||||
* @returns {Money}
|
* the currency must match or `TypeError` will be thrown. If not, it must be an integer or `TypeError` is thrown.
|
||||||
*/
|
*/
|
||||||
add(other: Money): Money {
|
add(other: Operand): Money {
|
||||||
|
|
||||||
assertType(other);
|
const bigNumber = coerceToBigNumber(other, true);
|
||||||
assertSameCurrency(this, other);
|
assertSameCurrency(this, other);
|
||||||
|
|
||||||
return new Money(this.amount + other.amount, this.currency);
|
return new Money(this.toBigNumberWithNoDecimals().plus(bigNumber).toNumber(), this.currency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates fund bases on the ratios provided returing an array of objects as a product of the allocation.
|
* Compares another numerical value with this Money object.
|
||||||
*
|
*
|
||||||
* @param {Array} other
|
* @param other the numerical value to compare against this Money object. If `other` is a `Money` object,
|
||||||
* @param {Money[]}
|
* the currencies must match or a `TypeError` is thrown.
|
||||||
|
* @returns -1 if smaller than other, 0 if equal to other, 1 if greater than other.
|
||||||
*/
|
*/
|
||||||
allocate(ratios: number[]): Money[] {
|
compare(other: Operand): number {
|
||||||
|
|
||||||
let remainder = this.amount;
|
|
||||||
const results: Money[] = [];
|
|
||||||
let total = 0;
|
|
||||||
|
|
||||||
ratios.forEach(function (ratio) {
|
|
||||||
total += ratio;
|
|
||||||
});
|
|
||||||
|
|
||||||
ratios.forEach(function (ratio) {
|
|
||||||
const share = Math.floor(this.amount * ratio / total);
|
|
||||||
results.push(new Money(share, this.currency));
|
|
||||||
remainder -= share;
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let i = 0; remainder > 0; i++) {
|
|
||||||
results[i] = new Money(results[i].amount + 1, results[i].currency);
|
|
||||||
remainder--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compares two instances of Money.
|
|
||||||
*
|
|
||||||
* @param {Money} other
|
|
||||||
* @returns {Number}
|
|
||||||
*/
|
|
||||||
compare(other: Money): number {
|
|
||||||
|
|
||||||
|
|
||||||
assertType(other);
|
const bigNumber = coerceToBigNumber(other);
|
||||||
assertSameCurrency(this, other);
|
assertSameCurrency(this, other);
|
||||||
|
|
||||||
if (this.amount === other.amount)
|
return this.toBigNumberWithNoDecimals().comparedTo(bigNumber);
|
||||||
return 0;
|
|
||||||
|
|
||||||
return this.amount > other.amount ? 1 : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Divides the object by the multiplier returning a new Money instance that holds the result of the operation.
|
* Divides the object by the divisor returning a new Money instance that holds the result of the operation.
|
||||||
*
|
*
|
||||||
* @param {Number} divisor
|
* @param divisor an object represented a numerical value to divide the current Money object by. If it's a Money object,
|
||||||
* @param {(x:number) => number} [fn=Math.round]
|
* the currency must match or `TypeError` will be thrown.
|
||||||
* @returns {Money}
|
* @param roundingMode the rounding mode to use if the result of the division would otherwise lead to a non-integer Money value. By default,
|
||||||
|
* we use the `RoundingMode.HalfUp` mode.
|
||||||
*/
|
*/
|
||||||
divide(divisor: number, fn?: (x: number) => number): Money {
|
divide(divisor: Operand, roundingMode: RoundingMode = RoundingMode.HalfUp): Money {
|
||||||
if (!isFunction(fn))
|
assertSameCurrency(this, divisor);
|
||||||
fn = Math.round;
|
return new Money(this.toBigNumberWithNoDecimals(roundingMode).dividedBy(coerceToBigNumber(divisor)).toNumber(), this.currency);
|
||||||
|
|
||||||
assertOperand(divisor);
|
|
||||||
const amount = fn(this.amount / divisor);
|
|
||||||
|
|
||||||
return new Money(amount, this.currency);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the two instances of Money are equal, false otherwise.
|
* Returns true if the two instances of Money are equal, false otherwise.
|
||||||
*
|
*
|
||||||
* @param {Money} other
|
* @param other an object represented a numerical value to compare to the current Money object to. If `other` is
|
||||||
* @returns {Boolean}
|
* a `Money` object, the currency must match for this to return true.
|
||||||
*/
|
*/
|
||||||
equals(other: Money): boolean {
|
equals(other: Operand): boolean {
|
||||||
|
return this.toBigNumberWithNoDecimals().isEqualTo(coerceToBigNumber(other)) &&
|
||||||
assertType(other);
|
(other instanceof Money ? this.currency === other.currency : false);
|
||||||
|
|
||||||
return this.amount === other.amount &&
|
|
||||||
this.currency === other.currency;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the value represented by this object is greater than the other.
|
* Checks whether the value represented by this object is greater than the other.
|
||||||
*
|
*
|
||||||
* @param {Money} other
|
* @param other an object represented a numerical value to compare to the current Money object to. If `other`
|
||||||
* @returns {boolean}
|
* is a Money instance, the currency must match or `TypeError` will be thrown.
|
||||||
*/
|
*/
|
||||||
greaterThan(other: Money): boolean {
|
greaterThan(other: Operand): boolean {
|
||||||
return 1 === this.compare(other);
|
assertSameCurrency(this, other);
|
||||||
|
return this.toBigNumberWithNoDecimals().isGreaterThan(coerceToBigNumber(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the value represented by this object is greater or equal to the other.
|
* Checks whether the value represented by this object is greater or equal to the other.
|
||||||
*
|
*
|
||||||
* @param {Money} other
|
* @param other an object represented a numerical value to compare to the current Money object to. If `other`
|
||||||
* @returns {boolean}
|
* is a Money instance, the currency must match or `TypeError` will be thrown.
|
||||||
*/
|
*/
|
||||||
greaterThanOrEqual(other: Money): boolean {
|
greaterThanOrEqual(other: Operand): boolean {
|
||||||
return 0 <= this.compare(other);
|
assertSameCurrency(this, other);
|
||||||
|
return this.toBigNumberWithNoDecimals().isGreaterThanOrEqualTo(coerceToBigNumber(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the amount is negative
|
* Returns true if the amount is negative
|
||||||
*
|
*
|
||||||
* @returns {boolean}
|
|
||||||
* @memberof Money
|
|
||||||
*/
|
*/
|
||||||
isNegative(): boolean {
|
isNegative(): boolean {
|
||||||
return this.amount < 0;
|
return this.toBigNumberWithNoDecimals().isNegative();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the amount is positive.
|
* Returns true if the amount is positive.
|
||||||
*
|
*
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
*/
|
||||||
isPositive(): boolean {
|
isPositive(): boolean {
|
||||||
return this.amount > 0;
|
return this.toBigNumberWithNoDecimals().isPositive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the amount is zero.
|
* Returns true if the amount is zero.
|
||||||
*
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
*/
|
||||||
isZero(): boolean {
|
isZero(): boolean {
|
||||||
return this.amount === 0;
|
return this.toBigNumberWithNoDecimals().isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the value represented by this object is less than the other.
|
* Checks whether the value represented by this object is less than the other.
|
||||||
*
|
*
|
||||||
* @param {Money} other
|
* @param other an object represented a numerical value to compare to the current Money object to. If `other`
|
||||||
* @returns {boolean}
|
* is a Money instance, the currency must match or `TypeError` will be thrown.
|
||||||
*/
|
*/
|
||||||
lessThan(other: Money): boolean {
|
lessThan(other: Operand): boolean {
|
||||||
return -1 === this.compare(other);
|
|
||||||
|
assertSameCurrency(this, other);
|
||||||
|
return this.toBigNumberWithNoDecimals().isLessThan(coerceToBigNumber(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the value represented by this object is less than or equal to the other.
|
* Checks whether the value represented by this object is less than or equal to the other.
|
||||||
*
|
*
|
||||||
* @param {Money} other
|
* @param other an object represented a numerical value to compare to the current Money object to. If `other`
|
||||||
* @returns {boolean}
|
* is a Money instance, the currency must match or `TypeError` will be thrown.
|
||||||
*/
|
*/
|
||||||
lessThanOrEqual(other: Money): boolean {
|
lessThanOrEqual(other: Money): boolean {
|
||||||
return 0 >= this.compare(other);
|
assertSameCurrency(this, other);
|
||||||
|
return this.toBigNumberWithNoDecimals().isLessThanOrEqualTo(coerceToBigNumber(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiplies the object by the multiplier returning a new Money instance that holds the result of the operation.
|
* Multiplies the object by the multiplier returning a new Money instance that holds the result of the operation.
|
||||||
*
|
*
|
||||||
* @param {number} multiplier
|
* @param multiplier an object represented a numerical value to multiply the current Money object by. If it's a Money object,
|
||||||
* @param {(x:number) => number} [fn=Math.round]
|
* the currency must match or `TypeError` will be thrown.
|
||||||
* @returns {Money}
|
* @param roundingMode the rounding mode to use if the result of the multiplication would otherwise lead to a non-integer Money value. By default,
|
||||||
|
* we use the `RoundingMode.HalfUp` mode.
|
||||||
*/
|
*/
|
||||||
multiply(multiplier: number, roundingFunction: (x: number) => number): Money {
|
multiply(multiplier: Operand, roundingMode: RoundingMode = RoundingMode.HalfUp): Money {
|
||||||
if (!isFunction(roundingFunction))
|
assertSameCurrency(this, multiplier);
|
||||||
roundingFunction = Math.round;
|
const unrounded = this.toBigNumberWithNoDecimals(roundingMode).multipliedBy(coerceToBigNumber(multiplier));
|
||||||
|
|
||||||
assertOperand(multiplier);
|
return new Money(unrounded.decimalPlaces(0, roundingMode).toNumber(), this.currency);
|
||||||
const amount = roundingFunction(this.amount * multiplier);
|
|
||||||
|
|
||||||
return new Money(amount, this.currency);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtracts the two objects creating a new Money instance that holds the result of the operation.
|
* Subtracts the two objects creating a new Money instance that holds the result of the operation.
|
||||||
*
|
*
|
||||||
* @param {Money} other
|
* @param other an object represented an integer value to subtract from the current Money object. If it's a Money object,
|
||||||
* @returns {Money}
|
* the currency must match or `TypeError` will be thrown. If not, it must be an integer or `TypeError` is thrown.
|
||||||
*/
|
*/
|
||||||
subtract(other: Money): Money {
|
subtract(other: Operand): Money {
|
||||||
|
|
||||||
assertType(other);
|
|
||||||
assertSameCurrency(this, other);
|
assertSameCurrency(this, other);
|
||||||
|
return new Money(this.toBigNumberWithNoDecimals().minus(coerceToBigNumber(other, true)).toNumber(), this.currency);
|
||||||
return new Money(this.amount - other.amount, this.currency);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a serialised version of the instance.
|
* Get the amount of the Money instance as a `BigNumber`.
|
||||||
|
*/
|
||||||
|
toBigNumber() : BigNumber {
|
||||||
|
return new BigNumber(this.amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a serialized version of the instance.
|
||||||
*
|
*
|
||||||
* @returns {{amount: number, currency: string}}
|
* @returns {{amount: number, currency: string}}
|
||||||
*/
|
*/
|
||||||
|
@ -274,4 +340,16 @@ export class Money {
|
||||||
currency: this.currency,
|
currency: this.currency,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private toBigNumberWithNoDecimals(roundingMode?:RoundingMode) : BigNumber {
|
||||||
|
const config:BigNumber.Config = {
|
||||||
|
DECIMAL_PLACES: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (roundingMode) {
|
||||||
|
config.ROUNDING_MODE = roundingMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new (BigNumber.clone(config))(this.toBigNumber());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,8 +16,8 @@ function rawFormatMoney(intl:IntlShapeParent, amount:Money, opts?:FormatMoneyOpt
|
||||||
currency: amount.currency.toUpperCase(),
|
currency: amount.currency.toUpperCase(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const adjustedAmount = amount.amount / Math.pow(10, formatter.resolvedOptions().maximumFractionDigits);
|
const adjustedAmount = amount.toBigNumber().dividedBy(Math.pow(10, formatter.resolvedOptions().maximumFractionDigits));
|
||||||
return formatter.format(adjustedAmount);
|
return formatter.format(adjustedAmount.toNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -111,6 +111,7 @@
|
||||||
"@material-ui/icons": "^4.9.1",
|
"@material-ui/icons": "^4.9.1",
|
||||||
"@rails/activestorage": "^6.0.2-2",
|
"@rails/activestorage": "^6.0.2-2",
|
||||||
"attr-binder": "0.3.1",
|
"attr-binder": "0.3.1",
|
||||||
|
"bignumber.js": "^9.0.0",
|
||||||
"chart.js": "2.1.4",
|
"chart.js": "2.1.4",
|
||||||
"color": "^3.1.0",
|
"color": "^3.1.0",
|
||||||
"commons.css": "0.1.8",
|
"commons.css": "0.1.8",
|
||||||
|
|
|
@ -4850,6 +4850,11 @@ big.js@^5.2.2:
|
||||||
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
|
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
|
||||||
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
|
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
|
||||||
|
|
||||||
|
bignumber.js@^9.0.0:
|
||||||
|
version "9.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.0.tgz#805880f84a329b5eac6e7cb6f8274b6d82bdf075"
|
||||||
|
integrity sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==
|
||||||
|
|
||||||
binary-extensions@^1.0.0:
|
binary-extensions@^1.0.0:
|
||||||
version "1.13.1"
|
version "1.13.1"
|
||||||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
|
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
|
||||||
|
|
Loading…
Reference in a new issue