Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

redux-transform-keys

1.0.0 • Public • Published

redux-transform-keys

CircleCI Codecov npm version License

FSA-compliant transform keys of payload object for Redux.

yarn add redux-transform-keys
 
# or 
 
npm i redux-transform-keys

FSA-compliant

Using in combination with redux-actions.

Because it supports FSA actions, you can use this in combination with redux-actions.

Usage

import { createStore, applyMiddleware, compose } from 'redux'
import transformKeys from 'redux-transform-keys'
 
const store = createStore(
  rootReducer,
  initialState,
  applyMiddleware(transformKeys({ caseStyle: 'camelCase' }))
)
 
dispatch({
  type: 'RECIEVE_USER_ENTITY',
  payload: { user_id: 1, user_name: 'sugarshin' },
  meta: { transformKeys: true },
})

It's ignored on error.

Run on error

// You can use `ignoreOnError` option
const middleware = transformKeys({ caseStyle: 'camelCase', ignoreOnError: false })
 
dispatch({
  type: 'RECIEVE_USER_ENTITY',
  payload: new Error('some error'),
  meta: { transformKeys: true },
  error: true,
})

Use transformers

import { transformKeys, transformers } from 'redux-transform-keys'
const camelizeKeys = object => transformKeys(object, transformers.camelCase)
const subject = { f_o_o: 1, bar: { Buz: 3, Qu_x: [{ qu_uX: 4 }] } }
const expected = { fOO: 1, bar: { buz: 3, quX: [{ quUX: 4 }] } }
deepEqual(camelizeKeys(subject), expected)

You can use 'camelCase' , 'snakeCase' or 'kebabCase' .

License

MIT

© sugarshin

install

npm i redux-transform-keys

Downloadsweekly downloads

0

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability