Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@keyvhq/memoize

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@keyvhq/memoize - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

4

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://keyv.js.org",
"version": "1.2.2",
"version": "1.2.3",
"main": "src/index.js",

@@ -54,3 +54,3 @@ "author": {

},
"gitHead": "7b8357384ebcc9936a7211d8b698a1d5e48ce9bb"
"gitHead": "787bc0f13a6e947f463a30c5b873639e962a0e69"
}

@@ -7,2 +7,6 @@ 'use strict'

const isFunction = input => typeof input === 'function'
const isNumber = input => typeof input === 'number'
const isString = input => typeof input === 'string'
const isUndefined = input => input === undefined
const identity = value => value

@@ -22,9 +26,9 @@

const keyv = keyvOptions instanceof Keyv ? keyvOptions : new Keyv(keyvOptions)
const ttl = typeof rawTtl === 'function' ? rawTtl : () => rawTtl
const staleTtl =
typeof rawStaleTtl === 'function'
? rawStaleTtl
: typeof rawStaleTtl === 'number'
const ttl = isFunction(rawTtl) ? rawTtl : () => rawTtl
const staleTtl = isFunction(rawStaleTtl)
? rawStaleTtl
: isNumber(rawStaleTtl)
? () => rawStaleTtl
: undefined
: rawStaleTtl
const pending = Object.create(null)

@@ -41,3 +45,3 @@

const raw = await keyv.store.get(keyv._getKeyPrefix(key))
return typeof raw === 'string' ? keyv.deserialize(raw) : raw
return isString(raw) ? keyv.deserialize(raw) : raw
}

@@ -52,5 +56,3 @@

return getRaw(key).then(data => {
if (!data || data.value === undefined) {
throw new Error('Not found')
}
if (!data || isUndefined(data)) throw new Error('Not found')
return data.value

@@ -77,3 +79,3 @@ })

if (pending[key] !== undefined) {
if (!isUndefined(pending[key])) {
return pAny([getStoredValue(key), pending[key]])

@@ -83,8 +85,10 @@ }

pending[key] = getRaw(key).then(async data => {
const hasValue = data ? data.value !== undefined : false
const hasValue = data ? !isUndefined(data.value) : false
const hasExpires = hasValue && typeof data.expires === 'number'
const ttlValue = hasExpires ? data.expires - Date.now() : undefined
const isExpired = staleTtl === undefined && hasExpires && ttlValue < 0
const isStale =
staleTtl !== undefined && hasExpires && ttlValue < staleTtl(data.value)
const staleTtlValue =
hasExpires && !isUndefined(staleTtl) ? staleTtl(data.value) : false
const isExpired = staleTtlValue === false && hasExpires && ttlValue < 0
const isStale = staleTtlValue && ttlValue < staleTtlValue
const info = { hasValue, key, isExpired, isStale }

@@ -91,0 +95,0 @@ const done = value => (objectMode ? [value, info] : value)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc