TinyToken SDK

JavaScript SDK for Text Compression API

Installation

Install the SDK using npm:

npm install tinytoken

Requirements

Quick Start

First, get your API key from tinytoken.org. Here's how to use the SDK:

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 result = await client.compress("Your text here");
console.log(result);

// Environment variables (recommended for security)
const client = new TinyToken(process.env.TINYTOKEN_API_KEY);
const result = await client.compress("Your text here", { quality: 0.8 });
console.log(result);

Response Format

The compress method returns a Promise that resolves to a compressed string.

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);
  }
}

Version

Current version: 0.1.4