🤝 A set of Persian Helpers for NodeJS to make your life easier

Overview

Persian Helpers

Persian Helpers is a minimal NodeJS package with a set of helpers/tools specifically for the Persian/Farsi language.

If you like the package and want to see more features being added in, giving it a star would help the project a lot. Thanks!

Table of contents

Installation

NPM:

npm install persian-helpers --save

Yarn:

yarn add persian-helpers

Usage

Importing Persian Helpers:

import * as persianHelpers from "persian-helpers";

// Or alternatively

import { convertDigits } from "persian-helpers";

  

console.log(persianHelpers.convertDigits("1000"));

// Or

console.log(convertDigits("1000"));

Converting English digits to Persian or vice versa

Options Description Default value
to (optional) Target language for converting the digits fa
separator (optional) A property to use separators for digits. For example with separator being enabled, instead of ۱۰۰۰۰۰۰, ۱,۰۰۰,۰۰۰ will be returned. undefined

Convert a number to Persian digits

convertDigits(1000); // "۱۰۰۰"

Convert a number to English digits

convertDigits("۱۲۳۴", { to: "en" }); // "1234"

Convert a number to Persian digits with digit separator

Note: separator can be set to any string and {separator: true} is a shorthand for {separator: '٬'}. An example is shown below.

convertDigits(1000, { separator: true }); // "۱٬۰۰۰"

convertDigits("مبلغ این محصول 950000 تومان می باشد.", { separator: true }); // "مبلغ این محصول ۹۵۰٬۰۰۰ تومان می باشد."

Convert a number to Persian digits with custom digit separator

convertDigits(1000, { separator: '-' }); // "۱-۰۰۰"

convertDigits also takes inputs other than number/string as shown below.

Convert a nested array to Persian digits

convertDigits([123, { test: '11۱' }, '4foo5bar6', [789]]); // [ '۱۲۳', { test: '۱۱۱' }, '۴foo۵bar۶', ['۷۸۹'], ]

Separating Persian or English digits in a string or number by commas or any separator

Options Description Default value
separator (optional) The string used for separating the digits. ,

Separate digits by commas in a string with Persian numbers

separateDigitsBySeparator('۱۰۰۰۰۰۰'); // "۱,۰۰۰,۰۰۰"

Separate digits by an unique separator in a string with Persian numbers

separateDigitsBySeparator('۱۰۰۰۰۰۰', { separator: '-' }); // "۱-۰۰۰-۰۰۰"

Separate digits by commas in a string containing numbers and letters

separateDigitsBySeparator('مبلغ این محصول ۱۰۰۰۰۰۰ تومان می باشد.'); // "مبلغ این محصول ۱,۰۰۰,۰۰۰ تومان می باشد."

Note: separateDigitsBySeparator also works with English digits or a string mixed with English and Persian digits

Generate Persian or English slugs based on a string

Options Description Default value
includeUpperCase (optional) Include upper case letters in the slug false
separator (optional) The separator between spaces in the slug -
to (optional) Target language for the slug en

Generate an English slug based on Persian string

generateSlug('سلام دنیا 💕'); // "slam-dnya"

Generate a Persian slug based on Persian string

generateSlug('سلام دنیا 💕'); // "سلام-دنیا"

Generate a Persian slug based on Persian string with an unique separator

generateSlug('سلام دنیا 💕', { separator: ' ' }); // "slam dnya"

Generate an English slug an also include uppercases

generateSlug('پکیج Persian Helper', { includeUpperCase: true }); // "pkyj-Persian-Helper"

Convert digits to words in Persian

Options Description Default value
ordinal (optional) Convert digits to ordinal digits false
throwErrorIfInvalid (optional) Throw error if digits cannot be converted false

Generate words from a number

convertDigitsToWords(1234) // "یک هزار و دویست و سی و چهار"
convertDigitsToWords(1234.121) // "یک هزار و دویست و سی و چهار ممیز یکصد و بیست و یک هزارم"
convertDigitsToWords(99999) // "نود و نه هزار و نهصد و نود و نه"

Generate words from Persian Digits

convertDigitsToWords('۹۹۹۹۹'); // "نود و نه هزار و نهصد و نود و نه"

Generate ordinal numbers from English/Persian digits

convertDigitsToWords(4, { ordinal: true }); // "چهارم"
convertDigitsToWords(41, { ordinal: true }); // "چهل و یکم"
convertDigitsToWords("۱", { ordinal: true }); // "اول"

Generate words from input but throw error if the input is invalid

convertDigitsToWords('۱', { ordinal: true, throwErrorIfInvalid: true }) // "اول"

convertDigitsToWords('۱d7s9dhsihd', { ordinal: true, throwErrorIfInvalid: true }) // Error: Cannot convert "۱d7s9dhsihd" to words.

Find any bugs/issues? Have suggestions?

If you encountered any issues or bugs while using Persian Helpers, or you want to see a feature getting added, please make sure to open a new issue.

Contribution

Contributions to Persian Helpers are greatly appreciated. To contribute:

  1. Fork the Project

  2. Create your Feature Branch (git checkout -b feature/NewHelper)

  3. Commit your Changes (git commit -m 'Add a NewHelper')

  4. Push to the Branch (git push origin feature/NewHelper)

  5. Open a Pull Request

License

Persian Helpers is licensed under the MIT License. Visit LICENSE.md for more information.

You might also like...

List of ~240,000 Persian words

an-array-of-persian-words List of ~240,000 English words. Derived from the Dehkhoda dictionary. Install npm: npm install an-array-of-persian-words Use

Mar 16, 2022

Multi-step wizard helpers for Alpine.js

Multi-step wizard helpers for Alpine.js

Alpine Wizard This package provides an Alpine directive (x-wizard) and a magic helper ($wizard) that allow you to quickly build multi-step wizards usi

Dec 23, 2022

Javascript Library providing form validation helpers

Javascript-Form-Validation Javascript Library providing form validation helpers Table of contents Installation Usage Include Library Use components Co

Mar 25, 2022

Bootstrap Persian/Gregorian Date Time Picker

Bootstrap Persian/Gregorian Date Time Picker

MD.BootstrapPersianDateTimePicker Bootstrap 5+ Persian And Gregorian Date Time Picker Major changes: Using Bootstrap 5 jQuery Removed Rewrite all code

Nov 23, 2022

A simple offline captcha in persian.

Nastaliq Captcha A simple offline captcha in persian. How to install npm install --save nastaliq-captcha How to use : const express = require("express

Nov 7, 2022

A JavaScript Library To Make Your Work Work Easier/Faster

Functionalty.js (beta) About ✍️ This Is A JavaScript Library To Make Your Work Easier/Faster, You Can See Functionalty.js Website From Here Project Cr

Aug 30, 2022

A JavaScript Library To Make Your Work Work Easier/Faster

Functionality.js (beta) About ✍️ This Is A JavaScript Library To Make Your Work Easier/Faster, You Can See Functionalty.js Website From Here Project C

May 25, 2022

A JavaScript Library To Make Your Work Work Easier/Faster

A JavaScript Library To Make Your Work Work Easier/Faster

Functionality.js About ✍️ This Is A JavaScript Library To Make Your Work Easier/Faster, You Can See Functionalty.js Website From Here Project Created

Jun 23, 2022

Make drag-and-drop easier using DropPoint. Drag content without having to open side-by-side windows

Make drag-and-drop easier using DropPoint. Drag content without having to open side-by-side windows

Make drag-and-drop easier using DropPoint! DropPoint helps you drag content without having to open side-by-side windows Works on Windows, Linux and Ma

Dec 29, 2022
Releases(v0.1.2)
  • v0.1.2(Apr 1, 2022)

    What's Changed

    • Fix issue in convert digits to words by @kasraghoreyshi in https://github.com/kasraghoreyshi/persian-helpers/pull/3

    Full Changelog: https://github.com/kasraghoreyshi/persian-helpers/compare/v0.1.1...v0.1.2

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Mar 31, 2022)

    What's Changed

    • Add support for decimals in convertDigitsToWords by @kasraghoreyshi in https://github.com/kasraghoreyshi/persian-helpers/pull/2
    • Fix multiple bugs and issues

    Full Changelog: https://github.com/kasraghoreyshi/persian-helpers/compare/v0.1.0...v0.1.1

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Mar 29, 2022)

Owner
Kasra Ghoreyshi
16, Iran
Kasra Ghoreyshi
An easy-to-use library to make your life easier when working with random numbers or random choices in javascript.

vrandom An easy-to-use library to make your life easier when working with random numbers or random choices in javascript. Table of contents Installati

Valerio Cipolla 1 Aug 16, 2022
A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Jean Rodríguez 7 Sep 13, 2022
Conways-game-of-life - A Conway's Game Of Life project using Python

conways-game-of-life A Conway's Game Of Life project using Python JavaScript Devlog January 1st 2022: also need to remember Python's syntax a bit will

Felipe Melgaço Magesty Silveira 0 Sep 23, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A JavaScript module that shortens your code, makes life easier, and makes development faster!

Quxt A JavaScript module that shortens your code, makes life easier, and makes development faster! Installation npm install quxt Quick Start Check ind

Qux App 5 May 8, 2022
A template created with the intention of making my life easier when starting a project, and the lives of other people. :>

Express API A simple and improved api with ExpressJS. ?? | Glossary Dependencies How to Start Routes Controllers & Models License Author ?? | Dependec

Feh's 3 Sep 22, 2022
pre-calculated list of similar Persian words ordered by rating and best match

similar-persian-words pre-calculated list of similar Persian words ordered by rating and best match. Install npm: npm install similar-persian-words Us

peyman farahmand 6 May 29, 2022