estimate-calculator
Small library to calculate and compare SLAs' shippingEstimate
Install
$ npm install @vtex/estimate-calculator
Usage
const estimateCalculator = require('@vtex/estimate-calculator')
estimateCalculator.getFastestSla([
{ id: 1, shippingEstimate: '50bd' },
{ id: 2, shippingEstimate: '15bd' },
{ id: 3, shippingEstimate: '100bd' },
])
API
getShippingEstimateQuantity(estimate)
Returns only the shippingEstimate quantity
estimate
Type: String
shippingEstimate of a given SLA
getShippingEstimateUnit(estimate)
Returns only the shippingEstimate unit
estimate
Type: String
shippingEstimate of a given SLA
getShippingEstimateQuantityInSeconds(estimate)
Returns shippingEstimate converted to seconds
estimate
Type: String
shippingEstimate of a given SLA
getLatestSla(slas)
Returns the SLA that will take the most time (i.e: worst-case scenario in a shippingEstimate context)
slas
Type: Array
List of SLAS
getFastestSla(slas)
Returns the SLA that will be fastest one (i.e: best-case scenario in a shippingEstimate context)
slas
Type: Array
List of SLAS
getCheapestSla(slas)
Returns the chepeast SLA
slas
Type: Array
List of SLAS
selectCheapestSlaForAllItems(logisticsInfo)
Returns the chepeast SLA for all items
logisticsInfo
Type: Object
Object that contains all the logistics information of an order
selectFastestSlaForAllItems(logisticsInfo)
Returns the fastest SLA for all items
logisticsInfo
Type: Array
Array that contains all the logistics information of each item of the order
Format of the Array:
[
Examples
estimateCalculator.getShippingEstimateQuantity('10m')
estimateCalculator.getShippingEstimateUnit('10m')
estimateCalculator.getShippingEstimateQuantityInSeconds('10m')
estimateCalculator.getLatestSla([
{ id: 1, shippingEstimate: '50h' },
{ id: 2, shippingEstimate: '15h' },
{ id: 3, shippingEstimate: '100h' },
])
estimateCalculator.getFastestSla([
{ id: 1, shippingEstimate: '50h' },
{ id: 2, shippingEstimate: '15h' },
{ id: 3, shippingEstimate: '100h' },
])
estimateCalculator.getCheapestSla([
{ id: 1, price: 50 },
{ id: 2, price: 15 },
{ id: 3, price: 100 },
])
estimateCalculator.selectCheapestSlaForAllItems(logistiscsInfo)
estimateShipping.selectFastestSlaForAllItems(logisticsInfo)