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

gemini-branch

v1.0.4

Published

Perform conditional branching using Gemini in natural language.

Downloads

492

Readme

GeminiBranch

npm version license

This library performs conditional branching using natural language, powered by Google's Gemini API. Think of it as a natural language if/else or switch statement.

Features

  • Natural Language branching: Branch complex, nuanced, or subjective conditions that are difficult to express with traditional code.
  • Dynamic Branching: Select the most appropriate option from a set of choices based on a natural language prompt.
  • Simple & Typed API: Easy-to-use, typed interface for seamless integration into TypeScript projects.
  • Error Handling: Built-in error handling for API failures and unexpected responses.

Installation

npm install gemini-branch

Usage

First, obtain a Google Gemini API key. You can get one from the Google AI Studio.

import { GeminiBranch } from 'gemini-branch';
import type { GeminiBranchResult } from 'gemini-branch';

let globalBranchResult: GeminiBranchResult | null = null;

globalBranchResult = await GeminiBranch({
    condition: "Which is the morning greeting?",
    choices: ["good morning", "hello", "good evening"],
    apiKey: "YOUR GEMINI API KEY",
    model: "gemma-3-27b-it",
});

console.log(globalBranchResult)
// { response: true, result: 'good morning', message: 'Success' }

Model Selection

You need to select a model from the Gemini or Gemma 3 model list.

API Reference

GeminiBranch is the main function that performs the conditional branching.

GeminiBranchOptions

| Parameter | Type | Description | Required | |-----------|------|-------------|----------| | condition | string | The natural language condition used for branching. | Yes | | choices | string[] | A list of candidate values. Gemini selects the single best-matching option. | Yes | | apiKey | string | Your Google Gemini API Key. | Yes | | model | string | The model to use for branching. | Yes | | else | string | A fallback value returned when no choice sufficiently matches the condition. | No | | consoleErrors | boolean | Log internal errors to the console. Default is false. | No |

GeminiBranchResult

| Parameter | Type | Description | |-----------|------|-------------| | response | boolean | true : The library executed correctly (including when the fallback else value is returned). false : An internal error occurred (API failure, schema violation, etc.). | | result | string | On success, a Gemini-selected value from choices or the fallback (else) value; on failure, "" or the else value if provided. | | message | string | Error message on failure, "Success" on success, "No matching choice" when else is selected |

⚠️ If else is not provided, the model is instructed to output "" when no choice matches.

License

This project is licensed under the MIT License. See the LICENSE file for details.