import { typeGuard } from "tsafe/typeGuard"; import { getPrototypeChain } from "./getPrototypeChain"; type SetLike = { values: () => Iterable; }; export namespace SetLike { export function match(set: Object): set is SetLike { return ( typeGuard>(set, true) && typeof set.values === "function" && getPrototypeChain.isMatched(set, /Set/) ); } } export type MapLike = { keys: () => Iterable; get(key: T): U | undefined; }; export namespace MapLike { export function match(map: Object): map is MapLike { return ( typeGuard>(map, true) && typeof map.keys === "function" && typeof map.get === "function" && getPrototypeChain.isMatched(map, /Map/) ); } } export namespace ArrayLike { export function match(arr: Object): arr is ArrayLike { return ( typeGuard>(arr, true) && typeof arr.length === "number" && arr.length !== 0 ? (`${arr.length - 1}` in arr) : getPrototypeChain.isMatched(arr, /Array/) ); } } export type DateLike = { getTime: ()=> number; } export namespace DateLike { export function match(date: Object): date is DateLike { return ( typeGuard(date, true) && typeof date.getTime === "function" && getPrototypeChain.isMatched(date, /Date/) ) } }