Skip to content

`kind-of` with single letter abbreviations to javascript native types, like `kindof(val, 'soa')` will return true if `val` is string, object or array. useful for DB/Schema/Object validations

License

Notifications You must be signed in to change notification settings

tunnckoCore/abbrev-kindof

Repository files navigation

Use abbreviations for checking type of given value. Like kindof(val, 'soa') to check that value is string, object or array.

code climate standard code style travis build status coverage status dependency status

Install

npm i abbrev-kindof --save

Usage

For more use-cases see the tests

const abbrevKindof = require('abbrev-kindof')

Check type of a val with abbreviations.

Params

  • val {Mixed}: value to check
  • type {String|Array}: list of single-letter (abbr) types
  • returns {Boolean}: if true, so val match one of the abbreviated types

Example

// `soa` here means - string, object or array
abbrevKindof(123, 'soa')          //=> false
abbrevKindof('foo bar', 'soa')    //=> true
abbrevKindof({a: 123}, 'soa')     //=> true
abbrevKindof(['c', 'd'], 'soa')   //=> true

Available abbreviations

Using map-types

  • a for array
  • b for boolean
  • f for function
  • n for number
  • o for object
  • r for regexp
  • s for string
  • y for symbol

Related Libs

  • assert-kindof: Check native type of the given value and throw TypeError if not okey. Expressive, elegant, behavior-driven API, good descriptive default error messages, simple and clean syntax. | homepage
  • is-kindof: Check type of given javascript value. Support promises, generators, streams, and native types. Thin wrapper around kind-of module. | homepage
  • kind-error: Base class for easily creating meaningful and quiet by default Error classes with sane defaults and assertion in mind. | homepage
  • kind-of: Get the native type of a value. | homepage
  • kind-of-extra: Extends kind-of type check utility with support for promises, generators, streams and errors. Like kindof(Promise.resolve(1)) === 'promise' and etc. | homepage
  • kind-of-types: List of all javascript types. Used and useful for checking, validation, sanitizing and testing. Like isStream, isPromise, isWeakset and etc. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

`kind-of` with single letter abbreviations to javascript native types, like `kindof(val, 'soa')` will return true if `val` is string, object or array. useful for DB/Schema/Object validations

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published