feat: import collections from URL (#2262)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { pipe } from "fp-ts/function"
|
||||
import cloneDeep from "lodash/cloneDeep"
|
||||
import isEqual from "lodash/isEqual"
|
||||
import { JSPrimitive, TypeFromPrimitive } from "./primtive"
|
||||
|
||||
export const objRemoveKey =
|
||||
<T, K extends keyof T>(key: K) =>
|
||||
@@ -19,34 +20,15 @@ export const objFieldMatches =
|
||||
(obj: T): obj is T & { [_ in K]: V } =>
|
||||
matches.findIndex((x) => isEqual(obj[fieldName], x)) !== -1
|
||||
|
||||
type JSPrimitive =
|
||||
| "undefined"
|
||||
| "object"
|
||||
| "boolean"
|
||||
| "number"
|
||||
| "bigint"
|
||||
| "string"
|
||||
| "symbol"
|
||||
| "function"
|
||||
|
||||
type TypeFromPrimitive<P extends JSPrimitive | undefined> =
|
||||
P extends "undefined"
|
||||
? undefined
|
||||
: P extends "object"
|
||||
? object | null // typeof null === "object"
|
||||
: P extends "boolean"
|
||||
? boolean
|
||||
: P extends "number"
|
||||
? number
|
||||
: P extends "bigint"
|
||||
? BigInt
|
||||
: P extends "string"
|
||||
? string
|
||||
: P extends "symbol"
|
||||
? Symbol
|
||||
: P extends "function"
|
||||
? Function
|
||||
: unknown
|
||||
export const objHasProperty =
|
||||
<O extends object, K extends string, P extends JSPrimitive | undefined>(
|
||||
prop: K,
|
||||
type?: P
|
||||
) =>
|
||||
// eslint-disable-next-line
|
||||
(obj: O): obj is O & { [_ in K]: TypeFromPrimitive<P> } =>
|
||||
// eslint-disable-next-line
|
||||
prop in obj && (type === undefined || typeof (obj as any)[prop] === type)
|
||||
|
||||
type TypeFromPrimitiveArray<P extends JSPrimitive | undefined> =
|
||||
P extends "undefined"
|
||||
@@ -67,16 +49,6 @@ type TypeFromPrimitiveArray<P extends JSPrimitive | undefined> =
|
||||
? Function[]
|
||||
: unknown[]
|
||||
|
||||
export const objHasProperty =
|
||||
<O extends object, K extends string, P extends JSPrimitive | undefined>(
|
||||
prop: K,
|
||||
type?: P
|
||||
) =>
|
||||
// eslint-disable-next-line
|
||||
(obj: O): obj is O & { [_ in K]: TypeFromPrimitive<P> } =>
|
||||
// eslint-disable-next-line
|
||||
prop in obj && (type === undefined || typeof (obj as any)[prop] === type)
|
||||
|
||||
export const objHasArrayProperty =
|
||||
<O extends object, K extends string, P extends JSPrimitive>(
|
||||
prop: K,
|
||||
|
||||
34
packages/hoppscotch-app/helpers/functional/primtive.ts
Normal file
34
packages/hoppscotch-app/helpers/functional/primtive.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
export type JSPrimitive =
|
||||
| "undefined"
|
||||
| "object"
|
||||
| "boolean"
|
||||
| "number"
|
||||
| "bigint"
|
||||
| "string"
|
||||
| "symbol"
|
||||
| "function"
|
||||
|
||||
export type TypeFromPrimitive<P extends JSPrimitive | undefined> =
|
||||
P extends "undefined"
|
||||
? undefined
|
||||
: P extends "object"
|
||||
? object | null // typeof null === "object"
|
||||
: P extends "boolean"
|
||||
? boolean
|
||||
: P extends "number"
|
||||
? number
|
||||
: P extends "bigint"
|
||||
? BigInt
|
||||
: P extends "string"
|
||||
? string
|
||||
: P extends "symbol"
|
||||
? Symbol
|
||||
: P extends "function"
|
||||
? Function
|
||||
: unknown
|
||||
|
||||
export const isOfType =
|
||||
<T extends JSPrimitive>(type: T) =>
|
||||
(value: unknown): value is T =>
|
||||
// eslint-disable-next-line valid-typeof
|
||||
typeof value === type
|
||||
13
packages/hoppscotch-app/helpers/functional/taskEither.ts
Normal file
13
packages/hoppscotch-app/helpers/functional/taskEither.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
|
||||
/**
|
||||
* A utility type which gives you the type of the left value of a TaskEither
|
||||
*/
|
||||
export type TELeftType<T extends TE.TaskEither<any, any>> =
|
||||
T extends TE.TaskEither<
|
||||
infer U,
|
||||
// eslint-disable-next-line
|
||||
infer _
|
||||
>
|
||||
? U
|
||||
: never
|
||||
Reference in New Issue
Block a user