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

@markupai/toolkit

v2.2.1

Published

This toolkit provides a type-safe way to interact with Markup AI services including style analysis, style guide management, and batch operations.

Readme

Markup AI API Toolkit

This toolkit provides a type-safe way to interact with Markup AI services including style analysis, style guide management, and batch operations.

Installation

npm install @markupai/toolkit

Usage

Style Analysis

The toolkit supports string content, File objects, and Buffer objects for style analysis with automatic MIME type detection for binary files. It also supports HTML content strings and files:

import {
  // Auto-polling convenience methods
  styleCheck,
  styleSuggestions,
  styleRewrite,
  // Async workflow helpers
  submitStyleCheck,
  submitStyleSuggestion,
  submitStyleRewrite,
  getStyleCheck,
  getStyleSuggestion,
  getStyleRewrite,
} from "@markupai/toolkit";

// Using string content
const stringRequest = {
  content: "This is a sample text for style analysis.",
  style_guide: "ap",
  dialect: "american_english",
  tone: "formal",
};

// Using HTML string content (auto-detected as text/html)
const htmlStringRequest = {
  content: "<!doctype html><html><body><p>Hello</p></body></html>",
  style_guide: "ap",
  dialect: "american_english",
  tone: "formal",
  // Optional: provide a filename to enforce MIME type
  documentNameWithExtension: "page.html",
};

// Using File object (browser environments)
const file = new File(["This is content from a file."], "document.txt", { type: "text/plain" });
const fileRequest = {
  content: { file }, // FileDescriptor (optionally add mimeType)
  style_guide: "chicago",
  dialect: "american_english",
  tone: "academic",
};

// Using BufferDescriptor (Node.js environments) - BINARY FILES SUPPORTED
const fs = require("fs");
const pdfBuffer = fs.readFileSync("technical-report.pdf");
const bufferRequest = {
  content: {
    buffer: pdfBuffer,
    mimeType: "application/pdf",
    documentNameWithExtension: "technical-report.pdf",
  },
  style_guide: "ap",
  dialect: "american_english",
  tone: "academic",
};

// Perform style analysis with polling (convenience)
const result = await styleCheck(stringRequest, config);
const fileResult = await styleCheck(fileRequest, config);
const pdfResult = await styleCheck(bufferRequest, config); // Works with PDFs!
const htmlResult = await styleCheck(htmlStringRequest, config); // Works with HTML!

// Get style suggestions
const suggestionResult = await styleSuggestions(stringRequest, config);

// Get style rewrites
const rewriteResult = await styleRewrite(stringRequest, config);

Batch Operations

For processing multiple documents efficiently, the toolkit provides batch operations:

import {
  styleBatchCheckRequests,
  styleBatchSuggestions,
  styleBatchRewrites,
} from "@markupai/toolkit";

const requests = [
  {
    content: "First document content",
    style_guide: "ap",
    dialect: "american_english",
    tone: "formal",
  },
  {
    content: "Second document content",
    style_guide: "chicago",
    dialect: "american_english",
    tone: "academic",
  },
  // ... more requests
];

// Batch style checks
const batchCheck = styleBatchCheckRequests(requests, config, {
  maxConcurrent: 5,
  retryAttempts: 3,
  retryDelay: 1_000,
  timeoutMillis: 30_000,
});

// Monitor progress (live snapshot)
console.log(`Started: total ${batchCheck.progress.total}`);
const interval = setInterval(() => {
  const p = batchCheck.progress;
  console.log(
    `Progress: ${p.completed}/${p.total} completed, ${p.inProgress} in-progress, ${p.failed} failed`,
  );
  if (p.completed + p.failed === p.total) clearInterval(interval);
}, 1_000);

// Await final results
batchCheck.promise.then((finalProgress) => {
  console.log(`Completed: ${finalProgress.completed}/${finalProgress.total}`);
  console.log(`Failed: ${finalProgress.failed}`);

  for (const [index, result] of finalProgress.results.entries()) {
    if (result.status === "completed") {
      console.log(`Request ${index}: ${result.result?.original.scores.quality.score}`);
    } else if (result.status === "failed") {
      console.log(`Request ${index} failed: ${result.error?.message}`);
    }
  }
});

// Batch suggestions
const batchSuggestions = styleBatchSuggestions(requests, config);

// Batch rewrites
const batchRewrites = styleBatchRewrites(requests, config);

// Cancel batch operations if needed
batchCheck.cancel();

Response Types

The toolkit provides comprehensive response types for different operations:

import type {
  StyleAnalysisSuccessResp,
  StyleAnalysisSuggestionResp,
  StyleAnalysisRewriteResp,
  StyleScores,
  Issue,
  IssueWithSuggestion,
} from "@markupai/toolkit";

// Style check response
const checkResult: StyleAnalysisSuccessResp = await styleCheck(request, config);
console.log(`Quality score: ${checkResult.original.scores.quality.score}`);
console.log(`Issues found: ${checkResult.original.issues.length}`);

// Style suggestion response
const suggestionResult: StyleAnalysisSuggestionResp = await styleSuggestions(request, config);
for (const issue of suggestionResult.original.issues) {
  console.log(`Issue: "${issue.original}" → Suggestion: "${issue.suggestion}"`);
}

// Style rewrite response
const rewriteResult: StyleAnalysisRewriteResp = await styleRewrite(request, config);
console.log(`Rewritten content: ${rewriteResult.rewrite.text}`);
console.log(`Rewrite quality score: ${rewriteResult.rewrite.scores.quality.score}`);

Configuration

The toolkit requires a configuration object with your API key and platform settings:

import { Config, Environment, PlatformType } from "@markupai/toolkit";

// Using environment-based configuration
const config: Config = {
  apiKey: "your-api-key-here",
  platform: {
    type: PlatformType.Environment,
    value: Environment.Prod, // or Environment.Stage, Environment.Dev
  },
};

// Using custom URL configuration
const configWithUrl: Config = {
  apiKey: "your-api-key-here",
  platform: {
    type: PlatformType.Url,
    value: "https://api.dev.markup.ai",
  },
};

Development

Prerequisites

  • Node.js (Latest LTS version recommended)
  • npm

Setup

  1. Clone the repository:
git clone https://github.com/markupai/toolkit
cd toolkit
  1. Install dependencies:
npm install

Building

To build the project:

npm run build

This will:

  1. Compile TypeScript files
  2. Generate type definitions
  3. Create both ESM and UMD bundles

Testing

The project uses Vitest for testing. There are two types of tests:

  1. Unit Tests: Located in test/unit/
  2. Integration Tests: Located in test/integration/

To run all tests:

npm test

To run unit tests only:

npm run test:unit

To run integration tests only:

npm run test:integration

Code Quality

The project includes linting and formatting tools:

# Check for linting issues
npm run lint:check

# Fix linting issues
npm run lint:fix

# Format code with Prettier
npm run format:fix

License

This project is licensed under the Apache-2.0 License, see the LICENSE file for details.