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 🙏

© 2026 – Pkg Stats / Ryan Hefner

kollar-ts

v0.2.0

Published

TypeScript port of kollaR - Eye tracking data analysis library with I-VT, I-DT, I2MC, and Adaptive fixation detection algorithms

Downloads

124

Readme

kollar-ts

TypeScript port of kollaR - Eye tracking data analysis library

License: GPL-3.0 TypeScript Node

Overview

kollar-ts is a TypeScript port of the R package kollaR by Johan Lundin Kleberg. It provides scientific algorithms for analyzing eye tracking data, including fixation detection, saccade analysis, and Area of Interest (AOI) analysis.

Features

  • 4 Fixation Detection Algorithms:

    • I-VT: Velocity-based algorithm
    • I-DT: Dispersion-based algorithm
    • I2MC: Two-means clustering algorithm
    • Adaptive: Adaptive velocity threshold algorithm
  • Preprocessing Pipeline:

    • Gap interpolation with margin-based approach
    • Moving average smoothing
    • RMS (precision) calculation
    • Downsampling for robustness
  • Analysis Tools:

    • Area of Interest (AOI) testing
    • Sample-to-sample precision metrics (RMSD)
    • Velocity profile analysis
    • Fixation merging and trimming
  • Full TypeScript Support:

    • Strict type checking
    • Comprehensive type definitions
    • IDE autocomplete support

Installation

npm install kollar-ts

Quick Start

import { preprocessGaze, calculateRMS } from 'kollar-ts';

// Your raw gaze data from eye tracker
const rawData = [
  { timestamp: 0, x: 512, y: 384 },
  { timestamp: 1.67, x: 513, y: 385 },
  // ... more samples
];

// Preprocess: interpolate gaps and smooth
const processed = preprocessGaze(rawData, {
  maxGapMs: 75,   // Interpolate gaps up to 75ms
  marginMs: 5,    // Use 5ms margin for interpolation
  filterMs: 15,   // 15ms moving average window
});

// Calculate precision metric
const rms = calculateRMS(processed, 'x', 'y', 40);
console.log(`Sample-to-sample precision: ${rms.toFixed(3)} degrees`);

Fixation Detection

import { algorithmIVT, algorithmIDT, algorithmI2MC, algorithmAdaptive } from 'kollar-ts';

// I-VT: Velocity-based detection
const ivtResult = algorithmIVT(processed, {
  velocityThreshold: 35, // degrees/second
  minFixationDuration: 40, // milliseconds
});

// I-DT: Dispersion-based detection
const idtResult = algorithmIDT(processed, {
  dispersionThreshold: 1.0, // degrees
  minDuration: 40, // milliseconds
});

// I2MC: Clustering-based detection (robust to noise)
const i2mcResult = algorithmI2MC(processed, {
  windowLengthMs: 200,
  downsamplingFactors: [2, 5, 10],
});

// Adaptive: Data-driven threshold
const adaptiveResult = algorithmAdaptive(processed, {
  onsetThresholdSd: 3,
  saveVelocityProfiles: true,
});

console.log(`Detected ${ivtResult.fixations.length} fixations`);

Development Status

Version 0.1.0 - Ready for initial release! ✅

✅ Complete Features

  • [x] Type System: Full TypeScript support with strict mode
  • [x] Preprocessing Pipeline: Interpolation, smoothing, RMS calculation, downsampling
  • [x] Fixation Detection Algorithms:
    • [x] I-VT (Velocity-based)
    • [x] I-DT (Dispersion-based)
    • [x] I2MC (Clustering-based)
    • [x] Adaptive (Data-driven thresholds)
  • [x] Fixation Utilities: Summarize, merge, trim
  • [x] AOI Analysis: Classification, dwell time, latency, transitions
  • [x] Comprehensive Testing: 257 tests with 91.64% coverage
  • [x] Working Examples: 7 complete examples demonstrating all features (including real data demo)
  • [x] Documentation: Complete API documentation and usage guides

Project Structure

kollar-ts/
├── src/
│   ├── types/           # TypeScript type definitions
│   ├── utils/           # Utility functions (math, stats, RLE, rolling)
│   ├── preprocessing/   # Data preprocessing pipeline
│   ├── core/           # Core fixation detection algorithms
│   ├── analysis/       # AOI and analysis functions
│   └── index.ts        # Main exports
├── test/
│   ├── unit/          # Unit tests
│   ├── integration/   # Integration tests
│   └── validation/    # Validation against R
├── examples/          # Usage examples
├── docs/             # Documentation
├── LICENSE           # GPL-3.0 license
└── CITATION.md       # Citation information

Attribution

This TypeScript implementation is a port of the R package kollaR by Johan Lundin Kleberg.

Original R Package

  • Author: Johan Lundin Kleberg
  • Email: [email protected]
  • Organization: Stockholm University
  • Repository: https://github.com/drjohanlk/kollaR
  • License: GPL-3.0

Research Citations

The algorithms in this library are based on peer-reviewed research:

I-VT and I-DT Algorithms

Salvucci, D. D., & Goldberg, J. H. (2000). Identifying fixations and saccades in eye-tracking protocols. Proceedings of the 2000 symposium on Eye tracking research & applications, 71-78. DOI: 10.1145/355017.355028

I2MC Algorithm

