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

A library that maps JSON file and in-memory data, and using lazy-writing strategy to reduce disk I/O.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

File Mapping

NPM

A library that maps JSON file and in-memory data, and using lazy-writing strategy to reduce disk I/O.

Usage

Simple Usage

import { mapping } from "file-mapping";

const data = mapping("./data.json", {});

data.name = "Jacob";
data.age = 19;

// Then, the file should be written automatically and only once.

Nested Data

import { mapping } from "file-mapping";

const data = mapping("./data.json", {});

data.collection = {};
data.collection.document = {};
data.collection.document.something = "something";
// Nested data are also supported.

Listen to file write

import { mapping } from "file-mapping";

const data = mapping("./data.json", {}, (data, changes) => {
    console.log(`write ${changes} changes into disk`, data);
});

for (let i = 0; i < 1000; i++) {
    data[`key-${i}`] = `value-${i}`;
}

Event Emitter style

Mapping also count the number of write operations internally, and you can use .data, .file, .written to get the informations.

import { Mapping } from "file-mapping";

const mapping = new Mapping("./data.json", {});
const data = mapping.data;

mapping.on("write", (data, changes) => {
    console.log(`write ${changes} changes into disk`, data);
});

for (let i = 0; i < 1000; i++) {
    data[`key-${i}`] = `value-${i}`;
}

Keywords

FAQs

Package last updated on 15 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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