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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@krutai/excel-comparison

v0.1.0

Published

A powerful library for comparing Excel and CSV files with intelligent column matching and difference reporting

Downloads

559

Readme

@krutai/excel-comparison

A powerful library for comparing Excel and CSV files by leveraging Backend APIs for high-performance processing.

Features

  • API-Driven Comparison: Offloads heavy Excel processing to a dedicated comparison service.
  • Smart Column Matching: Automatically detects matching columns between files on the server.
  • Detailed Summaries: Get row counts, matches, and differences instantly.
  • Professional Reports: Automatically generates styled Excel reports with highlighted differences.
  • Next.js & Serverless Ready: Optimized for modern web frameworks with zero heavy dependencies like xlsx.

Installation

npm install @krutai/excel-comparison

Quick Start

Basic Usage (Server-side)

import { krutExcelComparison } from "@krutai/excel-comparison";

// Create client
const client = krutExcelComparison({
  apiKey: process.env.KRUTAI_API_KEY,
  serverUrl: process.env.KRUTAI_SERVER_URL || "https://api.krut.ai"
});

// Compare files using buffers
const result = await client.compareFiles(
  file1Buffer, "file1.xlsx",
  file2Buffer, "file2.xlsx",
  { matchColumn: "Invoice" }
);

if (result.success) {
  console.log('Report URL:', result.downloadUrl);
}

Next.js API Route Integration

This is the recommended way to use the library in a Next.js application.

// app/api/compare/route.ts
import { NextRequest, NextResponse } from "next/server";
import {
    createComparisonClient,
    type CompareFilesOptions,
} from "@krutai/excel-comparison";

const SUPPORTED_EXTENSIONS = new Set(["xlsx", "xls", "csv"]);

function getFileExtension(fileName: string): string {
    const parts = fileName.toLowerCase().split(".");
    return parts.length > 1 ? parts[parts.length - 1] : "";
}

function isSupportedFile(file: File): boolean {
    return SUPPORTED_EXTENSIONS.has(getFileExtension(file.name));
}

function parseIgnoreColumns(value?: string): string[] | undefined {
    if (!value?.trim()) return undefined;
    if (value.trim().startsWith("[")) {
        try {
            const parsed = JSON.parse(value);
            if (Array.isArray(parsed)) return parsed.filter(i => typeof i === "string");
        } catch { }
    }
    return value.split(",").map(i => i.trim()).filter(Boolean);
}

export async function POST(req: NextRequest) {
    try {
        const formData = await req.formData();
        const file1 = formData.get("file1") as File | null;
        const file2 = formData.get("file2") as File | null;
        const matchColumn = formData.get("matchColumn") as string | undefined;

        if (!file1 || !file2) {
            return NextResponse.json({ error: "Both file1 and file2 are required" }, { status: 400 });
        }

        const client = createComparisonClient({
            apiKey: process.env.KRUTAI_API_KEY || '',
            serverUrl: process.env.KRUTAI_SERVER_URL || "http://localhost:8000"
        });

        const apiResponse = await client.compareFilesFromFileObjects(file1, file2, {
            matchColumn: matchColumn?.trim()
        });

        return NextResponse.json(apiResponse);
    } catch (err: unknown) {
        return NextResponse.json({ error: "Comparison failed" }, { status: 500 });
    }
}

API Reference

krutExcelComparison(config)

Convenience factory to create a ComparisonApiClient.

ComparisonApiClient

compareFiles(buffer1, name1, buffer2, name2, options)

Compare files using Node.js Buffers.

compareFilesFromFileObjects(file1, file2, options)

Compare files using Web File objects (useful in Browser or Next.js).

previewFiles(file1, file2)

Get a preview of the files (columns, row counts, and sample data) before committing to a full comparison.

Types

ComparisonApiResponse

interface ComparisonApiResponse {
  success: boolean;
  result?: {
    summary: {
      totalRows: number;
      matchesFound: number;
      differencesFound: number;
      uniqueToFile1: number;
      uniqueToFile2: number;
      status: 'SUCCESS' | 'PARTIAL' | 'NO_MATCH';
    };
    matchColumn: string;
    metadata: {
      file1Name: string;
      file1Columns: string[];
      file1RowCount: number;
      file2Name: string;
      file2Columns: string[];
      file2RowCount: number;
    };
  };
  downloadUrl?: string; // Link to the Excel report
  fileName?: string;
  error?: string;
}

Supported File Formats

  • .xlsx (Excel 2007+)
  • .xls (Excel 97-2003)
  • .csv (Comma Separated Values)

License

MIT