Skip to content

maxmmyron/asciish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asciish

asciish provides build-time shortcode-based emoticon injection for webpages and runtime unicode helpers.

Install

npm

npm i asciish

Use

build-time emoticon resolution

(NOTE: this feature is Vite/Rollup-only at the moment)

asciish provides a small plugin that provides shortcode-based emoticon injection (similar to how :fire: resolves to 🔥 on some platforms.)

Add the plugin to your config:

// vite.config.js
import { defineConfig } from "vite";
import { asciishPlugin } from "asciish";

export default defineConfig({
  plugins: [
    // other plugins...
    asciishPlugin(),
  ],
  // ...
});

Then, use the &<shortcode>; syntax in your source files:

<!-- src/index.html -->
<!-- ... -->
<body>
  <p>Today is a good day &smile;</p>
</body>
<!-- ... -->

This will compile to

<!-- dist/index.html -->
<!-- ... -->
<body>
  <p>Today is a good day :)</p>
</body>
<!-- ... -->

compiler options

you can pass in options to the plugin to customize its behavior:

// vite.config.js
import { defineConfig } from "vite";
import { asciishPlugin } from "asciish";

export default defineConfig({
  plugins: [
    // other plugins...
    asciishPlugin({
      parser: {
        emotes: false,
        // ...
      },
    }),
  ],
  // ...
});

parser: supports enabling/disabling certain regexp parsers at build-time:

  • emotes: enables/disables emote parsing (default: true)
  • punctuation: enables/disables pretty punctuation parsing (default: true)
  • shortcodes: enables/disables emoji shortcode (see ikatyang's emoji cheat sheet) parsing (default: true)
  • unicode: enables/disables unicode parsing (default: true)

runtime helpers

asciish provides multiple runtime helper functions for working with the Unicode standard.

You can include the runtime object in your code to access runtime helpers:

// src/index.svelte

<script>
  import {runtime} from 'asciish';
</script>

<p>{runtime.fanciful.toMono("Hello there!")}</p> // <p>𝕳𝖊𝖑𝖑𝖔 𝖙𝖍𝖊𝖗𝖊!</p>

<p>🧑‍🌾 = {runtime.emoji.split("🧑‍🌾").join(" + ")}</p> // <p>🧑‍🌾 = 🧑 + 🌾</p>

Planned Features

  • Plugin options (file extensions, preferred shortcode syntax, etc.)
  • Support for Webpack via custom loader
  • Support build-time randomized emote injection
  • Ignoring shortcode given some context (e.g. &smile; in a code block)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published