UNPKG

fp-ts-std

Version:

The missing pseudo-standard library for fp-ts.

32 lines (31 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.renameKey = exports.withDefaults = exports.omitFrom = exports.omit = exports.get = exports.pickFrom = exports.pick = exports.merge = void 0; const RA = require("fp-ts/ReadonlyArray"); const function_1 = require("fp-ts/function"); const Function_1 = require("./Function"); const Tuple_1 = require("./Tuple"); const merge = (x) => (y) => ({ ...x, ...y }); exports.merge = merge; const pick = (ks) => (x) => (0, function_1.pipe)(ks, RA.reduce({}, (ys, k) => (0, exports.merge)(ys)(k in x ? { [k]: x[k] } : {}))); exports.pick = pick; const pickFrom = () => exports.pick; exports.pickFrom = pickFrom; const get = (k) => (x) => x[k]; exports.get = get; const omit = (ks) => (x) => { const y = { ...x }; for (const k of ks) { delete y[k]; } return y; }; exports.omit = omit; const omitFrom = () => exports.omit; exports.omitFrom = omitFrom; exports.withDefaults = exports.merge; const renameKey = (oldK) => (newK) => (x) => { const newO = (x) => (oldK in x ? { [newK]: x[oldK] } : {}); return (0, function_1.pipe)(x, (0, Tuple_1.fanout)((0, exports.omitFrom)()([oldK]))(newO), (0, Function_1.uncurry2)(exports.merge)); }; exports.renameKey = renameKey;