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

@vue-persian/composables

v0.1.0

Published

A comprehensive TypeScript library of Persian language composables for Vue.js 3. This library provides utilities for working with Persian numbers, dates, currency, text normalization, and RTL/LTR direction handling.

Readme

@vue-persian/composables

A comprehensive TypeScript library of Persian language composables for Vue.js 3. This library provides utilities for working with Persian numbers, dates, currency, text normalization, and RTL/LTR direction handling.

Installation

npm install @vue-persian/composables
# or
yarn add @vue-persian/composables
# or
pnpm add @vue-persian/composables

Features

  • Direction Management: Toggle between RTL and LTR directions
  • Persian Digits: Convert between Western and Persian numerals
  • Number Formatting: Format numbers with Persian digits and separators
  • Date Conversion: Work with Jalali (Persian) calendar dates
  • Currency Formatting: Format amounts in Rial and Toman
  • Text Normalization: Normalize Persian text (Yeh, Keh, ZWNJ)
  • Input Handling: Auto-convert and normalize input values

Quick Start

<template>
  <div>
    <p>{{ persianDigits }}</p>
    <p>{{ formattedNumber }}</p>
    <p>{{ persianDate }}</p>
  </div>
</template>

<script setup lang="ts">
import { usePersianDigits, usePersianNumber, usePersianDate } from '@vue-persian/composables';

const { persian } = usePersianDigits('123');
const { formatted } = usePersianNumber(1234567);
const { persianDate } = usePersianDate();
</script>

API Documentation

useDirection

Manages document direction (RTL/LTR).

function useDirection(initialDirection?: Direction): {
  direction: Ref<Direction>;
  setDirection: (direction: Direction) => void;
  toggleDirection: () => void;
  isRtl: ComputedRef<boolean>;
}

Example:

<script setup lang="ts">
import { useDirection } from '@vue-persian/composables';

const { direction, setDirection, toggleDirection, isRtl } = useDirection('rtl');
</script>

usePersianDigits

Converts between Western and Persian digits.

function usePersianDigits(initialValue?: string | number): {
  persian: Ref<string>;
  western: ComputedRef<string>;
  setPersian: (value: string | number) => void;
  toWestern: () => string;
  hasPersianDigits: ComputedRef<boolean>;
}

Example:

<script setup lang="ts">
import { usePersianDigits } from '@vue-persian/composables';

const { persian, western, setPersian } = usePersianDigits('123');
console.log(persian.value); // '۱۲۳'
console.log(western.value); // '123'
</script>

usePersianNumber

Formats numbers with Persian digits and custom separators.

function usePersianNumber(
  initialValue?: number | string,
  options?: PersianNumberOptions
): {
  formatted: ComputedRef<string>;
  setNumber: (value: number | string) => void;
}

Options:

interface PersianNumberOptions {
  thousandSeparator?: string;  // Default: '٬'
  decimalSeparator?: string;   // Default: '٫'
  prefix?: string;
  suffix?: string;
  decimals?: number;
}

Example:

<script setup lang="ts">
import { usePersianNumber } from '@vue-persian/composables';

const { formatted } = usePersianNumber(1234567, {
  thousandSeparator: '٬',
  prefix: '$'
});
console.log(formatted.value); // '$۱٬۲۳۴٬۵۶۷'
</script>

usePersianDate

Works with Jalali (Persian) calendar dates.

function usePersianDate(
  initialDate?: Date,
  options?: PersianDateOptions
): {
  persianDate: ComputedRef<string>;
  jalali: ComputedRef<{ jy: number; jm: number; jd: number }>;
  setToday: () => void;
  setJalaliDate: (year: number, month: number, day: number) => void;
  toGregorian: () => { gy: number; gm: number; gd: number };
}

Options:

interface PersianDateOptions {
  format?: 'full' | 'long' | 'short' | 'time' | 'datetime';
  showYear?: boolean;
  showMonth?: boolean;
  showDay?: boolean;
  showWeekday?: boolean;
}

Example:

<script setup lang="ts">
import { usePersianDate } from '@vue-persian/composables';

const { persianDate, jalali, setToday } = usePersianDate(new Date(), {
  format: 'full'
});
console.log(persianDate.value); // 'یکشنبه ۱ فروردین ۱۴۰۳'
</script>

