Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@fantasticfiasco/expect

FantasticFiasco646Apache-2.01.1.0TypeScript support: included

A Node.js library written in TypeScript providing argument validation.

expect, argument, validation

readme

@fantasticfiasco/expect

Build Status Coverage Status npm version SemVer compatible

A Node.js library written in TypeScript providing argument validation.

Table of contents

Super simple to use

import * as expect from '@fantasticfiasco/expect';

function update(person) {
    expect.toExist(person.name);
    expect.toBeTrue(person.age >= 0, 'existential theories are not up for discussion');

    // Squint your eyes and imagine your code here...
}

Installation

npm install @fantasticfiasco/expect
# or
yarn add @fantasticfiasco/expect

API

toBeTrue(condition[, errorMessage])

  • condition: boolean The condition expected to be true
  • errorMessage: string The optional error message displayed if expectation fails

Expect a condition to be true.

toBeFalse(condition[, errorMessage])

  • condition: boolean The condition expected to be false
  • errorMessage: string The optional error message displayed if expectation fails

Expect a condition to be false.

toExist<T>(value[, errorMessage])

  • value: T The value expected to exist
  • errorMessage: string The optional error message displayed if expectation fails

Expect a value to exist.

toNotExist<T>(value[, errorMessage])

  • value: T The value expected not to exist
  • errorMessage: string The optional error message displayed if expectation fails

Expect a value not to exist.

toBeAlphanumeric(value[, errorMessage])

  • value: string The value expected to be alphanumeric
  • errorMessage: string The optional error message displayed if expectation fails

Expect a value to be alphanumeric.

toBeCharCodes(value, minCharCode, maxCharCode[, errorMessage])

  • value: string The value expected to have characters from a range of character codes
  • minCharCode: number The expected minimum character code
  • maxCharCode: number The expected maximum character code
  • errorMessage: string The optional error message displayed if expectation fails

Expect a value to only contain characters from a range of character codes.

Credit

Thank you JetBrains for your important initiative to support the open source community with free licenses to your products.

JetBrains

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

[1.1.0] - 2021-02-14

:zap: Added

  • toBeEmail - Expect a value to be an email (contributed by @alandev2)

[1.0.4] - 2019-12-27

:policeman: Security

  • Security vulnerability in transient dependency handlebars

[1.0.3] - 2019-07-14

:policeman: Security

  • Security vulnerability in transient dependency diff
  • Security vulnerability in transient dependency lodash

[1.0.2] - 2017-06-07

:policeman: Security

  • Security vulnerability in transient dependency handlebars
  • Security vulnerability in transient dependency js-yaml

[1.0.1] - 2017-04-10

:policeman: Security

  • Security vulnerability in transient dependency sshpk

[1.0.0] - 2017-06-22

:zap: Added

  • toBeTrue - Expect a condition to be true
  • toBeFalse - Expect a condition to be false
  • toExist - Expect a value to exist
  • toNotExist - Expect a value not to exist
  • toBeAlphanumeric - Expect a value to be alphanumeric
  • toBeCharCodes - Expect a value to only contain characters from a range of character codes