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

antiemdash

v1.0.1

Published

Remove or replace em dashes (—) in strings with a simple boolean parameter

Readme

antiemdash

A TypeScript library scaffolded by init-npm-pkg

A simple TypeScript utility to remove or replace em dashes (—) in strings, with built-in support for wrapping Vercel AI SDK functions.

— -> -

Installation

npm install antiemdash

Basic Usage

The core antiemdash function removes or replaces em dashes in strings:

import { antiemdash } from 'antiemdash';

// Remove em dashes (default behavior)
console.log(antiemdash('Hello—world')); // 'Helloworld'
console.log(antiemdash('Test—string—with—multiple—dashes')); // 'Teststringwithmultipledashes'

// Replace em dashes with regular dashes
console.log(antiemdash('Hello—world', true)); // 'Hello-world'
console.log(antiemdash('Test—string—with—multiple—dashes', true)); // 'Test-string-with-multiple-dashes'

// Handle edge cases
console.log(antiemdash('')); // ''
console.log(antiemdash('—')); // ''
console.log(antiemdash('—', true)); // '-'
console.log(antiemdash('No em dashes here')); // 'No em dashes here'

Vercel AI SDK Integration

Wrapping AI Functions

Use withAntiemdash to automatically process em dashes in AI function outputs:

import { withAntiemdash } from 'antiemdash';

// Example: Wrapping a custom AI function
const myAIFunction = async (prompt: string) => {
  // Simulate AI response with em dashes
  return `Here's your response—with some em dashes—for: ${prompt}`;
};

const cleanAI = withAntiemdash(myAIFunction);
const result = await cleanAI('test prompt');
console.log(result); // 'Here's your responsewith some em dashesfor: test prompt'

// With replacement instead of removal
const cleanAIWithDashes = withAntiemdash(myAIFunction, true);
const result2 = await cleanAIWithDashes('test prompt');
console.log(result2); // 'Here's your response-with some em dashes-for: test prompt'

Processing Complex AI Responses

The wrapper handles nested objects and arrays automatically:

import { withAntiemdash } from 'antiemdash';

const complexAI = async () => ({
  text: 'Main response—with dashes',
  messages: [
    { content: 'First—message' },
    { content: 'Second—message' }
  ],
  metadata: {
    summary: 'Summary with—dashes',
    tags: ['tag1', 'tag—with—dash']
  }
});

const cleanComplexAI = withAntiemdash(complexAI);
const result = await cleanComplexAI();

console.log(result);
// {
//   text: 'Main responsewith dashes',
//   messages: [
//     { content: 'Firstmessage' },
//     { content: 'Secondmessage' }
//   ],
//   metadata: {
//     summary: 'Summary withdashes',
//     tags: ['tag1', 'tagwithdash']
//   }
// }

Vercel AI SDK Specific Wrappers

For generateText Functions

import { createTextGenerator } from 'antiemdash';
import { generateText } from 'ai';

// Create a wrapper for generateText
const textWrapper = createTextGenerator();
const cleanGenerateText = textWrapper(generateText);

// Use it like the original generateText
const result = await cleanGenerateText({
  model: 'gpt-4',
  prompt: 'Write a sentence with em dashes'
});
// Result will have em dashes automatically removed

For streamText Functions

import { createStreamGenerator } from 'antiemdash';
import { streamText } from 'ai';

// Create a wrapper for streamText
const streamWrapper = createStreamGenerator();
const cleanStreamText = streamWrapper(streamText);

// Use it like the original streamText
const result = await cleanStreamText({
  model: 'gpt-4',
  prompt: 'Write a story with em dashes'
});
// Streamed chunks will have em dashes automatically processed

Real-World Example with Vercel AI SDK

import { createTextGenerator, createStreamGenerator } from 'antiemdash';
import { generateText, streamText } from 'ai';
import { openai } from '@ai-sdk/openai';

// Set up clean versions of AI functions
const cleanGenerateText = createTextGenerator()(generateText);
const cleanStreamText = createStreamGenerator()(streamText);

// Use in your API route or server function
export async function POST(req: Request) {
  const { prompt } = await req.json();

  // Generate clean text without em dashes
  const result = await cleanGenerateText({
    model: openai('gpt-4'),
    prompt: prompt,
    maxTokens: 1000,
  });

  return Response.json({ text: result.text });
}

// Or for streaming
export async function POST(req: Request) {
  const { prompt } = await req.json();

  const result = await cleanStreamText({
    model: openai('gpt-4'),
    prompt: prompt,
    maxTokens: 1000,
  });

  return result.toDataStreamResponse();
}

Advanced Usage: Custom Processing Options

import { withAntiemdash } from 'antiemdash';

// Create different processing configurations
const removeDashes = withAntiemdash(myAIFunction, false);
const replaceDashes = withAntiemdash(myAIFunction, true);

// Use them for different use cases
const summary = await removeDashes('Summarize this text');
const formatted = await replaceDashes('Format this text');

API Reference

antiemdash(str: string, replaceWithDash?: boolean): string

  • str (required): The input string containing em dashes
  • replaceWithDash (optional): If true, replaces em dashes with regular dashes (-). If false or omitted, removes em dashes entirely.
  • Returns: The processed string

withAntiemdash<T extends AIFunction>(aiFunction: T, replaceWithDash?: boolean): T

  • aiFunction (required): Any async function that returns a string or object with string properties
  • replaceWithDash (optional): Whether to replace em dashes with regular dashes (default: false)
  • Returns: A wrapped function that automatically processes em dashes in the output

createTextGenerator(replaceWithDash?: boolean)

  • replaceWithDash (optional): Whether to replace em dashes with regular dashes (default: false)
  • Returns: A function that wraps Vercel AI SDK's generateText function

createStreamGenerator(replaceWithDash?: boolean)

  • replaceWithDash (optional): Whether to replace em dashes with regular dashes (default: false)
  • Returns: A function that wraps Vercel AI SDK's streamText function

Development

npm install
npm run build
npm test