0.0.6 • Published 5 years ago

is-equal-type v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

is-equal-type

build status npm version

A module to deeply compare two values of an argument to evaluate if they are of the same type.

Why use?

  • You can easily verify that the JSON data you're getting from fetch API, for example, is really what you're expecting.
  • By predefining the data you expect, you can clarify the specification like a document.

Installation

You can install the package from npm.

npm install is-equal-type

Usage

General

You can verify the values as follows.

NOTE: Only one value (type) can be specified in an array.

import isEqualType from "is-equal-type";

const successData = {
  status: 200,
  data: {
    message: "hello world",
    favorites: ["ts", "js", "react"],
  },
};

const failureData = {
  status: 200,
  data: {},
};

const expect = {
  status: 0,
  data: {
    message: "",
    favorites: [""],
  },
};

console.log(isEqualType(successData, expect));
// => true

console.log(isEqualType(failureData, expect));
// => false

Any type

You can specify 'any' if you don't know what value to expect, or if you want to allow for more than one type.

Also, you can change the character that represents type any by specifying the 'anyType' option.

import isEqualType from "is-equal-type";

const successData = {
  status: 200,
  data: {
    message: "hello world",
    favorites: ["ts", "js", "react"],
  },
};

const expect = {
  status: 0,
  data: "any",
};

console.log(isEqualType(successData, expect));
// => true

Options

The following options can be set.

PropertyTypeDefaultDescription
deepboolean | undefinedtrueDeeply compare objects and arrays.
anyTypestring | undefined'any'Treats the specified string as type any.
strictKeyChecksboolean | undefinedtrueCheck that the keys of the dictionary are the same.

Support Type

This module can compare the following types.

  • Boolean
  • Null
  • Undefined
  • BigInt
  • String
  • Symbol
  • Object(dictionary, array)

License

MIT © kqito

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago