index overview
Added in v0.1.0
Table of contents
Arithmetic
add
Prefixed and curried version of JS +
infix operator. Works for strings and numbers.
Signature
export declare const add: { (n1: number): (n2: number) => number; (s1: string): (s2: string) => string }
Example
import { add } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 + val),
// Prefix
pipe(42, add(2))
)
Added in v0.1.0
div
Prefixed and curried version of JS /
infix operator
Signature
export declare const div: (n1: number) => (n2: number) => number
Example
import { div } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 / val),
// Prefix
pipe(42, div(2))
)
Added in v0.1.0
exp
Prefixed and curried version of JS **
infix operator
Signature
export declare const exp: (n1: number) => (n2: number) => number
Example
import { exp } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 ** val),
// Prefix
pipe(42, exp(2))
)
Added in v0.1.0
mul
Prefixed and curried version of JS *
infix operator
Signature
export declare const mul: (n1: number) => (n2: number) => number
Example
import { mul } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 * val),
// Prefix
pipe(42, mul(2))
)
Added in v0.1.0
rem
Prefixed and curried version of JS %
infix operator
Signature
export declare const rem: (n1: number) => (n2: number) => number
Example
import { rem } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 % val),
// Prefix
pipe(42, rem(2))
)
Added in v0.1.0
sub
Prefixed and curried version of JS -
infix operator
Signature
export declare const sub: (n1: number) => (n2: number) => number
Example
import { sub } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 - val),
// Prefix
pipe(42, sub(2))
)
Added in v0.1.0
Comparison
eq
Prefixed and curried version of JS ==
infix operator
Signature
export declare const eq: <A>(v1: A) => (v2: A) => boolean
Example
import { eq } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 == val),
// Prefix
pipe(42, eq(2))
)
Added in v0.1.0
gt
Prefixed and curried version of JS >
infix operator
Signature
export declare const gt: <A>(v1: A) => (v2: A) => boolean
Example
import { gt } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 > val),
// Prefix
pipe(42, gt(2))
)
Added in v0.1.0
gte
Prefixed and curried version of JS >=
infix operator
Signature
export declare const gte: <A>(v1: A) => (v2: A) => boolean
Example
import { gte } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 >= val),
// Prefix
pipe(42, gte(2))
)
Added in v0.1.0
lt
Prefixed and curried version of JS <
infix operator
Signature
export declare const lt: <A>(v1: A) => (v2: A) => boolean
Example
import { lt } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 < val),
// Prefix
pipe(42, lt(2))
)
Added in v0.1.0
lte
Prefixed and curried version of JS <=
infix operator
Signature
export declare const lte: <A>(v1: A) => (v2: A) => boolean
Example
import { lte } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 <= val),
// Prefix
pipe(42, lte(2))
)
Added in v0.1.0
neq
Prefixed and curried version of JS !=
infix operator
Signature
export declare const neq: <A>(v1: A) => (v2: A) => boolean
Example
import { neq } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 != val),
// Prefix
pipe(42, neq(2))
)
Added in v0.1.0
neqq
Prefixed and curried version of JS !==
infix operator
Signature
export declare const neqq: <A>(v1: A) => (v2: A) => boolean
Example
import { neqq } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (val) => 2 !== val),
// Prefix
pipe(42, neqq(2))
)
Added in v0.1.0
Logical
and
Prefixed and curried version of JS &&
infix operator
Signature
export declare const and: (v1: boolean) => (v2: boolean) => boolean
Example
import { and } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(true, (val) => val && true),
// Prefix
pipe(true, and(true))
)
Added in v0.1.0
not
Prefix version of JS !
unary operator
Signature
export declare const not: (b: boolean) => boolean
Example
import { not } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(true, (val) => !val),
// Prefix
pipe(true, not)
)
Added in v0.1.0
or
Prefixed and curried version of JS ||
infix operator
Signature
export declare const or: (v1: boolean) => (v2: boolean) => boolean
Example
import { or } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(true, (val) => val || false),
// Prefix
pipe(true, or(false))
)
Added in v0.1.0
Records
call
Invoke an object’s method
Signature
export declare const call: <N extends string, Args extends any[]>(
methodName: N,
...args: Args
) => <O extends Record<N, (...args: Args) => any>>(obj: O) => ReturnType<O[N]>
Example
import { call } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe(42, (obj) => obj.toString()),
// Prefix
pipe(42, call('toString'))
)
Added in v0.1.0
get
Access an object’s field
Signature
export declare const get: <N extends string>(propName: N) => <O extends Record<N, any>>(obj: O) => O[N]
Example
import { get } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe({ count: 42 }, ({ count }) => count),
// Prefix
pipe({ count: 42 }, get('count'))
)
Added in v0.1.0
merge
Merge two objects
Signature
export declare const merge: <O1>(obj1: O1) => <O2>(obj2: O2) => ShallowMerge<O1, O2>
Example
import { merge } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe({ count: 42, name: 'Joe' }, ({ ...obj }) => ({
...obj,
street: 'Main Street',
id: 0,
})),
// Prefix
pipe({ count: 42, name: 'Joe' }, merge({ street: 'Main Street', id: 0 }))
)
Added in v0.1.0
modify
Modify an object’s field with a function
Signature
export declare const modify: <N extends string, V1, V2, O extends Record<N, V1>>(
propName: N,
fn: (value: O[N]) => V2
) => (obj: O) => ShallowMerge<O, Record<N, V2>>
Example
import { modify, add } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe({ count: 42 }, (obj) => ({ count: obj.count + 1 })),
// Prefix
pipe({ count: 42 }, modify('count', add(1)))
)
Added in v0.1.0
remove
Delete an object’s field
Signature
export declare const remove: <N extends string>(
propName: N
) => <O extends Record<N, any>>(all: O) => Pick<O, Exclude<keyof O, N>>
Example
import { remove } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe({ count: 42, name: 'Joe' }, ({ count, ...obj }) => ({
...obj,
})),
// Prefix
pipe({ count: 42, name: 'Joe' }, remove('count'))
)
Added in v0.1.0
set
Set an object’s field to a value
Signature
export declare const set: <N extends string, V>(
propName: N,
value: V
) => <O extends Record<any, any>>(obj: O) => O & Record<N, V>
Example
import { set } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
assert.deepStrictEqual(
// Native
pipe({ count: 42 }, (obj) => ({ ...obj, name: 'Joe' })),
// Prefix
pipe({ count: 42 }, set('name', 'Joe'))
)
Added in v0.1.0
Types
ShallowMerge (type alias)
Merge two record types shallowly
Signature
export type ShallowMerge<O1, O2> = Omit<O1, keyof O2> & O2
Added in v0.2.0
Utils
unsafeCoerce
Unsafely coerce the type of a value to any other type
Signature
export declare const unsafeCoerce: <T>() => <G>(value: G) => T
Example
import { unsafeCoerce } from '@no-day/ts-prefix'
import { pipe } from 'fp-ts/function'
type Internal = { x: number }
type Public = { readonly _brand: unique symbol }
const value: Internal = { x: 3 }
assert.deepStrictEqual(
// Native
pipe(value, (obj) => (obj as unknown) as Public),
// Prefix
pipe(value, unsafeCoerce<Public>())
)
Added in v0.1.0