Skip to main content

normalize

Applies a named or custom normalizer to selected top-level fields.

normalize({
createdAt: 'isoDate',
balance: 'number',
verified: 'boolean',
total: 'currency:USD',
})(input);

Built-in normalizers

SpecAccepted valuesOutput
isoDateDate, date string, timestampISO string or null
numberFinite number or numeric value accepted by Number()number or null
booleanbooleans, 1/0, and case-insensitive true, false, yes, no, '1', '0'boolean or null
currency:USDFinite number or numeric valuelocale-formatted string or null

Null, undefined, the empty string, and invalid built-in inputs normalize to null. Currency formatting uses the runtime's default locale, so exact punctuation and symbol placement can vary between environments. The currency code must be supported by Intl.NumberFormat.

currency:CODE is a convenience, not a localization layer. When locale or user preferences matter, normalize to a number and format it in presentation code. See Scope and non-goals.

Custom normalizers

A callback receives the current field value and its key:

const transform = normalize({
username: (value, key) =>
typeof value === 'string' ? value.trim().toLowerCase() : null,
});

Custom callbacks control their own fallback and error behavior. They also run for a configured key that is absent from the input, receiving undefined.

Normalization is shallow and does not mutate the input. Callbacks are intended for transport-specific field conversion; validation, localization, and business rules remain outside ShapeWire's documented scope.

See Failure behavior for invalid values, unsupported currencies, missing fields, and callback errors.