{"_id":"mongoose-currency","_rev":"28-899d2ddac027bb97bc014ec4dc97549d","name":"mongoose-currency","description":"Adds schema type \"currency\" to mongoose. Great for converting user input.","dist-tags":{"latest":"0.3.0"},"versions":{"0.0.1":{"name":"mongoose-currency","version":"0.0.1","description":"Adds schema type \"currency\" to mongoose. Sets as int and gets as a floating point number","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"https://github.com/catalystmediastudios/mongoose-currency.git"},"keywords":["mongoose","currency","money"],"author":{"name":"Paul Smith","email":"catalystmediastudios@gmail.com"},"license":"MIT","gitHead":"80f9b6fa07591917779b470a3a92c6fe3aadd9fe","devDependencies":{"mocha":"1.9.x","should":"*","mongoose":"3.x"},"peerDependencies":{"mongoose":"3.x"},"_id":"mongoose-currency@0.0.1","dist":{"shasum":"56b80f97ddd2f0de986adf93cdf9198754b91bb9","tarball":"https://registry.npmjs.org/mongoose-currency/-/mongoose-currency-0.0.1.tgz","integrity":"sha512-9KSjiAWGYx5umNoaBEDbktNEOnfxBOVOaq7PqNLIT17W1AjtPHuXI9teGKkROzLrEp46i07M7lXiKdLngF3RrQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGK5UHhWqH1j4fK31gyFKgf8EmOptWUIATYFEs39ao+qAiEAhqacSDSfBs+j8bTGaAMwFaslW4myc80vjkgjODqBgpY="}]},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"},"maintainers":[{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"}],"directories":{}},"0.0.2":{"name":"mongoose-currency","version":"0.0.2","description":"Adds schema type \"currency\" to mongoose. Great for converting user input.","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"https://github.com/catalystmediastudios/mongoose-currency.git"},"keywords":["mongoose","currency","money"],"author":{"name":"Paul Smith","email":"catalystmediastudios@gmail.com"},"license":"MIT","gitHead":"80f9b6fa07591917779b470a3a92c6fe3aadd9fe","devDependencies":{"mocha":"1.9.x","should":"*","mongoose":"3.x"},"peerDependencies":{"mongoose":"3.x"},"_id":"mongoose-currency@0.0.2","dist":{"shasum":"241dba24e9fb4a898755e048a9d5ffd31a04cca5","tarball":"https://registry.npmjs.org/mongoose-currency/-/mongoose-currency-0.0.2.tgz","integrity":"sha512-UT1uaIaySvebPlfD5BMvprks7CbpaRhXT61eBEjzsrIrcTH/G782z5bEEAEOxR6FCca8tuPvIoP5sF5jOseOUw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC4IElpX07dENxe7IrVk58CtY4AZT0NZCgzgUrqj50+mQIhAKvH2hSxKsS31aK0RX2Pf3rUoc6lVPgMScuGmRKr4B5W"}]},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"},"maintainers":[{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"}],"directories":{}},"0.0.3":{"name":"mongoose-currency","version":"0.0.3","description":"Adds schema type \"currency\" to mongoose. Great for converting user input.","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"https://github.com/catalystmediastudios/mongoose-currency.git"},"keywords":["mongoose","currency","money"],"author":{"name":"Paul Smith","email":"catalystmediastudios@gmail.com"},"license":"MIT","gitHead":"80f9b6fa07591917779b470a3a92c6fe3aadd9fe","devDependencies":{"mocha":"1.9.x","should":"*","mongoose":"3.x","underscore":"1.x"},"peerDependencies":{"mongoose":"3.x"},"_id":"mongoose-currency@0.0.3","dist":{"shasum":"36696f3cc4fafaccd70f69084d5ce813002b453c","tarball":"https://registry.npmjs.org/mongoose-currency/-/mongoose-currency-0.0.3.tgz","integrity":"sha512-yT8HG+rD2bWT4GKUxmosWXh28q1xftW8suc+joOc5BXp8JQBHhyb7pzNzdzexFcXdy1QLJMno+H1gqDKioCElg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDlJkKWeOjJ1ydxuRcst3GFjrKKm7vXGl7ZPOMmbC5VUQIhAI1YINTWB4uIWG0hsENH2GOjnhBXGQ3BZlF4orBna1b9"}]},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"},"maintainers":[{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"}],"directories":{}},"0.0.4":{"name":"mongoose-currency","version":"0.0.4","description":"Adds schema type \"currency\" to mongoose. Great for converting user input.","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"https://github.com/catalystmediastudios/mongoose-currency.git"},"keywords":["mongoose","currency","money"],"author":{"name":"Paul Smith","email":"catalystmediastudios@gmail.com"},"license":"MIT","gitHead":"80f9b6fa07591917779b470a3a92c6fe3aadd9fe","devDependencies":{"mocha":"1.9.x","should":"*","mongoose":"3.x"},"peerDependencies":{"mongoose":"3.x"},"bugs":{"url":"https://github.com/catalystmediastudios/mongoose-currency/issues"},"_id":"mongoose-currency@0.0.4","dist":{"shasum":"41a441fc2b724085b9c5c482c3c704edf03d74d2","tarball":"https://registry.npmjs.org/mongoose-currency/-/mongoose-currency-0.0.4.tgz","integrity":"sha512-YZ9VW9HljWz+I++59AMrVKNK42Fe5oLmAwjbOA/wbJRH9at9glqvK8Zxw6GHPp1lIbF12Fow0nO442fKgiqiyw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDlRblEPMSq/1Pfd92ZIcaKLGtZRvd9GK5XoghfZKx3CwIgDnXtg02coN1KrOHubHeFpIugBHTWDvNAnQHXGv/lrgg="}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"},"maintainers":[{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"}],"directories":{}},"0.2.0":{"name":"mongoose-currency","version":"0.2.0","description":"Adds schema type \"currency\" to mongoose. Great for converting user input.","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"https://github.com/catalystmediastudios/mongoose-currency.git"},"keywords":["mongoose","currency","money"],"author":{"name":"Paul Smith","email":"catalystmediastudios@gmail.com"},"license":"MIT","gitHead":"80f9b6fa07591917779b470a3a92c6fe3aadd9fe","devDependencies":{"mocha":"1.9.x","should":"6.0.x","mongoose":"~> 4.x"},"peerDependencies":{"mongoose":"~> 4.x"},"bugs":{"url":"https://github.com/catalystmediastudios/mongoose-currency/issues"},"homepage":"https://github.com/catalystmediastudios/mongoose-currency","_id":"mongoose-currency@0.2.0","_shasum":"2f53272d5d720af35a171230fb30d6d22d74e451","_from":".","_npmVersion":"2.4.1","_nodeVersion":"0.10.36","_npmUser":{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"},"dist":{"shasum":"2f53272d5d720af35a171230fb30d6d22d74e451","tarball":"https://registry.npmjs.org/mongoose-currency/-/mongoose-currency-0.2.0.tgz","integrity":"sha512-38YAHJ61z9UB10aPr70pXWffPG0Qk5N3HRHVuBYi2Zfx6zU9vsbuPEQjhF2BOyFZxKm3BhBUnOKKBuwtgrWFCw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCM4GlR1Vj5aFqtJe2RX90ePgZWrCG9n4W3TmlOl1PgAgIgTdH3Q+bOKy9/kmCO+ecTZrcm8Hm6kXF2JfTkda+v7Us="}]},"maintainers":[{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"}],"directories":{}},"0.3.0":{"name":"mongoose-currency","version":"0.3.0","description":"Adds schema type \"currency\" to mongoose. Great for converting user input.","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/catalystmediastudios/mongoose-currency.git"},"keywords":["mongoose","currency","money"],"author":{"name":"Paul Smith","email":"catalystmediastudios@gmail.com"},"license":"MIT","gitHead":"80f9b6fa07591917779b470a3a92c6fe3aadd9fe","devDependencies":{"mocha":"^10.4.0","mongodb-memory-server":"^9.2.0","mongoose":">=4","should":"^13.2.3"},"peerDependencies":{"mongoose":">=4"},"_id":"mongoose-currency@0.3.0","bugs":{"url":"https://github.com/catalystmediastudios/mongoose-currency/issues"},"homepage":"https://github.com/catalystmediastudios/mongoose-currency#readme","_nodeVersion":"20.12.1","_npmVersion":"10.5.0","dist":{"integrity":"sha512-tykMlWKML7UW7hlmdvOf8d7BIRQaOpCXOGAzfOm74ysASd3lkvpyJYGycfhiJdQe+1ywyx7ljAvKG2fCGoFLWw==","shasum":"423c6f1581a89b925d7b115d418160a7255a5fad","tarball":"https://registry.npmjs.org/mongoose-currency/-/mongoose-currency-0.3.0.tgz","fileCount":4,"unpackedSize":14670,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB7kkNjRQgAZ1/AHcbNSm/9uOFxu8qrvcO5PSByQteTBAiEA/gSsXOldZAX0neld8C5uXgS82ItjlF8H56iJzUGwwK8="}]},"_npmUser":{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"},"directories":{},"maintainers":[{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-currency_0.3.0_1715005124410_0.43800019332092566"},"_hasShrinkwrap":false}},"readme":"## What it does\n\n* Saves a String as an integer (by stripping non digits and multiplying by 100) to prevent rounding errors when performing calculations (See gotchas for details)\n* Strips out symbols from the beginning of strings (sometimes users include the currency symbol)\n* Strips out commas (sometimes users add in commas or copy paste values into forms, e.g. \"1,000.50)\n* Only save from two digits past the decimal point (\"$500.559\" is converted to 50055 and doesn't round)\n* Strips [a-z, A-Z] from strings\n* Pass in a string or a number. Numbers will be stored AS IS.\n* Assumes that if you set the value to an integer you have already done the conversion (e.g. 50000 = $500.00)\n* If a floating point number is passed in it will round it. (500.55 -> 501). Just pass in integers to be safe.\n\n## How to use\n\n```JavaScript\nvar mongoose = require('mongoose');\nvar Schema = mongoose.Schema;\n// Will add the Currency type to the Mongoose Schema types\nrequire('mongoose-currency').loadType(mongoose);\nvar Currency = mongoose.Types.Currency;\n\n// If you don't have the Currency variable declared you can use 'mongoose.Types.Currency'\nvar ProductSchema = Schema({\n  price: { type: Currency }\n});\n\nvar Product = mongoose.model('Product', ProductSchema);\n\nvar product = new Product({ price: \"$1,200.55\" });\nproduct.price; // Number: 120055\nproduct.price = 1200;\nproduct.price; // Number 1200 It will not round or multiply. Stored AS IS and should represent $12.00\n```\n### Schema options\n\nAccepts mongoose [number schema options](http://mongoosejs.com/docs/api.html#schema-number-js)\n\n```JavaScript\n// Will validate that the minimum is $200.00 and max is $500.00\nvar ProductSchema = Schema({\n  price: { type: Currency, required: true, min: -20000, max: 50000 }\n});\n\n// See Gotchas (bottom) for details\n```\n### Displaying to end users (views, reports, etc.)\n\nTo display values to end users remember to call `.toFixed(2)`\n```JavaScript\nproduct.price.toFixed(2); // Returns 1200.55\n```\n\n## Testing\n\nMake sure to have mocha installed `npm install mocha`\n\nin the root directory of the project run `mocha test`\n\n## Todo\n\n* Add currency validation?\n* Add option for what Currency strips by default (, or .) Will work better in countries where values are represented like this: 1.000.000,00\n* Add option for precision\n* Add currency validator?\n* Change min/max validators to accept currency format e.g. 200 is $200.00 not $2.00. Not sure if this is the best way or not.\n\n## Gotchas\n\nThe currency is returned as an integer. Why? Because adding two floating points together can have rounding errors.\n```\n// Not good\n1.03+1.19; // 2.2199999999999998\n```\n\n### Calculations with currency with mongoose-currency.\n\n```JavaScript\nvar product1 = Product.findById('id');\nvar product2 = Product.findById('id2');\nproduct1.price; // returns 103 which represents $1.03\nproduct2.price; // returns 119 which represents $1.19\nvar sum = product1.price+product2.price / 100;\nsum.toFixed(2); // returns a number: 2.22\n```\n\n### Displaying values for end users\n\n```JavaScript\nvar record = Product.findById('yourid');\nrecord.price; // 10050 which represents $100.50\nrecord.price.toFixed(2); // return 100.50\n```\n\nWhen you set an integer it will NOT be multiplied by 100. It will be stored AS IS!\nThis is on purpose. This library is mainly for accepting USER generated inputs from forms, etc.\n```\nproduct.price = 100;\nproduct.price; // Returns 100 Does not multiply by 100. Represents $1.00\n```\n\n### Queries and validators\n\nRemember when doing queries that to find values greater than, less than, etc. you need to multiply by 100!\n\nSo to get values greater than $100.00 you need to run your query with 100 * 100 e.g. 10000\n\n*It is considered best practice to store money values as ints.\nIt will cause far fewer problems down the road*\n\nFor further reading: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html\n\nJust remember to call toFixed(2) whenever you want to display those values to end users.\n\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/paulcsmith/mongoose-currency/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n","maintainers":[{"name":"paulcsmith","email":"catalystmediastudios@gmail.com"}],"time":{"modified":"2024-05-06T14:18:44.743Z","created":"2013-04-20T21:00:06.900Z","0.0.1":"2013-04-20T21:00:09.630Z","0.0.2":"2013-04-20T21:35:43.819Z","0.0.3":"2013-04-20T22:10:33.643Z","0.0.4":"2014-01-02T21:53:00.719Z","0.2.0":"2015-06-04T14:05:07.644Z","0.3.0":"2024-05-06T14:18:44.557Z"},"author":{"name":"Paul Smith","email":"catalystmediastudios@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/catalystmediastudios/mongoose-currency.git"},"homepage":"https://github.com/catalystmediastudios/mongoose-currency#readme","keywords":["mongoose","currency","money"],"bugs":{"url":"https://github.com/catalystmediastudios/mongoose-currency/issues"},"license":"MIT","readmeFilename":"README.md","users":{"mgenev":true,"rmateus":true,"jcottam":true,"jonathas":true,"defking":true}}