Skip to content

JoeKarlsson/punc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

139 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Punc

npm version Build Status Coverage Status License: MIT

Ever wonder what your favorite books look like without words?

Punc is a modern TypeScript library for analyzing punctuation patterns in text files. It extracts punctuation marks, counts their frequency, calculates words per sentence, and can generate PDF visualizations showing only the punctuation.

Punctuation Visualization

Features

  • πŸ” Punctuation Analysis: Extract and count punctuation marks from text files
  • πŸ“Š Statistical Analysis: Calculate words-per-sentence averages
  • πŸ“„ PDF Generation: Create visual PDFs showing only punctuation patterns
  • 🎯 TypeScript Support: Full type safety and IntelliSense support
  • πŸš€ Modern ES Modules: Built with latest JavaScript standards
  • βœ… Comprehensive Testing: 100% test coverage with Jest
  • πŸ”§ Developer Experience: ESLint, Prettier, and automated CI/CD

Installation

npm install punc

Quick Start

import punc, { createPDF } from 'punc';

// Analyze punctuation in a text file
const result = await punc('path/to/your/file.txt');

console.log('Punctuation counts:', result.count);
console.log('Punctuation only:', result.body);
console.log('Words per sentence:', result.wordsPerSentence);
console.log('Spaced text:', result.spaced);

// Generate a PDF visualization
const pdfResult = await createPDF('path/to/your/file.txt');
console.log('PDF created:', pdfResult.pathToFile);

API Reference

punc(filePath, options?)

Analyzes punctuation in a text file and returns detailed statistics.

Parameters:

  • filePath (string): Path to the text file to analyze
  • options (PuncOptions | string, optional): Configuration options

Returns: Promise<PuncResult>

Example:

const result = await punc('alice.txt', {
  encoding: 'utf8',
  mapping: {
    ';': 0, ':': 0, "'": 0, '"': 0, ',': 0,
    '!': 0, '?': 0, '.': 0, '(': 0, ')': 0, '-': 0
  }
});

createPDF(filePath, options?)

Creates a PDF visualization showing only punctuation marks.

Parameters:

  • filePath (string): Path to the text file
  • options (PuncOptions | string, optional): Configuration options

Returns: Promise<PDFResult>

Example:

const pdfResult = await createPDF('alice.txt');
console.log('PDF saved to:', pdfResult.pathToFile);

Types

interface PunctuationCount {
  ';': number;
  ':': number;
  "'": number;
  '"': number;
  ',': number;
  '!': number;
  '?': number;
  '.': number;
  '(': number;
  ')': number;
  '-': number;
}

interface PuncResult {
  body: string;              // Punctuation marks only
  count: PunctuationCount;   // Count of each punctuation mark
  wordsPerSentence: number;  // Average words per sentence
  spaced: string;           // Text with words replaced by spaces
}

interface PDFResult {
  success: boolean;
  pathToFile: string;
}

Development

Prerequisites

  • Node.js 18+
  • npm

Setup

git clone https://github.com/JoeKarlsson/punc.git
cd punc
npm install

Available Scripts

npm run build          # Build the project (TypeScript + ESBuild)
npm run dev           # Watch mode for development
npm test              # Run tests with Jest
npm run test:watch    # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
npm run lint          # Run ESLint code quality checks
npm run lint:fix      # Fix ESLint issues automatically
npm run format        # Format code with Prettier
npm run type-check    # Check TypeScript types without emitting files
npm run markdown-lint # Check and fix markdown formatting
npm run check         # Run all checks (type-check + lint + markdown-lint + test)
npm run clean         # Clean build artifacts

Testing

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

Punctuation Marks

The library tracks these punctuation marks:

  • ; - Semicolon
  • : - Colon
  • ' - Single quote
  • " - Double quote
  • , - Comma
  • ! - Exclamation mark
  • ? - Question mark
  • . - Period
  • ( - Opening parenthesis
  • ) - Closing parenthesis
  • - - Hyphen/dash

Inspiration

This project was inspired by this article on Medium, which was in turn inspired by this person's work.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Ever wonder what your favorite books look like without words?

Resources

License

Stars

Watchers

Forks

Contributors