{"id":21835837,"url":"https://github.com/vtex/estimate-calculator","last_synced_at":"2025-04-14T09:15:26.095Z","repository":{"id":52142009,"uuid":"122253231","full_name":"vtex/estimate-calculator","owner":"vtex","description":"Small library to calculate and compare SLAs' shippingEstimate","archived":false,"fork":false,"pushed_at":"2023-07-11T13:32:43.000Z","size":1144,"stargazers_count":3,"open_issues_count":8,"forks_count":2,"subscribers_count":146,"default_branch":"master","last_synced_at":"2025-04-14T09:14:53.581Z","etag":null,"topics":["srv-checkout-ui","xp-shopping"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vtex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-20T20:38:20.000Z","updated_at":"2020-08-25T14:22:53.000Z","dependencies_parsed_at":"2024-11-27T20:38:20.493Z","dependency_job_id":null,"html_url":"https://github.com/vtex/estimate-calculator","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Festimate-calculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Festimate-calculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Festimate-calculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Festimate-calculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vtex","download_url":"https://codeload.github.com/vtex/estimate-calculator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248852184,"owners_count":21171842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["srv-checkout-ui","xp-shopping"],"created_at":"2024-11-27T20:25:15.615Z","updated_at":"2025-04-14T09:15:26.062Z","avatar_url":"https://github.com/vtex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# estimate-calculator\n\n\u003e Small library to calculate and compare SLAs' shippingEstimate\n\n## Install\n\n```sh\n$ npm install @vtex/estimate-calculator\n```\n\n## Usage\n\n```js\nconst estimateCalculator = require('@vtex/estimate-calculator')\n\nestimateCalculator.getFastestSla([\n        { id: 1, shippingEstimate: '50bd' },\n        { id: 2, shippingEstimate: '15bd' },\n        { id: 3, shippingEstimate: '100bd' },\n])\n// { id: 2, shippingEstimate: '15bd' }\n\n```\n## API\n\n### getShippingEstimateQuantity(estimate)\n\nReturns only the shippingEstimate quantity\n\n#### estimate\n\nType: `String`\n\nshippingEstimate of a given SLA\n\n### getShippingEstimateUnit(estimate)\n\nReturns only the shippingEstimate unit\n\n#### estimate\n\nType: `String`\n\nshippingEstimate of a given SLA\n\n### getShippingEstimateQuantityInSeconds(estimate)\n\nReturns shippingEstimate converted to seconds\n\n#### estimate\n\nType: `String`\n\nshippingEstimate of a given SLA\n\n### getLatestSla(slas)\n\nReturns the SLA that will take the most time (i.e: worst-case scenario in a shippingEstimate context)\n\n#### slas\n\nType: `Array`\n\nList of SLAS\n\n### getFastestSla(slas)\n\nReturns the SLA that will be fastest one (i.e: best-case scenario in a shippingEstimate context)\n\n#### slas\n\nType: `Array`\n\nList of SLAS\n\n### getCheapestSla(slas)\n\nReturns the chepeast SLA\n\n#### slas\n\nType: `Array`\n\nList of SLAS\n\n### selectCheapestSlaForAllItems(logisticsInfo)\n\nReturns the chepeast SLA for all items\n\n#### logisticsInfo\n\nType: `Object`\n\nObject that contains all the logistics information of an order\n\n### selectFastestSlaForAllItems(logisticsInfo)\n\nReturns the fastest SLA for all items\n\n#### logisticsInfo\n\nType: `Array`\n\nArray that contains all the logistics information of each item of the order\n\nFormat of the Array:\n```js\n[\n//   {\n//     itemIndex: 0,\n//     selectedSla: '',\n//     selectedDeliveryChannel: '',\n//     addressId: '62e1db5500824a66bcef708d09388a8e',\n//     slas: [\n//       {\n//         id: 'Normal',\n//         deliveryChannel: 'delivery',\n//         name: 'Normal',\n//         deliveryIds: [Object],\n//         shippingEstimate: '16bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 334,\n//         listPrice: 334,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//       {\n//         id: 'Expressa',\n//         deliveryChannel: 'delivery',\n//         name: 'Expressa',\n//         deliveryIds: [Object],\n//         shippingEstimate: '1bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 6666,\n//         listPrice: 6666,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//     ],\n//     shipsTo: ['BRA'],\n//     itemId: '100006784',\n//     deliveryChannels: [{ id: 'delivery' }, { id: 'pickup-in-point' }],\n//   },\n//   {\n//     itemIndex: 1,\n//     selectedSla: '',\n//     selectedDeliveryChannel: '',\n//     addressId: '62e1db5500824a66bcef708d09388a8e',\n//     slas: [\n//       {\n//         id: 'Normal',\n//         deliveryChannel: 'delivery',\n//         name: 'Normal',\n//         deliveryIds: [\n//           {\n//             courierId: '1',\n//             warehouseId: '1afe1cf',\n//             dockId: '1b91c3b',\n//             courierName: 'Courrier e-commerce',\n//             quantity: 1,\n//           },\n//         ],\n//         shippingEstimate: '16bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 333,\n//         listPrice: 333,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//       {\n//         id: 'Expressa',\n//         deliveryChannel: 'delivery',\n//         name: 'Expressa',\n//         deliveryIds: [Object],\n//         shippingEstimate: '1bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 6667,\n//         listPrice: 6667,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//     ],\n//     shipsTo: ['BRA'],\n//     itemId: '100006786',\n//     deliveryChannels: [{ id: 'delivery' }, { id: 'pickup-in-point' }],\n//   },\n//   {\n//     itemIndex: 2,\n//     selectedSla: '',\n//     selectedDeliveryChannel: '',\n//     addressId: '62e1db5500824a66bcef708d09388a8e',\n//     slas: [\n//       {\n//         id: 'Normal',\n//         deliveryChannel: 'delivery',\n//         name: 'Normal',\n//         deliveryIds: [Object],\n//         shippingEstimate: '16bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 333,\n//         listPrice: 333,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//       {\n//         id: 'Expressa',\n//         deliveryChannel: 'delivery',\n//         name: 'Expressa',\n//         deliveryIds: [Object],\n//         shippingEstimate: '1bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 6667,\n//         listPrice: 6667,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//     ],\n//     shipsTo: ['BRA'],\n//     itemId: '100006785',\n//     deliveryChannels: [{ id: 'delivery' }, { id: 'pickup-in-point' }],\n//   },\n// ]\n```\n#### Examples\n\n```js\n\nestimateCalculator.getShippingEstimateQuantity('10m')\n// 10\n\nestimateCalculator.getShippingEstimateUnit('10m')\n// m\n\nestimateCalculator.getShippingEstimateQuantityInSeconds('10m')\n// 600\n\nestimateCalculator.getLatestSla([\n  { id: 1, shippingEstimate: '50h' },\n  { id: 2, shippingEstimate: '15h' },\n  { id: 3, shippingEstimate: '100h' },\n])\n// { id: 3, shippingEstimate: '100h' }        \n\nestimateCalculator.getFastestSla([\n  { id: 1, shippingEstimate: '50h' },\n  { id: 2, shippingEstimate: '15h' },\n  { id: 3, shippingEstimate: '100h' },\n])\n // { id: 2, shippingEstimate: '15h' }\n\nestimateCalculator.getCheapestSla([\n  { id: 1, price: 50 },\n  { id: 2, price: 15 },\n  { id: 3, price: 100 },\n])\n// { id: 2, price: 15 }  \n\nestimateCalculator.selectCheapestSlaForAllItems(logistiscsInfo)\n\n// [\n//   {\n//     selectedSla: '',\n//     selectedDeliveryChannel: '',\n//     itemIndex: 0,\n//     addressId: '62e1db5500824a66bcef708d09388a8e',\n//     slas: [\n//       {\n//         id: 'Normal',\n//         deliveryChannel: 'delivery',\n//         name: 'Normal',\n//         deliveryIds: [[Object]],\n//         shippingEstimate: '16bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 334,\n//         listPrice: 334,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//       {\n//         id: 'Expressa',\n//         deliveryChannel: 'delivery',\n//         name: 'Expressa',\n//         deliveryIds: [[Object]],\n//         shippingEstimate: '2d',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 6666,\n//         listPrice: 6666,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//     ],\n//     shipsTo: ['BRA'],\n//     itemId: '100006784',\n//     deliveryChannels: [[Object], [Object]],\n//   },\n//   {\n//     selectedSla: '',\n//     selectedDeliveryChannel: '',\n//     itemIndex: 1,\n//     addressId: '62e1db5500824a66bcef708d09388a8e',\n//     slas: [\n//       {\n//         id: 'Normal',\n//         deliveryChannel: 'delivery',\n//         name: 'Normal',\n//         deliveryIds: [[Object]],\n//         shippingEstimate: '16bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 333,\n//         listPrice: 333,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//       {\n//         id: 'Expressa',\n//         deliveryChannel: 'delivery',\n//         name: 'Expressa',\n//         deliveryIds: [[Object]],\n//         shippingEstimate: '2d',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 6667,\n//         listPrice: 6667,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//     ],\n//     shipsTo: ['BRA'],\n//     itemId: '100006786',\n//     deliveryChannels: [{ id: 'delivery' }, { id: 'pickup-in-point' }],\n//   },\n//   {\n//     selectedSla: '',\n//     selectedDeliveryChannel: '',\n//     itemIndex: 2,\n//     addressId: '62e1db5500824a66bcef708d09388a8e',\n//     slas: [\n//       {\n//         id: 'Normal',\n//         deliveryChannel: 'delivery',\n//         name: 'Normal',\n//         deliveryIds: [[Object]],\n//         shippingEstimate: '16bd',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 333,\n//         listPrice: 333,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//       {\n//         id: 'Expressa',\n//         deliveryChannel: 'delivery',\n//         name: 'Expressa',\n//         deliveryIds: [[Object]],\n//         shippingEstimate: '2d',\n//         shippingEstimateDate: null,\n//         lockTTL: null,\n//         availableDeliveryWindows: [],\n//         deliveryWindow: null,\n//         price: 6667,\n//         listPrice: 6667,\n//         tax: 0,\n//         pickupStoreInfo: {\n//           isPickupStore: false,\n//           friendlyName: null,\n//           address: null,\n//           additionalInfo: null,\n//           dockId: null,\n//         },\n//       },\n//     ],\n//     shipsTo: ['BRA'],\n//     itemId: '100006785',\n//     deliveryChannels: [{ id: 'delivery' }, { id: 'pickup-in-point' }],\n//   },\n// ]\n\nestimateShipping.selectFastestSlaForAllItems(logisticsInfo)\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtex%2Festimate-calculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvtex%2Festimate-calculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtex%2Festimate-calculator/lists"}