This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createCipheriv, createDecipheriv} from "crypto"; | |
const ALGORITHM = "aes-256-cbc"; | |
const ENCODING = "utf8"; | |
const DEFAULT_INITIALIZATION_VECTOR = "0"; | |
const DEFAULT_SYMMETRIC_KEY = "d6F3Efeq"; | |
function encrypt(value: string, key = DEFAULT_SYMMETRIC_KEY, iv = DEFAULT_INITIALIZATION_VECTOR) { | |
const cipher = crypto.createCipheriv(ALGORITHM, key, iv); | |
let crypted = cipher.update(value, ENCODING, "base64"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ChangeType = 'add' | 'update' | 'delete' | 'reconfigure' | 'setPrototype' | 'preventExtensions'; | |
interface ChangeObjectBase<T> { | |
object: T; | |
type: ChangeType; | |
} | |
interface ChangeObjectUpdateDelete<T> extends ChangeObjectBase<T> { | |
name: keyof T | '__proto__'; | |
type: 'update' | 'delete' | 'setPrototype'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Link } from 'react-router-dom' | |
<Menu> | |
<Menu.Item as={Link} to='/home'> | |
Home | |
</Menu.Item> | |
</Menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Any<T = 'div'> extends Component<Props<T>> { | |
public static ofType<T>() { | |
return Any as Constructor<Any<T>>; | |
} | |
public render() { | |
const { is: Cmp = 'div', innerRef, ...props } = this.props as any; | |
return <Cmp ref={innerRef} {...props} />; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type TagProps<Tag extends keyof JSX.IntrinsicElements> = { | |
is: Tag; | |
innerRef?: JSX.IntrinsicElements[Tag]['ref']; | |
} & JSX.IntrinsicElements[Tag]; | |
type StatelessComponentProps<P> = { | |
is: SFC<P>; | |
} & P; | |
type ComponentClassProps<T, P> = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Props<T> = T extends 'div' | |
? JSX.IntrinsicElements['div'] | |
: T extends keyof JSX.IntrinsicElements | |
? TagProps<T> | |
: T extends ComponentType<infer P> | |
? ComponentProps<P> : never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Props<T> = T extends 'div' | |
? JSX.IntrinsicElements['div'] | |
: T extends keyof JSX.IntrinsicElements | |
? TagProps<T> | |
: T extends Component<infer P> | |
? ComponentClassProps<T, P> | |
: T extends SFC<infer P> ? StatelessComponentProps<P> : never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rendering a plain div | |
<Any />; // -> <div /> | |
// using props defined on a div | |
<Any style={{ color: 'red' }} />; // -> <div style={{ color: 'red' }} /> | |
// Declaring a new Input type | |
const Input = Any.ofType<'input'>(); | |
// Failure to pass literal 'input' to is will be a type failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import { Component, ComponentClass, SFC } from 'react'; | |
type Constructor<T = {}> = new (...args: any[]) => T; | |
type TagProps<Tag extends keyof JSX.IntrinsicElements> = { | |
is: Tag; | |
innerRef?: JSX.IntrinsicElements[Tag]['ref']; | |
} & JSX.IntrinsicElements[Tag]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const next = jest.fn(); | |
const baseAction = { | |
type: OrderDetailsActionConstants.INITIATE_ORDER_DETAILS_RETRIEVAL, | |
orderId: 'orderId', | |
patientId: 'patientId', | |
encounterId: 'encounterId' | |
}; | |
const action = Object.assign({}, baseAction, toRemove: 'toRemove'); | |
serializeInitiateOrderDetailsRetrievalAction()(next)(action); |
OlderNewer