JavaScript turns both Number("") and Number("0") into 0. That conversion can give a shipping widget the wrong message. In a retail policy CSV, the blank can mean no guest threshold was recorded. A zero can represent a published no-minimum policy for qualifying items.
Choose three states before parsing
The row examples are from Coupinify’s U.S. shipping policy table, a snapshot checked on November 18, 2026. The CSV field guest_minimum_usd represents the guest threshold for the shipping terms described in the row.
| Raw cell | Meaning in this dataset | Example |
|---|---|---|
| Blank | No general guest threshold recorded | Gap lists guest rates and separate member thresholds |
0 |
No guest spending minimum under the stated policy | Nordstrom offers free standard shipping on most items |
| Positive amount | Guest minimum from the policy | Target lists $35 for qualifying guest orders |
Keep the input column as text when the CSV reader imports it. Once a parser has coerced the blank to zero, the original distinction is gone.
Read the amount and coupon timing separately
Convert valid dollar strings to integer cents. Store coupon timing as a separate field because a dollar amount cannot tell you which subtotal the retailer tests.
const assert = require("node:assert/strict");
function readGuestMinimum(raw) {
const cell = raw.trim();
if (cell === "") return { kind: "not-listed" };
if (!/^\d+(?:\.\d{1,2})?$/.test(cell)) {
throw new TypeError("Expected a USD amount with up to two decimal places");
}
const [dollars, fraction = ""] = cell.split(".");
const cents = Number(dollars) * 100 + Number(fraction.padEnd(2, "0"));
if (!Number.isSafeInteger(cents)) {
throw new RangeError("USD amount exceeds the safe integer range");
}
return cents === 0 ? { kind: "no-minimum" } : { kind: "minimum", cents };
}
function mapPolicy(row) {
return {
retailer: row.retailer,
guestMinimum: readGuestMinimum(row.guest_minimum_usd),
discountTiming: row.discount_timing
};
}
assert.deepEqual(readGuestMinimum(""), { kind: "not-listed" });
assert.deepEqual(readGuestMinimum("0"), { kind: "no-minimum" });
assert.deepEqual(readGuestMinimum("35"), { kind: "minimum", cents: 3500 });
assert.deepEqual(readGuestMinimum("49.95"), { kind: "minimum", cents: 4995 });
assert.throws(() => readGuestMinimum("$35"), TypeError);
const sephora = mapPolicy({
retailer: "Sephora",
guest_minimum_usd: "50",
discount_timing: "not-stated"
});
assert.deepEqual(sephora, {
retailer: "Sephora",
guestMinimum: { kind: "minimum", cents: 5000 },
discountTiming: "not-stated"
});
console.log("All six checks passed.");
Save the snippet as shipping-policy.cjs and run node shipping-policy.cjs. The checks cover the empty cell, a published zero, a positive threshold, a decimal amount, a malformed amount and the separate timing field.
Carry the uncertainty into the UI
A not-listed amount can display “Check guest shipping rates.” A no-minimum amount can display “No spending minimum for eligible items.” For a positive threshold, display the amount alongside the separately recorded coupon timing.
Sephora illustrates the last case. Its published policy gave the guest minimum in the snapshot. It did not specify whether the calculation runs before or after a promo code. Preserving not-stated lets the widget show the amount while leaving coupon timing open. Keep the row’s shipping method, membership and item exceptions with the result.
AI disclosure. This article was drafted with AI. The policy examples were checked against the dated source, and the code was run in Node.js.
Top comments (0)