TypeScript SDK

Fully typed client for Node.js, Deno, Bun, and edge runtimes.

Installation

npm install kalimalab

Client initialization

typescript
import KalimaLab from 'kalimalab'const client = new KalimaLab({  apiKey: process.env.KALIMALAB_API_KEY,})
Set KALIMALAB_API_KEY in your environment. Never hard-code API keys in source code.

Methods

client.words.get

Fetch full linguistic details for a single word by its slug.

Try it
typescript
client.words.get(slug: string): Promise<Word>
ParamTypeReqDescription
slugstringYesWord slug or ID (from search results)

Returns: Promise<Word>

typescript
const word = await client.words.get('كتب')console.log(word.meaning_en)  // 'to write'console.log(word.root)        // 'كتب'
client.words.daily

Get the word of the day.

Try it
typescript
client.words.daily(): Promise<Word>

Returns: Promise<Word>

typescript
const word = await client.words.daily()console.log(word.word)       // 'الأَمَل'console.log(word.meaning_en) // 'hope'
client.words.random

Get randomly selected Arabic words.

Try it
typescript
client.words.random(params?: { count?: number }): Promise<Word[]>
ParamTypeReqDescription
countnumberNo1–20 words. Default: 1.

Returns: Promise<Word[]>

typescript
const words = await client.words.random({ count: 5 })words.forEach(w => console.log(w.word))
client.words.validate

Check whether Arabic strings exist in the KalimaLab database.

Try it
typescript
client.words.validate(words: string[]): Promise<ValidationResult>
ParamTypeReqDescription
wordsstring[]YesUp to 100 Arabic words to validate

Returns: Promise<{ valid: string[], invalid: string[], count: { valid: number, invalid: number } }>

typescript
const result = await client.words.validate(['كتب', 'xyz123', 'مدرسة'])console.log(result.valid)   // ['كتب', 'مدرسة']console.log(result.invalid) // ['xyz123']
client.text.analyze

Analyze a passage of Arabic text.

Try it
typescript
client.text.analyze(text: string): Promise<TextAnalysis>
ParamTypeReqDescription
textstringYesArabic text to analyze (max 5,000 characters)

Returns: Promise<TextAnalysis> — { wordCount, letterCount, uniqueWords, frequency }

typescript
const analysis = await client.text.analyze('بسم الله الرحمن الرحيم')console.log(analysis.wordCount)   // 4
client.stats.get

Return database statistics.

Try it
typescript
client.stats.get(): Promise<Stats>

Returns: Promise<{ totalWords: number, totalRoots: number, totalPatterns: number }>

typescript
const stats = await client.stats.get()console.log(stats.totalWords) // 477000

Error handling

typescript
import KalimaLab, { KalimaLabError } from 'kalimalab'try {  const result = await client.words.search({ q: 'كتب' })} catch (err) {  if (err instanceof KalimaLabError) {    console.error(err.status)  // 401, 429, 500    console.error(err.code)    // 'unauthorized' | 'rate_limited' | ...    console.error(err.message)  }}

TypeScript types

typescript
import type {  Word,  SearchResult,  TextAnalysis,  ValidationResult,  Stats,  KalimaLabError,} from 'kalimalab'