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

@bernierllc/content-type-tweet

v1.2.0

Published

Tweet content type with 280-character validation, Twitter API publishing, thread support, and media attachments

Readme

@bernierllc/content-type-tweet

Tweet content type extending @bernierllc/content-type-text with 280-character validation, Twitter-aware text processing, thread support, media attachments, and Twitter API v2 publishing.

Installation

npm install @bernierllc/content-type-tweet

Features

  • 280-character validation using Twitter's official text parsing library
  • Entity extraction - Automatic extraction of hashtags, mentions, and URLs
  • Thread support - Create and publish multi-tweet threads
  • Media attachments - Support for images, GIFs, and videos (up to 4)
  • Poll support - Create tweets with polls (2-4 options)
  • Twitter API v2 integration - Publish tweets directly to Twitter
  • Scheduled tweets - Schedule tweets for future publishing
  • Quote tweets - Quote existing tweets
  • Reply support - Reply to tweets

Usage

Basic Tweet Creation

import { TweetContentType } from '@bernierllc/content-type-tweet';

const tweetType = new TweetContentType({
  storage: {
    type: 'file',
    directory: './content/tweets',
  },
  twitter: {
    appKey: process.env.TWITTER_APP_KEY!,
    appSecret: process.env.TWITTER_APP_SECRET!,
    accessToken: process.env.TWITTER_ACCESS_TOKEN,
    accessSecret: process.env.TWITTER_ACCESS_SECRET,
    authType: 'oauth1',
  },
});

// Create a tweet
const result = await tweetType.createTweet({
  content: 'Hello world! #TypeScript @bernierllc',
});

if (result.success) {
  console.log(`Tweet created: ${result.data}`);
}

Tweet Validation

// Validate tweet content before creating
const validation = tweetType.validateTweet('This is a test tweet!');

if (validation.data?.valid) {
  console.log(`Valid tweet (${validation.data.characterCount}/280 characters)`);
} else {
  console.log('Tweet exceeds character limit');
}

Publishing Tweets

// Create and publish a tweet
const createResult = await tweetType.createTweet({
  content: 'Hello from @bernierllc/content-type-tweet!',
});

if (createResult.success) {
  const publishResult = await tweetType.publishTweet(createResult.data!);

  if (publishResult.success) {
    console.log(`Published: ${publishResult.tweetUrl}`);
  }
}

Tweet Threads

import { createThread } from '@bernierllc/content-type-tweet';

// Create a thread from multiple tweets
const thread = createThread([
  'This is the first tweet in a thread.',
  'This is the second tweet.',
  'And this is the third tweet!',
]);

if (thread.success) {
  // Publish the entire thread
  const result = await tweetType.publishThread(thread.data!);
  console.log(`Thread published: ${result.success}`);
}

Media Attachments

// Create a tweet with media
const result = await tweetType.createTweet({
  content: 'Check out these amazing photos! 📸',
  media: [
    {
      type: 'image',
      url: 'https://example.com/photo1.jpg',
      altText: 'Beautiful sunset',
    },
    {
      type: 'image',
      url: 'https://example.com/photo2.jpg',
      altText: 'Mountain landscape',
    },
  ],
});

Polls

// Create a tweet with a poll
const result = await tweetType.createTweet({
  content: 'What is your favorite programming language?',
  poll: {
    options: ['TypeScript', 'JavaScript', 'Python', 'Go'],
    durationMinutes: 1440, // 24 hours
  },
});

Scheduled Tweets

// Schedule a tweet for later
const createResult = await tweetType.createTweet({
  content: 'This will be posted tomorrow!',
});

if (createResult.success) {
  const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000);
  await tweetType.scheduleTweet(createResult.data!, tomorrow);
}

API Reference

TweetContentType

Main class for managing tweet content.

Methods

  • createTweet(data: Partial<TweetContentMetadata>): Promise<TweetContentResult<string>> - Create a new tweet
  • readTweet(filePath: string): Promise<TweetContentResult<TweetContentMetadata>> - Read tweet from file
  • updateTweet(filePath: string, data: Partial<TweetContentMetadata>): Promise<TweetContentResult<void>> - Update tweet
  • deleteTweet(filePath: string): Promise<TweetContentResult<void>> - Delete tweet
  • publishTweet(filePath: string): Promise<TweetPublishResult> - Publish tweet to Twitter
  • publishThread(thread: TweetThread): Promise<TweetContentResult<TweetPublishResult[]>> - Publish thread
  • scheduleTweet(filePath: string, scheduledFor: Date): Promise<TweetContentResult<void>> - Schedule tweet
  • validateTweet(content: string): TweetContentResult<{ valid: boolean; characterCount: number }> - Validate tweet
  • register(registry: ContentTypeRegistry): Promise<TweetContentResult<void>> - Register with content type registry

Validation Functions

  • validateTweetContent(content: string): TweetContentResult<TweetValidationResult> - Validate tweet using Twitter's parser
  • extractHashtags(content: string): string[] - Extract hashtags from content
  • extractMentions(content: string): string[] - Extract mentions from content
  • extractUrls(content: string): string[] - Extract URLs from content
  • extractEntities(content: string) - Extract all entities (hashtags, mentions, URLs)
  • isTweetValid(content: string): boolean - Check if tweet is valid
  • getCharacterCount(content: string): number - Get weighted character count

Thread Functions

  • createThread(tweets: string[], threadId?: string): TweetContentResult<TweetThread> - Create thread from tweet array
  • validateThread(thread: TweetThread): TweetContentResult<boolean> - Validate thread
  • splitIntoThread(text: string, maxLength?: number): TweetContentResult<string[]> - Split long text into thread

Configuration

Environment Variables

# Twitter API Configuration (required for publishing)
TWITTER_APP_KEY=your_app_key
TWITTER_APP_SECRET=your_app_secret

# OAuth 1.0a (for user authentication)
TWITTER_ACCESS_TOKEN=your_access_token
TWITTER_ACCESS_SECRET=your_access_secret

# OAuth 2.0 (alternative)
TWITTER_CLIENT_ID=your_client_id
TWITTER_CLIENT_SECRET=your_client_secret

# Bearer Token (for app-only authentication)
TWITTER_BEARER_TOKEN=your_bearer_token

# Authentication Type
TWITTER_AUTH_TYPE=oauth1  # oauth1 | oauth2

# Tweet Content Configuration (optional)
TWEET_STORAGE_DIR=./content/tweets  # Default tweet storage directory
TWEET_STORAGE_TYPE=file  # file | database

Integration Status

  • Logger: not-applicable - Core content type package
  • Docs-Suite: ready - TypeDoc format, complete API documentation
  • NeverHub: optional - Tweet publishing events

Dependencies

Dependent Packages

  • @bernierllc/content-editor-service - Content editing orchestration
  • @bernierllc/social-publisher - Multi-platform social publishing
  • @bernierllc/content-management-suite - Complete content management ecosystem

License

Copyright (c) 2025 Bernier LLC

This file is licensed to the client under a limited-use license. The client may use and modify this code only within the scope of the project it was delivered for. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.

See Also