1.1.25 ā€¢ Published 6 months ago

extra-async-function v1.1.25

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

An async function is a function that delivers its result asynchronously (through Promise). šŸ“¦ Node.js, šŸŒ Web, šŸ“œ Files, šŸ“° JSDoc, šŸ“˜ Wiki.

This package is an variant of extra-function, and includes methods for transforming async functions. The result of an async function can be manipulated with negate. If a pure async function is expensive, its results can cached with memoize. Parameters of a function can be manipulated with reverse, spread, unspread. reverse flips the order of parameters, spread spreads the first array parameter of a function, and unspread combines all parameters into the first parameter (array). If you want some functional behavior, compose, composeRight, curry, and curryRight can be used. composeRight is also known as pipe-forward operator or function chaining. If you are unfamiliar, Haskell is a great purely functional language, and there is great haskell beginner guide to learn from.

To control invocation time of a function, use delay. A function can be rate controlled with debounce, debounceEarly, throttle, throttleEarly. debounce and debounceEarly prevent the invocation of a function during hot periods (when there are too many calls), and can be used for example to issue AJAX request after user input has stopped (for certain delay time). throttle and throttleEarly can be used to limit the rate of invocation of a function, and can be used for example to minimize system usage when a user is constantly refreshing a webpage. Except restrict, all rate/time control methods can be flushed (flush()) to invoke the target function immediately, or cleared (clear()) to disable invocation of the target function.

In addition, is, name, and length obtain metadata (about) information on an async function. To attach a this to a function, use bind. A few generic async functions are also included: ARGUMENTS, NOOP, IDENTITY, COMPARE.

This package is available in Node.js and Web formats. To use it on the web, simply use the extra_async_function global variable after loading with a <script> tag from the jsDelivr CDN.

Stability: Experimental.

const xasyncfn = require('extra-async-function');
// import * as xasyncfn from "extra-async-function";
// import * as xasyncfn from "https://unpkg.com/extra-async-function/index.mjs"; (deno)

// 1. Basic tests.
async function example1() {
  var a = xasyncfn.composeRight(async x => x*x, async x => x+2);
  await a(10);
  // ā†’ 102

  var a = xasyncfn.curry(async (x, y) => x+y);
  await a(2)(3);
  // ā†’ 7

  var a = xasyncfn.unspread(async (...xs) => Math.max(...xs));
  await a([2, 3, 1]);
  // ā†’ 1.25
}
example1();

Index

PropertyDescription
ARGUMENTSResolve all the arguments passed, as an array.
NOOPDo nothing.
IDENTITYReturn the same (first) value.
COMPARECompare two async values.
nameGet the name of a function.
lengthGet the number of parameters of a function.
bindBind this-object, and optional prefix arguments to a function.
callInvoke a function with specified this-object, and arguments provided individually.
applyInvoke a function with specified this-object, and arguments provided as an array.
isCheck if value is an async function.
isGeneratorCheck if value is a generator function.
contextifyContextify a function by accepting the first parameter as this-object.
decontextifyDecontextify a function by accepting this-object as the first argument.
negateGenerate a result-negated version of an async function.
memoizeGenerate result-cached version of an async function.
reverseGenerate a parameter-reversed version of a function.
spreadGenerate a (first) parameter-spreaded version of a function.
unspreadGenerate a (first) parameter-collapsed version of a function.
attachAttach prefix arguments to leftmost parameters of a function.
attachRightAttach suffix arguments to rightmost parameters of a function.
composeCompose async functions together, in applicative order.
composeRightCompose async functions together, such that result is piped forward.
curryGenerate curried version of a function.
curryRightGenerate right-curried version of a function.
deferGenerate deferred version of a function, that executes after the current stack has cleared.
delayGenerate delayed version of a function.
restrictGenerate restricted-use version of a function.
restrictOnceRestrict a function to be used only once.
restrictBeforeRestrict a function to be used only upto a certain number of calls.
restrictAfterRestrict a function to be used only after a certain number of calls.
debounceGenerate debounced version of a function.
debounceEarlyGenerate leading-edge debounced version of a function.
throttleGenerate throttled version of a function.
throttleEarlyGenerate leading-edge throttled version of a function.

References

npm.io ORG DOI Coverage Status Test Coverage Maintainability

1.1.25

6 months ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.24

1 year ago

1.1.21

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.20

1 year ago

1.1.16

2 years ago

1.1.17

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.17

2 years ago