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

redux-toolbelt

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-toolbelt - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

326

commonjs/lib/immutables.js

@@ -1,1 +0,325 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.makeArray = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.addItems = addItems;
exports.addItemsInIndex = addItemsInIndex;
exports.removeItem = removeItem;
exports.removeItemsById = removeItemsById;
exports.replaceItem = replaceItem;
exports.repositionItem = repositionItem;
exports.repositionItemById = repositionItemById;
exports.updateItem = updateItem;
exports.updateItemById = updateItemById;
exports.updateItemsByFilter = updateItemsByFilter;
exports.updateItemsById = updateItemsById;
exports.upsertItemsById = upsertItemsById;
exports.filterByIds = filterByIds;
exports.updateObjectProperty = updateObjectProperty;
exports.updateObjectProperties = updateObjectProperties;
var _lodash = require('lodash.inrange');
var _lodash2 = _interopRequireDefault(_lodash);
var _lodash3 = require('lodash.ismatch');
var _lodash4 = _interopRequireDefault(_lodash3);
var _lodash5 = require('lodash.ismatchwith');
var _lodash6 = _interopRequireDefault(_lodash5);
var _lodash7 = require('lodash.isequal');
var _lodash8 = _interopRequireDefault(_lodash7);
var _lodash9 = require('lodash.isfunction');
var _lodash10 = _interopRequireDefault(_lodash9);
var _lodash11 = require('lodash.without');
var _lodash12 = _interopRequireDefault(_lodash11);
var _lodash13 = require('lodash.constant');
var _lodash14 = _interopRequireDefault(_lodash13);
var _lodash15 = require('lodash.concat');
var _lodash16 = _interopRequireDefault(_lodash15);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var DEFAULT_ID_SELECTOR = function DEFAULT_ID_SELECTOR(item) {
return item.id;
};
var EMPTY_ARRAY = [];
// addItems(arr, newItem, newItem2)
function addItems(arr) {
for (var _len = arguments.length, newItems = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
newItems[_key - 1] = arguments[_key];
}
if (newItems.length === 0) {
return arr || EMPTY_ARRAY;
}
if (!arr || arr.length == 0) {
return newItems;
}
return [].concat(_toConsumableArray(arr), newItems);
}
// addItemsInIndex(arr, 2, newItem, newItem2)
function addItemsInIndex(arr, index) {
for (var _len2 = arguments.length, newItems = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
newItems[_key2 - 2] = arguments[_key2];
}
if (newItems.length === 0) {
return arr || EMPTY_ARRAY;
}
return [].concat(_toConsumableArray(arr.slice(0, index)), newItems, _toConsumableArray(arr.slice(index)));
}
// removeItem(arr, 2)
function removeItem(arr, index) {
return index > arr.length - 1 ? arr : [].concat(_toConsumableArray(arr.slice(0, index)), _toConsumableArray(arr.slice(index + 1)));
}
// removeItemsById(arr, ['id_1', 'id_2'])
// removeItemsById(arr, ['id_1', 'id_2'], item => item.id)
function removeItemsById(arr, itemsToDelete) {
var idSelector = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_ID_SELECTOR;
if (!arr || arr.length === 0) {
return arr || EMPTY_ARRAY;
}
var idsToDelete = itemsToDelete.map(idSelector);
var newArray = arr.filter(function (item) {
return !idsToDelete.includes(idSelector(item));
});
return arr.length === newArray.length ? arr : newArray;
}
// replaceItem(arr, 2, newItem)
function replaceItem(arr, index, newItem) {
return [].concat(_toConsumableArray(arr.slice(0, index)), [newItem], _toConsumableArray(arr.slice(index + 1)));
}
function _getArrIndex(arr, index) {
switch (index) {
case 'start':
return 0;
case 'end':
return arr.length - 1;
default:
return index;
}
}
// repositionItem(arr, 2, 4)
// repositionItem(arr, 2, 'start')
// repositionItem(arr, 2, 'end')
function repositionItem(arr, oldIndex, newIndex) {
if (!arr || arr.length === 0) {
return arr || EMPTY_ARRAY;
}
var actualOldIndex = _getArrIndex(arr, oldIndex);
var actualNewIndex = _getArrIndex(arr, newIndex);
if (actualOldIndex === actualNewIndex) {
return arr;
}
var item = arr[actualOldIndex];
var newArray = (0, _lodash12.default)(arr, item);
newArray.splice(actualNewIndex, 0, item);
return newArray;
}
// repositionItemById(arr, 'id_1', 3)
// repositionItemById(arr, 'id_1', 'start')
// repositionItemById(arr, 'id_1', 'end')
// repositionItemById(arr, 'id_1', 3, item => item.id)
function repositionItemById(arr, itemId, newIndex) {
var idSelector = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_ID_SELECTOR;
var itemIndex = arr.findIndex(function (item) {
return idSelector(item) === itemId;
});
return itemIndex < 0 ? arr : repositionItem(arr, itemIndex, newIndex);
}
function _makeGetUpdatedPropsFunc(newProps) {
return (0, _lodash10.default)(newProps) ? newProps : function (item) {
return newProps;
};
}
// updateItem(arr, 2, {prop1: 'new value', prop2: 'new value'})
// updateItem(arr, 2, item => ({prop: item.prop+2, prop2: 'new value'}))
function updateItem(arr, index, newProps) {
if (!arr || !(0, _lodash2.default)(index, arr.length)) {
return arr || EMPTY_ARRAY;
}
var item = arr[index];
var updatedProps = _makeGetUpdatedPropsFunc(newProps)(item);
return (0, _lodash4.default)(item, updatedProps) ? arr : [].concat(_toConsumableArray(arr.slice(0, index)), [_extends({}, item, updatedProps)], _toConsumableArray(arr.slice(index + 1)));
}
// updateItemById(arr, 2, {prop1: 'new value', prop2: 'new value'})
// updateItemById(arr, 2, {prop1: 'new value', prop2: 'new value'}, item => item.id)
// updateItemById(arr, 2, item => ({prop: item.prop+2, prop2: 'new value'}))
// updateItemById(arr, 2, item => ({prop: item.prop+2, prop2: 'new value'}), item => item.id)
function updateItemById(arr, id, newProps) {
var idSelector = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_ID_SELECTOR;
if (!arr || arr.length === 0) {
return arr || EMPTY_ARRAY;
}
var index = arr.findIndex(function (item) {
return idSelector(item) === id;
});
return updateItem(arr, index, newProps);
}
// updateItemsByFilter(arr, item => item.flag, {prop1: 'new value', prop2: 'new value'}) {
// updateItemsByFilter(arr, item => item.flag, item => ({prop: item.prop+2, prop2: 'new value'}))
function updateItemsByFilter(arr, filter, newProps) {
var getUpdatedProps = _makeGetUpdatedPropsFunc(newProps);
var hasChanges = false;
var result = arr.map(function (item) {
if (!filter(item)) {
return item;
}
var updatedProps = getUpdatedProps(item);
if ((0, _lodash4.default)(item, updatedProps)) {
return item;
}
hasChanges = true;
return _extends({}, item, updatedProps);
});
return hasChanges ? result : arr;
}
// updateItemsById(arr, [{id: 'id_1', prop: 3, prop2: 'val'}])
// updateItemsById(arr, [{id: 'id_1', prop: 3, prop2: 'val'}], item => item.id)
function updateItemsById(arr, updatedItems) {
var idSelector = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_ID_SELECTOR;
if (!updatedItems || updatedItems.length === 0) {
return arr || EMPTY_ARRAY;
}
var updatedItemsMap = new Map(updatedItems.map(function (item) {
return [idSelector(item), item];
}));
var hasChanges = false;
var result = arr.map(function (item) {
var itemId = idSelector(item);
if (!updatedItemsMap.has(itemId)) {
return item;
}
var updatedItem = updatedItemsMap.get(itemId);
var isItemMatching = (0, _lodash6.default)(item, updatedItem, function (objValue, srcValue) {
return (0, _lodash8.default)(objValue, srcValue);
});
if (isItemMatching) {
return item;
}
hasChanges = true;
return _extends({}, item, updatedItem);
});
return hasChanges ? result : arr;
}
// upsertItemsById(arr, [{id: 'id_1', prop: 3, prop2: 'val'}])
// upsertItemsById(arr, [{id: 'id_1', prop: 3, prop2: 'val'}], item => item.id)
function upsertItemsById(arr, updatedItems) {
var idSelector = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_ID_SELECTOR;
if (!updatedItems || updatedItems.length === 0) {
return arr || EMPTY_ARRAY;
}
if (!arr) {
return updatedItems || EMPTY_ARRAY;
}
var updatedItemsMap = new Map(updatedItems.map(function (item) {
return [idSelector(item), item];
}));
var hasChanges = false;
var result = arr.map(function (item) {
var itemId = idSelector(item);
if (!updatedItemsMap.has(itemId)) {
return item;
}
var updatedItem = updatedItemsMap.get(itemId);
updatedItemsMap.delete(itemId);
if ((0, _lodash4.default)(item, updatedItem)) {
return item;
}
hasChanges = true;
return _extends({}, item, updatedItem);
});
updatedItemsMap.forEach(function (item) {
return result.push(item);
});
return hasChanges ? result : arr;
}
// filterByIds(arr, ['id_1', 'id_2'])
// filterByIds(arr, ['id_1', 'id_2'], item => item.id)
function filterByIds(arr, itemsIds) {
var idSelector = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_ID_SELECTOR;
if (!arr || arr.length === 0 || !itemsIds) {
return arr || EMPTY_ARRAY;
}
if (itemsIds.length === 0) {
return EMPTY_ARRAY;
}
var filteredArr = arr.filter(function (item) {
return itemsIds.includes(idSelector(item));
});
return filteredArr.length === arr.length ? arr : filteredArr;
}
// updateObjectProperty(obj, prop, newVal)
// updateObjectProperty(obj, prop, updateFunc)
function updateObjectProperty(obj, prop, val) {
var updateFunc = (0, _lodash10.default)(val) ? val : (0, _lodash14.default)(val);
var oldVal = obj[prop];
var newVal = updateFunc(oldVal);
return oldVal === newVal ? obj : _extends({}, obj, _defineProperty({}, prop, newVal));
}
// updateObjectProperties(obj, {prop1: newVal, prop2: updateFunc})
function updateObjectProperties(obj, updates) {
return Object.keys(updates).reduce(function (result, key) {
return updateObjectProperty(result, key, updates[key]);
}, obj);
}
var makeArray = exports.makeArray = function makeArray(assets) {
// Convers the object into array (if it's not an array already)
return (0, _lodash16.default)(assets);
};

2

package.json
{
"name": "redux-toolbelt",
"version": "1.5.0",
"version": "1.6.0",
"description": "",

@@ -5,0 +5,0 @@ "browser": "dist/redux-toolbelt.js",

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