Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-persist-transform-filter

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-persist-transform-filter - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

46

index.js
import { createTransform } from 'redux-persist';
import get from 'lodash.get';
import set from 'lodash.set';
import unset from 'lodash.unset';
export default (reducerName, inboundPaths, outboundPaths) => {
export default function createFilter (reducerName, inboundPaths, outboundPaths, transformType = 'whitelist') {
return createTransform(

@@ -10,3 +11,3 @@ // inbound

return inboundPaths
? persistFilter(inboundState, inboundPaths)
? persistFilter(inboundState, inboundPaths, transformType)
: inboundState;

@@ -18,13 +19,21 @@ },

return outboundPaths
? persistFilter(outboundState, outboundPaths)
? persistFilter(outboundState, outboundPaths, transformType)
: outboundState;
},
{whitelist: [reducerName]}
{'whitelist': [reducerName]}
);
};
export function persistFilter (state, paths = []) {
const subset = {};
export function createWhitelistFilter (reducerName, inboundPaths, outboundPaths) {
return createFilter(reducerName, inboundPaths, outboundPaths, 'whitelist');
}
export function createBlacklistFilter (reducerName, inboundPaths, outboundPaths) {
return createFilter(reducerName, inboundPaths, outboundPaths, 'blacklist');
}
export function persistFilter (state, paths = [], transformType = 'whitelist') {
let subset = {};
// support only one key

@@ -35,11 +44,24 @@ if (typeof paths === 'string') {

paths.forEach((path) => {
const value = get(state, path);
if (transformType === 'whitelist') {
paths.forEach((path) => {
const value = get(state, path);
if (typeof value !== 'undefined') {
set(subset, path, value);
}
});
if (typeof value !== 'undefined') {
set(subset, path, value);
}
});
} else if (transformType === 'blacklist') {
subset = Object.assign({}, state);
paths.forEach((path) => {
const value = get(state, path);
if (typeof value !== 'undefined') {
unset(subset, path);
}
});
} else {
subset = state;
}
return subset;
}
{
"name": "redux-persist-transform-filter",
"version": "0.0.6",
"version": "0.0.7",
"description": "Filter transformator for redux-persist",

@@ -30,4 +30,5 @@ "main": "dist/index.js",

"dependencies": {
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2"
"lodash.get": "^4.5.0",
"lodash.set": "^4.5.0",
"lodash.unset": "^4.5.2"
},

@@ -34,0 +35,0 @@ "devDependencies": {

@@ -24,5 +24,11 @@ # redux-persist-transform-filter

// you want to remove some keys before you save
const saveSubsetBlacklistFilter = createBlacklistFilter(
'myReducerTwo',
['keyYouDontWantToSave1', 'keyYouDontWantToSave2']
);
// you want to load only a subset of your state of reducer two
const loadSubsetFilter = createFilter(
'myReducerTwo',
'myReducerThree',
null,

@@ -35,3 +41,3 @@ ['keyYouWantToLoad1', 'keyYouWantToLoad2']

const saveAndloadSubsetFilter = createFilter(
'myReducerThree',
'myReducerFour',
['one', 'two']

@@ -44,2 +50,3 @@ ['three', 'four']

saveSubsetFilter,
saveSubsetBlacklistFilter,
loadSubsetFilter,

@@ -46,0 +53,0 @@ saveAndloadSubsetFilter,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc