Bookmark this: tool.io/cost/printing/source-code
Printing Cost Calculator Source Code
Browse the implementation files for Printing Cost Calculator.tool.ts typescript
import {
CURRENCY_OPTIONS,
formatCostSummary,
formatMoney,
parseCurrency,
parseNonnegative,
parsePositive
} from '../calculation';
import { calculatePrintingCost } from '@tool.io/tools/cost/printing';
export const printingCost = (
currencyInput: unknown,
pagesInput: unknown,
copiesInput: unknown,
inkPerPageInput: unknown,
paperPerPageInput: unknown,
setupInput: unknown
): string => {
const currency = parseCurrency(currencyInput);
const pages = parseNonnegative(pagesInput);
const copies = parsePositive(copiesInput);
const ink = parseNonnegative(inkPerPageInput);
const paper = parseNonnegative(paperPerPageInput);
const setup = parseNonnegative(setupInput);
if (
!currency ||
pages === null ||
copies === null ||
ink === null ||
paper === null ||
setup === null ||
!Number.isInteger(pages) ||
!Number.isInteger(copies)
)
return '';
const result = calculatePrintingCost(
pages,
copies,
ink,
paper,
setup,
currency
);
if (!result) return '';
return formatCostSummary([
['Printed pages', result.printedPages.toLocaleString('en-US')],
['Ink and paper', formatMoney(result.variableCost, currency)],
['Setup cost', formatMoney(result.setupCost, currency)],
['Total cost', formatMoney(result.totalCost, currency)],
['Cost per copy', formatMoney(result.costPerCopy, currency)]
]);
};
export const Tool: TypeTool = {
name: 'Printing Cost Calculator',
slug: 'cost/printing',
intro:
'Estimate ink, paper, setup, total, and per-copy printing costs.',
tool: printingCost,
i: [
{
example: 'USD',
label: 'Currency',
options: CURRENCY_OPTIONS,
placeholder: 'Select currency',
type: 'select'
},
{
example: '20',
label: 'Pages per Copy',
placeholder: 'Pages in one copy',
type: 'number'
},
{
example: '10',
label: 'Copies',
placeholder: 'Number of copies',
type: 'number'
},
{
example: '0.08',
label: 'Ink Cost per Page',
placeholder: 'Ink or toner cost',
type: 'number'
},
{
example: '0.02',
label: 'Paper Cost per Page',
placeholder: 'Paper cost',
type: 'number'
},
{
example: '5',
label: 'Setup Cost',
placeholder: 'One-time setup cost',
type: 'number'
}
],
o: [
{
example:
'Printed pages: 200\nInk and paper: $20.00\nSetup cost: $5.00\nTotal cost: $25.00\nCost per copy: $2.50',
label: 'Printing Cost',
placeholder: 'Printing costs will appear here...',
render: 'textarea',
type: 'text'
}
],
cite: [
{
title: 'Printing - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Printing'
}
]
};
export default Tool;
Description
Browse the implementation files for Printing Cost Calculator.