# @planjs/utils

> 🔧 Common tools collection

Latest version **1.18.4** (published 2023-07-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @planjs/utils
pnpm add @planjs/utils
yarn add @planjs/utils
bun add @planjs/utils
```

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.18.4 |
| Published | 2023-07-06 |
| First published | 2020-09-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 10 |
| Unpacked size | 482 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | fupengl |
| Maintainers | fupengl |
| Keywords | es6, promise, fp, bom, ts-utils, uuid |

## Links

- npm: https://www.npmjs.com/package/@planjs/utils
- Repository: https://github.com/planjs/utils
- Homepage: https://planjs.github.io/utils/
- Issues: https://github.com/planjs/utils/issues
- npm.io page: https://npm.io/package/@planjs/utils

## Dependencies (10)

- [decimal.js](https://npm.io/package/decimal.js.md) ^10.3.1
- [query-string](https://npm.io/package/query-string.md) ^7.0.1
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.19.4
- [lodash.debounce](https://npm.io/package/lodash.debounce.md) ^4.0.8
- [lodash.throttle](https://npm.io/package/lodash.throttle.md) ^4.1.1
- [lodash.clonedeep](https://npm.io/package/lodash.clonedeep.md) ^4.5.0
- [event-target-shim](https://npm.io/package/event-target-shim.md) ^6.0.2
- [@types/lodash.debounce](https://npm.io/package/@types/lodash.debounce.md) ^4.0.6
- [@types/lodash.throttle](https://npm.io/package/@types/lodash.throttle.md) ^4.1.6
- [@types/lodash.clonedeep](https://npm.io/package/@types/lodash.clonedeep.md) ^4.5.6

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.18.4 (latest) — 2023-07-06
- 1.18.3 — 2023-07-05
- 1.18.2 — 2023-06-08
- 1.18.1 — 2023-01-17
- 1.18.0 — 2022-10-19
- 1.17.1 — 2022-10-11
- 1.17.0 — 2022-09-01
- 1.16.0 — 2022-08-22
- 1.15.15 — 2022-08-12
- 1.15.14 — 2022-08-12
- 1.15.13 — 2022-08-05
- 1.15.12 — 2022-07-26
- 1.15.11 — 2022-07-10
- 1.15.10 — 2022-07-10
- 1.15.9 — 2022-07-04
- … 89 more at https://npm.io/package/@planjs/utils/versions

## README

# utils

![npm](https://img.shields.io/npm/v/@planjs/utils?label=@planjs/utils) ![npm](https://packagephobia.now.sh/badge?p=@planjs/utils) [![action](https://github.com/planjs/utils/actions/workflows/npm-publish.yml/badge.svg?branch=master)](https://github.com/planjs/utils/actions/workflows/npm-publish.yml)
<br/> [![NPM](https://nodei.co/npm/@planjs/utils.png?downloads=true&downloadRank=true&stars=true)](https://npmjs.org/package/@planjs/utils)

> 🔧 contactInfoDefault [doc](https://planjs.github.io/utils/)

## Installation

```bash
npm i @planjs/utils
```

## Usage

```javascript
import {
  delay,
  retry,
  pTry,
  sequenceChain,
  nextTick,
  range,
  REG_TEL_PHONE,
  eventCenter,
  TimeoutMap,
} from '@planjs/utils';

// promise utils
async function main() {
  await delay(100);
  function fetchData() {
    return Promise.reject(new Error('testing'));
  }
  await retry(fetchData, { maxAttempts: 3, delayMs: 500 })();
}

const pool = asyncPool({ maxConcurrency: 10 });

const randArr = range(1, 10);

nextTick(async () => {
  const [err, res] = await pTry(main());
  if (!err) {
    console.log(res);
  }
  let start = Date.now();
  await Promise.all(randArr.map((v) => pool.executor(delay(v))));
  // The timer has an accuracy problem
  if (Date.now() - start + 1 >= Math.max(...randArr)) {
    console.log('concurrency');
  }
  const count = (a = 0) => ++a;
  const val = await sequenceChain([...range(0, 10).map((v) => [count])])();
  console.log(val); // 11
});

// commonly used regex
REG_TEL_PHONE.test('132xxxxxxx'); // false

// event center
eventCenter.on('log', console.log);
eventCenter.trigger('log', 'planjs');

// ext obj
const timeoutMap = new TimeoutMap({
  timeout: 200,
  passiveDeletion: true,
  onTimeout(k, v) {
    console.log(`expired key [${k}], val [${v}]`);
  },
});
timeoutMap.set('name', 'fupengl');
delay(201).then(() => timeoutMap.get('name')); // null
```

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