When publishing a function/snippet, explicitly define the API contract: (1) platform/runtime assumptions, (2) input shape and required types, (3) option defaults/behavior, and (4) output/return type consistency. Ensure examples and docs match the contract.
Apply as a checklist
opts parameter, document required fields and defaults (e.g., what happens when omitted).[] over -1 when your return is otherwise an array).Example: consistent return type
// Prefer: always return an array
const indexOfAll = (arr, val) => {
const indices = [];
arr.forEach((el, i) => {
if (el === val) indices.push(i);
});
return indices; // [] when not found
};