World Register of Marine Species (WoRMS) JS SDK

TypeScript SDK for accessing the World Register of Marine Species (WoRMS) APIs. Fully typed based on the official WoRMS REST API Specification.

✨ Features
- 🔷 Fully typed - Auto-generated types from WoRMS OpenAPI specification
- 📖 Automatic pagination - Handles pagination automatically for large datasets
- 🛡️ Error handling - Typed errors
- 📚 Complete - Covers all main WoRMS APIs including attributes and taxonomic ranks
🚀 Installation
npm install @koale/worms-js-sdk
yarn add @koale/worms-js-sdk
pnpm add @koale/worms-js-sdk
📖 Basic Usage
Example
import { WormsClient, AphiaRecord } from '@koale/worms-js-sdk';
const worms = new WormsClient();
const records = await worms.searchByScientificName("Homo sapiens");
console.log(`Found ${records.length} records`);
const marineRecords = await worms.searchByScientificName("Carcharodon", {
like: true,
marineOnly: true,
extantOnly: true,
pagination: {
autoIterate: true,
maxResults: 100
}
});
const recentRecords = await worms.getRecordsByDate("2023-01-01", {
endDate: "2023-12-31",
marineOnly: true,
pagination: { autoIterate: true }
});
import { WormsClient } from '@koale/worms-js-sdk';
const worms = new WormsClient();
const allChildren = await worms.getChildren(2, {
marineOnly: true,
pagination: { autoIterate: true }
});
const firstBatch = await worms.getChildren(2, {
pagination: { autoIterate: false },
offset: 1
});
Detailed Information
const stats = await worms.getRecordStats(105838);
console.log(`Children: ${stats.childrenCount}`);
console.log(`Synonyms: ${stats.synonymsCount}`);
console.log(`Vernaculars: ${stats.vernacularsCount}`);
console.log(`Distributions: ${stats.distributionsCount}`);
console.log(`Sources: ${stats.sourcesCount}`);
const fullRecord = await worms.getFullRecord(105838);
console.log(`Full record with linked data: ${fullRecord.scientificname}`);
🎯 Complete API Reference
Search Methods
searchByScientificName() | Search by scientific name | ✅ |
searchByVernacular() | Search by vernacular name | ✅ |
searchByScientificNames() | Batch search by scientific names | ❌ |
fuzzyMatch() | Fuzzy search with TAXAMATCH algorithm | ❌ |
getRecordsByDate() | Get records by date range | ✅ |
Records
getRecord() | Get record by AphiaID | ❌ |
getRecords() | Get multiple records by AphiaIDs | ❌ |
getFullRecord() | Get full record (JSON-LD) | ❌ |
getAphiaId() | Get AphiaID by name | ❌ |
getName() | Get name by AphiaID | ❌ |
exists() | Check if AphiaID exists | ❌ |
Taxonomic Hierarchy
getClassification() | Complete classification | ❌ |
getChildren() | Direct children | ✅ |
getSynonyms() | Synonyms | ✅ |
getVernaculars() | Vernacular names | ❌ |
Geographic & Reference Data
getDistributions() | Geographic distributions | ❌ |
getSources() | Sources and references | ❌ |
Attributes
getAttributeKeys() | Get attribute keys by ID | ❌ |
getAttributeValues() | Get attribute values by category | ❌ |
getAttributes() | Get attributes by AphiaID | ❌ |
getAphiaIdsByAttribute() | Get AphiaIDs by attribute | ✅ |
Taxonomic Ranks
getTaxonRanksById() | Get taxonomic ranks by ID | ❌ |
getTaxonRanksByName() | Get taxonomic ranks by name | ❌ |
getRecordsByTaxonRank() | Get records by taxonomic rank | ✅ |
External IDs
getExternalId() | Get external ID by AphiaID |
getRecordByExternalId() | Get record by external ID |
Supported external ID types: algaebase
, bold
, dyntaxa
, fishbase
, iucn
, lsid
, ncbi
, tsn
, gisd
Utility Methods
These are utility methods that are wrappers around the other methods.
getRecordStats() | Get complete statistics for a record |
getAllResults() | Get all results from a paginated function |
exists() | Check if an AphiaID exists |
🛡️ Error Handling
import { WormsError } from '@koale/worms-js-sdk';
try {
const record = await worms.getRecord(999999999);
} catch (error) {
if (error instanceof WormsError) {
console.error(`WoRMS Error: ${error.message}`);
console.error(`Status: ${error.status}`);
} else {
console.error('Unknown error:', error);
}
}
🔧 Client Configuration
const client = new WormsClient({
baseUrl: "https://www.marinespecies.org/rest",
fetchOptions: {
headers: {
"User-Agent": "MyApp/1.0",
"Accept": "application/json"
},
timeout: 10000
}
});
📊 TypeScript Types
All types are fully typed:
import type {
AphiaRecord,
Classification,
Distribution,
Vernacular,
Source,
AphiaRank,
AttributeKey,
AttributeValue,
Attribute,
AphiaAttributeSet,
AphiaRecordFull,
WormsClientOptions,
PaginationOptions,
PaginatedResult,
WormsError
} from '@koale/worms-js-sdk';
🚀 Complete Examples
Check the examples/index.ts file for complete usage examples.
Run the examples:
pnpm run example
tsx examples/index.ts
📝 License
MIT License. See LICENSE for more details.
🙏 Acknowledgments
💬 Support
For issues or questions: