0.4.0 • Published 2 months ago

@ahouse/object-utilities v0.4.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

@ahouse/object-utilities

A few utility functions for JavaScript/TypeScript objects and arrays, with no external dependencies.

Installation

npm install @ahouse/object-utilites

Functions

arraysAreEqual

Check if two arrays have the same values.

import { arraysAreEqual } from '@ahouse/object-utilities';

const a  = [4, 'test', {x: ''}];
const a2 = [4, 'test', {x: ''}];
const b  = [4, 'test', {x: 'test'}];
const c  = [4, 'test', {y: ''}];
const d  = [4, 'test', {x: '', y: ''}];

arraysAreEqual(a, a);  // true
arraysAreEqual(a, a2); // true
arraysAreEqual(a, b);  // false
arraysAreEqual(a, c);  // false
arraysAreEqual(a, d);  // false

arrayToObject

Converts an array into an object that has the same values, where the key is one of the value's properties instead of an index.

clone

Deep copy an object (i.e. recursively copy inner objects as well).

cloneAndMerge

Merge an object (or several) with another object, into a new object, recursively.

flattenTree

Flatten multi-level objects.

isObject

Check if a variable is an object, but not an array (unlike typeof x === 'object').

map

Checks if two arrays have the same values.

merge

Merge an object (or several) into another object, recursively.

Contributing

See contributing.md.