Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

object-array-utils

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-array-utils - npm Package Compare versions

Comparing version
1.3.0
to
1.4.0
+2
-2
package.json
{
"name": "object-array-utils",
"version": "1.3.0",
"version": "1.4.0",
"description": "Utilities for working with arrays and objects",

@@ -10,3 +10,3 @@ "scripts": {

"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/core": "^7.17.8",
"@babel/preset-env": "^7.16.11",

@@ -13,0 +13,0 @@ "jest": "^27.5.1"

@@ -58,2 +58,6 @@ # `object-array-utils`

import { filterProps } from 'object-array-utils';
filterProps({ prop1: 1, prop2: 2 }, ['prop1', 'prop3']) // { prop1: 1 }
import { isObjectSubset } from 'object-array-utils';

@@ -60,0 +64,0 @@

@@ -169,2 +169,24 @@ function isNullOrUndefined(v) {

function filterProps(o, props) {
return props.reduce((newObject, prop) => {
return (prop in o)
? { ...newObject, [prop]: o[prop] }
: newObject;
}, {});
}
// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/groupBy
// function groupArrayElementsBy(arrayOfObjects, getKey) {
// return arrayOfObjects.reduce(function (resultingObject, object) {
// const key = getKey(object);
// if (!resultingObject[key]) {
// resultingObject[key] = [];
// }
// resultingObject[key].push(object);
// return resultingObject;
// }, {});
// }
function isObjectSubset(superObject, subObject, options = {}) {

@@ -271,2 +293,3 @@ if (!isObject(superObject) || !isObject(subObject)) {

deepFreeze,
filterProps,
hasObjectProp,

@@ -273,0 +296,0 @@ hasObjectProps,

import {
areArraysEqual,
areObjectsEqual,
isEmptyArray,
deepFreeze,
hasObjectProps
filterProps,
hasObjectProps,
isEmptyArray
} from './index';

@@ -75,2 +76,9 @@

test('filterProps', () => {
expect(filterProps({ foo: 1, bar: 2 }, ['foo'])).toEqual({ foo: 1 });
expect(filterProps({ foo: 1, bar: 2 }, ['bar'])).toEqual({ bar: 2 });
expect(filterProps({ foo: 1, bar: 2 }, ['bar', 'foo'])).toEqual({ foo: 1, bar: 2 });
expect(filterProps({ foo: 1, bar: 2 }, ['bar', 'foo', 'baz'])).toEqual({ foo: 1, bar: 2 });
});
test('isEmptyArray', () => {

@@ -77,0 +85,0 @@ expect(isEmptyArray([])).toBeTruthy();