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

react-rtl-utils

v1.0.1

Published

React utilities for RTL layouts — hooks and components for bidirectional text, RTL-aware positioning, and direction detection

Readme

react-rtl-utils — React Hooks & Components for RTL and Bidirectional Text

npm version npm downloads CI TypeScript License: MIT

React hooks and components for RTL layouts — auto-detect text direction, flip styles, and handle bidirectional content for Hebrew, Arabic, and Persian apps. Zero dependencies.

import { useTextDirection, BidiText } from "react-rtl-utils";

const dir = useTextDirection("שלום עולם"); // "rtl"
<BidiText>שלום עולם</BidiText>  // auto dir="rtl"
<BidiText>Hello World</BidiText> // auto dir="ltr"

For Hebrew, Arabic, Persian, and Urdu apps. Zero dependencies.

react-rtl-utils demo — auto-detecting text direction for Hebrew and English in React

Install

npm install react-rtl-utils

Usage

Direction Detection

import { detectDirection, isRtl, isMixed } from "react-rtl-utils";

detectDirection("שלום עולם"); // "rtl"
detectDirection("Hello World"); // "ltr"
isRtl("مرحبا"); // true
isMixed("hello שלום"); // true

Hooks

import {
  useDirection,
  useTextDirection,
  useDocumentDirection,
} from "react-rtl-utils";

function App() {
  const { direction, toggleDirection } = useDirection("ltr");
  return (
    <div dir={direction}>
      <button onClick={toggleDirection}>Toggle Direction</button>
    </div>
  );
}

function TextInput({ value }: { value: string }) {
  const dir = useTextDirection(value);
  return <input dir={dir} value={value} />;
}

function Layout() {
  const dir = useDocumentDirection();
  // Reactively tracks <html dir="..."> changes
}

Components

import { BidiText, DirectionProvider, RtlFlip } from "react-rtl-utils";

// Auto-detects direction per text content
<BidiText>שלום עולם</BidiText>
<BidiText>Hello World</BidiText>

// Wraps children with dir attribute
<DirectionProvider direction="rtl">
  <YourApp />
</DirectionProvider>

// Conditionally render based on direction
<RtlFlip
  direction={dir}
  rtl={<span>→</span>}
  ltr={<span>←</span>}
/>

CSS Utilities

import { logicalValue, flipProperty, rtlStyle } from "react-rtl-utils";

logicalValue("rtl", "left", "right"); // "right"
flipProperty("rtl", "marginLeft"); // "marginRight"

const style = rtlStyle(
  "rtl",
  { marginLeft: 10, textAlign: "left" },
  { marginLeft: 0, marginRight: 10, textAlign: "right" },
);

API

Detection

| Function | Description | | ----------------------- | ------------------------------------------------------ | | detectDirection(text) | Returns "rtl" or "ltr" based on character majority | | isRtl(text) | Check if text is RTL | | isLtr(text) | Check if text is LTR | | hasRtlChars(text) | Check if text contains any RTL characters | | hasLtrChars(text) | Check if text contains any LTR characters | | isMixed(text) | Check if text contains both RTL and LTR characters |

Hooks

| Hook | Description | | ------------------------ | --------------------------------------- | | useDirection(initial?) | Stateful direction with toggle | | useTextDirection(text) | Auto-detect direction from text | | useDocumentDirection() | Track <html dir> attribute reactively |

Components

| Component | Description | | --------------------- | ----------------------------------------------- | | <BidiText> | Auto-sets dir attribute based on text content | | <DirectionProvider> | Wraps children with dir attribute | | <RtlFlip> | Renders different content for RTL vs LTR |

CSS Utilities

| Function | Description | | --------------------------------- | ------------------------------ | | logicalValue(dir, start, end) | Pick value based on direction | | flipProperty(dir, prop) | Flip CSS property name for RTL | | rtlStyle(dir, base, overrides?) | Merge RTL style overrides |

Supported RTL Scripts

Hebrew, Arabic, Syriac, Thaana, Mandaic, Arabic Extended, Arabic Presentation Forms

Author

Ofer Shapira

LinkedIn GitHub

License

MIT © Ofer Shapira