@odiak/modify
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@odiak/modify

Just immutably modify objects/arrays.

Example

import { modify } from '@odiak/modify'

const object = {
  a: 'hello',
  b: [
    { x: 1, y: 2 },
    { x: 5, y: 3 },
  ],
}

modify(object, (m) => m.set('a', 'world')) // { a: 'world' ... }
modify(object, (m) => m.set('a', (m) => m.value + '!!')) // { a: 'hello!!' ... }
// replace() behaves same as set(), but can change type.
modify(object, (m) => m.replace('a', (m) => m.value.length)) // { a: 5 ... }
modify(object, (m) => m.setDeep(['b', 1, 'y'], 99)) // { ... b: [{ x: 1, y: 2}, {x: 5, y: 99}] }

const array = ['hey', 'ok', 'nice']
modify(array, (m) => m.set(1, 'yo')) // ['hey', 'yo', 'nice']

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i @odiak/modify

    Weekly Downloads

    0

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    6.86 kB

    Total Files

    5

    Last publish

    Collaborators

    • odiak