How to use p-memoize - 7 common examples

To help you get started, we’ve selected a few p-memoize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Julien-Broyard / JikanTS / src / utils.ts View on Github external
// Constants
export const baseUrl = "https://api.jikan.moe/v3";
export const queue = new PQueue({ concurrency: 2 });

// Custom http client
const http = got.extend({
  baseUrl,
  headers: {
    "User-Agent": `${pkg.name} / ${pkg.version} (${pkg.repository.url})`
  },
  json: true
});

// Memoized http client
export const api = PMemoize(http, { cache: new LRU({ maxSize: 1000 }) });

// Fast JSON logger
export const Logger = pino({
  name: "jikants",
  prettyPrint: true
});
github textlint-rule / textlint-rule-no-dead-link / src / no-dead-link.js View on Github external
function reporter(context, options = {}) {
  const { Syntax, getSource, report, RuleError, fixer, getFilePath } = context;
  const helper = new RuleHelper(context);
  const ruleOptions = { ...DEFAULT_OPTIONS, ...options };
  const isAliveURI = createCheckAliveURL(ruleOptions);
  // 30sec memorized
  const memorizedIsAliveURI = pMemoize(isAliveURI, {
    maxAge: 30 * 1000,
  });
  /**
   * Checks a given URI's availability and report if it is dead.
   * @param {TextLintNode} node TextLintNode the URI belongs to.
   * @param {string} uri a URI string to be linted.
   * @param {number} index column number the URI is located at.
   * @param {number} maxRetryCount retry count of linting
   */
  const lint = async ({ node, uri, index }, maxRetryCount) => {
    if (isIgnored(uri, ruleOptions.ignore)) {
      return;
    }

    if (isRelative(uri)) {
      if (!ruleOptions.checkRelative) {
github faceit-enhancer / faceit-enhancer / src / content / helpers / faceit-api.js View on Github external
payload
    } = json

    if ((result && result !== 'ok') || (code && code !== 'OPERATION-OK')) {
      throw new Error(json)
    }

    return camelcaseKeys(payload || json, { deep: true })
  } catch (err) {
    console.error(err)

    return null
  }
}

const fetchApiMemoized = pMemoize(fetchApi, {
  maxAge: CACHE_TIME
})

export const getUser = userId => fetchApiMemoized(`/core/v1/users/${userId}`)

export const getPlayer = nickname =>
  fetchApiMemoized(`/core/v1/nicknames/${nickname}`)

export const getPlayerMatches = (userId, game, size = 21) =>
  fetchApiMemoized(
    `/stats/v1/stats/time/users/${userId}/games/${game}?size=${size}`
  )

export const getPlayerStats = async (userId, game, size = 20) => {
  if (game !== 'csgo') {
    return null
github dherault / serverless-offline / src / lambda / handler-runner / docker-runner / DockerImage.js View on Github external
'pull',
        '--disable-content-trust=false',
        imageNameTag,
      ])
    } catch (err) {
      console.error(err.stderr)
      throw err
    }
  }

  async pull() {
    return DockerImage._memoizedPull(this._imageNameTag)
  }
}

DockerImage._memoizedPull = promiseMemoize(DockerImage._pullImage)
github feross / bitmidi.com / src / lib / memo.js View on Github external
export function memo (fn) {
  return pMemoize(fn, {
    maxAge: MEMO_MAX_AGE,
    cache: new QuickLRU({ maxSize: MEMO_MAX_SIZE })
  })
}
github codesandbox / codesandboxer / packages / bitbucket-codesandboxer / src / components / GitFileExplorer.js View on Github external
import PropTypes from 'prop-types';
import pMemoize from 'p-memoize';
import AsyncSelect from 'react-select/lib/Async';
import * as bitbucket from '../utils/bitbucket';

type State = {
  inputValue: string,
};
const propTypes = {
  onFileSelect: PropTypes.func,
  repoName: PropTypes.string,
  repoOwner: PropTypes.string,
  repoRef: PropTypes.string,
};

const memoizedBBCall = pMemoize(bitbucket.getBitbucketDir);

function bbDirListToOptions(dirList) {
  return dirList.map(file => {
    const isDir = file.type === 'directory';
    const label = isDir ? `📂 ${file.path}/` : `📄 ${file.path}`;
    const value = isDir ? `${file.path}/` : file.path;
    return {
      value,
      label,
      isDir,
    };
  });
}

function inputValueToDirPath(inputValue) {
  const re = /(\S+\/).*/;
github simpleviewinc / mongolayer / src / index.js View on Github external
var _clearConnectCache = function() {
	pMemoize.clear(_getClientCached);
}

p-memoize

Memoize promise-returning & async functions

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Popular p-memoize functions