redux-transform-keys
TypeScript icon, indicating that this package has built-in type declarations

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    1
  • 0.0.1
    1

Package Sidebar

Install

npm i redux-transform-keys

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

8.11 kB

Total Files

12

Last publish

Collaborators

  • sugarshin