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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@deltachat/message_parser_wasm

v0.11.0

Published

Parsing of Links, Email adresses, simple text formatting (markdown subset), user mentions, hashtags and more in DeltaChat messages.

Downloads

1,395

Readme

DeltaChat Message Parser WASM

Parsing of Links, email addresses, simple text formatting (markdown subset), user mentions, hashtags and more in DeltaChat messages.

The specification can be found in spec.md.

The parser is written in rust with the nom crate and compiled to web assembly for this package.

The Idea behind it

Have the same rich message parsing on all platforms.

The basic idea is that core can use this library to convert messages to an AST format, that can then be displayed by the UIs how they see fit, for desktop it will be converted to react elements.

Desktop already uses this package (minus the markdown, because it does not make sense to only have markdown on desktop and not also on iOS and android) as wasm module (see ./message_parser_wasm), later this will probably be integrated into deltachat core.

Read more about the project on github: https://github.com/deltachat/message-parser

🚴 Usage

function parse_text(s: string, enable_markdown: boolean): ParsedElement[];
import init, { parse_text } from "./pkg/message_parser_wasm.js";

init().then(() => {
    let parsed = parse_text("hello **world**", true)

    let result = parsed.map(element => {
        switch element.t {
            case "Bold":
                return `<b>${element.c}</b>`
                break;
            case "Text"
                return element.c
            // ...
            default
                console.error(`type ${element.t} not known/implemented yet`, element);
                return JSON.stringify(element)
        }
    }).join("")

    console.log(result) // "hello <b>world</b>"
})

DO NOT actually write html with user input like that, this is for demonstration purposes ONLY! It let's you and your users open to XSS attacks, the examples bellow are much better suitable for reference or copy+pasting.

also see example.js and test it live on https://deltachat.github.io/message-parser/

For usage in react you can look at how we integrated this package in deltachat-desktop: deltachat-desktop/src/renderer/components/message/MessageMarkdown.tsx

If you want to see it in action in deltachat-desktop, feel free to download it on https://get.delta.chat.

Emoji Helper functions

/** returns first emoji from text if text begins with an emoji */
export function get_first_emoji(input: string): string | undefined;
/** If string contains only emojis count the emojis otherwise retuns null */
export function count_emojis_if_only_contains_emoji(input: string): number | undefined;

For Devs

🛠️ Build with wasm-pack build

wasm-pack build --scope deltachat --target web

🔬 Test in Headless Browsers with wasm-pack test

wasm-pack test --headless --firefox

🎁 Publish to NPM with wasm-pack publish

wasm-pack publish --target web