Skip to content

EmptyStringToNullPipe

NestJS pipe for request body string normalization.

ts
import { EmptyStringToNullPipe } from '@querry-kit/nest-util';

Constructor

EmptyStringToNullPipe does not require constructor arguments.

ts
const pipe = new EmptyStringToNullPipe();

transform(value, metadata)

Transforms value only when metadata.type === 'body'.

For body values, the pipe recursively:

  • trims non-empty strings
  • converts empty or whitespace-only strings to null
  • preserves non-string primitive values
  • normalizes nested objects and arrays
ts
const pipe = new EmptyStringToNullPipe();

pipe.transform({ name: '  Ada  ', note: '' }, { type: 'body' } as never);

// { name: 'Ada', note: null }

Query parameters, route parameters, and other metadata types are returned unchanged.

Released under the MIT License.