Socket
Socket
Sign inDemoInstall

@basementuniverse/async

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @basementuniverse/async

Async versions of common list functions


Version published
Weekly downloads
10
decreased by-23.08%
Maintainers
1
Install size
8.89 kB
Created
Weekly downloads
 

Readme

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
*/

Keywords

FAQs

Last updated on 13 Apr 2022

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc