Jsonjsdb Builder

0.6.11 · active · verified Wed Apr 22

The `jsonjsdb-builder` package, currently at version 0.6.11, is a development tool that transforms structured data, primarily from Excel (.xlsx) files and Markdown documents, into two JSON-based formats. It generates a compact `.json.js` file (an array of arrays) optimized for efficient, server-less loading in web browsers (e.g., via `file://`), and a standard `.json` file (an array of objects) for general tooling and readability. This package is part of the broader `jsonjsdb` ecosystem, including a Python component. Its release cadence is driven by bug fixes and developer experience improvements, such as recent patches to prevent unnecessary database rewrites during development. A key differentiator is its tight integration with front-end build systems like Vite, offering automated data regeneration and hot-reloading, which streamlines the development of applications leveraging local, structured data.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `JsonjsdbBuilder` class, set up a temporary output directory for generated JSON files, and show where Excel source files would be specified for conversion. It illustrates the basic API usage for setting up the builder environment.

import JsonjsdbBuilder from 'jsonjsdb-builder';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { mkdtemp, rm } from 'fs/promises';
import os from 'os';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

async function runQuickstart() {
  let tempDir;
  try {
    tempDir = await mkdtemp(path.join(os.tmpdir(), 'jsonjsdb-builder-'));
    const outputDbPath = path.join(tempDir, 'app_db');
    const sourceDbPath = path.join(tempDir, 'db');

    // In a real scenario, place .xlsx files in 'sourceDbPath' (e.g., path.join(sourceDbPath, 'users.xlsx'))
    // The builder will read these files and generate JSON outputs.
    
    console.log(`Simulating JSONJSDB build process:`)
    console.log(`  Output directory: ${outputDbPath}`);
    console.log(`  Source Excel directory: ${sourceDbPath}`);

    const builder = new JsonjsdbBuilder();
    await builder.setOutputDb(outputDbPath);
    // To actually process files, ensure 'sourceDbPath' contains .xlsx files.
    // await builder.updateDb(sourceDbPath); 
    console.log('Builder initialized and output directory set. Call builder.updateDb() with your source Excel directory.');
    console.log('Generated .json.js and .json files would appear in the output directory.');

  } catch (error) {
    console.error('Quickstart failed:', error);
  } finally {
    if (tempDir) {
      console.log(`Cleaning up temporary directory: ${tempDir}`);
      await rm(tempDir, { recursive: true, force: true });
    }
  }
}

runQuickstart();

view raw JSON →