0.2.2 • Published 2 years ago

ts-utility-lib v0.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

TS Utility Library

This is a library with utility functions for typescript.

Usage

An example usage would look something like the following

  // Get a user from an api call and cache it with the memoize function
  const getUser = useMemoize(async (id: string) => promise(id), {
    getKey: id => id,
  });

  // Wrap a single function returning a promise which is used multiple times
  const resolveGetUser = usePromiseAll((user: User) =>
    getUser(user.id).then(result => (user.promise = result))
  );

  // Wrap multiple promise with the promise all function
  const resolveGetUserAndProduct = usePromiseAll((user: User) => [
    getUser(user.id).then(result => (user.promise = result)),
    getProduct(user.productId).then(result => (user.product = result))
  ]);
  
  // Collect all promises
  for (const user of userArray) {
    resolveGetUser(user);
  }

  // Resolve all promises simultaneously
  await resolveGetUser.resolve();
0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago