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

saudi-riyal

v1.0.0

Published

The definitive Saudi Riyal (SAR) symbol library. Auto-detects Unicode 17 support, provides smart fallbacks, and formats currency beautifully.

Downloads

18

Readme

🇸🇦 Saudi Riyal

npm version License: MIT TypeScript

The definitive Saudi Riyal (SAR) library. Display and format the Saudi Riyal symbol with automatic Unicode 17 detection, smart fallbacks, and beautiful formatting.

🇸🇦 اقرأ بالعربي


Why This Library?

| Feature | saudi-riyal | Others | |---------|-------------|--------| | Unicode 17 (U+20C1) auto-detection | ✅ | ❌ | | Smart fallback chain | ✅ | ❌ | | Works without custom fonts | ✅ | ❌ | | Number formatting (Arabic/English) | ✅ | ❌ | | React/Vue components | ✅ | ❌ | | TypeScript support | ✅ | Partial | | Zero dependencies (core) | ✅ | ❌ | | Tree-shakeable | ✅ | ❌ |

Quick Start

npm install saudi-riyal
import { sar, formatSAR } from 'saudi-riyal';

// Get the symbol (auto-detects best method)
console.log(sar()); // ﷼ or the new Unicode 17 symbol

// Format currency
console.log(formatSAR(1234.56)); // ﷼ 1,234.56

That's it. No font setup, no configuration. It just works.


Features

🔮 Future-Proof

Automatically uses Unicode 17's official Saudi Riyal symbol (U+20C1) when the system supports it. Falls back gracefully on older systems.

import { supportsUnicode17, detectBestStrategy } from 'saudi-riyal';

if (supportsUnicode17()) {
  console.log('Your system supports the new symbol!');
}

console.log(detectBestStrategy()); // 'unicode17' | 'font' | 'legacy'

💰 Beautiful Formatting

import { formatSAR, format } from 'saudi-riyal';

// Basic formatting
formatSAR(1234.56);                    // ﷼ 1,234.56

// Arabic numerals
formatSAR(1234.56, { arabicNumerals: true }); // ﷼ ١٬٢٣٤٫٥٦

// Arabic style (symbol after)
format.ar(1234.56);                    // ١٬٢٣٤٫٥٦ ﷼

// English style
format.en(1234.56);                    // SAR 1,234.56

// Compact notation
format.compactAr(1500000);             // ١.٥ مليون ﷼
format.compactEn(1500000);             // SAR 1.5M

// Accounting format (negative in parentheses)
format.accounting(-1234.56);           // (﷼ 1,234.56)

⚛️ React Components

import { SaudiRiyal, SaudiRiyalPrice, useSaudiRiyal } from 'saudi-riyal/react';

// Simple symbol
<SaudiRiyal /> 100

// Formatted price
<SaudiRiyalPrice amount={1234.56} />
<SaudiRiyalPrice amount={1234.56} arabicNumerals />
<SaudiRiyalPrice amount={1500000} compact />

// Hook for custom usage
function PriceDisplay() {
  const { symbol, strategy } = useSaudiRiyal();
  return <span>{symbol} 100</span>;
}

💚 Vue Components

<script setup>
import { SaudiRiyal, SaudiRiyalPrice } from 'saudi-riyal/vue';
</script>

<template>
  <SaudiRiyal /> 100
  <SaudiRiyalPrice :amount="1234.56" />
  <SaudiRiyalPrice :amount="1234.56" arabic-numerals />
</template>

🎨 CSS Utilities

<!-- Include the CSS -->
<link rel="stylesheet" href="https://unpkg.com/saudi-riyal/dist/saudi-riyal.css">

<!-- Use the classes -->
<span class="sar"></span> 100
<span class="sar-before">100</span>
<span class="sar-after">100</span>

<!-- With the price component -->
<span class="sar-price">1,234.56</span>

Installation

npm / yarn / pnpm

npm install saudi-riyal
yarn add saudi-riyal
pnpm add saudi-riyal

CDN

<!-- ESM -->
<script type="module">
  import { sar, formatSAR } from 'https://esm.sh/saudi-riyal';
</script>

<!-- CSS only -->
<link rel="stylesheet" href="https://unpkg.com/saudi-riyal/dist/saudi-riyal.css">

API Reference

Symbol Functions

sar(options?)

Get the Saudi Riyal symbol string.

sar()                           // Auto-detect best symbol
sar({ strategy: 'legacy' })     // Force legacy symbol (﷼)
sar({ strategy: 'unicode17' })  // Force Unicode 17 (may not render)
sar({ strategy: 'text-ar' })    // Use text (ر.س)

getSymbol(options?)

Get the symbol with metadata.

const result = getSymbol();
console.log(result.symbol);     // The symbol string
console.log(result.strategy);   // Which strategy was used
console.log(result.isPreferred); // Whether this is the best available

Formatting Functions

formatSAR(amount, options?)

Format a number as Saudi Riyal currency.

| Option | Type | Default | Description | |--------|------|---------|-------------| | locale | string | 'ar-SA' | Locale for number formatting | | decimals | number | 2 | Decimal places | | symbolPosition | 'before' \| 'after' | auto | Symbol position | | space | boolean | true | Space between symbol and number | | arabicNumerals | boolean | false | Use ٠١٢٣٤٥٦٧٨٩ | | compact | boolean | false | Compact notation (1K, 1M) | | accounting | boolean | false | Parentheses for negative | | useCode | boolean | false | Use "SAR" instead of symbol |

parseSAR(formatted)

Parse a formatted string back to a number.

parseSAR('﷼ 1,234.56');     // 1234.56
parseSAR('١٬٢٣٤٫٥٦ ر.س');   // 1234.56

Detection Functions

supportsUnicode17()

Check if the system supports the Unicode 17 symbol.

supportsSaudiRiyalFont(fontFamily?)

Check if a custom font is loaded.

detectBestStrategy()

Get the recommended rendering strategy.


Symbol Reference

| Symbol | Code Point | Support | Use Case | |--------|------------|---------|----------| | (new) | U+20C1 | Unicode 17+ | Future-proof apps | | ﷼ | U+FDFC | Universal | Maximum compatibility | | (font) | U+E900 | Custom font | When font is loaded | | ر.س | Text | Universal | Fallback | | SAR | Text | Universal | International |


Browser Support

  • ✅ Chrome 80+
  • ✅ Firefox 75+
  • ✅ Safari 13+
  • ✅ Edge 80+
  • ✅ Node.js 16+

Unicode 17 symbol support depends on system fonts (expected in OS updates 2025-2026).


Migration from Other Libraries

From @emran-alhaddad/saudi-riyal-font

// Before: Required font setup
import "@emran-alhaddad/saudi-riyal-font/index.css";
// <span class="icon-saudi_riyal_new"></span>

// After: Just works
import { sar } from 'saudi-riyal';
console.log(sar()); // Automatically uses best available method

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © Abdullah Alzhrani