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

@4kk11/cooklang-sankey

v0.1.5

Published

Generate Sankey diagram data from Cooklang recipes

Readme

cooklang-sankey

Generate Sankey diagram data from Cooklang recipes.

Installation

npm install cooklang-sankey

Usage

Browser Environment

import { CooklangParser, generateSankeyData, optimizeSankeyData } from 'cooklang-sankey';

// Create a parser instance
const parser = new CooklangParser();

// Your Cooklang recipe text
const recipeText = `
---
title: カルボナーラ
servings: 2
---

@パスタ{200g}を茹でる。
@卵{2個}と@パルメザンチーズ{50g}を混ぜる。
@ベーコン{100g}を炒める。
パスタとソースを合わせて完成。
`;

// Parse the recipe text
const [recipe] = parser.parse(recipeText);

// Generate Sankey data from parsed recipe
const data = generateSankeyData(recipe, {
  finalNodeName: "完成品",
  normalization: "logarithmic",
});

// Optionally optimize the data
const optimized = data ? optimizeSankeyData(data) : null;

console.log(optimized);

Node.js Environment

import { CooklangParser, generateSankeyData, optimizeSankeyData } from 'cooklang-sankey';

// Create parser instance
const parser = new CooklangParser();

const recipeText = `
@パスタ{200g}を茹でる。
@卵{2個}と@パルメザンチーズ{50g}を混ぜる。
`;

// Parse the recipe text
const [recipe] = parser.parse(recipeText);

// Generate Sankey data from parsed recipe
const data = generateSankeyData(recipe);
const optimized = data ? optimizeSankeyData(data) : null;

console.log(JSON.stringify(optimized, null, 2));

API

generateSankeyData(recipe, options?)

Generates Sankey diagram data from a parsed Cooklang recipe.

Parameters:

  • recipe: CooklangRecipe - Parsed Cooklang recipe object
  • options?: SankeyGeneratorOptions
    • finalNodeName?: string - Name for the final node (default: "完成品")
    • normalization?: "logarithmic" | "linear" | "none" - Value normalization method
    • minLinkValue?: number - Minimum link value (default: 0.1)

Returns: SankeyData | null

optimizeSankeyData(data)

Validates and optimizes Sankey data by removing invalid links and orphaned nodes.

Returns: SankeyData

Types

interface SankeyData {
  nodes: SankeyNode[];
  links: SankeyLink[];
}

interface SankeyNode {
  id: string;
  name: string;
  category: "ingredient" | "process" | "final";
  value: number;
  label: string;
  originalValue?: number;
  metadata?: BaseNodeMetadata;
}

interface SankeyLink {
  source: string;
  target: string;
  value: number;
  originalValue?: number;
  metadata?: BaseLinkMetadata;
}

React Integration

For React applications, we recommend creating custom hooks:

import { useMemo } from 'react';
import {
  CooklangParser,
  generateSankeyData,
  optimizeSankeyData,
  type CooklangRecipe
} from 'cooklang-sankey';

// Create a singleton parser instance
const parser = new CooklangParser();

export function useSankeyData(recipeText: string) {
  return useMemo(() => {
    if (!recipeText) return null;

    // Parse the recipe text
    const [recipe] = parser.parse(recipeText);

    // Generate Sankey data from parsed recipe
    const data = generateSankeyData(recipe);
    return data ? optimizeSankeyData(data) : null;
  }, [recipeText]);
}

// Or if you already have a parsed recipe:
export function useSankeyDataFromRecipe(recipe: CooklangRecipe | null) {
  return useMemo(() => {
    if (!recipe) return null;
    const data = generateSankeyData(recipe);
    return data ? optimizeSankeyData(data) : null;
  }, [recipe]);
}

License

MIT