
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Remove or replace em dashes (—) in strings with a simple boolean parameter
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.
— -> -
npm install antiemdash
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'
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'
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']
// }
// }
generateText
Functionsimport { 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
streamText
Functionsimport { 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
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();
}
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');
antiemdash(str: string, replaceWithDash?: boolean): string
str
(required): The input string containing em dashesreplaceWithDash
(optional): If true
, replaces em dashes with regular dashes (-
). If false
or omitted, removes em dashes entirely.withAntiemdash<T extends AIFunction>(aiFunction: T, replaceWithDash?: boolean): T
aiFunction
(required): Any async function that returns a string or object with string propertiesreplaceWithDash
(optional): Whether to replace em dashes with regular dashes (default: false
)createTextGenerator(replaceWithDash?: boolean)
replaceWithDash
(optional): Whether to replace em dashes with regular dashes (default: false
)generateText
functioncreateStreamGenerator(replaceWithDash?: boolean)
replaceWithDash
(optional): Whether to replace em dashes with regular dashes (default: false
)streamText
functionnpm install
npm run build
npm test
FAQs
Remove or replace em dashes (—) in strings with a simple boolean parameter
The npm package antiemdash receives a total of 69 weekly downloads. As such, antiemdash popularity was classified as not popular.
We found that antiemdash demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.