1.0.6 โ€ข Published 6 months ago

emoji-transpiler v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Emoji Transpiler ๐Ÿ”„ JavaScript

A fun and experimental transpiler that converts emoji-based source code into executable JavaScript. Write your code using emojis and run it as regular JavaScript!

Installation

npm install emoji-transpiler

Usage

const { transpileEmojiToJS } = require('emoji-transpiler');

// Write your emoji code
const emojiSource = `
๐Ÿ“ฆ message ๐Ÿ˜Š
โค๏ธ message
`;

// Transpile to JavaScript
const jsCode = transpileEmojiToJS(emojiSource);
console.log(jsCode);
// Output: const message "Hello, World!" console.log message

Emoji Syntax

Here's the mapping of emojis to JavaScript constructs:

Variables and Constants

  • ๐Ÿ“ฆ โ†’ const
  • ๐Ÿ“ โ†’ let

Functions

  • ๐Ÿ• โ†’ function
  • ๐Ÿ‘‰ โ†’ =>

Control Flow

  • ๐Ÿค” โ†’ if
  • ๐Ÿงข โ†’ else
  • ๐Ÿ” โ†’ while

Canvas Operations

  • ๐Ÿ–ผ๏ธ โ†’ document.createElement('canvas')
  • ๐ŸŽจ โ†’ getContext('2d')
  • ๐Ÿ—๏ธ โ†’ document.body.appendChild
  • โฌœ โ†’ fillRect
  • ๐Ÿ”ฒ โ†’ clearRect
  • ๐ŸŒˆ โ†’ fillStyle

DOM Operations

  • ๐Ÿ” โ†’ document.querySelector
  • ๐Ÿ“ก โ†’ addEventListener

Animation

  • ๐Ÿ”„ โ†’ requestAnimationFrame

Arithmetic

  • โž• โ†’ +
  • โž– โ†’ -
  • โœ–๏ธ โ†’ *
  • โž— โ†’ /

Logic

  • ๐Ÿ™Œ โ†’ ===
  • ๐Ÿ‘Ž โ†’ !==
  • ๐Ÿ’ก โ†’ &&
  • ๐Ÿšช โ†’ ||

Input/Output

  • โค๏ธ โ†’ console.log
  • ๐Ÿ“ฉ โ†’ prompt

Example

Here's a simple bouncing square animation written in emoji code:

๐Ÿ“ฆ canvas ๐Ÿ–ผ๏ธ
๐Ÿ“ฆ ctx = canvas ๐ŸŽจ "2d"
canvas ๐Ÿ—๏ธ

๐Ÿ“ฆ x = 100
๐Ÿ“ฆ y = 100
๐Ÿ“ฆ dx = 2
๐Ÿ“ฆ dy = 2

๐Ÿ• update ๐Ÿ‘‰ {
  ctx ๐Ÿ”ฒ 0, 0, canvas.width, canvas.height
  ctx ๐ŸŒˆ = "red"
  ctx โฌœ x, y, 50, 50

  x = x โž• dx
  y = y โž• dy
  ๐Ÿ”„ update
}

update()

More Examples

Hello World

๐Ÿ“ฆ greeting ๐Ÿ˜Š
โค๏ธ greeting

Simple Counter

๐Ÿ“ฆ count ๐Ÿ”ข

๐Ÿ• increment ๐Ÿ‘‰ {
  count count โž• 1
  โค๏ธ count
}

๐Ÿ“ก "click" increment

Drawing on Canvas

๐Ÿ“ฆ canvas ๐Ÿ–ผ๏ธ
๐Ÿ“ฆ ctx = canvas ๐ŸŽจ "2d"
canvas ๐Ÿ—๏ธ

ctx ๐ŸŒˆ = "blue"
ctx โฌœ 10, 10, 100, 100

Development

Running Tests

npm test

Building from Source

git clone https://github.com/yourusername/emoji-transpiler.git
cd emoji-transpiler
npm install

Common Patterns

Event Handling

๐Ÿ“ฆ button ๐Ÿ” "#myButton"
button ๐Ÿ“ก "click" ๐Ÿ‘‰ {
  โค๏ธ "Button clicked!"
}

