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

brainfock-variants

v1.0.0

Published

Create custom Brainfuck variants with your own operators - encode and decode between standard BF and custom syntax

Readme

brainfuck-variants

npm version License: MIT

Create custom Brainfuck variants with your own operators! This library allows you to encode and decode between standard Brainfuck code and custom syntax using any characters, words, or even emojis.

✨ Features

  • 🎨 Custom Operators - Use any string as operators (single/multi-character, emoji, unicode)
  • 🔄 Bidirectional - Encode BF to custom syntax and decode back
  • High Performance - Optimized decoder with Trie-based algorithm
  • 🎯 Zero Dependencies - Pure JavaScript, no external dependencies
  • 📦 ES Modules - Modern ESM support
  • 🛡️ Type Safe - TypeScript definitions included
  • 🎭 Presets - Built-in presets for common use cases

📦 Installation

npm install brainfuck-variants

🚀 Quick Start

import { createBrainfuckTranslator } from 'brainfuck-variants';

// Create a translator with custom operators
const translator = createBrainfuckTranslator(
  'inc',    // + (increment)
  'dec',    // - (decrement)
  'next',   // > (move right)
  'prev',   // < (move left)
  'out',    // . (output)
  'in',     // , (input)
  'begin',  // [ (loop start)
  'end'     // ] (loop end)
);

// Encode Brainfuck to custom syntax
const bfCode = '++[>++<-]';
const encoded = translator.encode(bfCode);
console.log(encoded); // "incincbeginnextincincprevdecend"

// Decode back to Brainfuck
const decoded = translator.decode(encoded);
console.log(decoded); // "++[>++<-]"

// Validate encoded string
console.log(translator.isValid(encoded)); // true

📚 API Reference

createBrainfuckTranslator(opPlus, opMinus, opRight, opLeft, opOutput, opInput, opLoopStart, opLoopEnd)

Creates a new translator with custom operators.

Parameters:

  • opPlus - Operator for + (increment)
  • opMinus - Operator for - (decrement)
  • opRight - Operator for > (move right)
  • opLeft - Operator for < (move left)
  • opOutput - Operator for . (output)
  • opInput - Operator for , (input)
  • opLoopStart - Operator for [ (loop start)
  • opLoopEnd - Operator for ] (loop end)

Returns: Translator object with the following methods:

translator.encode(bfCode)

Encodes standard Brainfuck code to custom syntax.

const encoded = translator.encode('++[>++<-]');

translator.decode(encodedStr)

Decodes custom syntax back to standard Brainfuck.

const decoded = translator.decode('incincbeginnextincincprevdecend');

translator.isValid(encodedStr)

Checks if an encoded string is valid (contains only recognized operators).

const isValid = translator.isValid('incincbegin'); // true
const invalid = translator.isValid('invalid123');  // false

translator.getOptimizedDecoder()

Returns an optimized decoder function using Trie-based algorithm (better for repeated decoding).

const fastDecode = translator.getOptimizedDecoder();
const decoded = fastDecode('incincbegin');

translator.getOperators()

Returns an array of all custom operators.

const ops = translator.getOperators();
// ['inc', 'dec', 'next', 'prev', 'out', 'in', 'begin', 'end']

translator.getOpMap()

Returns the operator mapping (BF → Custom).

const map = translator.getOpMap();
// { '+': 'inc', '-': 'dec', ... }

translator.getReverseOpMap()

Returns the reverse operator mapping (Custom → BF).

const reverseMap = translator.getReverseOpMap();
// { 'inc': '+', 'dec': '-', ... }

createPresetTranslator(preset)

Creates a translator using a built-in preset.

Available Presets:

  • 'verbose' - ['INC', 'DEC', 'NEXT', 'PREV', 'OUT', 'IN', 'BEGIN', 'END']
  • 'emoji' - ['➕', '➖', '➡️', '⬅️', '📤', '📥', '🔁', '⏹️']
  • 'short' - ['inc', 'dec', 'nxt', 'prv', 'out', 'inp', 'bgn', 'end']
  • 'minimal' - ['i', 'd', 'r', 'l', 'o', 'n', '[', ']']
  • 'chinese' - ['加', '减', '右', '左', '输出', '输入', '循环开始', '循环结束']
  • 'pascal' - ['Inc', 'Dec', 'MoveRight', 'MoveLeft', 'Write', 'Read', 'While', 'EndWhile']
import { createPresetTranslator } from 'brainfuck-variants';

const emojiTranslator = createPresetTranslator('emoji');
const encoded = emojiTranslator.encode('++[>++<-]');
console.log(encoded); // "➕➕🔁➡️➕➕⬅️➖⏹️"

🎯 Examples

Multi-Character Operators

const translator = createBrainfuckTranslator(
  'PLUS', 'MINUS', 'RIGHT', 'LEFT',
  'OUTPUT', 'INPUT', 'LOOP_START', 'LOOP_END'
);

const encoded = translator.encode('++.');
console.log(encoded); // "PLUSPLUSOUTPUT"

Emoji Operators

const translator = createBrainfuckTranslator(
  '😀', '😢', '👉', '👈', '🗣️', '👂', '🔁', '⏹️'
);

const encoded = translator.encode('+>.');
console.log(encoded); // "😀👉🗣️"

Mixed Length Operators

const translator = createBrainfuckTranslator(
  '++',    // +
  '--',    // -
  '>',     // >
  '<',     // <
  'print', // .
  'read',  // ,
  '[',     // [
  ']'      // ]
);

const encoded = translator.encode('++.');
console.log(encoded); // "++++print"

Overlapping Operators

The decoder automatically handles overlapping operators by matching the longest possible operator first:

const translator = createBrainfuckTranslator(
  'a',   // +
  'ab',  // -
  'abc', // >
  'b',   // <
  'c',   // .
  'ca',  // ,
  'cab', // [
  'cba'  // ]
);

// Uses longest-match strategy
console.log(translator.decode('abc')); // ">" (matches 'abc', not 'a' + 'b' + 'c')

Hello World Example

const translator = createBrainfuckTranslator(
  'inc', 'dec', 'next', 'prev',
  'out', 'in', 'begin', 'end'
);

const helloWorld = '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.';
const encoded = translator.encode(helloWorld);
const decoded = translator.decode(encoded);

console.log(decoded === helloWorld); // true

🔧 Advanced Usage

Performance Optimization

For repeated decoding operations, use the optimized decoder:

const translator = createBrainfuckTranslator(/* ... */);
const optimizedDecode = translator.getOptimizedDecoder();

// Much faster for repeated calls
for (let i = 0; i < 10000; i++) {
  const result = optimizedDecode(encodedString);
}

Validation

Check if a string is valid before decoding:

if (translator.isValid(input)) {
  const decoded = translator.decode(input);
  // Process decoded BF code
} else {
  console.error('Invalid input string');
}

Custom Language Creation

Create your own Brainfuck-inspired language:

const sqlTranslator = createBrainfuckTranslator(
  'INCREMENT',
  'DECREMENT',
  'SELECT',
  'FROM',
  'INSERT',
  'DELETE',
  'BEGIN',
  'COMMIT'
);

const bfCode = '+>.<';
const sql = sqlTranslator.encode(bfCode);
// "INCREMENTSELECTINSERTFROM"

🎨 Use Cases

  • 🎭 Obfuscation - Hide Brainfuck code using custom syntax
  • 🎓 Education - Teach programming concepts with readable operators
  • 🎮 Code Golf - Create compact BF variants
  • 🌐 Language Variants - Implement localized BF versions
  • 🛠️ DSL Creation - Build domain-specific languages based on BF
  • 🎪 Fun Projects - Create emoji-based programming languages

📝 TypeScript Support

This package includes TypeScript definitions:

import { createBrainfuckTranslator, createPresetTranslator, BRAINFUCK_OPS } from 'brainfuck-variants';

const translator = createBrainfuckTranslator(
  'inc', 'dec', 'next', 'prev',
  'out', 'in', 'begin', 'end'
);

const encoded: string = translator.encode('++.');

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT © [Your Name]

🔗 Links

⭐ Star History

If you find this project useful, please give it a star on GitHub!


Made with ❤️ for the esoteric programming language community