@ph-itdev/shipping-rate-calc 0.2026.625
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/index.d.ts +2 -0
- package/index.js +35 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @ph-itdev/shipping-rate-calc
|
|
2
|
+
|
|
3
|
+
Calculate shipping rates by weight, dimensions, zone, and carrier with support for domestic and international freight.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ph-itdev/shipping-rate-calc
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { } = require('@ph-itdev/shipping-rate-calc');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
See source code for full API documentation.
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
MIT
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
*Auto-generated by logistics-npm pipeline — 2026-06-25*
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Shipping Rate Calculator
|
|
2
|
+
// Calculate shipping rates by weight, dimensions, zone, and carrier with support for domestic and international freight.
|
|
3
|
+
// Auto-generated by @ph-itdev/logistics-pipeline
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const WEIGHT_BREAKS = [
|
|
7
|
+
{ min: 0, max: 1, rate: 5.99 },
|
|
8
|
+
{ min: 1, max: 5, rate: 8.99 },
|
|
9
|
+
{ min: 5, max: 20, rate: 12.99 },
|
|
10
|
+
{ min: 20, max: 70, rate: 18.99 },
|
|
11
|
+
{ min: 70, max: 150, rate: 28.99 },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const ZONE_MULTIPLIERS = { local: 1.0, regional: 1.3, national: 1.8, international: 3.2 };
|
|
15
|
+
|
|
16
|
+
function getWeightRate(weightLbs) {
|
|
17
|
+
const tier = WEIGHT_BREAKS.find(b => weightLbs >= b.min && weightLbs < b.max);
|
|
18
|
+
if (!tier) throw new Error(`Weight ${weightLbs}lbs exceeds max supported (150lbs)`);
|
|
19
|
+
return tier.rate;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function calculateShipping({ weight, dimensions, zone = 'national', carrier = 'standard' }) {
|
|
23
|
+
if (!weight || weight <= 0) throw new Error('Weight must be positive');
|
|
24
|
+
const { length = 0, width = 0, height = 0 } = dimensions || {};
|
|
25
|
+
const dimensionalWeight = (length * width * height) / 139;
|
|
26
|
+
const billableWeight = Math.max(weight, dimensionalWeight);
|
|
27
|
+
const baseRate = getWeightRate(billableWeight);
|
|
28
|
+
const multiplier = ZONE_MULTIPLIERS[zone] || ZONE_MULTIPLIERS.national;
|
|
29
|
+
const carrierSurcharge = carrier === 'express' ? 1.5 : carrier === 'overnight' ? 2.5 : 1.0;
|
|
30
|
+
const total = +(baseRate * multiplier * carrierSurcharge).toFixed(2);
|
|
31
|
+
return { baseRate, multiplier, carrierSurcharge, billableWeight: +billableWeight.toFixed(1), total };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
module.exports = { calculateShipping, getWeightRate, WEIGHT_BREAKS, ZONE_MULTIPLIERS };
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ph-itdev/shipping-rate-calc",
|
|
3
|
+
"version": "0.2026.0625",
|
|
4
|
+
"description": "Calculate shipping rates by weight, dimensions, zone, and carrier with support for domestic and international freight.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "node test.js",
|
|
10
|
+
"lint": "echo 'lint ok'"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"logistics",
|
|
14
|
+
"automation",
|
|
15
|
+
"shipping",
|
|
16
|
+
"supply-chain",
|
|
17
|
+
"shipping"
|
|
18
|
+
],
|
|
19
|
+
"author": "@ph-itdev",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/nilskie06/shipping-rate-calc.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/nilskie06/shipping-rate-calc#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/nilskie06/shipping-rate-calc/issues"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=14.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|