# @openinf/util-object

> Common JavaScript Object type-related utilities

Latest version **2.0.1** (published 2021-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @openinf/util-object
pnpm add @openinf/util-object
yarn add @openinf/util-object
bun add @openinf/util-object
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-02-08 |
| First published | 2021-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 22.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | The OpenINF Authors |
| Maintainers | dereknongeneric |
| Keywords | JavaScript, Object, type, utilities |

## Links

- npm: https://www.npmjs.com/package/@openinf/util-object
- Repository: https://github.com/openinf/util-types
- Homepage: https://github.com/openinf/util-types#readme
- Issues: https://github.com/openinf/util-types/issues
- npm.io page: https://npm.io/package/@openinf/util-object

## Dependencies (1)

- [@openinf/util-types](https://npm.io/package/@openinf/util-types.md) ^2.0.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-02-08
- 2.0.0 — 2021-02-03
- 1.2.0 — 2021-01-27
- 1.0.1 — 2021-01-17
- 1.0.0 — 2021-01-17

## README

<h1 align="center">@openinf/util-object</h1>

<p align="center">Common JavaScript Object type-related utilities</p>

<br />

<p align="center">
  <a href="https://www.npmjs.com/package/@openinf/util-object"><img src="https://img.shields.io/npm/v/@openinf/util-object?style=plastic" alt="view on npm" /></a>
  <img src="https://img.shields.io/github/languages/top/openinf/util-object?color=blue&style=plastic" />
  <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/github/license/openinf/util-object?color=blue&style=plastic" alt="License: MIT" /></a>
</p>

<br />

_The high-level goal of `@openinf/util-object` is to serve as a Node.js package
containing utilities for **common JavaScript Object type-related utilities**
primarily enabling users to perform comparisons and analyze object contents. As
is the case with any software project in continuous development, omissions and
errors may exist, for which contributions are welcome._

<br />

---

<br />

## Installation

`@openinf/util-object` runs on Node.js and is available via `npm`.

```bash
npm install @openinf/util-object
```

## Usage

```ts
import { hasOwn } from '@openinf/util-object';

export class GhFileImporter {
  constructor(options: GhFileImporterOptions) {
    if (!hasOwn(options, 'destDir')) {
      throw new MissingOptionError('destDir');
    }
  }
}
```

<br />

---

<br />

## Functions

<dl>
<dt><a href="#map">map([opt_initial])</a> ⇒ <code>T</code></dt>
<dd><p>Returns a map-like object. If <code>opt_initial</code> is provided, copies its own
properties into the newly created object.</p>
</dd>
<dt><a href="#hasOwn">hasOwn(obj, key)</a> ⇒ <code>boolean</code></dt>
<dd><p>Checks if the given key is a property in the map.</p>
</dd>
<dt><a href="#ownProperty">ownProperty(obj, key)</a> ⇒ <code>unknown</code></dt>
<dd><p>Returns obj[key] iff key is obj&#39;s own property (is not inherited).
Otherwise, returns undefined.</p>
</dd>
<dt><a href="#deepMerge">deepMerge(target, source, depth)</a> ⇒ <code>Object</code></dt>
<dd><p>Deep merges source into target.</p>
</dd>
<dt><a href="#omit">omit(o, props)</a> ⇒ <code>Record.&lt;string, (number|RegExp)&gt;</code></dt>
<dd></dd>
<dt><a href="#objectsEqualShallow">objectsEqualShallow(o1, o2)</a> ⇒ <code>boolean</code></dt>
<dd></dd>
<dt><a href="#memo">memo(obj, prop, factory)</a> ⇒ <code>R</code></dt>
<dd><p>Takes an object, a property name, and a factory function. If the value of
the property is undefined, it generates a value with the factory function,
updates the object originally passed, and returns the value that was returned
by the factory function.</p>
</dd>
</dl>

<a name="map"></a>

## map([opt_initial]) ⇒ <code>T</code>
Returns a map-like object. If `opt_initial` is provided, copies its own
properties into the newly created object.

**Kind**: global function  

| Param | Type | Description |
| --- | --- | --- |
| [opt_initial] | <code>T</code> | This should typically be an object literal. |

<a name="hasOwn"></a>

## hasOwn(obj, key) ⇒ <code>boolean</code>
Checks if the given key is a property in the map.

**Kind**: global function  

| Param | Type | Description |
| --- | --- | --- |
| obj | <code>T</code> | a map like property. |
| key | <code>string</code> |  |

<a name="ownProperty"></a>

## ownProperty(obj, key) ⇒ <code>unknown</code>
Returns obj[key] iff key is obj's own property (is not inherited).
Otherwise, returns undefined.

**Kind**: global function  

| Param | Type |
| --- | --- |
| obj | <code>Record.&lt;string, (number\|RegExp)&gt;</code> | 
| key | <code>string</code> | 

<a name="deepMerge"></a>

## deepMerge(target, source, depth) ⇒ <code>Object</code>
Deep merges source into target.

**Kind**: global function  
**Throws**:

- <code>Error</code> If source contains a circular reference.
Note: Only nested objects are deep-merged, primitives and arrays are not.


| Param | Type | Default | Description |
| --- | --- | --- | --- |
| target | <code>Object</code> |  |  |
| source | <code>Object</code> |  |  |
| depth | <code>number</code> | <code>10</code> | The maximum merge depth. If exceeded, Object.assign                       will be used instead. |

<a name="deepMerge..queue"></a>

### deepMerge~queue : <code>Array.&lt;ITargetSourceDepth&gt;</code>
**Kind**: inner constant of [<code>deepMerge</code>](#deepMerge)  
<a name="omit"></a>

## omit(o, props) ⇒ <code>Record.&lt;string, (number\|RegExp)&gt;</code>
**Kind**: global function  
**Returns**: <code>Record.&lt;string, (number\|RegExp)&gt;</code> - An object with the given properties removed.  

| Param | Type | Description |
| --- | --- | --- |
| o | <code>Record.&lt;string, (number\|RegExp)&gt;</code> | An object to remove properties from. |
| props | <code>Array.&lt;string&gt;</code> | A list of properties to remove from the Object. |

<a name="objectsEqualShallow"></a>

## objectsEqualShallow(o1, o2) ⇒ <code>boolean</code>
**Kind**: global function  

| Param | Type |
| --- | --- |
| o1 | <code>!Record.&lt;string, (number\|RegExp)&gt;</code> \| <code>null</code> \| <code>undefined</code> | 
| o2 | <code>!Record.&lt;string, (number\|RegExp)&gt;</code> \| <code>null</code> \| <code>undefined</code> | 

<a name="memo"></a>

## memo(obj, prop, factory) ⇒ <code>R</code>
Takes an object, a property name, and a factory function. If the value of
the property is undefined, it generates a value with the factory function,
updates the object originally passed, and returns the value that was returned
by the factory function.

**Kind**: global function  

| Param | Type |
| --- | --- |
| obj | <code>T</code> | 
| prop | <code>string</code> | 
| factory | <code>function</code> | 


<br />

---

<br />

<p align="center">&copy; The OpenINF Authors</center></p>
<p align="center"><img height="32px" width="32px" src="https://raw.githubusercontent.com/openinf/openinf.github.io/live/logo.svg" /></p>

---
_Source: https://npm.io/package/@openinf/util-object · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
