JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 210
  • Score
    100M100P100Q93296F
  • License ISC

Performs a runtime check that guarantees the type and value of properties in some scopes

Package Exports

  • @xtitusx/type-guard

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@xtitusx/type-guard) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

type-guard

TypeDoc: https://htmlpreview.github.io/?https://raw.githubusercontent.com/xtitusx/type-guard/master/docs/index.html

Simple examples:

const arraySuccess: boolean = TypeGuard.array().hasMinSize(2).contains("foo").guard(['foo', 'bar']).isSuccess();

const booleanSuccess: boolean = TypeGuard.boolean().isTrue().guard(1 > 0).isSuccess();

const classSuccess: boolean = TypeGuard.class().isInstanceOf(Number).guard(new Number(1)).isSuccess();

const dateStringSuccess: boolean = TypeGuard.dateString().isIso8601Date().isSameOrBefore('2016-01-20T00:00:00+02:00').guard('2015-02-28');

const nilSuccess: boolean = TypeGuard.nil().isNil(null).guard(null).isSuccess();

const numberSuccess: boolean = TypeGuard.number().isIn(10, 20).isEven().guard(14).isSuccess();

const stringSuccess: boolean = TypeGuard.string().isAlpha().contains('foo').hasMaxLength(100).isTrimmed('left').guard("Lorem ipsum foo").isSuccess();

Bulk examples:

const guardResult = new GuardResultBulk() .add([ TypeGuard.array().hasMinSize(2).contains("foo").guard(['foo', 'bar'], TypeGuard.string().equals('foo').guard('foo'), TypeGuard.number().isIn(10, 20).isEven().guard(14), ]) .combine();

const guardResult = new GuardResultBulk() .add([ TypeGuard.array().hasMinSize(2).contains("foo").guard(['foo', 'bar'], TypeGuard.string().equals('foo').guard('foo'), TypeGuard.number().isIn(10, 20).isEven().guard(14), ]) .stack();