Merge branch 'master' into observable-improvement
This commit is contained in:
commit
aa9b4994d3
4 changed files with 43 additions and 3 deletions
|
|
@ -2,6 +2,7 @@
|
|||
/// <reference lib="es2017.sharedmemory"/>
|
||||
/// <reference lib="esnext.asynciterable"/>
|
||||
/// <reference lib="dom"/>
|
||||
import {URL} from 'url';
|
||||
|
||||
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
||||
type Primitive = null | undefined | string | number | boolean | Symbol;
|
||||
|
|
@ -188,6 +189,19 @@ namespace is { // tslint:disable-line:no-namespace
|
|||
export const directInstanceOf = <T>(instance: unknown, klass: Class<T>): instance is T => Object.getPrototypeOf(instance) === klass.prototype;
|
||||
export const urlInstance = (value: unknown): value is URL => isObjectOfType<URL>(TypeName.URL)(value);
|
||||
|
||||
export const urlString = (value: unknown) => {
|
||||
if (!string(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(value); // tslint:disable-line no-unused-expression
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const truthy = (value: unknown) => Boolean(value);
|
||||
export const falsy = (value: unknown) => !value;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue