7.11.77 • Published 10 months ago

@erboladaiorg/totam-ratione-deleniti v7.11.77

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

Installation

yarn add @erboladaiorg/totam-ratione-deleniti --save

Usage

const { Cache } = require("@erboladaiorg/totam-ratione-deleniti")

const maxSize = 2 // will limit max cache size upon cache.get()
const getUser = async (id) => {
  const response = await fetch("https://dummyjson.com/users/" + id)
  const { firstName, lastName, address } = await response.json()

  return {
    id,
    name: `${firstName} ${lastName}`,
    address,
  }
}

const usersCached = new Cache(getUser, maxSize)

Promise.all([
  usersCached.get(1),
  usersCached.get(2),
  usersCached.get(3),
  usersCached.get(4),
]).then((users) => {
  console.log(usersCached.data) // contains only last maxSize users (3 and 4)
  console.log(usersCached.size) // 2
})
const { Cache } = require("@erboladaiorg/totam-ratione-deleniti")
// create cache with factory function (may take any number of parameters)
const cache = new Cache(() => Math.random())

// each time you call the cache.get with same parameters
// you will get the same once lazy cached answer
const a = cache.get(1, 2, 3)
const b = cache.get(1, 2, 3) // this will return the same as above
const c = cache.get(1, 2)
const d = cache.get(1, 2, 4)

console.log(a === b) // true
console.log(a !== c) // true
console.log(a !== d) // true

API

class Cache<T = unknown> {
  constructor(factoryFunction: (...args: any[]) => T, maxSize: number = Infinity) {
    //
  }
}
  • creates a LaterMom (Lazy Map) instance with factory function for lazy cache

methods

  • get(...args: any[]): T - get entry at key created from args, lazy instantiated by factory
  • createKey(...args: any[]): string - creates string key
  • create(...args: any[]): T - wrapped factory function
  • hasKey(key: string): boolean - check if has entry at key
  • has(...args: any[]): boolean - check if has entry at key created from args
  • deleteKey(key: string): boolean - deletes entry from data at key
  • delete(...args): boolean - deletes entry from data at key created from args
  • size: number - returns size of data
  • maxSize: number - on insert the oldest items are deleted until reached maxSize

properties:

  • data: Map

Tests

