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

@simahfud/pine-to-kline

v0.1.4

Published

PineScript v5/v6 interpreter for KlineChart registerIndicator — compile Pine indicators to JS

Readme

🌲 pine-to-kline

An independent interpreter that compiles Pine Script (v5/v6) into indicators compatible with the KlineChart charting library.

Designed as a plugin for @simahfud/klinecharts-pro.

Features

  • Clean-room implementation: Converts Pine Script directly to KlineChart's IndicatorTemplate format
  • Series Emulation: Bar-by-bar evaluation to support close[1] historical access syntax
  • Pine Functions: Includes most-used ta.*, math.*, and color.* built-ins
  • Inputs & Styling: Maps input.int(), plot(), and hline() to KlineChart parameters and figures
  • Zero Dependencies: Independent pure-TS library

Installation

npm install pine-to-kline

(Note: Requires klinecharts >= 9.0.0 as a peer dependency)

Basic Usage

import { PineInterpreter } from 'pine-to-kline'

const pine = new PineInterpreter()

// Compile Pine Script
const result = pine.compile(`
  //@version=5
  indicator("My SMA", overlay=true)
  length = input.int(14, "Length")
  plot(ta.sma(close, length), "SMA", color=color.blue)
`)

if (result.success) {
  // result.indicatorConfig is a valid KlineChart IndicatorTemplate
  klineChart.addIndicator(result.indicatorConfig, true)
}

Plugin Integration with KlineChart Pro

The library includes a dedicated plugin wrapper for @simahfud/klinecharts-pro.

import { createPinePlugin } from 'pine-to-kline/plugin'

// Initialize the plugin
const pineAPI = createPinePlugin()

// 1. Compile and register the indicator
const indicatorName = pineAPI.run(`
  //@version=5
  indicator("RSI", overlay=false)
  length = input.int(14, "Length")
  plot(ta.rsi(close, length), "RSI", color=color.purple)
  hline(70, "OB", color=color.red)
  hline(30, "OS", color=color.green)
`)

// 2. Add the registered indicator to your chart pane
klineChart.createIndicator(indicatorName, true, { id: 'pane_1' })

Supported Pine Features (Phase 1)

Built-in TA (ta.*)

  • Moving Averages: sma, ema, rma, wma, hma, vwma, swma, dema, tema
  • Momentum: rsi, macd, stoch, cci, mom, roc
  • Volatility: atr, bb (Bollinger Bands), kc (Keltner Channels), donchian, tr
  • Crossover: crossover, crossunder, cross, change, rising, falling
  • Utility: highest, lowest, highestbars, lowestbars, barssince, valuewhen, pivothigh, pivotlow, cum, stdev, percentrank

Math (math.*)

  • abs, ceil, floor, round, log, log10, pow, sqrt, exp, max, min, sign, avg, sum, sin, cos, tan, asin, acos, atan, random, todegrees, toradians

Colors (color.*)

  • All standard color constants (e.g. color.red, color.blue)
  • Functions: color.new(), color.rgb(), color.from_gradient()

Inputs

  • input(), input.int(), input.float(), input.bool(), input.string(), input.color(), input.source()

Advanced Features (V5 / V6)

  • User-Defined Types (Structs): type definitions with strong typing
  • User-Defined Methods: method definitions extending native or custom types
  • Array / Matrix: Generic type support (array.new<Type>()) and array literal syntax ([a, b, c])
  • Modules: import and export statements
  • Expressions: if and switch statements evaluated as expressions

Architecture

The interpreter pipeline works in 4 phases:

  1. Lexer: Tokenizes the source code, handling Pine's indentation blocks.
  2. Parser: A recursive-descent parser that builds an Abstract Syntax Tree (AST).
  3. Runtime Engine: Evaluates the AST using a SeriesEmulator to provide var persistence and [] lookbacks.
  4. Adapter: Transpiles the runtime's Intermediate Representation (IR) into a KlineChart IndicatorTemplate.

License

Apache-2.0