pathmirror
Advanced key mirror function that can mirror nested object keys. Intended for the generation of flux action type names.
Installation
npm install pathmirror --save
Usage
; const mirrored = ; console; // foo_bar_baz
You can change the default delimiter via the second parameter.
; const mirrored = ; console; // foo.bar.baz
Advanced Options
There are several hooks to manipulate the produced output.
For example can you add a prefix or suffix to your created paths, change the separator or transform the path before creating the mirrored
object.
; const mirrored = ; console; // prefix/FOO_BAR_BAZ/suffix
For more advanced scenarios each string option can be a function which is called with the final path as string array.
; const mirrored = ; console; // 1/foo:bar/2console; // 2/baz.foobar/1
Use Case
This module is intended for generating hierachical action names when working with flux:
; const actions = ; console;/*{ APP: { INIT: 'APP_INIT' }, POSTS: { REQUEST: 'POSTS_REQUEST', FETECHED: 'POSTS_FETECHED', ERROR: 'POSTS_ERROR' }} */