API reference › @evolu/common › Type › maxSize

function maxSize<Max extends number>(
  max: ValidateBrandFactoryCount<Max>,
): BrandFactory<`MaxSize${Max}`, ValueWithSize, MaxSizeError<Max>>;

Defined in: packages/common/src/Type.ts:14728

Maximum-size Brand for values whose size is at most max.

Applies to the same values as minSize. For a Blob or File, such as an upload, it limits the byte count; instanceOf(Blob) also accepts a File. The size is checked after the parent has validated every element or entry, so it does not limit the validation work for a large Set or Map.

Example

import {
  assertEqual,
  assertErr,
  assertTrue,
  instanceOf,
  maxSize,
} from "@evolu/common";

const Upload = maxSize(1_048_576)(instanceOf(Blob));

assertTrue(Upload.is(new Blob(["Hello"])));

const invalid = Upload.fromUnknown(new Blob([new Uint8Array(1_048_577)]));
assertErr(invalid);
assertEqual(
  Upload.formatError(invalid.error),
  "The size 1048577 exceeds the maximum size of 1048576.",
);