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

@escrow-protocol/contract-generator

v1.0.5

Published

A deterministic contract generator that produces consistent PDFs across different environments and timezones. Perfect for blockchain applications requiring global consensus.

Readme

@escrow-protocol/contract-generator

A deterministic TypeScript library for generating PDF contracts from Markdown templates with dynamic content substitution. Produces identical PDFs across all global environments - perfect for blockchain applications and distributed systems requiring consensus.

🌟 Key Features

  • 🌍 Global Consensus: Same input produces identical PDFs worldwide (tested across 8 different timezones/locales)
  • 📝 Template-based: Use Markdown templates with placeholder variables
  • 🔄 Conditional logic: Support for {{#if}} blocks and complex conditions
  • 💰 Smart formatting: Automatic currency, date, and percentage formatting
  • 📄 Professional PDFs: Generate clean, formatted documents using pdfmake
  • 🛡️ Type-safe: Full TypeScript support with comprehensive type definitions
  • 🧪 Well-tested: 100% consensus verification across global environments
  • 🌐 Cross-platform: Works in both Node.js and browser environments

Installation

npm install @escrow-protocol/contract-generator

Usage

Basic Example

import { EscrowContractGenerator } from "@escrow-protocol/contract-generator"

const template = `
# Contract Agreement

**Parties:**
- **Buyer**: {{format_party:parties.buyer}}
- **Seller**: {{format_party:parties.seller}}

**Amount**: {{format_currency:terms.amount,terms.currency}}

{{#if exists:terms.delivery_date}}
**Delivery Date**: {{format_date:terms.delivery_date}}
{{/if}}
`

const contractData = {
  parties: {
    buyer: {
      name: "John Doe",
      type: "Individual",
      jurisdiction: "New York, USA",
      address: "123 Main St, New York, NY"
    },
    seller: {
      name: "Acme Corp",
      type: "Corporation",
      entity_type: "LLC",
      jurisdiction: "Delaware, USA",
      address: "456 Business Ave, Delaware, DE"
    }
  },
  terms: {
    amount: 50000,
    currency: "USD",
    delivery_date: "2024-12-31"
  }
}

const generator = new EscrowContractGenerator(template)

// Generate PDF
const { pdfData, warnings } = await generator.generatePDF(contractData, {
  pageSize: "A4",
  margins: { top: 50, bottom: 50, left: 50, right: 50 }
})

// Save or serve the PDF
const blob = new Blob([pdfData], { type: "application/pdf" })

Template Syntax

Variables

{{variable.path}}           // Simple variable substitution
{{nested.object.property}}  // Nested object access
{{array.0.property}}        // Array index access

Formatters

{{format_party:parties.buyer}}           // Format party description
{{format_currency:amount,currency}}      // Format currency with locale
{{format_date:delivery_date}}            // Format date
{{doc_name:documents.contract}}          // Get document name

Conditional Logic

{{#if exists:variable}}
Content to include if variable exists
{{/if}}

{{#if not_exists:variable}}
Content to include if variable doesn't exist
{{/if}}

{{#if variable == 'value'}}
Content if variable equals value
{{else}}
Alternative content
{{/if}}

API Reference

EscrowContractGenerator

Constructor

new EscrowContractGenerator(template: string)

Methods

generatePDF(data, options?)
generatePDF(
  data: any,
  options?: PDFOptions
): Promise<{ pdfData: ArrayBuffer; warnings: string[] }>

Parameters:

  • data: Contract data object with variables for template substitution
  • options: PDF generation options (optional)

Returns: Promise resolving to an object with:

  • pdfData: ArrayBuffer containing the generated PDF
  • warnings: Array of warning messages for unresolved placeholders

PDFOptions

interface PDFOptions {
  margins?: {
    top?: number
    right?: number
    bottom?: number
    left?: number
  }
  defaultStyle?: {
    font?: string
    fontSize?: number
    lineHeight?: number
  }
  pageSize?: string // Default: 'A4'
  pageOrientation?: "portrait" | "landscape" // Default: 'portrait'
  header?: (currentPage: number, pageCount: number) => Content
  footer?: (currentPage: number, pageCount: number) => Content
  watermark?: string
  callback?: (pdfData: ArrayBuffer) => void
}

Development

Building the Library

npm run build

Testing

# Run basic tests
npm test

# Run comprehensive consensus tests (8 global environments)
npm run test:consensus

# Run all tests
npm run test:all

🌍 Global Consensus

This library has been specifically designed and tested to produce identical PDF outputs regardless of:

  • Timezone (tested across 8 different zones: US, UK, Japan, Germany, Australia, Brazil, India, Russia)
  • System locale settings
  • Operating system
  • Node.js vs browser environment

For more details, see CONSENSUS_FIX.md.

License

MIT License - see LICENSE file for details.