$ jest
 PASS  ./index.test.js
  ✓ Calls factory once when asked for same key many times (62 ms)
  ✓ Getter is able to handle multiple arguments
  ✓ Readme has working code (1 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        0.946 s, estimated 1 s
Ran all test suites.
Done in 1.44s.

License

MIT

Author

Jacek Pietal @ 2019-2021

maketypeerrorexitforEachspeedreversedlengthpropertiesinfileendpointchildwhichsnsCSSStyleDeclarationRegExp.prototype.flagspackagesObject.keysserializetypedglobalThismonorepoES8matchesArray.prototype.findLastconfigurableslicereadablestreamjoitoArrayRxchaioptimistwritablegroupBydeepassertionesacornESnextbrowserslistidleschemehttpvariablesECMAScript 2020protocolumnECMAScript 2018traversepostcssdynamodbcontainsqueueMicrotasktoobjectrfc4122schemaprettyjapaneseemitfantasy-landmetadatasubprocessmapreducemodulesmatchbufferbytezodcurriedclonejsdomlivetypedarraycompile lesssortIteratorvariables in cssloggingprotocol-bufferssuperstructestreeawssymbolwaapivalueRegExp#flagswindowssortedparsingspecWeakSetES2022linkstructuredCloneuninstalles2018privatedeep-cloneArray.prototype.containscryptglacierobjutil.inspectlrucloudsearchdefinePropertyprivate dataroutingcommand-line@@toStringTagES2015Int32Arraylanguageerror-handlingTypeBoxweakmapformatshrinkwrapRFC-6455offsetponyfillauthenticationsimpledbInt16ArrayReactiveXbundlerObjecttoolkittypescriptjson-schema-validatorcloudformationobjectECMAScript 5prototypeautoscalingzxArrayBuffer.prototype.sliceoncees-shimsprogressdescriptionlockfileSystem.globalextramkdirplogirqbundlingasciiwriteclassnamesvpccss nestingdirectorytoolsrfc9562mergefull-widthArray.prototype.filtereslintpluginuuidwhatwgdefinejwtnumbererrorsetio-tsdragnegativeargumentiterateebsrobustdeepcloneoptimizerexpressrouteECMAScript 2016regular-expressionsyntaxerrorformsglobtostringtagsymbolsES5package managerinstallerinputdiffflagspnpm9warningreact animationsqspyyamlnpmignorevaluesbindpredictableECMAScript 2022corehotautoprefixerhelpersopensslclientkeyminimalcryptopreprocessorlintroute53channelnegative zeroArray.prototype.includestoStringTagiefnmatchsharedarraybuffercore-jsBigUint64ArrayswfPushbyteLengthimportxhrstreamseventsencryptiontranspilerhookformes-shim APIglobal objectgetoptreact posefindloadbalancing.gitignoresafecssdataviewcss variablefast-deep-clonetestingES2020s3viewsymlinkamazonlastdropes5executeUint16ArrayslotcollectionsignedES2017ES2023operating-systemhooksassignlistenerssameValueZeroinvariantES2019json-schema-validationcloudtraillesscssvalidatortrimEndes2017chineseUint32ArrayquotedescriptorshasOwnPropertysharednativeloggermrueslint-plugintoReversedfullECMAScript 2021cacheflatpopmotionargscolumnstddfromextendstatelessSymbol.toStringTagprotobufzeroarraybuffersignalnpmcircularvalidateauthfullwidthruntimeprefixentriesflattendirbootstrap cssrdscallboundArrayBuffer#sliceECMAScript 2019colorsimportexportlocalrapidMicrosofttslibclass-validatorpromiseless.jsasyncvisualwalkpostcss-pluginObject.iskeysFunction.prototype.nameflatMapES2016babel-coreArray.prototype.flatlibphonenumberreactfindLastIndextsArrayBufferES2021unicodedependency managerfastifyECMAScript 6clireact-componentreact-hook-formbannershimreact-hooksjshintemrmapfpshelperbeanstalktypanionInt8Arraytakefspropertycjkkinesisnamescss lessinspectgraphqlvalidationexit-codeiamArray.prototype.findLastIndextypesafeterminternal slotfastcopyequalityescapetacitworkflowcloudwatchcheckapolloimmutableregular expressionspawnaccessores2016MapastarraysstablejsquerystringifytrimStartmake dirObject.valuespackage.jsonmkdirmulti-packagestylingbinec2regextelephonejson-schemaAsyncIteratorbyteOffsettoSortedrgbsignalsRxJSconsumebrowserlistJSON-Schemahigher-orderselfstyleguideECMAScript 2017settingsomitpureshellcolourfilterhardlinkses-abstractpatchreduxcreateuploadeslintmkdirsredux-toolkitvarspathansireadableserializationdayjsconfignoperedactignoreless csses6gradients css3readtypemovestringfigletgenericses8intrinsictypesindicatoranimationutilitypreserve-symlinksdomlazyparserfunctionstextFloat64Arrayworkspace:*artES7real-timeincludeswafpasswordSetmanagerjsxcallgetOwnPropertyDescriptorharmonypersistentchromeenumerablebufferscallbindpipecurlPromiseiteratorasterisksassertscall-boundperformancetyped arrayoptioninterruptsttyworkersequencebcryptconcatpropposeHyBiiteration256setterconsoletrimajaxUint8ArrayES6pushenvironmentsreplayhashweaksetowncallbackdependenciesObservableselmstylesheetObject.fromEntriesBigInt64ArrayyupfindLastidentifiersECMAScriptutilscompileragentsymlinksguidproxyregular.envreact-testing-librarypinourldeterministicrequesttrimRightwait
7.11.77

10 months ago

7.11.76

10 months ago

7.10.76

10 months ago

7.10.75

10 months ago

7.10.74

10 months ago

7.10.73

11 months ago

7.10.72

11 months ago

7.10.71

11 months ago

7.10.70

11 months ago

7.10.69

11 months ago

7.10.68

11 months ago

7.10.67

11 months ago

7.10.66

11 months ago

7.10.65

11 months ago

7.10.64

11 months ago

7.10.63

11 months ago

7.10.62

11 months ago

7.10.61

11 months ago

7.10.60

11 months ago

7.10.59

11 months ago

7.10.58

11 months ago

7.10.57

11 months ago

6.10.57

11 months ago

6.10.56

11 months ago

6.9.56

11 months ago

6.9.55

11 months ago

6.9.54

11 months ago

6.9.53

11 months ago

6.9.52

11 months ago

6.9.51

11 months ago

6.9.50

11 months ago

6.9.49

11 months ago

6.9.48

11 months ago

6.9.47

11 months ago

6.9.46

11 months ago

6.9.45

12 months ago

6.9.44

12 months ago

6.9.43

12 months ago

6.9.42

12 months ago

6.9.41

12 months ago

6.9.40

12 months ago

6.9.39

12 months ago

6.9.38

12 months ago

6.8.38

12 months ago

6.8.37

12 months ago

6.8.36

12 months ago

6.8.35

12 months ago

6.8.34

12 months ago

6.8.33

12 months ago

6.8.32

12 months ago

6.8.31

12 months ago

6.8.30

12 months ago

6.8.29

12 months ago

6.7.29

12 months ago

6.7.28

12 months ago

6.7.27

1 year ago

6.7.26

1 year ago

6.6.26

1 year ago

6.6.25

1 year ago

6.6.24

1 year ago

6.6.23

1 year ago

6.6.22

1 year ago

6.6.21

1 year ago

6.6.20

1 year ago

6.6.19

1 year ago

6.6.18

1 year ago

6.6.17

1 year ago

6.5.17

1 year ago

5.5.17

1 year ago

4.5.17

1 year ago

4.5.16

1 year ago

4.5.15

1 year ago

4.4.15

1 year ago

4.4.14

1 year ago

4.4.13

1 year ago

4.4.12

1 year ago

4.4.11

1 year ago

4.4.10

1 year ago

3.4.10

1 year ago

3.3.10

1 year ago

3.2.10

1 year ago

2.2.10

1 year ago

2.2.9

1 year ago

2.2.8

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago