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

tinytoken

v0.1.6

Published

JavaScript SDK for TinyToken API - Requires API key from https://tinytoken.org

Readme

TinyToken SDK

Text compression API client for JavaScript/TypeScript.

Installation

npm install tinytoken

Getting Started

1. Get Your API Key

First, you'll need to get an API key from TinyToken:

  1. Visit https://tinytoken.org
  2. Sign up for an account
  3. Navigate to your dashboard
  4. Copy your API key

2. Basic Usage

import { compress, TinyToken } from 'tinytoken';

// Method 1: Using the standalone function
const result = await compress("Your text here", { 
  apiKey: "your-api-key-here" 
});
console.log(result);

// Method 2: Using the TinyToken class (recommended)
const client = new TinyToken("your-api-key-here");
const result2 = await client.compress("Your text here");
console.log(result2);

3. Environment Variables

For security, it's recommended to store your API key in environment variables:

// Set in your environment
// TINYTOKEN_API_KEY=your-api-key-here

import { TinyToken } from 'tinytoken';

const client = new TinyToken(process.env.TINYTOKEN_API_KEY);
const result = await client.compress("Your text here");

API Reference

TinyToken Class

Constructor

new TinyToken(apiKey: string)

Parameters:

  • apiKey (required): Your TinyToken API key

Throws:

  • TinyTokenError: If API key is missing or empty

Methods

  • compress(text: string, options?: CompressOptions): Promise<string>
    • text: The text to compress
    • options: Optional configuration
      • apiKey: Override the instance API key
      • quality: Compression quality (0-1)

Standalone Function

compress(text: string, options: CompressOptions): Promise<string>

  • text: The text to compress
  • options: Configuration object
    • apiKey (required): API key for authentication
    • quality: Compression quality (0-1)

Throws:

  • TinyTokenError: If API key is missing or empty

Advanced Usage

Compression Quality

You can specify the compression quality (0-1, where 1 is maximum compression):

const client = new TinyToken("your-api-key-here");
const result = await client.compress("Your text here", { quality: 0.8 });

Error Handling

The SDK throws TinyTokenError for various error conditions:

import { TinyToken, TinyTokenError } from 'tinytoken';

try {
  const client = new TinyToken("your-api-key-here");
  const result = await client.compress("Your text here");
  console.log(result);
} catch (error) {
  if (error instanceof TinyTokenError) {
    console.error('TinyToken Error:', error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}

Common Error Types:

  • Invalid or missing API key
  • Invalid request parameters
  • Rate limit exceeded
  • Connection errors
  • Timeout errors
  • Invalid response format

Security Best Practices

  1. Never commit API keys to version control
  2. Use environment variables to store your API key
  3. Rotate your API keys regularly
  4. Use different API keys for different environments (development, staging, production)

Examples

Node.js with Environment Variables

// .env file
// TINYTOKEN_API_KEY=your-api-key-here

require('dotenv').config();
const { TinyToken } = require('tinytoken');

const client = new TinyToken(process.env.TINYTOKEN_API_KEY);

async function compressText() {
  try {
    const compressed = await client.compress("This is a long text that needs compression...");
    console.log('Compressed:', compressed);
  } catch (error) {
    console.error('Error:', error.message);
  }
}

compressText();

TypeScript

import { TinyToken, CompressOptions, TinyTokenError } from 'tinytoken';

class TextCompressor {
  private client: TinyToken;

  constructor(apiKey: string) {
    this.client = new TinyToken(apiKey);
  }

  async compressWithQuality(text: string, quality: number): Promise<string> {
    try {
      return await this.client.compress(text, { quality });
    } catch (error) {
      if (error instanceof TinyTokenError) {
        throw new Error(`Compression failed: ${error.message}`);
      }
      throw error;
    }
  }
}

License

MIT