@jetta/item-amount-controller
v0.1.0-0
Published
Tracks and decrements grouped item quantities
Keywords
Readme
@jetta/item-amount-controller
JavaScript library that groups item quantities by id and decrements them during allocation.
Requirements
- Node.js 24+
- npm
How to install
npm ci
npm run buildConsumers install the published package:
npm install @jetta/item-amount-controllerUsage
import { Item_Amount_Controller } from '@jetta/item-amount-controller'
const controller = new Item_Amount_Controller([
{ _id: 'box', get_amount: () => 2, get_id: () => 'box' }
])
controller.discount_single_item({ _id: 'box' })CommonJS:
const { Item_Amount_Controller } = require('@jetta/item-amount-controller')The default key is item._id when it is present, otherwise item.get_id(). Pass a second constructor argument to group by another key. copy() clones the amount map and then uses the default key.
Dependencies
No runtime dependencies.
Scripts
| Command | Description |
|---------|-------------|
| npm test | Mocha tests |
| npm run lint | ESLint |
| npm run build | Emit ESM and CommonJS to build/ and check both entries |
| npm run coverage | Tests with 80% coverage gate (local) |
| npm run coverage:ci | Tests with 75% coverage gate (CI) |
| npm run lint:package | publint strict check |
Layout
src/index.js— public exportssrc/Item_Amount_Controller.js— amount ledgersrc/exceptions/— unknown id and insufficient amounttest/src/— mirrorssrc/
