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

fs-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

fs-memoize - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

80

dist/index.js

@@ -1,17 +0,42 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var fs = require('fs');
var path = require('path');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import fs from 'fs';
import path from 'path';
var DEFAULT_CACHE_DIR = '/tmp/fs-memoize';
var TTL_EXTENSION = '.ttl';
var fsMemoize = function (fn, _a) {
export var fsMemoize = function (fn, _a) {
var cacheBaseKey = _a.cacheBaseKey, cacheDirOverride = _a.cacheDir, ttl = _a.ttl;

@@ -23,5 +48,5 @@ return function () {

}
return tslib.__awaiter(void 0, void 0, void 0, function () {
return __awaiter(void 0, void 0, void 0, function () {
var cacheDir, cacheKey, contentPath, ttlPath, cacheMiss, ttl_1;
return tslib.__generator(this, function (_a) {
return __generator(this, function (_a) {
if (process.env.NODE_ENV === 'test') {

@@ -32,7 +57,7 @@ return [2, fn.apply(void 0, args)];

cacheKey = "" + cacheBaseKey + encodeURIComponent(JSON.stringify(args));
contentPath = path__default['default'].join(cacheDir, cacheKey);
contentPath = path.join(cacheDir, cacheKey);
ttlPath = "" + contentPath + TTL_EXTENSION;
cacheMiss = function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
cacheMiss = function () { return __awaiter(void 0, void 0, void 0, function () {
var content;
return tslib.__generator(this, function (_a) {
return __generator(this, function (_a) {
switch (_a.label) {

@@ -42,4 +67,4 @@ case 0: return [4, fn.apply(void 0, args)];

content = _a.sent();
fs__default['default'].writeFileSync(contentPath, JSON.stringify(content));
fs__default['default'].writeFileSync(ttlPath, JSON.stringify(new Date(Date.now() + ttl)));
fs.writeFileSync(contentPath, JSON.stringify(content));
fs.writeFileSync(ttlPath, JSON.stringify(new Date(Date.now() + ttl)));
return [2, content];

@@ -49,9 +74,9 @@ }

}); };
if (!fs__default['default'].existsSync(cacheDir)) {
fs__default['default'].mkdirSync(cacheDir);
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir);
}
if (fs__default['default'].existsSync(contentPath) && fs__default['default'].existsSync(ttlPath)) {
ttl_1 = new Date(JSON.parse(fs__default['default'].readFileSync(ttlPath, 'utf8')));
if (fs.existsSync(contentPath) && fs.existsSync(ttlPath)) {
ttl_1 = new Date(JSON.parse(fs.readFileSync(ttlPath, 'utf8')));
if (ttl_1.valueOf() > new Date().valueOf()) {
return [2, JSON.parse(fs__default['default'].readFileSync(contentPath, 'utf8'))];
return [2, JSON.parse(fs.readFileSync(contentPath, 'utf8'))];
}

@@ -65,2 +90,3 @@ else {

}
return [2];
});

@@ -70,3 +96,1 @@ });

};
exports.fsMemoize = fsMemoize;
{
"name": "fs-memoize",
"version": "1.1.0",
"version": "1.1.1",
"main": "dist/index.js",

@@ -11,3 +11,3 @@ "types": "dist/index.d.ts",

"lint": "eslint --ext .ts,.tsx src",
"build": "rollup -c",
"build": "rm -rf dist && tsc",
"jest": "jest",

@@ -17,4 +17,2 @@ "prepublishOnly": "yarn build"

"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^26.0.23",

@@ -29,7 +27,5 @@ "@typescript-eslint/eslint-plugin": "^4.27.0",

"jest": "^27.0.4",
"rollup": "^2.52.1",
"ts-jest": "^27.0.3",
"tslib": "^2.3.0",
"typescript": "^4.3.4"
}
}
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