New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

denim-memoize

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

denim-memoize - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.idea/denim-memoize.iml

10

index.js

@@ -1,10 +0,8 @@

export default (fn) => {
export default fn => {
const cache = {}
return (...fnArgs) => {
const cacheKey = fnArgs.toString()
if(typeof cache[cacheKey] === 'undefined'){
let result = fn(...fnArgs)
cache[cacheKey] = result
if (typeof cache[cacheKey] === 'undefined') {
let result = fn(...fnArgs)
cache[cacheKey] = result
}

@@ -11,0 +9,0 @@ return cache[cacheKey]

28

index.spec.js
import { expect, assert } from 'chai'
import memoizeFactory from './index'
describe('memoizeFactory', ()=>{
it('should return a function', ()=>{
const result = memoizeFactory(()=>{})
describe('memoizeFactory', () => {
it('should return a function', () => {
const result = memoizeFactory(() => {})
assert.isFunction(result)
})
it('should return memoized result of function', ()=> {
it('should return memoized result of function', () => {
const result_gen = () => Math.floor(Math.random() * 100000) + 1

@@ -24,5 +24,5 @@ const functionToMemoize = () => result_gen()

it('should return memoized result of function with parameters', ()=> {
it('should return memoized result of function with parameters', () => {
const result_gen = () => Math.floor(Math.random() * 100000) + 1
const functionToMemoize = (x) => result_gen()
const functionToMemoize = x => result_gen()
const nonMemoizeResult1 = functionToMemoize(1)

@@ -38,2 +38,18 @@ const nonMemoizeResult2 = functionToMemoize(1)

})
it('should return memoized result of async funcition', done => {
const result_gen = () => Math.floor(Math.random() * 100000) + 1
const functionToMemoize = async x => result_gen()
const nonMemoizeResult1 = functionToMemoize(1)
const nonMemoizeResult2 = functionToMemoize(1)
const memoizedFunction = memoizeFactory(functionToMemoize)
const memoizeResult1 = memoizedFunction(1)
const memoizeResult2 = memoizedFunction(1)
Promise.all([memoizeResult1, memoizeResult2]).then(results => {
assert.notEqual(nonMemoizeResult1, nonMemoizeResult2)
assert.strictEqual(results[0], results[1])
done()
})
})
})
{
"name": "denim-memoize",
"version": "1.0.1",
"version": "1.0.2",
"description": "Utility to memoize functions",

@@ -5,0 +5,0 @@ "main": "index.js",

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