Hessels, R. S., Niehorster, D. C., Kemner, C., & Hooge, I. T. C. (2017). Noise-robust fixation detection in eye movement data: Identification by two-means clustering (I2MC). Behavior Research Methods, 49(5), 1802-1823. DOI: 10.3758/s13428-016-0822-1

Adaptive Velocity Threshold

Nyström, M., & Holmqvist, K. (2010). An adaptive algorithm for fixation, saccade, and glissade detection in eyetracking data. Behavior Research Methods, 42(1), 188-204. DOI: 10.3758/BRM.42.1.188

Please cite both the original R package and the relevant research papers when using this library.

See CITATION.md for complete citation information.

API Documentation

Preprocessing

import { preprocessGaze, calculateRMS } from 'kollar-ts';

// Main preprocessing pipeline
const processed = preprocessGaze(rawData, {
  maxGapMs: 75,      // Max gap to interpolate (ms)
  marginMs: 5,       // Margin for interpolation (ms)
  filterMs: 15,      // Moving average window (ms)
  xcol: 'x',         // X coordinate column name
  ycol: 'y',         // Y coordinate column name
  naIgnore: true,    // Ignore NAs when filtering
});

// Calculate precision (RMS)
const rms = calculateRMS(processed, 'x', 'y', 40);

Utilities

import { mean, median, sd, mad } from 'kollar-ts/utils';
import { rollmean, rollmedian } from 'kollar-ts/utils';
import { rle, findRuns } from 'kollar-ts/utils';

// Statistical functions
const m = mean([1, 2, 3, null, 4], true);  // true = remove NAs
const med = median([1, 2, 10, 4, 5], true);

// Rolling operations
const smoothed = rollmean(data, 5, 'center');  // 5-sample window

// Run-length encoding
const encoded = rle([1, 1, 2, 2, 2, 3]);
// { lengths: [2, 3, 1], values: [1, 2, 3] }

Examples

The examples/ directory contains complete, runnable examples demonstrating all features:

Algorithm Examples

  • examples/i-vt.ts - I-VT velocity-based fixation detection
  • examples/i-dt.ts - I-DT dispersion-based fixation detection
  • examples/i2mc.ts - I2MC clustering-based algorithm (robust to noise)
  • examples/adaptive.ts - Adaptive data-driven threshold algorithm
  • examples/aoi-analysis.ts - Area of Interest (AOI) analysis and gaze transitions

Real Data Demo

examples/real-data-demo.ts - Complete pipeline demonstration using real eye tracking data

# Run the real data demo
npx tsx examples/real-data-demo.ts

This example shows:

  • Loading real gaze data from JSON
  • Preprocessing (interpolation, smoothing, RMS calculation)
  • Running all 4 fixation detection algorithms
  • Comparing algorithm results
  • Performance analysis and spatial distribution

The demo uses sample data representative of Tobii Pro Spectrum recordings at 1200 Hz. For full datasets from the original R package, see examples/data/README.md for export instructions.

Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Watch mode for tests
npm run test:watch

# Type checking
npm run typecheck

# Linting
npm run lint

Contributing

Contributions are welcome! This project maintains scientific accuracy as its top priority. All algorithm implementations must match the R package behavior and be validated against R outputs.

Guidelines

  1. Scientific Accuracy: All algorithms must be validated against R implementation
  2. Testing: Comprehensive unit and validation tests required
  3. Documentation: TSDoc comments for all public APIs
  4. Type Safety: Strict TypeScript mode, no any types
  5. Code Style: Follow existing patterns, use Prettier

License

GPL-3.0 - This project uses the same license as the original R package to ensure it remains open and accessible to the research community.

See LICENSE for full license text.

Roadmap

Phase 1: Foundation ✅ COMPLETE

  • [x] Project setup and configuration
  • [x] Type definitions
  • [x] Utility functions
  • [x] Preprocessing pipeline

Phase 2: Core Algorithms ✅ COMPLETE

  • [x] Fixation utility functions
  • [x] I-DT algorithm
  • [x] I-VT algorithm
  • [x] I2MC algorithm
  • [x] Adaptive algorithm

Phase 3: Analysis & Validation ✅ COMPLETE

  • [x] AOI analysis (11 functions)
  • [x] Comprehensive unit tests (257 tests)
  • [x] 91.64% test coverage
  • [x] Integration testing

Phase 4: Documentation & Examples ✅ COMPLETE

  • [x] Complete examples (6 examples)
  • [x] Usage guides
  • [x] API documentation
  • [x] README and guides

Phase 5: Publication 🚀 READY

  • [ ] npm publication (ready to publish)
  • [ ] GitHub release (v0.1.0)
  • [ ] Research community announcement

Future Enhancements (Post v0.1.0)

  • [ ] R validation script integration
  • [ ] Performance benchmarks vs R
  • [ ] Algorithm-specific documentation pages
  • [ ] CI/CD pipeline (GitHub Actions)

Support

Citation

If you use kollar-ts in your research, please cite both this TypeScript implementation and the original R package. See CITATION.md for complete citation information.

Acknowledgments

This TypeScript port was created by H.Kaan Koyukan.

Special thanks to:

  • Johan Lundin Kleberg for the original R implementation
  • All researchers who developed and validated these eye tracking algorithms
  • The eye tracking research community

Note: This is a scientific software project. Precision and accuracy are paramount. All algorithm implementations are validated against the original R package to ensure research reliability.