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

@giancosta86/hermes-react

v3.1.0

Published

Elegant i18n for React in TypeScript

Downloads

9

Readme

hermes-react

Elegant i18n for React in TypeScript

GitHub CI npm version MIT License

Screenshot

hermes-react is a TypeScript library for React dedicated to i18n - especially elegant decorated typography, for example romanization of non-latin writing systems - inspired by my general-purpose hermes library.

Installation

TypeScript

The package on NPM is:

@giancosta86/hermes-react

The public API entirely resides in the root package index, so you shouldn't reference specific modules.

CSS stylesheet

The library comes with a ready-made CSS stylesheet - providing typographic enhancements such as pinyin tone colors - which you can optionally reference in your projects.

In particular, if you are using Next.js, you just need to add one line to the import block of your _app.tsx file:

import "@giancosta86/hermes-react/dist/index.css";

Once referenced the CSS stylesheet, if you start decorating characters with the provided metadata - such as the ones in the Pinyin namespace - you'll see them rendered in color by the <DecoratedText/> component.

Usage

DecoratedText

<DecoratedText/> is a component with the following properties:

  • text - the text to be formatted

  • metadataByChar - mapping each decorated character to its typographic metadata

where metadataByChar is just an object whose entries have:

  • for key, a single character that should be decorated

  • for value, the related CharMetadata object containing at least one of:

    • the annotation string - to be printed on top of the character

    • optionally, a class name string used to style the whole character box

The component formats the given text according to the following algorithm:

  1. The text is trimmed

  2. Any \r\n is converted to \n

  3. Every additional \n at the end of a \n\n sequence is ignored

  4. The text is split into paragraphs - <p> blocks - separated by \n\n sequences that are used as separators and then ignored

  5. Within every paragraph:

    1. \n is mapped to <br/>

    2. for every other character:

      • if the character has metadata in the metadataByChar map:

        • the related annotation string is printed on top of the character

        • the whole structure is packed into a <ruby> tag, styled with the (optional) requested classes

      • otherwise, the character is printed verbatim, with no additional HTML tags

Pinyin - Simplified Chinese

When annotating a pinyin logogram, you can associate to its className metadata one of the following values (actually, strings) of the Pinyin namespace:

  • flat

  • rising

  • fallingRising

  • falling

  • neuter

If you need more granular control, you can reference the constants declared in the PinyinTone namespace - having the same names but providing just the tone class name.

If you import the stylesheet provided by the library, the component will render the characters in color.

Glyph character classes

The Glyph namespace provides general-purpose class names - such as latin, nonLatin, phonogram, logogram, ..., which you can use to style your decorated characters.

Russian

Russian alphabet

Via the Russian.metadataByChar object, you can add romanization to any Russian text - as well as a default set of fine-grained, stylable CSS classes:

import { DecoratedText, Russian } from "@giancosta86/hermes-react";

<DecoratedText
  text="АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя"
  metadataByChar={Russian.metadataByChar}
/>;

Of course, should you need just the CSS classes instead of the romanization, you can simply create a custom copy of Russian.metadataByChar without the annotation field.

See also

  • hermes - Minimalist i18n in TypeScript

  • rimbu - Immutable collections and tools for TypeScript

  • Next.js - The React Framework for the Web