# objpop

> Pop properties from objects and verify you got all of them.

Latest version **0.3.6** (published 2025-02-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install objpop
pnpm add objpop
yarn add objpop
bun add objpop
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.6 |
| Published | 2025-02-22 |
| First published | 2018-07-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | M.K. |
| Maintainers | mk-pmb |

## Links

- npm: https://www.npmjs.com/package/objpop
- Repository: https://github.com/mk-pmb/objpop-js
- Homepage: https://github.com/mk-pmb/objpop-js/#readme
- Issues: https://github.com/mk-pmb/objpop-js/issues
- npm.io page: https://npm.io/package/objpop

## Recent versions

- 0.3.6 (latest) — 2025-02-22
- 0.3.5 — 2025-02-18
- 0.3.4 — 2024-12-09
- 0.3.3 — 2023-12-04
- 0.3.2 — 2023-08-21
- 0.3.1 — 2022-04-03
- 0.2.1 — 2020-11-30
- 0.2.0 — 2020-08-10
- 0.1.4 — 2020-07-30
- 0.1.3 — 2020-06-22
- 0.1.2 — 2020-06-20
- 0.1.1 — 2020-06-14
- 0.1.0 — 2018-07-26

## README

<!--#echo json="package.json" key="name" underline="=" -->
objpop
======
<!--/#echo -->

<!--#echo json="package.json" key="description" -->
Pop properties from objects and verify you got all of them.
<!--/#echo -->


Usage
-----

from [test/usage.mjs](test/usage.mjs):

<!--#include file="test/usage.mjs" transform="mjsUsageDemo1802" -->
<!--#verbatim lncnt="32" -->
```javascript
import objPop from 'objpop';
function makeSandwich(receipe) {
  const pop = objPop(receipe);
  const sandwich = ('🍞'
    + repeat(pop.ifHas('lettuce', 0), '🍀') // unicode is weak on salad.
    + repeat(pop.ifHas('tomato', 0), '🍅')
    + repeat(pop.ifHas('ham', 0), '🍗')  // close enough.
    + repeat(pop.ifHas('pineapple', 0), '🍍')
    + repeat(pop.ifHas('cheese', 0), '🧀')
    + repeat(pop.ifHas('cherry', 0), '🍒')
  );
  pop.expectEmpty('unknown ingredients');
  return sandwich;
}

const hawaii = { ham: 1, pineapple: 1, cheese: 1, cherry: 1 };
assert.equal(makeSandwich(hawaii), '🍞🍗🍍🧀🍒');

// Original object wasn't modified, so it works again:
assert.equal(makeSandwich(hawaii), '🍞🍗🍍🧀🍒');

// Except when you use direct mode (.d):
const directPop = objPop.d(hawaii);
assert.equal(directPop('cherry'), 1);
assert.equal(directPop('cherry'), undefined);

const blt = { bacon: 2, lettuce: 3, tomato: 3 };
assert.throws(() => makeSandwich(blt),
  'LeftoverKeys: unknown ingredients: bacon');
// Unicode would be way better with bacon.
```
<!--/include-->



<!--#toc stop="scan" -->



Known issues
------------

* Needs more/better tests and docs.
* Starting in v0.2.0, you can no longer pop inherited properties even in
  direct mode. The former `.ifHas` method has become the default.




&nbsp;


License
-------
<!--#echo json="package.json" key=".license" -->
ISC
<!--/#echo -->

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