0.0.3 • Published 3 years ago

@symblight/keyset v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Javascript object toolset

get started

npm install @symblight/keyset

tools

update

Mutate a copy of data without changing the original source

import {update} from '@symblight/keyset'

const updated = update<EntryType, OutputType>({}, (object) =>
      object
        .$set('key', {
          statement: {
            user: 'Alexey',
            allows: true,
            stack: ['react', 'nodejs'],
          },
        })
        .key.statement.$setBy((statement) => ({
          ...statement,
          user: 'Vi',
          job: 'dev',
        }))
        .$set('test', 'LOL')
        .$remove('test')
	)

console.log(updated)

/*
{
      key: {
        statement: {
          user: 'Vi',
          job: 'dev',
          allows: true,
          stack: ['react', 'nodejs'],
        },
      },
    }
*/

get

import { get } from '@symblight/keyset'

const game = {
  name: 'cyberpunk',
  state: {
    title: 'Game',
    type: {
      tag: 'dev',
    },
  },
}

const result = get(game, ['state', 'type', 'tag']) // output: dev

set

import { set } from '@symblight/keyset'

const game = {
  name: 'cyberpunk',
  state: {
    title: 'Game',
    type: {
      tag: 'dev',
    },
  },
}

const result = set(game, ['state', 'type', 'tag'], 'prod') // output: object game

remove

import { remove } from '@symblight/keyset'

const game = {
  name: 'cyberpunk',
  state: {
    title: 'Game',
    type: {
      tag: 'dev',
    },
  },
}

const result = remove(game, ['state', 'type', 'tag']) // output: object game

setBy

import { setBy } from '@symblight/keyset'

const game = {
  name: 'cyberpunk',
  state: {
    title: 'Game',
    type: {
      tag: 'dev',
    },
  },
}

const result = setBy(game, ['state', 'type'], (type) => ({ tag: 'prod', version: 1 })) // output: object game

deepCopy

Copy prototype properties as well as own properties into the new object. by rfdc:

import {deepCopy} from '@symblight/keyset'

const copied = deepCopy(copied)

pipe

import {pipe} from '@symblight/keyset'

const result = pipe(fn1, fn2, fn3)(object)

compose

import {compose} from '@symblight/keyset'

const result = compose(fn1, fn2, fn3)(object)
0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago