# onweakonlythrottle

> A tiny lib for throttle/debounce only on weak devices

Latest version **1.0.2** (published 2021-10-20) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-10-20 |
| First published | 2021-10-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Maksym Kupriichuk |
| Maintainers | mkupriichuk |
| Keywords | throttle, debounce, lodash.debounce, lodash.throttle |

## Links

- npm: https://www.npmjs.com/package/onweakonlythrottle
- Repository: https://github.com/mkupriichuk/onweakonlythrottle
- Homepage: https://github.com/mkupriichuk/onweakonlythrottle#readme
- Issues: https://github.com/mkupriichuk/onweakonlythrottle/issues
- npm.io page: https://npm.io/package/onweakonlythrottle

## Dependencies (2)

- [lodash.debounce](https://npm.io/package/lodash.debounce.md) ^4.0.8
- [lodash.throttle](https://npm.io/package/lodash.throttle.md) ^4.1.1

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2021-10-20
- 1.0.1 — 2021-10-20
- 1.0.0 — 2021-10-16

## README

**English** | [Русский](./README.ru.md)
# Throttle on weak device

> A tiny lib for lodash throttle/debounce only on weak devices

## Whats is a "weak" device?

> Weak device is a mobile with 4 or less cores or a computer with 2 or less cores

## Table of Contents

* [Installation](#installation)
* [Basic usage](#basic-usage)
* [Advanced usage](#advanced-usage)
* [Lodash links](#lodash-links)

# Installation

```sh
$ npm install onweakonlythrottle
```

## Basic usage

```js
import {throttleOnWeak, debounceOnWeak} from 'onweakonlythrottle'

function _log(n = 0) {
	console.log(1 + n);
}

const logWithThrottle = throttleOnWeak(_log, 300)

const logWithDebounce = debounceOnWeak(_log, 300)

document.addEventListener('scroll', logWithThrottle);
// with arguments
document.addEventListener('scroll', () => logWithDebounce(2));
```
## Advanced usage

By default a weak device is checked using the following expression:

```js
const _isWeakDevice =
	(window.navigator.hardwareConcurrency <= 4
	&& /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
	|| window.navigator.hardwareConcurrency <= 2;
```

However you can replace it or merge with:

```js
import {throttleOnWeak, debounceOnWeak} from 'onweakonlythrottle'

function _log(n = 0) {
	console.log(1 + n);
}

const logWithThrottle = throttleOnWeak(_log, 300)

const isIE = /MSIE|Trident/.test(navigator.userAgent);

const logWithDebounceOnIe = debounceOnWeak(_log, 300, _, isIE)
/* !!You need to pass custom checker as the fourth parameter,
because the third is lodash.debounce/throttle options (see links below) */


const logWithDebounceOnIeAndDefaultWeak = debounceOnWeak(_log, 300, {leading: true}, {merge: true, exp: isIE})
/* if checker is a string it will replace the default one (as above).
But you can pass a object with two parameters: merge: true and exp: your checker.
Then they will merge.
({leading: true} this is one of the options that lodash can use (links below)) */

document.addEventListener('scroll', logWithThrottle);
// with arguments
document.addEventListener('scroll', () => logWithDebounce(2));

document.addEventListener('scroll', logWithDebounceOnIe);
document.addEventListener('scroll', logWithDebounceOnIeAndDefaultWeak);
```

## Lodash links

[Lodash throttle](https://lodash.com/docs/4.17.15#throttle) </br>
[Lodash debounce](https://lodash.com/docs/4.17.15#debounce) </br>

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