# only-some-times

> wrapper to function, check that functions is called only some times given

Latest version **1.0.1** (published 2018-06-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install only-some-times
pnpm add only-some-times
yarn add only-some-times
bun add only-some-times
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-06-01 |
| First published | 2018-05-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jesus Cereceres |
| Maintainers | cereceres |
| Keywords | some, times, wrapper, function |

## Links

- npm: https://www.npmjs.com/package/only-some-times
- Repository: https://github.com/Cereceres/only-some-times
- Homepage: https://github.com/Cereceres/only-some-times#readme
- Issues: https://github.com/Cereceres/only-some-times/issues
- npm.io page: https://npm.io/package/only-some-times

## Dependencies (1)

- [joi](https://npm.io/package/joi.md) ^13.3.0

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads
- [@react-md/material-icons](https://npm.io/package/@react-md/material-icons.md) — 1.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-06-01
- 1.0.0 — 2018-05-31
- 0.0.5 — 2018-05-29
- 0.0.3 — 2018-05-28
- 0.0.2 — 2018-05-28
- 0.0.1 — 2018-05-28

## README

# only-some-times
wrap function to be spied if called some times, return the same value like other function and accept the same arguments

# Usage

```js
const wrapper = require('only-some-times');
let called = 0;
const wrapped = wrapper(() => called++, 3);
wrapped();
wrapped();
wrapped();
wrapped();
wrapped();
assert(called === 3);
wrapped.cbIsCalled === 3 // true

// you can use the reset, to set counter to zero again
const wrapped = wrapper(() => called++, 3);
wrapped();
wrapped();
wrapped();
wrapped();
wrapped();
assert(called === 3);
assert(wrapped.cbIsCalled === 3);
wrapped.reset();
wrapped();
wrapped();
wrapped();
assert(called === 6);
assert(wrapped.cbIsCalled === 3);

// you can pass a joi schema to validate arguments
const schema  = joi.object().keys({
    0: joi.array()
})
const wrapped = wrapper(() => called++, 3, schema);
try {
    wrapped('string');
} catch (error) {
    // error is a joi error
}
```

# API onlySomeTimes(cb,[times, joiSchema, errorHandlerBadParams]) -> cbWrapped

If joiSchema is given the arguments is validated before the cb is called, if there are any error in validate params and errorHandlerBadParams is not given the error is thrown.

## onlySomeTimes.cbIsCalled -> number
number <= times
## onlySomeTimes.reset() -> onlySomeTimes
reset the cbIsCalled to zero

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