This package has been deprecated

Author message:

Use @quenk/noni instead.

@quenk/kindof
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

KindOf

Provides a function that tests whether a value matches a given pattern.

Installation

  npm install --save @quenk/kindof

Usage

kindOf takes two parameters, the first is the value to test and the second the pattern.

  import {kindOf} from '@quenk/kindof';

  class T {
  
    name: 'King T'

  }

  const t = new T();

  if(kindOf(1, 1))
    console.log('yes');

  if(kindOf(1, Number))
    console.log('yes');

  if(kindOf('one', 'one'))
    console.log('yes')

  if(kindOf('one', String))
    console.log('yes')

  if(kindOf(t, T))
    console.log('yes')

  if(kindOf(t, {name:String}))
    console.log('yes')

Description

Currently pattern matches are carried out like this:

Pattern Description Example
string Matches the string exactly. kindOf('somestring', 'somestring')
number Matches the number exactly. kindOf(1, 1)
boolean Matches the boolean literal exactly. kindOf(true, true); kindOf(false, false)
object Treated as a shape, each key is treated as a pattern. kindOf({one:1, two:'two'}, {one:1, two:String})
function Treated as a constructor and results in an instanceof check. kindOf(new Point(), Point)
String Matches any string value. kindOf('foo', String)
Boolean Matches any boolean value. kindOf(false, Boolean)
Number Matches any number value. kindOf(12, Number)
Array Matches an array regardless of content. kindOf([12], Array)

License

Apache-2.0 (c) Quenk Technologies Limited.

Readme

Keywords

Package Sidebar

Install

npm i @quenk/kindof

Weekly Downloads

6

Version

1.2.0

License

Apache-2.0

Unpacked Size

9.4 kB

Total Files

10

Last publish

Collaborators

  • metasansana