Animation Loop

๐Ÿ“ฆ x ๐Ÿ”ข

๐Ÿ• animate ๐Ÿ‘‰ {
  x = x โž• 1
  โค๏ธ x
  ๐Ÿ”„ animate
}

animate()

Testing

The test script (npm test) demonstrates the transpilation process but doesn't execute the generated code, as many examples require a browser environment for DOM manipulation and Canvas API access.

To test the generated code: 1. Run npm test to see the transpiled JavaScript 2. Copy the output into a browser console or HTML file 3. Run it in a browser environment

For example:

<!DOCTYPE html>
<html>
<head>
    <title>Emoji Transpiler Test</title>
</head>
<body>
    <script>
        // Paste transpiled code here
    </script>
</body>
</html>

License

MIT ยฉ Tom Tarpey

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

Notes

This is an experimental project meant for fun and learning. It's not recommended for production use.

Features

  • ๐ŸŽฏ Simple and intuitive emoji-based syntax
  • ๐Ÿ”„ Direct transpilation to JavaScript
  • ๐ŸŽจ Built-in support for Canvas operations
  • ๐ŸŽฎ Animation and game development friendly
  • ๐Ÿงช Perfect for educational purposes
  • ๐Ÿš€ Zero dependencies

More Examples

Hello World

๐Ÿ“ฆ greeting ๐Ÿ˜Š
โค๏ธ greeting

Simple Counter

๐Ÿ“ฆ count ๐Ÿ”ข

๐Ÿ• increment ๐Ÿ‘‰ {
  count count โž• 1
  โค๏ธ count
}

๐Ÿ“ก "click" increment

Drawing on Canvas

๐Ÿ“ฆ canvas ๐Ÿ–ผ๏ธ
๐Ÿ“ฆ ctx canvas ๐ŸŽจ "2d"
canvas ๐Ÿ—๏ธ

ctx ๐ŸŒˆ "blue"
ctx โฌœ 10 10 100 100

Development

Running Tests

npm test

Building from Source

git clone https://github.com/yourusername/emoji-transpiler.git
cd emoji-transpiler
npm install

Debugging

If your emoji code isn't working as expected:

  1. Check the transpiled JavaScript output using console.log(jsCode)
  2. Verify that all emojis are properly spaced
  3. Ensure you're using supported emoji tokens
  4. Check browser console for any JavaScript errors

Common Patterns

Event Handling

๐Ÿ“ฆ button ๐Ÿ” "#myButton"
button ๐Ÿ“ก "click" ๐Ÿ‘‰ {
  โค๏ธ "Button clicked!"
}

Animation Loop

๐Ÿ“ฆ x ๐Ÿ”ข

๐Ÿ• animate ๐Ÿ‘‰ {
  x x โž• 1
  โค๏ธ x
  ๐Ÿ”„ animate
}

animate()

Browser Support

This package works in all modern browsers that support:

  • Canvas API
  • requestAnimationFrame
  • ES6 features

Roadmap

  • Add TypeScript support
  • Implement more JavaScript features
  • Add syntax highlighting for popular editors
  • Create playground website
  • Add unit tests
  • Support for async/await operations

Similar Projects

FAQ

Why use emojis for coding?

While not practical for production, emoji coding can be:

  • A fun way to learn programming concepts
  • An engaging teaching tool
  • A creative coding experiment

Can I use this in production?

This project is meant for educational and experimental purposes. We don't recommend using it in production environments.

How do I contribute?

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Testing

The test script (npm test) demonstrates the transpilation process but doesn't execute the generated code, as many examples require a browser environment for DOM manipulation and Canvas API access.

To test the generated code: 1. Run npm test to see the transpiled JavaScript 2. Copy the output into a browser console or HTML file 3. Run it in a browser environment

For example:

<!DOCTYPE html>
<html>
<head>
    <title>Emoji Transpiler Test</title>
</head>
<body>
    <script>
        // Paste transpiled code here
    </script>
</body>
</html>
1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago