{"_id":"@bitzlato/money-js","_rev":"4-c537ad21c4a1b9135dac26071ec3aa2e","name":"@bitzlato/money-js","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.2":{"name":"@bitzlato/money-js","version":"0.0.2","description":"A small library for working with monetary values","author":{"name":"Maksim Gerasimov","email":"treizeger@gmail.com","url":"http://github.com/trzmaxim"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bitzlato/money-js.git"},"bugs":{"url":"https://github.com/bitzlato/money-js/issues"},"homepage":"https://github.com/bitzlato/money-js#readme","main":"dist/index.cjs.js","module":"dist/index.esm.js","types":"dist/index.d.ts","scripts":{"build":"rollup -c","test":"npx jest && npx tsc --noEmit"},"dependencies":{"@types/big.js":"^6.1.2","big.js":"^6.1.1","toformat":"^2.0.0"},"devDependencies":{"@swc/core":"^1.2.102","@swc/jest":"^0.2.5","@types/jest":"^27.0.2","jest":"^27.3.1","rollup":"^1.29.0","rollup-plugin-typescript2":"^0.30.0","typescript":"^4.4.4"},"gitHead":"28f06c602b4f4d75ce5badcb55d64f7dec49375e","_id":"@bitzlato/money-js@0.0.2","_nodeVersion":"16.12.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-hLGimcgIlnwOD+P4xOT1agq81Q/z50eBC8xOXUzZjDn33/J2leWd3M6w2zpyrgn3KSr0pVut3JbxrDtqZX85HQ==","shasum":"220cc1d135c236ee2f4c026c71ef3a7d08e68556","tarball":"https://registry.npmjs.org/@bitzlato/money-js/-/money-js-0.0.2.tgz","fileCount":8,"unpackedSize":18445,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFH//omQ8gn4g0hyQn31GG/3yU82keeR4zgA34JRtNgrAiEAlahVQq2D2VuUqkAW/ljARgqR6qmqdCCC8j033T63T3w="}]},"_npmUser":{"name":"trzmaxim","email":"treizeger@gmail.com"},"directories":{},"maintainers":[{"name":"trzmaxim","email":"treizeger@gmail.com"},{"name":"telecommit","email":"igork@bitzlato.com"},{"name":"bitzlato-com","email":"ops@bitzlato.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/money-js_0.0.2_1635448826411_0.785448726675372"},"_hasShrinkwrap":false},"0.0.3":{"name":"@bitzlato/money-js","version":"0.0.3","description":"A small library for working with monetary values","author":{"name":"Maksim Gerasimov","email":"treizeger@gmail.com","url":"http://github.com/trzmaxim"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bitzlato/money-js.git"},"bugs":{"url":"https://github.com/bitzlato/money-js/issues"},"homepage":"https://github.com/bitzlato/money-js#readme","main":"dist/index.cjs.js","module":"dist/index.esm.js","types":"dist/index.d.ts","scripts":{"build":"rollup -c","test":"npx jest && npx tsc --noEmit"},"dependencies":{"@types/big.js":"^6.1.2","big.js":"^6.1.1","toformat":"^2.0.0"},"devDependencies":{"@swc/core":"^1.2.102","@swc/jest":"^0.2.5","@types/jest":"^27.0.2","jest":"^27.3.1","rollup":"^1.29.0","rollup-plugin-typescript2":"^0.30.0","typescript":"^4.4.4"},"gitHead":"91b24c1421ea8b087123d5f05a52ca412776cee8","_id":"@bitzlato/money-js@0.0.3","_nodeVersion":"16.12.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-2kWYeObvROslm4MahsfZAHIYqFqIqpNeQaimSZH1YEG8XDd8I4CVQGUBQgmPf1EQ0MGOI+uzytJKwhK/ORWJgA==","shasum":"55e89672edb44e8bdefd8831d9d5221588a442a3","tarball":"https://registry.npmjs.org/@bitzlato/money-js/-/money-js-0.0.3.tgz","fileCount":8,"unpackedSize":18431,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDQwOJ6adcIx1GR7UrdjHeB2HLUmRinEloiYKG2CCokyAiEAx1Hs7SZDiwMxhejerXojO1YT3wmTF+5siVee9H4Brn4="}]},"_npmUser":{"name":"trzmaxim","email":"treizeger@gmail.com"},"directories":{},"maintainers":[{"name":"c0gnize","email":"cognize6@gmail.com"},{"name":"trzmaxim","email":"treizeger@gmail.com"},{"name":"telecommit","email":"igork@bitzlato.com"},{"name":"bitzlato-com","email":"ops@bitzlato.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/money-js_0.0.3_1636551521173_0.8571768843791181"},"_hasShrinkwrap":false},"0.0.4":{"name":"@bitzlato/money-js","version":"0.0.4","description":"A small library for working with monetary values","author":{"name":"Maksim Gerasimov","email":"treizeger@gmail.com","url":"http://github.com/trzmaxim"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bitzlato/money-js.git"},"bugs":{"url":"https://github.com/bitzlato/money-js/issues"},"homepage":"https://github.com/bitzlato/money-js#readme","main":"dist/index.cjs.js","module":"dist/index.esm.js","types":"dist/index.d.ts","scripts":{"build":"rollup -c","test":"npx jest && npx tsc --noEmit"},"dependencies":{"@types/big.js":"^6.1.2","big.js":"^6.1.1","toformat":"^2.0.0"},"devDependencies":{"@swc/core":"^1.2.121","@swc/jest":"^0.2.15","@types/jest":"^27.0.3","jest":"^27.4.5","rollup":"^1.29.0","rollup-plugin-typescript2":"^0.31.1","typescript":"^4.5.4"},"gitHead":"8cc9f7b034e2a9cd0729f2719582b53f3b17b446","_id":"@bitzlato/money-js@0.0.4","_nodeVersion":"16.12.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-cDwzt8Lzx2ktttbXeV65WZriHgQjnWDOF/iaksvchq7i9nu9H4U7drmwLPW450oYkgg7JYjElqiziHzcqLrypw==","shasum":"40a6cc2710f0d915ba0f126cc24eedbc8204e3f4","tarball":"https://registry.npmjs.org/@bitzlato/money-js/-/money-js-0.0.4.tgz","fileCount":8,"unpackedSize":18584,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhwZzXCRA9TVsSAnZWagAAsJ0P/0sd2K/uPPYGdlei/sa2\nu13zjU1Sc5AXs4yfN8KohMbsum3ZSEbuuqwKRgifLPzldpPmZaYrtfkOG5e4\nMmKv/tAT18nBthXJEXM7OL9wtNHNEAdjmLKaJArBP8n4OPvmAWHcTxp0JqbI\nxFZIBRMpIQV0e2Jjkk1a/W/EDmOjAxPonOAa3I/BvXf4DiJXEVpDtlY1yo/l\n8Lp8eUqrKP471+jklR1au7raDadBCHKfazzloCCtAyD8+bJAgRwgmFc/3vQ4\nmh6soIJsBGylBgxmf6bGsI3BBasx8v7EAfGyflbRiMLow/7BdkHbZUj8eDu9\n189GHfYyI45f8odYryXNg0YFZ6D69/+jfn+1kWwjCaNbaiNoTO3E4ERuWP98\neKXlO/TSMWbW5zI3ejk3Iu4NH8Y4yPTcsUMCq87D8+v1/NJbEE3llNmBydaa\n6wwn7Ijgo6Oz+VAwnaMeAvnfjezn3i71KZoYaBpSXVlFH0qmgxY7FvzvYLBZ\nRB1jRgQUBP9Tqm9d7ZB2eNZL6IeU/f1YLsBb+Lp25GOXcVyBqp0CBfPbM5fP\nO/5PHAqytAPFeH3z8Fi/LYpUmXGJJ+WLi2o3ITwq4R76vUKo99zUqhqFyU30\n6z2f3SReGCbrSoxLR3wjQurlHu6Kg/GY4mcwEei9dd3tzDRACNxyr4ErlGIN\nxrql\r\n=jrhW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCi6XWAs3BoUtQmDUHyCX8K0UKaFs44L1XW/eEcrN/iJQIhANa0WxNT+n8O1XeBUwBSXbZuYjyC4BU1YB1m9ELGltc6"}]},"_npmUser":{"name":"trzmaxim","email":"treizeger@gmail.com"},"directories":{},"maintainers":[{"name":"c0gnize","email":"cognize6@gmail.com"},{"name":"trzmaxim","email":"treizeger@gmail.com"},{"name":"telecommit","email":"igork@bitzlato.com"},{"name":"bitzlato-com","email":"ops@bitzlato.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/money-js_0.0.4_1640078551001_0.016609794345496587"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-28T19:20:26.354Z","0.0.2":"2021-10-28T19:20:26.541Z","modified":"2022-04-04T19:14:49.921Z","0.0.3":"2021-11-10T13:38:41.311Z","0.0.4":"2021-12-21T09:22:31.204Z"},"maintainers":[{"name":"c0gnize","email":"cognize6@gmail.com"},{"name":"trzmaxim","email":"treizeger@gmail.com"},{"name":"telecommit","email":"igork@bitzlato.com"},{"name":"bitzlato-com","email":"ops@bitzlato.com"}],"description":"A small library for working with monetary values","homepage":"https://github.com/bitzlato/money-js#readme","repository":{"type":"git","url":"git+https://github.com/bitzlato/money-js.git"},"author":{"name":"Maksim Gerasimov","email":"treizeger@gmail.com","url":"http://github.com/trzmaxim"},"bugs":{"url":"https://github.com/bitzlato/money-js/issues"},"license":"MIT","readme":"# @bitzlato/money-js\n\nThis is a small library for working with monetary values. Based on [big.js](https://github.com/MikeMcl/big.js/) and follows [Martin Fowler's Money Type](https://martinfowler.com/eaaCatalog/money.html).\n\n## Install\n\n    npm i @bitzlato/money-js\n\n## Usage\n\n### Creating a money object\n\nThe library does not contain information about currencies, you have to define them yourself.\n\n```typescript\nconst USD: Currency = {\n  code: 'USD',\n  minorUnit: 2,\n};\n\nconst BTC: Currency = {\n  code: 'BTC',\n  minorUnit: 8,\n};\n```\n\n```typescript\nimport { Money } from '@bitzlato/money-js';\n\n// Money.fromDecimal(amount: number | string, currency: Currency, roundingMode?: RoundingMode) => Money\nconst dollars = Money.fromDecimal(10.25, USD);\nconst bitcoins = Money.fromDecimal('0.05316732', BTC);\n// Money.toCents() => string\nbitcoins.toCents(); // '5316732'\n\n// Money.fromCents(amount: number | string, currency: Currency, roundingMode?: RoundingMode) => Money\nconst tenDollars = Money.fromCents(1000, USD);\nconst fiveBitcoins = Money.fromCents('500000000', BTC);\n// Money.toString() => string\nfiveBitcoins.toString(); // '5.00000000'\n\n// new Money(amount: Big, currency: Currency, roundingMode?: RoundingMode) => Money\nconst fiveDollars = new Money(new Big('5'), USD);\n// Money.toJSON() => { amount: string; currency: Currency }\nJSON.stringify(fiveDollars); // '{\"amount\":\"5.00\",\"currency\":{\"code\":\"USD\",\"minorUnit\":2}}'\n```\n\n### Arithmetic\n\n```typescript\nconst tenDollars = Money.fromCents(1_000, USD);\n\n// Money.add(money: Money) => Money\ntenDollars.add(Money.fromCents(250, USD)); // 12.50 USD\n\n// Money.subtract(money: Money) => Money\ntenDollars.subtract(Money.fromCents(250, USD)); // 7.50 USD\n\n// Money.multiply(multiplier: Big | string | number) => Money\ntenDollars.multiply(2.5); // 25.00 USD\n\n// Money.divide(divisor: Big | string | number) => Money\ntenDollars.divide(2.5); // 4 USD\n```\n\nAdding or subtracting different currencies will cause an error:\n\n```typescript\nMoney.fromCents(1_000, USD).add(Money.fromCents(200_000, BTC)); // Error: Different currencies\n```\n\n### Comparing\n\n```typescript\nconst tenDollars = Money.fromCents(1_000, USD);\nconst bigger = Money.fromCents(1_500, USD);\nconst smaller = Money.fromCents(500, USD);\nconst equal = Money.fromDecimal(10, USD);\nconst bitcoins = Money.fromCents(200_000, BTC);\n\n// Money.equals(money: Money) => boolean\n// Money.eq(money: Money) => boolean\ntenDollars.equals(bitcoins); // false\ntenDollars.equals(equal); // true\n\n// Money.compare(money: Money) => -1 | 0 | 1\ntenDollars.compare(bigger); // -1\ntenDollars.compare(smaller); // 1\ntenDollars.compare(equal); // 0\ntenDollars.compare(bitcoins); // Error: Different currencies\n\n// Money.lessThan(money: Money) => boolean\n// Money.lt(money: Money) => boolean\ntenDollars.lessThan(bigger); // true\n// Money.lessThanOrEqual(money: Money) => boolean\n// Money.lte(money: Money) => boolean\ntenDollars.lessThanOrEqual(equal); // true\ntenDollars.lessThanOrEqual(smaller); // false\n\n// Money.greaterThan(money: Money) => boolean\n// Money.gt(money: Money) => boolean\ntenDollars.greaterThan(smaller); // true\n// Money.greaterThanOrEqual(money: Money) => boolean\n// Money.gte(money: Money) => boolean\ntenDollars.greaterThanOrEqual(equal); // true\ntenDollars.greaterThanOrEqual(bigger); // false\n```\n\n### Asserts\n\n```typescript\n// Money.isZero() => boolean\nMoney.fromCents(0, USD).isZero(); // true\nMoney.fromCents(100, USD).isZero(); // false\n\n// Money.isPositive() => boolean\n// Money.isNegative() => boolean\nconst dollars = Money.fromCents(-100, USD);\ndollars.isPositive(); // false\ndollars.isNegative(); // true\nconst zero = Money.fromCents(0, USD);\nzero.isNegative(); // false\nzero.isPositive(); // true\n```\n\n### Convert\n\n```typescript\nMoney.fromCents(100_000_000, BTC).convert(60_737, USD).toString(); // '60737.00'\n```\n\n### Formatting\n\n```typescript\n// Money.toFormat(formatOptions?: FormatOptions) => string\nMoney.fromCents(12_340_000_000, USD).toFormat(); // '123,400,000.00'\nMoney.fromDecimal('1000.00010000', BTC).toFormat(); // '1,000.0001'\nMoney.fromDecimal('10230.0', BTC).toFormat(); // '10,230.00'\nMoney.fromDecimal('1000000', BTC).toFormat(); // '1,000,000.00'\n```\n\nFormatting options:\n\n```typescript\ninterface FormatOptions {\n  // The minimum number of displayed fraction digits\n  minFractionDigits?: number; // default: 2\n  // The maximum number of displayed fraction digits\n  maxFractionDigits?: number; // default: 20\n  // The flag whether to remove the trailing fractional zeros\n  removeTrailingFractionalZeros?: boolean; // default: true\n  // The decimal separator\n  decimalSeparator?: string; //\n  // The grouping separator of the integer part\n  groupSeparator?: string;\n  // The primary grouping size of the integer part\n  groupSize?: number;\n  // The secondary grouping size of the integer part\n  secondaryGroupSize?: number;\n  // The grouping separator of the fraction part\n  fractionGroupSeparator?: string;\n  // The grouping size of the fraction part\n  fractionGroupSize?: number;\n}\n```\n\n```typescript\nconst bitcoins = Money.fromDecimal('1330000.128345', BTC);\nconst dollars = Money.fromDecimal('0.128345', USD);\n\nbitcoins.toFormat({\n  decimalSeparator: ',',\n  groupSeparator: ' ',\n}); // '1 330 000,128345'\nbitcoins.toFormat({ maxFractionDigits: 4 }); // '1,330,000.1283'\ndollars.toFormat({ maxFractionDigits: 6 }); // '0.13'\ndollars.toFormat({ minFractionDigits: 0, maxFractionDigits: 1 }); // '0.1'\nbitcoins.toFormat({ removeTrailingFractionalZeros: false }); // 1,330,000.12834500\n```\n\n### Rounding\n\n- `Money.ROUND_HALF_UP`\n- `Money.ROUND_HALF_EVEN` - The default. [Bankers Rounding](http://wiki.c2.com/?BankersRounding).\n- `Money.ROUND_DOWN`\n- `Money.ROUND_UP`\n\nYou can specify any of these roundings when creating:\n\n```typescript\nMoney.fromDecimal(10.2548, USD, Money.ROUND_UP).toString(); // '10.26'\n```\n\n## Test\n\n    npm test\n\n## License\n\n[MIT](LICENSE).\n","readmeFilename":"README.md"}