npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@joker7t/common-core

v1.0.2

Published

NPM page: https://www.npmjs.com/package/@joker7t/common-core

Downloads

4

Readme

common-core

NPM page: https://www.npmjs.com/package/@joker7t/common-core

Installation:

Using Yarn

yarn add @joker7t/common-core

Using NPM

npm i @joker7t/common-core

Features:

Utils

  • memoize(func: T): T
    • An implementation of lodash's memoize function except it will memoize a function call based on all function arguments.
  • errorText(error: unknown): string
    • Parsing error to message, return turn default message if exist otherwise return default error message ('Oops, an unexpected error occurred').
  • groupByKeySet(items: T[], keySelector: (value: T) => string[])
    • Grouping items by each key in keySelector
  • dateToIsoDate(dateString: string): string
    • Transform a DD/MM/YYYY date string to ISO date string
  • isIsoDateValid(isoDateString: any): isoDateString is string
    • Validate an ISO date string
  • formatNumber(num: number)
    • Format number to K base.
  • formatFileSize(size: number)
    • Format file size to ['B', 'KB', 'MB', 'GB', 'TB'] suffix.

Async utils

  • HttpClient
    • The client is build on top of fetch. This means you can provide a fetch implementation in the browser i.e. window.fetch, or node-fetch for NodeJS.
      • fetch: Works the same as the global fetch function in Javascript. This is the only mandatory ClientOption.
      • baseUrl: This configures the default baseUrl for our fetch requests.
      • headers: This configures the default request headers.
      • fetchOptions: These are options that are passed onto fetch calls. They are used to set the http agent in NodeJS.
      • retry: There are a few different strategies you may use to retry calls. By default, an exponential backoff with 4 attempts is used but you may choose this amount of yourself if you wish. You may also decide the backoff strategy. This may either ber backoffFixed where a retry is consistently made after a certain number of seconds, or backoffExponential where the backoff starts with an initial number of seconds and increases up to a maximum number of seconds. For example, to create a retry strategy 10 times with 1 attempt every 2 seconds increasing with and extra 3 seconds each time.
        • The following errors are retried by default:
          • ApiTooManyRequestsError
          • ApiGatewayTimeoutError
          • ApiServiceUnavailableError
          • ApiNetworkError
      • rateLimit: Configures client-side rate limiting. The default client-side rate limit is set to 1 request/second to match the default client gateway limit. if you are using the HttpClient with the service gateway you will want to configure a rate limit matching the service's configured gateway rate limit.
      • disableErrorTransform: This option cannot be used when the HttpClient is passed to a generated API client class, but is useful when using the HttpClient as a drop in replacement for window.fetch. The error transform refers to the conversion of http errors to the corresponding x-rest error object i.e. ApiNotFoundError. Given this conversion is non-standard fetch behavior we have provided the option to turn it off.
  • Lock
    • acquire waits for the lock and then executes the provided callback ensuring the lock is released after the callback completes.
    • example:
      const lock = new Lock();
            
      //..
            
      await lock.acquire(() => {
      // critical section
      });
  • sleep(seconds: number)
    • returns a promise that resolves after for the given number of seconds using setTimeout.

Error templates

  • Template for common api errors:
    • CustomError
    • ApiBadRequestError
    • ApiUnauthorizedError
    • ApiForbiddenError
    • ApiNotFoundError
    • ApiRequestTimeoutError
    • ApiConflictError
    • ApiUnprocessableEntityError
    • ApiTooManyRequestsError
    • ApiInternalError
    • ApiServiceUnavailableError
    • ApiGatewayTimeoutError
    • ApiNetworkError

Versions:

You can check all the versions here.