1.0.3 • Published 7 months ago

cash-register v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

workflow

cash-register

cash-register is a simple JavaScript module that helps you calculate and break down change owed after a transaction. It is designed with Canadian currency denominations in mind, considering the absence of pennies in Canada.

Installation

You can install cash-register via npm:

npm install cash-register

Usage

Import the module into your JavaScript code:

const { calculateTotalChange, calculateRoundedChange, calculateChangeBreakdown } = require('cash-register');

Calculate Total Change

The calculateTotalChange function calculates the total change by subtracting the total amount due from the total money received.

const totalChange = calculateTotalChange(totalDue, moneyReceived);

Calculate Rounded Change

The calculateRoundedChange function calculates the change by rounding to the nearest 0.05. This is suitable for handling Canadian currency without pennies.

const roundedChange = calculateRoundedChange(totalDue, moneyReceived);

Calculate Change Breakdown

The calculateChangeBreakdown function provides a breakdown of the change, specifying the number of each coin denomination owed as change. This function is suitable for Canadian currency where there are loonies and toonies, but no pennies.

const changeBreakdown = calculateChangeBreakdown(totalDue, moneyReceived);

Example

const { calculateTotalChange, calculateRoundedChange, calculateChangeBreakdown } = require('cash-register');

const totalDue = 10.0;
const moneyReceived = 20.0;

const totalChange = calculateTotalChange(totalDue, moneyReceived);
const roundedChange = calculateRoundedChange(totalDue, moneyReceived);
const changeBreakdown = calculateChangeBreakdown(totalDue, moneyReceived);

console.log(`Total Change: $${totalChange}`);
console.log(`Rounded Change: $${roundedChange}`);
console.log(changeBreakdown);

Output

Total Change: $10.0
Rounded Change: $10.0
You need to dispense 5 toonies.
acornacorn-import-assertionsacorn-jsxajvajv-keywordsansi-escapesansi-regexansi-stylesanymatchargparsebabel-jestbabel-plugin-istanbulbabel-plugin-jest-hoistbabel-preset-current-node-syntaxbabel-preset-jestbalanced-matchbrace-expansionbracesbrowserslistbserbuffer-fromcallsitescamelcasecaniuse-litechalkchar-regexchrome-trace-eventci-infocjs-module-lexercliuiclone-deepcocollect-v8-coveragecolor-convertcolor-namecolorettecommanderconcat-mapconvert-source-mapcross-spawndebugdedentdeep-isdeepmergedetect-newlinediff-sequencesdoctrineelectron-to-chromiumemitteryemoji-regexenhanced-resolveenvinfoerror-exes-module-lexerescaladeescape-string-regexpeslint-scopeeslint-visitor-keysespreeesprimaesqueryesrecurseestraverseesutilseventsexecaexitexpectfast-deep-equalfast-json-stable-stringifyfast-levenshteinfastest-levenshteinfastqfb-watchmanfile-entry-cachefill-rangefind-upflat-cacheflattedfs.realpathfseventsfunction-bindgensyncget-caller-fileget-package-typeget-streamglobglob-parentglob-to-regexpglobalsgraceful-fsgraphemerhashas-flaghtml-escaperhuman-signalsignoreimport-freshimport-localimurmurhashinflightinheritsinterpretis-arrayishis-core-moduleis-extglobis-fullwidth-code-pointis-generator-fnis-globis-numberis-path-insideis-plain-objectis-streamisexeisobjectistanbul-lib-coverageistanbul-lib-instrumentistanbul-lib-reportistanbul-lib-source-mapsistanbul-reportsjest-changed-filesjest-circusjest-clijest-configjest-diffjest-docblockjest-eachjest-environment-nodejest-get-typejest-haste-mapjest-leak-detectorjest-matcher-utilsjest-message-utiljest-mockjest-pnp-resolverjest-regex-utiljest-resolvejest-resolve-dependenciesjest-runnerjest-runtimejest-snapshotjest-utiljest-validatejest-watcherjest-workerjs-tokensjs-yamljsescjson-bufferjson-parse-even-better-errorsjson-schema-traversejson-stable-stringify-without-jsonifyjson5keyvkind-ofkleurlevenlevnlines-and-columnsloader-runnerlocate-pathlodash.mergelru-cachemake-dirmakeerrormerge-streammicromatchmime-dbmime-typesmimic-fnminimatchmsnatural-compareneo-asyncnode-int64node-releasesnormalize-pathnpm-run-pathonceonetimeoptionatorp-limitp-locatep-tryparent-moduleparse-jsonpath-existspath-is-absolutepath-keypath-parsepicocolorspicomatchpiratespkg-dirprelude-lspretty-formatpromptspunycodepure-randqueue-microtaskrandombytesreact-isrechoirrequire-directoryresolveresolve-cwdresolve-fromresolve.exportsreusifyrimrafrun-parallelsafe-bufferschema-utilssemverserialize-javascriptshallow-cloneshebang-commandshebang-regexsignal-exitsisteransislashsource-mapsource-map-supportsprintf-jsstack-utilsstring-lengthstring-widthstrip-ansistrip-bomstrip-final-newlinestrip-json-commentssupports-colorsupports-preserve-symlinks-flagtapableterserterser-webpack-plugintest-excludetext-tabletmplto-fast-propertiesto-regex-rangetype-checktype-detecttype-festupdate-browserslist-dburi-jsv8-to-istanbulwalkerwatchpackwebpack-mergewebpack-sourceswhichwildcardwrap-ansiwrappywrite-file-atomicy18nyallistyargsyargs-parseryocto-queue
1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago