Socket
Book a DemoInstallSign in
Socket

@basementuniverse/async

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@basementuniverse/async

Async versions of common list functions

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
0
Created
Source

Async

Async versions of common list functions.

Installation

npm install @basementuniverse/async

Usage

See docs for more information.

asyncForEach

import { asyncForEach } from '@basementuniverse/async';

await asyncForEach<string>(
  [
    'one',
    'two',
    'three',
  ],
  async (value: string) => {
    await fetch(`localhost:8080/${value}`);
  }
);

asyncMap

import { asyncMap } from '@basementuniverse/async';

const results = await asyncMap<string, number>(
  [
    '123',
    '456',
    '789',
  ],
  async (value: string) => {
    // asynchronous stuff here...
    return Number(value);
  }
);

/*
results: [123, 456, 789]

Note that the order of results might be different.
*/

asyncFilter

import { asyncFilter } from '@basementuniverse/async';

const results = await asyncFilter<string>(
  [
    'allowed1',
    'notAllowed2',
    'allowed3',
    'notAllowed4',
  ],
  async (value: string) => {
    // asynchronous stuff here...
    return value.startsWith('allowed');
  }
);

/*
results: ['allowed1', 'allowed2']

Note that the order of results might be different.
*/

asyncReduce

import { asyncReduce } from '@basementuniverse/async';

const result = await asyncReduce<string, number>(
  [
    '1',
    '2',
    '3',
  ],
  async (previous: number, current: string) => {
    // asynchronous stuff here...
    return previous + Number(current);
  },
  0
);

/*
result: 6
*/

asyncFind

import { asyncFind } from '@basementuniverse/async';

const result = await asyncFind<string>(
  [
    'one',
    'two',
    'three',
  ],
  async (value: string) => {
    // asynchronous stuff here...
    return value === 'two';
  }
);

/*
result: 'two'
*/

asyncFindIndex

import { asyncFindIndex } from '@basementuniverse/async';

const result = await asyncFindIndex<string>(
  [
    'one',
    'two',
    'three',
  ],
  async (value: string) => {
    // asynchronous stuff here...
    return value === 'two';
  }
);

/*
result: 1
*/

Keywords

async

FAQs

Package last updated on 29 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.