UNPKG

@tractorzoom/equipment-attributes

Version:

Source of truth for equipment attributes by category

62 lines (61 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAttrText = void 0; const subcategories_1 = require("../subcategories"); const format_1 = require("./format"); const getAttrText = (attr, props) => { const attrName = attr.name; const subcategory = props.subcategory || ''; if (attr.type === 'string') { return props[attrName]; } if (attrName === 'width' && (props.widthFeet || props.widthInches)) { let ft = props.widthFeet; let inches = props.widthInches; if (inches && !ft && ![subcategories_1.TURF, subcategories_1.TILE_PLOW].includes(subcategory)) { ft = inches / 12; inches = 0; } if (ft && inches) { return `${(0, format_1.formatNumberWithThousandSeparator)(ft)}' ${(0, format_1.formatNumberWithThousandSeparator)(inches)}"`; } if (ft) { return `${(0, format_1.formatNumberWithThousandSeparator)(ft)} ft`; } return `${(0, format_1.formatNumberWithThousandSeparator)(inches)} inches`; } if (attrName === 'capacity' && (props.ton || props.gallon || props.bushels)) { const ton = props.ton; const gallon = props.gallon; const bushels = props.bushels; if (ton) { return `${(0, format_1.formatNumberWithThousandSeparator)(ton)} T`; } if (bushels) { return `${(0, format_1.formatNumberWithThousandSeparator)(bushels)} Bu`; } return `${(0, format_1.formatNumberWithThousandSeparator)(gallon)} Gal`; } if (attr.switch || typeof props[attrName] === 'boolean') { if (props[attrName]) { return 'Yes'; } else if (props[attrName] === false) { return 'No'; } else return ''; } // biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation> if (props.hasOwnProperty(attrName)) { const value = props[attrName]; if (attr.shortName) { return `${(0, format_1.formatNumberWithThousandSeparator)(value)} ${attr.shortName}`; } else { return (0, format_1.formatNumberWithThousandSeparator)(value); } } return ''; }; exports.getAttrText = getAttrText;