@fye/carrier-tracking-links
Advanced tools
Comparing version 1.0.0 to 1.1.0
36
index.js
@@ -50,9 +50,37 @@ /* | ||
function getTrackingLink(rawTrackingNumber) { | ||
function formatCarrier(carrier) { | ||
const parts = carrier | ||
.replace(/-/gi, ' ') | ||
.trim() | ||
.split(' '); | ||
if (parts.length) { | ||
let name = (parts[0] || '').trim(); | ||
if (name.toUpperCase() === 'FEDEXSP') { | ||
// treat smart post as fedex | ||
name = 'FedEx'; | ||
} | ||
return name; | ||
} | ||
return carrier; | ||
} | ||
function getTrackingLink(rawTrackingNumber, carrier) { | ||
// remove spaces from the tracking number | ||
const trackingNumber = (rawTrackingNumber || '').replace(/\s/gi, ''); | ||
const matched = CARRIER_REGEX_CACHE.find(cache => { | ||
return cache.reg.test(trackingNumber); | ||
}); | ||
let matched; | ||
if (carrier) { | ||
const formattedCarrier = formatCarrier(carrier).toLowerCase(); | ||
matched = CARRIERS.find(cache => { | ||
return cache.name.toLowerCase() === formattedCarrier; | ||
}); | ||
} else { | ||
matched = CARRIER_REGEX_CACHE.find(cache => { | ||
return cache.reg.test(trackingNumber); | ||
}); | ||
} | ||
if (!matched) { | ||
@@ -59,0 +87,0 @@ return null; |
{ | ||
"name": "@fye/carrier-tracking-links", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Return Carrier Name and Link for a Tracking Number", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "a1456d3f533fd7b64d4ab3270c62a0fae66e95eb" | ||
"gitHead": "ed3426ab9e2882a19cc3b4694131fa308e80ce52" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2938
79