usePersianCurrency

Formats amounts in Rial and Toman.

function usePersianCurrency(
  initialAmount?: number,
  options?: PersianCurrencyOptions
): {
  currency: ComputedRef<string>;
  setAmount: (value: number) => void;
  convertUnit: () => void;
  unitLabel: ComputedRef<string>;
}

Options:

interface PersianCurrencyOptions {
  unit?: 'rial' | 'toman';
  separator?: string;
  decimals?: number;
  showUnit?: boolean;
}

Example:

<script setup lang="ts">
import { usePersianCurrency } from '@vue-persian/composables';

const { currency, convertUnit } = usePersianCurrency(1000000, {
  unit: 'toman',
  showUnit: true
});
console.log(currency.value); // '۱۰۰٬۰۰۰ تومان'
</script>

usePersianText

Normalizes Persian text (Yeh, Keh, ZWNJ).

function usePersianText(
  initialText?: string,
  options?: TextNormalizationOptions
): {
  normalized: ComputedRef<string>;
  yehNormalized: ComputedRef<string>;
  kehNormalized: ComputedRef<string>;
  zwnjHandled: ComputedRef<string>;
  setText: (value: string) => void;
  append: (value: string) => void;
}

Options:

interface TextNormalizationOptions {
  normalizeYeh?: boolean;
  normalizeKeh?: boolean;
  handleZWNJ?: boolean;
}

Example:

<script setup lang="ts">
import { usePersianText } from '@vue-persian/composables';

const { normalized } = usePersianText('سلامي كتاب', {
  normalizeYeh: true,
  normalizeKeh: true
});
console.log(normalized.value); // 'سلامی کتاب'
</script>

usePersianInput

Handles input with auto-conversion and normalization.

function usePersianInput(options?: {
  autoConvert?: boolean;
  normalize?: boolean;
  textOptions?: TextNormalizationOptions;
}): {
  value: Ref<string>;
  inputAttrs: ComputedRef<{ value: string; dir: 'rtl' }>;
  handleInput: (event: Event) => void;
  handlePaste: (event: ClipboardEvent) => void;
}

Example:

<template>
  <input v-bind="inputAttrs" @input="handleInput" @paste="handlePaste" />
</template>

<script setup lang="ts">
import { usePersianInput } from '@vue-persian/composables';

const { inputAttrs, handleInput, handlePaste } = usePersianInput({
  autoConvert: true,
  normalize: true
});
</script>

Utility Functions

Digits

import {
  toPersianDigits,
  toWesternDigits,
  hasPersianDigits,
  formatNumber
} from '@vue-persian/composables';

toPersianDigits('123'); // '۱۲۳'
toWesternDigits('۱۲۳'); // '123'
hasPersianDigits('۱۲۳'); // true
formatNumber(1234567, { thousandSeparator: '٬' }); // '۱٬۲۳۴٬۵۶۷'

Text

import {
  normalizeYeh,
  normalizeKeh,
  handleZWNJ,
  normalizePersianText
} from '@vue-persian/composables';

normalizeYeh('سلامي'); // 'سلامی'
normalizeKeh('كتاب'); // 'کتاب'
handleZWNJ('میروم'); // 'می\u200cروم'
normalizePersianText('سلامي كتاب', {
  normalizeYeh: true,
  normalizeKeh: true
}); // 'سلامی کتاب'

Types

type Direction = 'rtl' | 'ltr';

interface PersianNumberOptions {
  thousandSeparator?: string;
  decimalSeparator?: string;
  prefix?: string;
  suffix?: string;
  decimals?: number;
}

interface PersianCurrencyOptions {
  unit?: 'rial' | 'toman';
  separator?: string;
  decimals?: number;
  showUnit?: boolean;
}

type DateFormat = 'full' | 'long' | 'short' | 'time' | 'datetime';

interface PersianDateOptions {
  format?: DateFormat;
  showYear?: boolean;
  showMonth?: boolean;
  showDay?: boolean;
  showWeekday?: boolean;
}

interface TextNormalizationOptions {
  normalizeYeh?: boolean;
  normalizeKeh?: boolean;
  handleZWNJ?: boolean;
}

interface JalaliDate {
  jy: number;
  jm: number;
  jd: number;
}

Contributing

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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

MIT

Acknowledgments