Achar
All the utility functions you'll need to build a fully functional e-commerce site
Created with
Getting started
Achar is an open-source, free project developed by the Basalam developers. You can use the achar-js
package in your e-commerce project by installing it from npm
$ npm install achar-js // Or $ npm install --save achar-js for npm < 5.0.0
Or
$ yarn add achar-js
Basic usage
You can use achar-js like any other JavaScript package.
// Full Import
import * as achar from "achar-js"
achar.rialToToman(20000, { currencry: true, separator: true }) // تومان 2,000
// Import multiple utilities
import { rialToToman, isObject } from "achar-js"
isObject({}) // true
rialToToman(20000, { currencry: true, separator: true }) // تومان 2,000
// Single use (Default Exported)
import rialToToman from "achar-js/rialToToman"
rialToToman(20000, { currencry: true, separator: true }) // تومان 2,000
Usage
Here you can see an overview of the different utilities available and how they work
convertToSnakeCase
Converts snake_case
words to camelCase
import { convertToSnakeCase } from "achar-js"
convertToSnakeCase("message_status") // messageStatus
It's also works with javascript objects or arrays
convertToSnakeCase({ message_status: "dont_touch", items: ["camel_me"] }) // { messageStatus: "dont_touch", items: ["camelMe"] }
generateUniqueId
Generates a unique id with the requested length
import { generateUniqueId } from "achar-js"
generateUniqueId(16) // fk5ghtmvlprt2zyn
isObject
Checks whether the input value is an object or not
import { isObject } from "achar-js"
isObject({}) // true
isObject([]) // false
isObject([]) // false
numberSeparator
Separates the inputted number
import { numberSeparat } from "achar-js"
numberSeparat(2000) // "2,000"
numberSeparat("2000") // "2,000"
rialToToman
Converts Rials to Tomans
import { rialToToman } from "achar-js"
rialToToman(20000) // 2000
rialToToman("20000") // "2000"
rialToToman("20000", { currency: true }) // "2000 تومان"
rialToToman("20000", { separator: true }) // "2,000"
rialToHumanizeToman
Converts Rials to Tomans in a human-readable form
import { rialToHumanizeToman } from "achar-js"
rialToHumanizeToman(20000) // "2,000 تومان"
toEnglishDigits
Converts Arabic or Persian numbers to English
import { toEnglishDigits } from "achar-js"
toEnglishDigits("۴۰۰۰ بار سلام بر تو") // "4000 بار سلام بر تو"
toEnglishDigits("٤۰۰۰ تحية لكم") // "4000 تحياتي لكم"