Skip to main content

Installation

Install the SDK using npm or yarn:
npm install username-dev

Quick Start

Import and initialize the client with your API key:
import { UsernameClient } from 'username-dev';

const client = new UsernameClient('un_live_your_api_key_here');
const result = await client.check('paris');

console.log(result);
// {
//   username: "paris",
//   isReserved: true,
//   isDeleted: false,
//   categories: [
//     {
//       category: "city",
//       metadata: {
//         country: "FR"
//       }
//     }
//   ]
// }

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:
import { UsernameClient, UsernameCheckResponse } from 'username-dev';

const client = new UsernameClient('un_live_xxx');
const result: UsernameCheckResponse = await client.check('admin');

Error Handling

The SDK throws typed errors that match the API error responses:
import { UsernameClient, InvalidApiKeyError, QuotaExceededError } from 'username-dev';

const client = new UsernameClient('un_live_xxx');

try {
  const result = await client.check('test');
} catch (error) {
  if (error instanceof InvalidApiKeyError) {
    console.error('Invalid API key');
  } else if (error instanceof QuotaExceededError) {
    console.error('Quota exceeded');
  } else {
    console.error('Unexpected error:', error);
  }
}

API Reference

UsernameClient

Main client class for interacting with the username.dev API.

Constructor

new UsernameClient(apiKey: string)

Methods

check(username: string): Promise<UsernameCheckResponse>
Check if a username is reserved. Parameters:
  • username (string): The username to check
Returns: Promise resolving to UsernameCheckResponse Example:
const result = await client.check('berlin');

Resources