Add is.urlInstance
This commit is contained in:
parent
2dbf247fc0
commit
7e71742a0f
2 changed files with 13 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import util from 'util';
|
||||
import symbolObservable from 'symbol-observable';
|
||||
import {URL} from 'url';
|
||||
|
||||
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
||||
type Primitive = null | undefined | string | number | boolean | Symbol;
|
||||
|
|
@ -177,6 +178,7 @@ namespace is { // tslint:disable-line:no-namespace
|
|||
export const dataView = isObjectOfType<DataView>(TypeName.DataView);
|
||||
|
||||
export const directInstanceOf = <T>(instance: any, klass: Class<T>): instance is T => Object.getPrototypeOf(instance) === klass.prototype;
|
||||
export const urlInstance = (value: any): value is URL => !nullOrUndefined(value) && directInstanceOf<URL>(value, URL);
|
||||
|
||||
export const truthy = (value: any) => Boolean(value);
|
||||
export const falsy = (value: any) => !value;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import net from 'net';
|
|||
import Stream from 'stream';
|
||||
import util from 'util';
|
||||
import tempy from 'tempy';
|
||||
import {URL} from 'url';
|
||||
import test, {TestContext, Context} from 'ava';
|
||||
import {JSDOM} from 'jsdom';
|
||||
import {Subject, Observable} from 'rxjs';
|
||||
|
|
@ -534,6 +535,16 @@ test('is.directInstanceOf', t => {
|
|||
t.false(m.directInstanceOf(errorSubclass, Error));
|
||||
});
|
||||
|
||||
test('is.urlInstance', t => {
|
||||
const url = new URL('https://google.com');
|
||||
|
||||
t.true(m.urlInstance(url));
|
||||
|
||||
t.false(m.urlInstance({}));
|
||||
t.false(m.urlInstance(undefined));
|
||||
t.false(m.urlInstance(null));
|
||||
});
|
||||
|
||||
test('is.truthy', t => {
|
||||
t.true(m.truthy('unicorn'));
|
||||
t.true(m.truthy('🦄'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue