npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

is-any-type

v0.0.4

Published

is-any-type simple functionality alternative to check data type references such as typeof and instanceof

Downloads

3,929

Readme

Is Any Type

Build Status Coverage Status npm version node-current npm npm bundle size npm bundle size Snyk Vulnerabilities for GitHub Repo PRs Welcome

is-any-type simple functionality alternative to check data type references such as typeof and instanceof, this can be used anywhere such as typeof and instanceof, for documentation under v4 check here.

Installation

npm install is-any-type -S or yarn add is-any-type -S

Example Usage

  • Example Usage Using CommonJS Module

    const { assert } = require('is-any-type')
    
    let isString = assert.isString('hello wordl') // => true
    let isNumber = assert.isNumber(new Date().getFullYear) // => true
    let isNull = assert.isNull(null) // => true
    let isUndefined = assert.isUndefined(undefined) // => true
    let isObject = assert.isObject({}) // => true
    let isArray = assert.isArray([]) // => true
    let isFunction = assert.isFunction(() => {}) // => true
    let isPromise = assert.isPromise(new Promise((resolve) => resolve('hello wordl'))) // => true
    let isBuffer = assert.isBuffer(Buffer.from('hello world')) // => true
    let isBoolean = assert.isBoolean(true) // => true
    
    let isString = assert.isString(2021) // => false
    let isNumber = assert.isNumber('hello world') // => false
    let isNull = assert.isNull(undefined) // => false
    let isUndefined = isType(null) // => false
    let isObject = assert.isObject([]) // => false
    let isArray = assert.isArray({}) // => false
    let isFunction = assert.isFunction(Promise.resolve('hello world')) // => false
    let isPromise = assert.isPromise(() => 'hello world') // => false
    let isBuffer = assert.isBuffer('hello world') // => false
    let isBoolean = assert.isBoolean(null) // => false
    
    let isStringCompare = assert.isStringCompare('hello wordl', 'hello wordl') // => true
    let isNumberCompare = assert.isNumberCompare(new Date().getFullYear, new Date().getFullYear) // => true
    let isNullCompare = assert.isNullCompare(null, null) // => true
    let isUndefinedCompare = assert.isUndefinedCompare(undefined, undefined) // => true
    let isObjectCompare = assert.isObjectCompare({}, {}) // => true
    let isArrayCompare = assert.isArrayCompare([], []) // => true
    let isFunctionCompare = assert.isFunctionCompare(() => {}, Function) // => true
    let isPromiseCompare = assert.isPromiseCompare(Promise.resolve('hello world'), Promise.resolve('hello world')) // => true
    let isBufferCompare = assert.isBufferCompare(Buffer.from('hello world'), Buffer.from('hello world')) // => true
    let isBooleanCompare = assert.isBooleanCompare(true, false) // => true
    
    let isStringCompare = assert.isStringCompare('hello wordl', 2021) // => false
    let isNumberCompare = assert.isNumberCompare(new Date().getFullYear, 'hello wordl') // => false
    let isNullCompare = assert.isNullCompare(null, true) // => false
    let isUndefinedCompare = assert.isUndefinedCompare(undefined, null) // => false
    let isObjectCompare = assert.isObjectCompare({}, []) // => false
    let isArrayCompare = assert.isArrayCompare([], {}) // => false
    let isFunctionCompare = assert.isFunctionCompare(() => {}, Promise) // => false
    let isPromiseCompare = assert.isPromiseCompare(Promise.resolve('hello world'), Promise.resolve('hello world')) // => false
    let isBufferCompare = assert.isBufferCompare(Buffer.from('hello world'), Promise.resolve('hello wordl')) // => false
    let isBooleanCompare = assert.isBooleanCompare(true, 2021) // => false
  • Example Usage Using ESM Module

    import { assert } from 'is-any-type'
    
    let isString = assert.isString('hello wordl') // => true
    let isNumber = assert.isNumber(new Date().getFullYear) // => true
    let isNull = assert.isNull(null) // => true
    let isUndefined = assert.isUndefined(undefined) // => true
    let isObject = assert.isObject({}) // => true
    let isArray = assert.isArray([]) // => true
    let isFunction = assert.isFunction(() => {}) // => true
    let isPromise = assert.isPromise(new Promise((resolve) => resolve('hello wordl'))) // => true
    let isBuffer = assert.isBuffer(Buffer.from('hello world')) // => true
    let isBoolean = assert.isBoolean(true) // => true
    
    let isString = assert.isString(2021) // => false
    let isNumber = assert.isNumber('hello world') // => false
    let isNull = assert.isNull(undefined) // => false
    let isUndefined = isType(null) // => false
    let isObject = assert.isObject([]) // => false
    let isArray = assert.isArray({}) // => false
    let isFunction = assert.isFunction(Promise.resolve('hello world')) // => false
    let isPromise = assert.isPromise(() => 'hello world') // => false
    let isBuffer = assert.isBuffer('hello world') // => false
    let isBoolean = assert.isBoolean(null) // => false
    
    let isStringCompare = assert.isStringCompare('hello wordl', 'hello wordl') // => true
    let isNumberCompare = assert.isNumberCompare(new Date().getFullYear, new Date().getFullYear) // => true
    let isNullCompare = assert.isNullCompare(null, null) // => true
    let isUndefinedCompare = assert.isUndefinedCompare(undefined, undefined) // => true
    let isObjectCompare = assert.isObjectCompare({}, {}) // => true
    let isArrayCompare = assert.isArrayCompare([], []) // => true
    let isFunctionCompare = assert.isFunctionCompare(() => {}, Function) // => true
    let isPromiseCompare = assert.isPromiseCompare(Promise.resolve('hello world'), Promise.resolve('hello world')) // => true
    let isBufferCompare = assert.isBufferCompare(Buffer.from('hello world'), Buffer.from('hello world')) // => true
    let isBooleanCompare = assert.isBooleanCompare(true, false) // => true
    
    let isStringCompare = assert.isStringCompare('hello wordl', 2021) // => false
    let isNumberCompare = assert.isNumberCompare(new Date().getFullYear, 'hello wordl') // => false
    let isNullCompare = assert.isNullCompare(null, true) // => false
    let isUndefinedCompare = assert.isUndefinedCompare(undefined, null) // => false
    let isObjectCompare = assert.isObjectCompare({}, []) // => false
    let isArrayCompare = assert.isArrayCompare([], {}) // => false
    let isFunctionCompare = assert.isFunctionCompare(() => {}, Promise) // => false
    let isPromiseCompare = assert.isPromiseCompare(Promise.resolve('hello world'), Promise.resolve('hello world')) // => false
    let isBufferCompare = assert.isBufferCompare(Buffer.from('hello world'), Promise.resolve('hello wordl')) // => false
    let isBooleanCompare = assert.isBooleanCompare(true, 2021) // => false
  • Example Usage Using CommonJS Module With Jest

