Comenzando

Aprende c贸mo instalar y usar ToonJS en tu proyecto

Instalaci贸n

Instala ToonJS usando npm o yarn:

npm install @cescofors/toonjs

or

yarn add @cescofors/toonjs

Uso B谩sico

Importa Toon y crea un dataset:

import { ToonFactory } from '@cescofors/toonjs';

// Create a dataset from TOON format
const restaurantes = ToonFactory.from(`
  restaurantes[3]{nombre,ciudad,calificacion,precio}:
    Can Cesco,Barcelona,4.8,45
    El Bulli,Girona,5.0,120
    Tickets,Barcelona,4.6,65
`);

// Get all data
console.log(restaurantes.all());

Filtrado

Filtra filas basado en condiciones:

// Filter by condition
const topRated = restaurantes
  .filter(r => r.calificacion >= 4.7)
  .all();

console.log(topRated);
// Returns restaurants with rating >= 4.7

Encadenamiento

Encadena m煤ltiples operaciones:

// Chain multiple operations
const result = restaurantes
  .filter(r => r.ciudad === 'Barcelona')
  .sortBy(['calificacion'], ['desc'])
  .select(['nombre', 'calificacion'])
  .take(5)
  .all();

console.log(result);
// Top 5 Barcelona restaurants by rating

Estad铆sticas

Calcula estad铆sticas sobre tus datos:

// Calculate statistics
const stats = restaurantes.stats('precio');

console.log(stats);
// { min: 45, max: 120, avg: 76.67, sum: 230, count: 3, median: 65 }

// Correlation between fields
const correlation = restaurantes.correlation('precio', 'calificacion');
console.log(correlation); // Correlation coefficient

Series Temporales

Analiza datos de series temporales:

const ventas = ToonFactory.from(`
  ventas[5]{fecha,ingresos}:
    2024-01,15000
    2024-02,18000
    2024-03,16500
    2024-04,19000
    2024-05,21000
`);

// Calculate rolling average (3-month window)
const withMA = ventas.rolling('ingresos', 3, 'avg');

// Calculate percentage changes
const withPctChange = withMA.pctChange('ingresos');

console.log(withPctChange.all());

Exportando

Exporta a diferentes formatos:

// Export to different formats
const csvData = restaurantes.toCSV();
const jsonData = restaurantes.toJSON();
const toonData = restaurantes.toToon();

// Display as ASCII table
console.log(restaurantes.toTable());

馃挕 Tip: Check out the Playground to try ToonJS interactively in your browser.