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

typa

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typa - npm Package Compare versions

Comparing version 0.1.14 to 0.1.15

{
"name": "typa",
"version": "0.1.14",
"version": "0.1.15",
"description": "JavaScript type checker utility",

@@ -5,0 +5,0 @@ "main": "dist/typa.min.js",

@@ -10,3 +10,3 @@ Typa

```
npm install typa
npm install typa
```

@@ -16,11 +16,23 @@

```
import {is} from 'typa'
import {is} from 'typa'
// or
/* or */
const is = require('typa')
const is = require('typa')
```
Available Types
---------------
**Quick Start**
```
const hello = 'Hello!'
const goodbye = ['Goodbye!', 'Adios!', 'Au revoir!']
if (is.str(hello)) console.log(hello)
// => 'Hello!'
if (is.str(goodbye)) console.log(hello)
// => no result
```
API
---
+ <a href="#array">*arr*</a> → Array

@@ -45,14 +57,9 @@ + <a href="#bad">*bad*</a> → Null, undefined, empty, or an error

Typa Function
-------------
Typa Method
-----------
Checks if value matches the specified type, then returns the first function (or value) if true or the second function (or value) if false.
Ternary function that checks if the supplied value matches the specified type, then returns the first function (or value) if true or the second function (or value) if false.
Method:
**.typa**($type, $value, $fn1, $fn2)
```
is.typa($type, $value, $fn1, $fn2)
```
Example:
```
const myString = 'this is a string'

@@ -71,236 +78,141 @@ const myArray = 'this is also a string, not an array'

Individual Checks
-----------------
Individual Methods
------------------
<a name="array"></a>**Array**
Method:
<a name="array"></a>**.arr**($value) — Array
```
is.arr($value)
const isArray = is.arr(['text', 12])
// => true
```
Example:
```
const isArray = is.arr(['text', 12])
// => true
```
<a name="bad"></a>**Bad**
Method:
<a name="bad"></a>**.bad**($value) — Null, undefined, empty, or an error
```
is.bad($value)
```
Example:
```
let isBad = is.bad(null)
// => true
let isBad = is.bad(null)
// => true
isBad = is.bad(undefined)
// => true
isBad = is.bad(undefined)
// => true
isBad = is.bad({})
// => true
isBad = is.bad({})
// => true
isBad = is.bad(new Error('This is an error'))
// => true
isBad = is.bad(new Error('This is an error'))
// => true
```
<a name="boolean"></a>**Boolean**
Method:
<a name="boolean"></a>**.bool**($value) — Boolean
```
is.bool($value)
```
Example:
```
let isBool = is.bool(true)
// => true
let isBool = is.bool(true)
// => true
isBool = is.bool(false)
// => true
isBool = is.bool(false)
// => true
```
<a name="date"></a>**Date**
Method:
<a name="date"></a>**.date**($value) — Date
```
is.date($value)
const isDate = is.date(new Date())
// => true
```
Example:
```
const isDate = is.date(new Date())
// => true
```
<a name="empty"></a>**Empty**
Method:
<a name="empty"></a>**.empty**($value) — Empty string, array, or object
```
is.empty($value)
```
Example:
```
let isEmpty = is.empty('')
// => true
let isEmpty = is.empty('')
// => true
isEmpty = is.empty([])
// => true
isEmpty = is.empty([])
// => true
isEmpty = is.empty({})
// => true
isEmpty = is.empty({})
// => true
```
<a name="error"></a>**Error**
Method:
<a name="error"></a>**.err**($value) — Error
```
is.err($value)
const isErr = is.err(new Error('This is an error.'))
// => true
```
Example:
```
const isErr = is.err(new Error('This is an error.'))
// => true
```
<a name="function"></a>**Function**
Method:
<a name="function"></a>**.fn**($value) — Function
```
is.fn($value)
const isFn = is.fn(() => { console.log('Hi!') })
// => true
```
Example:
```
const isFn = is.fn(() => { console.log('Hi!') })
// => true
```
<a name="integer"></a>**Integer**
Method:
<a name="integer"></a>**.int**($value) — Integer
```
is.int($value)
const isInt = is.int(12)
// => true
```
Example:
```
const isInt = is.int(12)
// => true
```
<a name="json"></a>**JSON**
Method:
<a name="json"></a>**.json**($value) — Serialized JSON object
```
is.json($value)
const isJson = is.json('{"key": "value"}')
// => true
```
Example:
```
const isJson = is.json('{"key": "value"}')
// => true
```
<a name="null"></a>**Null**
Method:
<a name="null"></a>**.nll**($value) — Null
```
is.nll($value)
const isNll = is.nll(null)
// => true
```
Example:
```
const isNll = is.nll(null)
// => true
```
<a name="noru"></a>**Null or Undefined**
Method:
<a name="noru"></a>**.noru**($value) — Null or Undefined
```
is.noru($value)
```
Example:
```
let isNoru = is.noru(null)
// => true
let isNoru = is.noru(null)
// => true
isNoru = is.noru(undefined)
// => true
isNoru = is.noru(undefined)
// => true
```
<a name="number"></a>**Number**
Method:
<a name="number"></a>**.num**($value) — Number
```
is.num($value)
const isNum = is.num(28.2)
// => true
```
Example:
```
const isNum = is.num(28.2)
// => true
```
<a name="object"></a>**Object**
Method:
<a name="object"></a>**obj**($value) — Object
```
is.obj($value)
const isObj = is.obj({ key: 'value' })
// => true
```
Example:
```
const isObj = is.obj({ key: 'value' })
// => true
```
<a name="promise"></a>
**Promise**
Method:
<a name="promise"></a>**.prom**($value) — Promise
```
is.prom($value)
```
Example:
```
const myPromise = new Promise((resolve, reject) => {
try {
console.log('I make a promise to you')
resolve()
} catch(err) {
reject(err)
}
})
const myPromise = new Promise((resolve, reject) => {
try {
console.log('I make a promise to you')
resolve()
} catch(err) {
reject(err)
}
})
const isProm = is.prom(myPromise)
// => true
const isProm = is.prom(myPromise)
// => true
```
<a name="regex"></a>
**Regex**
Method:
<a name="regex"></a>**.regex**($value) — Regular Expression
```
is.regex($value)
const isRegex = is.regex(new Regex(/\W/))
// => true
```
Example:
```
const isRegex = is.regex(new Regex(/\W/))
// => true
```
<a name="string"></a>
**String**
Method:
<a name="string"></a>**.str**($value) — String
```
is.str($value)
const isStr = is.str('text')
// => true
```
Example:
```
const isStr = is.str('text')
// => true
```
<a name="symbol"></a>
**Symbol**
Method:
<a name="symbol"></a>**.sym**($value) — Symbol
```
is.sym($value)
const isSym = is.sym(Symbol(42))
// => true
```
Example:
```
const isSym = is.sym(Symbol(42))
// => true
```
<a name="undefined"></a>
**Undefined**
Method:
<a name="undefined"></a>**.undef**($value) — Undefined
```
is.undef($value)
const isUndef = is.undef(undefined)
// => true
```
Example:
```
const isUndef = is.undef(undefined)
// => true
```

@@ -106,23 +106,6 @@ // array

const is = {
arr,
bad,
bool,
date,
empty,
err,
fn,
int,
json,
nll,
noru,
num,
obj,
prom,
regex,
str,
sym,
typa,
undef
arr, bad, bool, date, empty, err, fn, int, json, nll,
noru, num, obj, prom, regex, str, sym, typa, undef
}
module.exports = is