const { assert } = require('is-any-type')

describe('Is Any Type Group Testing', () => {

  test('Should be value is string', () => {
    const type = assert.isString('hello wordl')
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be string match value from string', () => {
    const type = assert.isStringCompare('hello wordl', 'hello wordl')
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is number', () => {
    const type = assert.isNumber(2021)
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be number match value from number', () => {
    const type = assert.isNumberCompare(2021, 2021)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is object', () => {
    const type1 = assert.isObject({ name: 'john doe' })
    const type2 = assert.isObject({})
    
    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be object match value from object', () => {
    const type1 = assert.isObjectCompare({ name: 'john doe' }, { name: 'john doe' })
    const type2 = assert.isObjectCompare({}, {})

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be value is array', () => {
    const type1 = assert.isArray([1, 2, 3, 4, 5])
    const type2 = assert.isArray([])
    
    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be array match value from array', () => {
    const type1 = assert.isArrayCompare([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])
    const type2 = assert.isArrayCompare([], [])

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be value is function', () => {
    const type = assert.isFunction(() => 'hello wordl')

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be function match value from function', () => {
    const type = assert.isFunctionCompare(() => 'hello wordl', () => 'hello wordl 2')

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })


  test('Should be value is promise', () => {
    const promise = async () => 'hello wordl'

    const type1 = assert.isPromise(Promise.resolve('hello wordl'))
    const type2 = assert.isPromise(new Promise((resolve, reject) => resolve('hello wordl')))
    const type3 = assert.isPromise(promise())

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()
    expect(type3).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
    expect(type3).toBeTruthy()
  })

  test('Should be promise match value from promise', () => {
    const promise = async () => 'hello wordl'

    const type1 = assert.isPromiseCompare(Promise.resolve('hello wordl'), Promise.resolve('hello wordl'))
    const type2 = assert.isPromiseCompare(new Promise((resolve, reject) => resolve('hello wordl')), promise())
    const type3 = assert.isPromiseCompare(promise(), Promise.resolve('hello wordl'))

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()
    expect(type3).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
    expect(type3).toBeTruthy()
  })


  test('Should be value is buffer', () => {
    const type = assert.isBuffer(Buffer.from('hello wordl'))

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be buffer match value from buffer', () => {
    const type = assert.isBufferCompare(Buffer.from('hello wordl'), Buffer.from('hello john'))

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is null', () => {
    const type = assert.isNull(null)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be null match value from null', () => {
    const type = assert.isNullCompare(null, null)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is from undefined', () => {
    let result
    const type = assert.isUndefined(result)
    
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('undefined match value from undefined', () => {
    const type = assert.isUndefinedCompare(undefined, undefined)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is from boolean', () => {
    const type = assert.isBoolean(true)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be boolean match value from boolean', () => {
    const type = assert.isBooleanCompare(true, false)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })
})
  • Example Usage Using ESM Module With Jest

import { assert } from 'is-any-type'

describe('Is Any Type Group Testing', () => {

  test('Should be value is string', () => {
    const type = assert.isString('hello wordl')
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be string match value from string', () => {
    const type = assert.isStringCompare('hello wordl', 'hello wordl')
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is number', () => {
    const type = assert.isNumber(2021)
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be number match value from number', () => {
    const type = assert.isNumberCompare(2021, 2021)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is object', () => {
    const type1 = assert.isObject({ name: 'john doe' })
    const type2 = assert.isObject({})
    
    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be object match value from object', () => {
    const type1 = assert.isObjectCompare({ name: 'john doe' }, { name: 'john doe' })
    const type2 = assert.isObjectCompare({}, {})

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be value is array', () => {
    const type1 = assert.isArray([1, 2, 3, 4, 5])
    const type2 = assert.isArray([])
    
    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be array match value from array', () => {
    const type1 = assert.isArrayCompare([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])
    const type2 = assert.isArrayCompare([], [])

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
  })

  test('Should be value is function', () => {
    const type = assert.isFunction(() => 'hello wordl')

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be function match value from function', () => {
    const type = assert.isFunctionCompare(() => 'hello wordl', () => 'hello wordl 2')

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })


  test('Should be value is promise', () => {
    const promise = async () => 'hello wordl'

    const type1 = assert.isPromise(Promise.resolve('hello wordl'))
    const type2 = assert.isPromise(new Promise((resolve, reject) => resolve('hello wordl')))
    const type3 = assert.isPromise(promise())

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()
    expect(type3).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
    expect(type3).toBeTruthy()
  })

  test('Should be promise match value from promise', () => {
    const promise = async () => 'hello wordl'

    const type1 = assert.isPromiseCompare(Promise.resolve('hello wordl'), Promise.resolve('hello wordl'))
    const type2 = assert.isPromiseCompare(new Promise((resolve, reject) => resolve('hello wordl')), promise())
    const type3 = assert.isPromiseCompare(promise(), Promise.resolve('hello wordl'))

    expect(type1).toBeDefined()
    expect(type2).toBeDefined()
    expect(type3).toBeDefined()

    expect(type1).toBeTruthy()
    expect(type2).toBeTruthy()
    expect(type3).toBeTruthy()
  })


  test('Should be value is buffer', () => {
    const type = assert.isBuffer(Buffer.from('hello wordl'))

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be buffer match value from buffer', () => {
    const type = assert.isBufferCompare(Buffer.from('hello wordl'), Buffer.from('hello john'))

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is null', () => {
    const type = assert.isNull(null)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be null match value from null', () => {
    const type = assert.isNullCompare(null, null)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is from undefined', () => {
    let result
    const type = assert.isUndefined(result)
    
    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('undefined match value from undefined', () => {
    const type = assert.isUndefinedCompare(undefined, undefined)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be value is from boolean', () => {
    const type = assert.isBoolean(true)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })

  test('Should be boolean match value from boolean', () => {
    const type = assert.isBooleanCompare(true, false)

    expect(type).toBeDefined()
    expect(type).toBeTruthy()
  })
})

Testing

  • Testing Via Local

    npm run test or make test
  • Testing Via Local And Build

    make build
  • Testing Via Docker

    docker build -t is-any-type or make dkb tag=is-any-type

Bugs

For information on bugs related to package libraries, please visit here

Contributing

Want to make Is-Any-Type more perfect ? Let's contribute and follow the contribution guide.

License