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

file-mapping

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-mapping - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

lib/index.js

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

var O=Object.create;var h=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var N=(r,t)=>{for(var e in t)h(r,e,{get:t[e],enumerable:!0})},v=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of j(t))!L.call(r,n)&&n!==e&&h(r,n,{get:()=>t[n],enumerable:!(i=M(t,n))||i.enumerable});return r};var g=(r,t,e)=>(e=r!=null?O(J(r)):{},v(t||!r||!r.__esModule?h(e,"default",{value:r,enumerable:!0}):e,r)),P=r=>v(h({},"__esModule",{value:!0}),r);var k={};N(k,{Collection:()=>f,Mapping:()=>p,mapping:()=>y});module.exports=P(k);var x=g(require("events")),u=g(require("fs"));function b(r,t=0){let e=new Set;return JSON.stringify(r,(i,n)=>{if(n&&typeof n=="object"){if(e.has(n))return;e.add(n)}else if(typeof n=="bigint")return n.toString();return n},t)}function y(r,t,e){let i=u.default.existsSync(r)?JSON.parse(u.default.readFileSync(r,"utf8")):JSON.parse(b(t))||Object.create(null),n=Promise.resolve(!0),a=0,w=new Set,T={get:(s,o)=>{let c=s[o];return typeof c=="object"&&c!==null&&!w.has(s[o])&&(s[o]=new Proxy(c,T),w.add(s[o])),s[o]},set:(s,o,c)=>(s[o]=c,a++,(async()=>(await n,a!==0&&(n=new Promise(_=>{u.default.writeFileSync(r,JSON.stringify(i),"utf8"),e&&e(i,a),a=0,_(!0)}))))(),!0)};return new Proxy(i,T)}var p=class extends x.default{constructor(e,i){super();this._written=0;this._file=e,this._data=this.map(e,i)._data}get data(){return this._data}get file(){return this._file}get written(){return this._written}map(e,i){return this._data=y(e,i,(n,a)=>{this._written++,this.emit("write",n,a)}),this._file=e,this}};var d=g(require("fs")),m=g(require("path")),S=require("crypto");var f=class{constructor(t,e){this.collection=new Map;this.storage=m.default.resolve(t),this.proto=e,d.default.existsSync(this.storage)||d.default.mkdirSync(this.storage,{recursive:!0})}get(t){return this.collection.has(t)||this.collection.set(t,new p(m.default.resolve(this.storage,(0,S.createHash)("sha256").update(t).digest("hex")+".json"),this.proto)),this.collection.get(t)}data(t){return this.get(t).data}delete(t){if(this.collection.has(t)){let e=this.get(t);return d.default.unlinkSync(e.file),this.collection.delete(t)}return!1}};0&&(module.exports={Collection,Mapping,mapping});
var O=Object.create;var h=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var N=(r,t)=>{for(var e in t)h(r,e,{get:t[e],enumerable:!0})},v=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!L.call(r,n)&&n!==e&&h(r,n,{get:()=>t[n],enumerable:!(i=j(t,n))||i.enumerable});return r};var g=(r,t,e)=>(e=r!=null?O(J(r)):{},v(t||!r||!r.__esModule?h(e,"default",{value:r,enumerable:!0}):e,r)),P=r=>v(h({},"__esModule",{value:!0}),r);var k={};N(k,{Collection:()=>l,Mapping:()=>c,mapping:()=>y});module.exports=P(k);var x=g(require("events")),u=g(require("fs"));function b(r,t=0){let e=new Set;return JSON.stringify(r,(i,n)=>{if(n&&typeof n=="object"){if(e.has(n))return;e.add(n)}else if(typeof n=="bigint")return n.toString();return n},t)}function y(r,t,e){let i=u.default.existsSync(r)?JSON.parse(u.default.readFileSync(r,"utf8")):typeof t=="object"?JSON.parse(b(t)):Object.create(null),n=Promise.resolve(!0),a=0,w=new Set,T={get:(s,o)=>{let p=s[o];return typeof p=="object"&&p!==null&&!w.has(s[o])&&(s[o]=new Proxy(p,T),w.add(s[o])),s[o]},set:(s,o,p)=>(s[o]=p,a++,(async()=>(await n,a!==0&&(n=new Promise(_=>{u.default.writeFileSync(r,JSON.stringify(i),"utf8"),e&&e(i,a),a=0,_(!0)}))))(),!0)};return new Proxy(i,T)}var c=class extends x.default{constructor(e,i){super();this._written=0;this._file=e,this._data=this.map(e,i)._data}get data(){return this._data}get file(){return this._file}get written(){return this._written}map(e,i){return this._data=y(e,i,(n,a)=>{this._written++,this.emit("write",n,a)}),this._file=e,this}};var d=g(require("fs")),f=g(require("path")),S=require("crypto");var l=class{constructor(t,e){this.collection=new Map;this.storage=f.default.resolve(t),this.proto=e,d.default.existsSync(this.storage)||d.default.mkdirSync(this.storage,{recursive:!0})}get(t){return this.collection.has(t)||this.collection.set(t,new c(f.default.resolve(this.storage,(0,S.createHash)("sha256").update(t).digest("hex")+".json"),this.proto)),this.collection.get(t)}data(t){return this.get(t).data}delete(t){if(this.collection.has(t)){let e=this.get(t);return d.default.unlinkSync(e.file),this.collection.delete(t)}return!1}};0&&(module.exports={Collection,Mapping,mapping});
{
"name": "file-mapping",
"version": "0.2.0",
"version": "0.2.1",
"description": "A library that maps JSON file and in-memory data, and using lazy-writing strategy to reduce disk I/O.",

@@ -5,0 +5,0 @@ "author": "JacobLinCool <jacoblincool@gmail.com> (https://github.com/JacobLinCool)",

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