object-shape-tester - v6.3.3
    Preparing search index...

    Function createCustomShape

    • Easily create a custom shape.

      Type Parameters

      • T

      Parameters

      • __namedParameters: { checkValue: (value: unknown) => value is T; default: T; name: string }

      Returns (defaultValue?: T) => Shape<TUnsafe<T>>

      import {checkValidShape, createCustomShape} from 'object-shape-tester';
      import {UtcIsoString, isValidIsoString} from 'date-vir';

      const utcIsoStringShape = createCustomShape({
      default: new Date().toISOString() as UtcIsoString,
      name: 'UtcIsoString',
      checkValue(value) {
      return isValidIsoString(value);
      },
      });

      const myShape = utcIsoStringShape();

      checkValidShape(new Date().toISOString(), myShape); // `true`
      checkValidShape('', myShape); // `false`