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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pronumjs

v1.0.1

Published

A small javascript util library, to convert integer numbers to their written equivalent, currently supports Arabic and English language, and may support other languages

Downloads

7

Readme

pronumjs (pronounce number js)

A small javascript util library, to convert integer numbers to their written equivalent, currently supports Arabic and English language, and may support other languages

Installing

Clone using git

git clone  https://github.com/waelhasan/pronumjs.git  pronumjs
cd pronumjs/
npm install

Install with npm

npm install --save pronumjs

Testing

npm test

Usage

  • Using it is realy simple, just import the convert function, and use it, by passing the number as a number or a string:
const { convert } = require('pronumjs');

console.log(convert(164)); // 'مئة و أربع وستون'
console.log(convert(456295)); // 'أربع مئة و ست وخمسون ألف و مئتان و خمس وتسعون'
console.log(convert(86752985)); // 'ست و ثمانون مليون و سبع مئة و اثنان وخمسون ألف و تسع مئة و خمس وثمانون'
console.log(convert('123456789123')); //'مئة و ثلاث وعشرون بليون و أربع مئة و ست وخمسون مليون و سبع مئة و تسع وثمانون ألف و مئة و ثلاث وعشرون'

Notice that we use the string form of the numbers in the situations where the numbers will change the format in the runtime, e.g. the number 123456789123123876983273 will be converted to the form "1.2345678912312388e+23", which will be a problem for the algorithm (at least currently)

console.log(123456789123123876983273); // logs: 1.2345678912312388e+23

YOU ARE ENCOURAGED TO USE THE STRING FORMAT ALL THE TIME

Also notice that it will throw an error if you:

  • didn't pass any value
  • passed a non numeric value

So this code:

const { convert } = require('pronumjs');

try {
    const value = convert();
    // or any of the following:
    // const value = convert('test');
    // const value = convert(true);
    // const value = convert({ test: true });
}
catch (error) {
    console.log('[X] ERROR: ', error);
}

Will give the following result:

[X] ERROR:  Error: Expected a number or a stringified number, but found something else.
    at translate (/home/wael/dev/pronumjs/src/translate.js:6:15)
    at Object.<anonymous> (/home/wael/dev/pronumjs/test.js:5:17)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:617:3
  • Also you can pass an options object as a second parameter, which can have the following attributes:
  1. language: to choose from the available supported languages (currently "ar" for Arabic, and "en" for English. with "ar" as the default)
console.log(convert(1245, {
    language: 'ar',
}));
// ألف و مئتان و خمس وأربعون

console.log(convert(1245, {
    language: 'en'
}));
// one thousand and two hundred and forty five
  1. unitsSeparator: the string that will be used to separate the different units of the number (each 3 digits are a unit)
console.log(convert(84958, {
    language: 'ar',
    unitsSeparator: '،'
}));
// أربع و ثمانون ألف ، تسع مئة و ثمان وخمسون

console.log(convert(84958, {
    language: 'en',
    unitsSeparator: ', '
}));
// eighty four thousand ,  nine hundred and fifty eight
  1. separator: the string that will be used to separate the digits in the same unit of the number
console.log(convert(456295, {
    language: 'ar',
    separator: 'ثم'
}));
// سبع ملايين ثم خمس مئة و ثلاث وستون ألف ثم تسع مئة و اثنان وثمانون

console.log(convert(456295, {
    language: 'en',
    separator: '&'
}));
// four hundred & fifty six thousand and two hundred & ninety five

You can combine all the options:

console.log(convert(7563982, {
    language: 'ar',
    unitsSeparator: '#',
    separator: '&'
}));
// سبع ملايين # خمس مئة & ثلاث &ستون ألف # تسع مئة & اثنان &ثمانون

console.log(convert(7563982, {
    language: 'en',
    unitsSeparator: '#',
    separator: '&'
}));
// seven millions # five hundred & sixty three thousand # nine hundred & eighty two

Todo:

  • Support gender (in Arabic language)
  • Support floating point numbers
  • Add proper commenting to the code

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details