Skip to main content
Module

x/fae/propIs.ts

A functional module for Deno inspired from Ramda.
Latest
File
// Copyright (c) 2020 Jozty. All rights reserved. MIT license.
import curryN from './utils/curry_n.ts';import type { Obj, PH } from './utils/types.ts';import type { Prop } from './prop.ts';import { is } from './utils/is.ts';
// @typestype PropIs_1<T> = (type: string) => boolean;
type PropIs_2<T> = (name: Prop) => boolean;
type PropIs_3 = <T>(obj: Obj<T>) => boolean;
type PropIs_2_3 = & ((name: Prop) => PropIs_3) & (<T>(name: PH, obj: Obj<T>) => PropIs_2<T>) & (<T>(name: Prop, obj: Obj<T>) => boolean);
type PropIs_1_3 = & ((type: string) => PropIs_3) & (<T>(type: PH, obj: Obj<T>) => PropIs_1<T>) & (<T>(type: string, obj: Obj<T>) => boolean);
type PropIs_1_2<T> = & ((type: string) => PropIs_2<T>) & ((type: PH, name: Prop) => PropIs_1<T>) & ((type: string, name: Prop) => boolean);
type PropIs = & ((type: string) => PropIs_2_3) & ((type: PH, name: Prop) => PropIs_1_3) & (<T>(type: PH, name: PH, obj: Obj<T>) => PropIs_1_2<T>) & ((type: string, name: Prop) => PropIs_3) & (<T>(type: string, name: PH, obj: Obj<T>) => PropIs_2<T>) & (<T>(type: PH, name: Prop, obj: Obj<T>) => PropIs_1<T>) & (<T>(type: string, name: Prop, obj: Obj<T>) => boolean);
function _propIs<T>(type: string, name: Prop, obj: Obj<T>) { return is(obj[name], type);}
/** * Returns `true` if the specified object property is of the given type; * `false` otherwise. * * Fae.propIs('Number', 'a', {a: 1, y: 2}); //=> true * Fae.propIs('String', 'a', {a: 'foo'}); //=> true * Fae.propIs('Number', 'a', {}); //=> false */export const propIs: PropIs = curryN(3, _propIs);