New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wessberg/typedetector

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wessberg/typedetector

A class that holds a set of predicate methods that detects the native type of the input.

  • 1.0.6
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

TypeDetector NPM version

A class that holds a few simple predicate functions for detecting the native type of input.

Installation

Simply do: npm install @wessberg/typedetector.

Usage

const typeDetector = new TypeDetector();
if (typeDetector.isFunction(something)) {
	// something is typed as a function in here.
	something(arg);
}
const set1 = new Set([1, 2, 3]);
const set2 = new Set([3, 2, 1]);
const set3 = set1;
typeDetector.isEqual(set1, set2); // returns true, their contents are the same.
typeDetector.isEqual(set1, set3); // returns true, by referential equality.

The library only covers a few of the built-in types since instanceof checks covers the rest. But, for things such as strings, numbers and booleans, the predicates will be truthy if their object wrapper types is also used, e.g.:

typeDetector.isNumber(new Number(2)) // returns true

Changelog:

v1.0.6:

  • Made type updates to make TypeDetector compatible with Typescript ^2.4.1.

v1.0.5:

  • Added typedetection for class instances and class constructors. Added new 'getTypeOf' values. Classes no longer has the types 'function' for constructors and 'object' for instances, but rather 'constructor' for constructors and 'class' for class instances.

v1.0.4:

  • Fixed a bug where getTypeOf would not catch null or undefined values.

v1.0.3:

  • Added a getTypeOf method that returns a more appropriate stringified name of the type of the given data.

v1.0.1:

  • A few updates in the README.

v1.0.0:

  • First release. Contains a few methods for things that traditional instanceof checks doesn't cover.

Keywords

FAQs

Package last updated on 28 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc