How to use the moize.default function in moize

To help you get started, we’ve selected a few moize 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 ehmicky / log-process-errors / gulp / utils / localpack-code / root.js View on Github external
const pkgDir = require('pkg-dir')
const moize = require('moize').default

// Retrieve package root directory
const getPackageRoot = async function(cwd) {
  const packageRoot = await pkgDir(cwd)

  assert(
    packageRoot !== null,
    'The root directory of this package was not found',
  )

  return packageRoot
}

const mGetPackageRoot = moize(getPackageRoot)

module.exports = {
  getPackageRoot: mGetPackageRoot,
}
github ehmicky / log-process-errors / gulp / utils / get-versions / range.js View on Github external
}

// `opts.range` defaults to `engines.node` field in `package.json`
const getDefaultRange = function() {
  const packageRoot = pkgDir.sync()

  if (packageRoot === null) {
    return
  }

  // eslint-disable-next-line import/no-dynamic-require
  const { engines: { node } = {} } = require(`${packageRoot}/package.json`)
  return node
}

const mGetDefaultRange = moize(getDefaultRange)

const normalizeRange = function({ range }) {
  const rangeA = validRange(range)
  assert(rangeA !== null, `Invalid Node.js versions range: ${range}`)
  return rangeA
}

// Filter releases using `opts.range` and only keep major releases that have
// at lease one minor/patch release.
const applyOnMajorReleases = function({ majorReleases, range }) {
  return majorReleases
    .map(majorRelease => applyOnMajorRelease({ majorRelease, range }))
    .filter(hasReleases)
}

const applyOnMajorRelease = function({
github ehmicky / log-process-errors / gulp / utils / get-versions / all.js View on Github external
// eslint-disable-next-line import/no-internal-modules
const RELEASE_SCHEDULE = require('node-releases/data/release-schedule/release-schedule')
const { major, minor } = require('semver')
const moize = require('moize').default

// Retrieve all Node.js releases, grouped by major release.
// Major release also indicate:
//  - whether they are currently supported
//  - whether they are/were LTS
const getAllMajorReleases = function() {
  return Object.entries(RELEASE_SCHEDULE)
    .map(normalizeMajorRelease)
    .filter(hasReleases)
}

const mGetAllMajorReleases = moize(getAllMajorReleases)

const normalizeMajorRelease = function([
  majorVersion,
  { start, end, codename },
]) {
  // Strip 'v' from version
  const majorVersionA = majorVersion.slice(1)

  const supported = isSupported({ start, end })
  const lts = codename !== undefined
  const releases = getReleases({ majorVersion: majorVersionA })

  return { majorVersion: majorVersionA, supported, lts, releases }
}

// Check if Node.js is currently supporting this version
github anywhichway / nano-memoize / benchmark / index.js View on Github external
const runSingleParameterSuite = () => {
  const fibonacciSuite = new Benchmark.Suite('Single parameter');
  const fibonacciNumber = 35;

  const mUnderscore = underscore(fibonacci);
  const mLodash = lodash(fibonacci);
 // const mRamda = ramda(fibonacci);
  const mMemoizee = memoizee(fibonacci);
  const mFastMemoize = fastMemoize(fibonacci);
  const mAddyOsmani = addyOsmani(fibonacci);
  const mMemoizerific = memoizerific(Infinity)(fibonacci);
  const mLruMemoize = lruMemoize(Infinity)(fibonacci);
  const mMoize = moize(fibonacci);
  const mMicroMemoize = microMemoize(fibonacci);
  const mIMemoized = iMemoized.memoize(fibonacci);
  const mNano = nanomemoize(fibonacci);


  return new Promise((resolve) => {
    fibonacciSuite
	    .add('nano-memoize', () => {
	    	mNano(fibonacciNumber);
	    })
      .add('addy-osmani', () => {
        mAddyOsmani(fibonacciNumber);
      })
      .add('lodash', () => {
        mLodash(fibonacciNumber);
      })
github aduth / memize / benchmark / index.js View on Github external
const runMultiplePrimitiveSuite = () => {
	const fibonacciSuite = new Benchmark.Suite( 'Multiple parameters (Primitive)' );
	const fibonacciNumber = 35;
	const isComplete = false;

	const mMemoizee = memoizee( fibonacciMultiplePrimitive );
	const mFastMemoize = fastMemoize( fibonacciMultiplePrimitive );
	const mMemoizejs = memoizejs( fibonacciMultiplePrimitive );
	const mMemoizerific = memoizerific( Infinity )( fibonacciMultiplePrimitive );
	const mLruMemoize = lruMemoize( Infinity )( fibonacciMultiplePrimitive );
	const mMoize = moize( fibonacciMultiplePrimitive );
	const mMoizeSerialize = moize.serialize( fibonacciMultiplePrimitive );
	const mMemize = memize( fibonacciMultiplePrimitive );

	return new Promise( ( resolve ) => {
		fibonacciSuite
			.add( 'memoizee', () => {
				mMemoizee( fibonacciNumber, isComplete );
			} )
			.add( 'fast-memoize', () => {
				mFastMemoize( fibonacciNumber, isComplete );
			} )
			.add( 'memoizejs', () => {
				mMemoizejs( fibonacciNumber, isComplete );
			} )
			.add( 'memoizerific', () => {
				mMemoizerific( fibonacciNumber, isComplete );
github anywhichway / nano-memoize / benchmark / index.js View on Github external
const runMultiplePrimitiveSuite = () => {
  const fibonacciSuite = new Benchmark.Suite('Multiple parameters (Primitive)');
  const fibonacciNumber = 35;
  const isComplete = false;

  const mMemoizee = memoizee(fibonacciMultiplePrimitive);
  const mFastMemoize = fastMemoize(fibonacciMultiplePrimitive);
  const mAddyOsmani = addyOsmani(fibonacciMultiplePrimitive);
  const mMemoizerific = memoizerific(Infinity)(fibonacciMultiplePrimitive);
  const mLruMemoize = lruMemoize(Infinity)(fibonacciMultiplePrimitive);
  const mMoize = moize(fibonacciMultiplePrimitive);
  const mMicroMemoize = microMemoize(fibonacciMultiplePrimitive);
  const mIMemoized = iMemoized.memoize(fibonacciMultiplePrimitive);
  const mNano = nanomemoize(fibonacciMultiplePrimitive);

  return new Promise((resolve) => {
    fibonacciSuite
	    .add('nano-memoize', () => {
	    	mNano(fibonacciNumber, isComplete);
	    })
      .add('addy-osmani', () => {
        mAddyOsmani(fibonacciNumber, isComplete);
      })
      .add('lru-memoize', () => {
        mLruMemoize(fibonacciNumber, isComplete);
      })
      .add('memoizee', () => {
github aduth / memize / benchmark / index.js View on Github external
const runMultipleObjectSuite = () => {
	const fibonacciSuite = new Benchmark.Suite( 'Multiple parameters (Object)' );
	const fibonacciNumber = 35;
	const isComplete = {
		isComplete: false,
	};

	const mMemoizee = memoizee( fibonacciMultipleObject );
	const mFastMemoize = fastMemoize( fibonacciMultipleObject );
	const mMemoizejs = memoizejs( fibonacciMultipleObject );
	const mMemoizerific = memoizerific( Infinity )( fibonacciMultipleObject );
	const mLruMemoize = lruMemoize( Infinity )( fibonacciMultipleObject );
	const mMoize = moize( fibonacciMultipleObject );
	const mMoizeSerialize = moize.serialize( fibonacciMultipleObject );
	const mMemize = memize( fibonacciMultipleObject );

	return new Promise( ( resolve ) => {
		fibonacciSuite
			.add( 'memoizee', () => {
				mMemoizee( fibonacciNumber, isComplete );
			} )
			.add( 'fast-memoize', () => {
				mFastMemoize( fibonacciNumber, isComplete );
			} )
			.add( 'memoizejs', () => {
				mMemoizejs( fibonacciNumber, isComplete );
			} )
			.add( 'memoizerific', () => {
				mMemoizerific( fibonacciNumber, isComplete );
github aduth / memize / benchmark / index.js View on Github external
const runSingleParameterSuite = () => {
	const fibonacciSuite = new Benchmark.Suite( 'Single parameter' );
	const fibonacciNumber = 35;

	const mUnderscore = underscore( fibonacci );
	const mLodash = lodash( fibonacci );
	const mRamda = ramda( fibonacci );
	const mMemoizee = memoizee( fibonacci );
	const mFastMemoize = fastMemoize( fibonacci );
	const mMemoizejs = memoizejs( fibonacci );
	const mMemoizerific = memoizerific( Infinity )( fibonacci );
	const mLruMemoize = lruMemoize( Infinity )( fibonacci );
	const mMoize = moize( fibonacci );
	const mMoizeSerialize = moize.serialize( fibonacci );
	const mMemize = memize( fibonacci );

	return new Promise( ( resolve ) => {
		fibonacciSuite
			.add( 'underscore', () => {
				mUnderscore( fibonacciNumber );
			} )
			.add( 'lodash', () => {
				mLodash( fibonacciNumber );
			} )
			.add( 'memoizee', () => {
				mMemoizee( fibonacciNumber );
			} )
			.add( 'ramda', () => {
				mRamda( fibonacciNumber );
github ehmicky / log-process-errors / gulp / utils / get-versions / main.js View on Github external
const moize = require('moize').default

const { getAllMajorReleases } = require('./all')
const { filterReleases } = require('./filter')
const { applyRange } = require('./range')
const { pickVersions } = require('./pick')

const getNodeVersions = function({ range, old = false, lts = false } = {}) {
  const majorReleases = getAllMajorReleases()
  const majorReleasesA = filterReleases({ majorReleases, old, lts })
  const majorReleasesB = applyRange({ majorReleases: majorReleasesA, range })
  const versions = pickVersions({ majorReleases: majorReleasesB })
  return versions
}

const mGetNodeVersions = moize(getNodeVersions)

module.exports = {
  getNodeVersions: mGetNodeVersions,
}
github anywhichway / nano-memoize / benchmark / index.js View on Github external
const runMultipleObjectSuite = () => {
  const fibonacciSuite = new Benchmark.Suite('Multiple parameters (Object)');
  const fibonacciNumber = 35;
  const isComplete = {
    isComplete: false
  };

  const mMemoizee = memoizee(fibonacciMultipleObject);
  const mFastMemoize = fastMemoize(fibonacciMultipleObject);
  const mAddyOsmani = addyOsmani(fibonacciMultipleObject);
  const mMemoizerific = memoizerific(Infinity)(fibonacciMultipleObject);
  const mLruMemoize = lruMemoize(Infinity)(fibonacciMultipleObject);
  const mMoize = moize(fibonacciMultipleObject);
  const mMicroMemoize = microMemoize(fibonacciMultipleObject);
  const mNano = nanomemoize(fibonacciMultipleObject);
  
  return new Promise((resolve) => {
    fibonacciSuite
	    .add('nano-memoize', () => {
	    	mNano(fibonacciNumber,isComplete);
	    })
      .add('addy-osmani', () => {
        mAddyOsmani(fibonacciNumber, isComplete);
      })
      .add('lru-memoize', () => {
        mLruMemoize(fibonacciNumber, isComplete);
      })
      .add('memoizee', () => {
        mMemoizee(fibonacciNumber, isComplete);

moize

Blazing fast memoization based on all parameters passed

MIT
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis