npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lazy-load-store

v1.7.2

Published

Effortlessly store large nested object values in files with automatic retrieval and reference handling.

Downloads

74

Readme

📦 lazy-load-store

Armazene facilmente valores grandes de objetos aninhados em arquivos com recuperação automática e manuseio de referências.


🚀 Instalação

npm install lazy-load-store

📖 Uso

Exemplo básico

import { Storage } from "lazy-load-store";

// Cria ou recupera a instância singleton
const storage = new Storage();

// Armazena uma string pequena diretamente
storage.smallValue = "Hello, world!";
console.log(storage.smallValue); // "Hello, world!"

// Armazena uma string grande em arquivo
const largeString = "A".repeat(1500); // Excede o limite para salvar em arquivo
storage.largeValue = largeString;

console.log(storage.largeValue); // "A..." (conteúdo recuperado do arquivo)
console.log(storage.getFileName("largeValue")); // "largeValue_<timestamp>.txt"

🗂️ Exemplo com objetos aninhados

const storage = new Storage();

storage.nested = {
  key1: "B".repeat(2000), // Salvo em arquivo
  key2: "small value", // Armazenado diretamente
};

console.log(storage.nested.key1); // Conteúdo do arquivo
console.log(storage.nested.key2); // "small value"
console.log(storage.getFileName("nested"));
// { key1: "nested_key1_<timestamp>.txt" }

📂 Definindo o local de armazenamento

Agora é possível informar o diretório onde os arquivos serão salvos ao instanciar o Storage:

import { Storage } from "lazy-load-store";

// Cria uma nova instância que salva os arquivos no diretório "./custom-storage"
const customStorage = new Storage("./custom-storage");

customStorage.largeValue = "C".repeat(2000);
console.log(customStorage.getFileName("largeValue")); // Arquivo salvo em ./custom-storage

Caso não seja informado, o diretório padrão é o local de execução do processo.


🎯 Utilizando Callbacks

Você pode passar uma função de callback que será chamada sempre que um valor for lido do storage:

import { Storage } from "lazy-load-store";

const storage = new Storage(
  "./storage-dir",
  undefined,
  (target, prop, value, receiver) => {
    console.log(`Propriedade ${prop} foi acessada!`);
    console.log(`Valor recuperado:`, value);
  }
);

storage.someValue = "teste";
console.log(storage.someValue); // Irá disparar o callback

O callback recebe quatro parâmetros:

  • target: A instância do Storage
  • prop: Nome da propriedade acessada
  • value: Valor recuperado
  • receiver: O objeto proxy

Este recurso é útil para monitorar acessos aos dados, implementar logs ou realizar ações específicas quando determinadas propriedades são lidas.


🧹 Limpeza e destruição

const storage = new Storage();

// Remove arquivos criados e reseta o storage
storage.destroy();

🧪 Testes

npm test

🛡️ API

storage: Storage

Instância singleton para manipulação de dados.

📥 Métodos:

  • storage[key] = value: Define um valor (salva em arquivo se for grande).
  • storage[key]: Recupera o valor, lendo o arquivo se necessário.
  • storage.getFileName(property: string): Obtém o nome do arquivo salvo.
  • storage.destroy(): Remove arquivos criados e limpa o cache.
  • new Storage(basePath?: string, data?: Record<string, unknown>, callback?: (target: Storage, prop: string, value: unknown, receiver: unknown) => void): Cria uma instância com configurações personalizadas.

📝 Licença

MIT License © 2025