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

memoize-fs

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoize-fs - npm Package Compare versions

Comparing version 1.4.1 to 2.0.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

### 2.0.0 (2020-02-03)
* __BREAKING CHANGE__: drop support for node < 10
* fix: shift-parser throws when we try to use astBody: true (#17)
* update all dependencies
### 1.4.1 (2018-07-29)

@@ -2,0 +8,0 @@

80

index.js

@@ -1,11 +0,8 @@

'use strict'
const mkdirp = require('mkdirp')
const fs = require('fs')
const path = require('path')
const rmdir = require('rimraf')
const crypto = require('crypto')
const meriyah = require('meriyah')
var Promise = require('es6-promise').Promise
var mkdirp = require('mkdirp')
var fs = require('fs')
var path = require('path')
var rmdir = require('rimraf')
var crypto = require('crypto')
var parseScript = require('shift-parser').parseScript
module.exports = buildMemoizer

@@ -15,3 +12,3 @@ module.exports.getCacheFilePath = getCacheFilePath

function serialize (val) {
var circRefColl = []
const circRefColl = []
return JSON.stringify(val, function (name, value) {

@@ -34,6 +31,13 @@ if (typeof value === 'function') {

function getCacheFilePath (fn, args, opt) {
var salt = opt.salt || ''
var fnStr = (opt.noBody ? '' : opt.astBody ? JSON.stringify(parseScript(String(fn))) : String(fn))
var argsStr = serialize(args)
var hash = crypto.createHash('md5').update(fnStr + argsStr + salt).digest('hex')
const salt = opt.salt || ''
let fnStr = ''
if (!opt.noBody) {
fnStr = String(fn)
if (opt.astBody) {
fnStr = meriyah.parse(fnStr, { jsx: true, next: true })
}
fnStr = opt.astBody ? JSON.stringify(fnStr) : fnStr
}
const argsStr = serialize(args)
const hash = crypto.createHash('md5').update(fnStr + argsStr + salt).digest('hex')
return path.join(opt.cachePath, opt.cacheId, hash)

@@ -43,3 +47,3 @@ }

function buildMemoizer (options) {
var promiseCache = {}
const promiseCache = {}

@@ -57,9 +61,5 @@ // check args

return new Promise(function (resolve, reject) {
mkdirp(cachePath, function (err) {
if (err) {
reject(err)
} else {
resolve()
}
})
return mkdirp(cachePath).then(() => {
resolve()
}).catch(reject)
})

@@ -85,3 +85,3 @@ }

var optExt = opt || {}
const optExt = opt || {}

@@ -97,5 +97,5 @@ if (typeof fn !== 'function') {

return new Promise(function (resolve) {
var memFn = function () {
var args = Array.prototype.slice.call(arguments)
var fnaCb = args.length ? args[args.length - 1] : undefined
const memFn = function () {
const args = Array.prototype.slice.call(arguments)
const fnaCb = args.length ? args[args.length - 1] : undefined

@@ -106,3 +106,3 @@ if (typeof fnaCb === 'function' && fnaCb.length > 0) {

var filePath = getCacheFilePathBound(fn, args, optExt)
const filePath = getCacheFilePathBound(fn, args, optExt)

@@ -115,9 +115,9 @@ if (promiseCache[filePath]) {

function cacheAndReturn () {
var result
let result
function writeResult (r, cb) {
var resultObj,
resultString
let resultObj
let resultString
if ((r && typeof r === 'object') || typeof r === 'string') {
resultObj = {data: r}
resultObj = { data: r }
resultString = serialize(resultObj)

@@ -143,4 +143,4 @@ } else {

args.push(function (/* err, result... */) {
var cbErr = arguments[0]
var cbArgs = Array.prototype.slice.call(arguments)
const cbErr = arguments[0]
const cbArgs = Array.prototype.slice.call(arguments)
cbArgs.shift()

@@ -193,3 +193,3 @@ if (cbErr) {

fs.readFile(filePath, {encoding: 'utf8'}, function (err, data) {
fs.readFile(filePath, { encoding: 'utf8' }, function (err, data) {
if (err) {

@@ -249,3 +249,3 @@ return cacheAndReturn()

} else {
var cachPath = cacheId ? path.join(options.cachePath, cacheId) : options.cachePath
const cachPath = cacheId ? path.join(options.cachePath, cacheId) : options.cachePath
rmdir(cachPath, function (err) {

@@ -263,9 +263,9 @@ if (err) {

function getCacheFilePathBound (fn, args, opt) {
return getCacheFilePath(fn, args, Object.assign({}, opt, {cachePath: options.cachePath}))
return getCacheFilePath(fn, args, Object.assign({}, opt, { cachePath: options.cachePath }))
}
var cache = initCache(options.cachePath)
const cache = initCache(options.cachePath)
return {
'fn': function (fn, opt) {
fn: function (fn, opt) {
return cache.then(function () {

@@ -277,5 +277,5 @@ return memoizeFn(fn, opt)

},
'getCacheFilePath': getCacheFilePathBound,
'invalidate': invalidateCache
getCacheFilePath: getCacheFilePathBound,
invalidate: invalidateCache
}
}
{
"name": "memoize-fs",
"version": "1.4.1",
"version": "2.0.0",
"description": "memoize/cache in file system solution for Node.js",

@@ -22,21 +22,20 @@ "author": "Boris Diakur <contact@borisdiakur.com> (https://github.com/borisdiakur)",

"engines": {
"node": ">= 0.10.12",
"npm": ">= 1.2.32"
"node": ">= 10.0.0",
"npm": ">= 6.0.0"
},
"dependencies": {
"es6-promise": "^4.2.4",
"mkdirp": "^0.5.1",
"rimraf": "^2.6.2",
"shift-parser": "^5.2.4"
"meriyah": "^1.9.7",
"mkdirp": "^1.0.3",
"rimraf": "^3.0.1"
},
"devDependencies": {
"coveralls": "^3.0.2",
"eslint": "^5.2.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"coveralls": "^3.0.9",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"mocha": "^7.0.1",
"mocha-lcov-reporter": "1.3.0"

@@ -43,0 +42,0 @@ },

@@ -7,3 +7,2 @@ # memoize-fs

[![Coverage Status](https://coveralls.io/repos/borisdiakur/memoize-fs/badge.svg?branch=master)](https://coveralls.io/r/borisdiakur/memoize-fs?branch=master)
[![Dependency Status](https://gemnasium.com/borisdiakur/memoize-fs.svg)](https://gemnasium.com/borisdiakur/memoize-fs)
[![npm version](https://badge.fury.io/js/memoize-fs.svg)](http://badge.fury.io/js/memoize-fs)

@@ -197,2 +196,3 @@ [![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

- It converts `NaN` to `undefined` silently
- It converts all objects, no matter what class they were an instance of, to objects with prototype `Object` (see [#16](https://github.com/borisdiakur/memoize-fs/issues/16))

@@ -199,0 +199,0 @@ Some "limitations" can not (yet?) be worked around:

Sorry, the diff of this file is not supported yet

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