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

number-translator

v2.0.1

Published

Translate numbers into words!

Downloads

36

Readme

Number-translator

How to use:

    const { translateNumber } = require("number-translator");
    
    translateNumber(x)        // where x is number OR string of numbers.
    translateNumber(123)      // —> "сто двадцать три"
    translateNumber("123")    // —> "сто двадцать три"
    translateNumber(-1.23)    // —> "минус одна целая двадцать три сотых"
    translateNumber(2231.1)   // —> "две тысяча двести тридцать одна целая одна десятая"

Breaking change in 2.0.0

translateNumber returns an object with two properties — type and message. This was done in order to distinguish if input was valid or not.

    const { translateNumber } = require("number-translator");
    
    translateNumber(x)        // where x is number OR string of numbers.
    translateNumber(123)      // —> {message: "сто двадцать три", type: "valid"}
    translateNumber("123")    // —> {message: "сто двадцать три", type: "valid"}
    translateNumber(-1.23)    // —> {message: "минус одна целая двадцать три сотых", type: "valid"}
    translateNumber(2231.1)   // —> {message: "две тысяча двести тридцать одна целая одна десятая", type: "valid"}
    translateNumber("22.31.1")   // —> {message: /* EXTRA_SYMBOLS_ERROR */, type: "error"}

Limits

Integer

Range: [-10306 + 1, 10306 - 1]

Non-integer

Range: [-10306 + 10-305, 10306 - 10-305]

Errors

Every input passes the next tests in the same order before translating.

Not a number

Next values cause a return of [NOT_A_NUMBER]-error: empty value (nothing is passed), empty string (""), [], {}, null, NaN, undefined Also, if input is a string where the first symbol is not a number, function will return a [NOT_A_NUMBER]-error.

translateNumber(); // —> "Passed value is not a number."

Not safe number

Then, if the passed value is a number (not a string of numbers) that is not from the range [-9007199254740991; 9007199254740991], it causes a return of the [NOT_SAFE_NUMBER]-error.

translateNumber(13151521521513839838443821214); // —> "Passed number is not safe. Safe numbers are numbers in range [-9007199254740991; 9007199254740991]. You can pass the number wrapped in quotes to avoid this limitation."

Non-numeric symbols

Any character except of digits, "-" and "." causes a return of a [NON_NUMERIC_SYMBOLS]-error.

translateNumber("21412f212412412"); // —> "There are non-numeric symbols in the passed string."

Extra symbols

If there are more than one of "-" or ".", then it returns an [EXTRA_SYMBOLS]-error.

translateNumber("-2222222-222222"); // —> "Passed number is not a valid number."

Too big number

If the number is out of the limits, then it returns a [TOO_BIG_NUMBER]-error.

translateNumber("1".repeat(307)); // —> "Passed number is not a valid number."

Live demo:

https://hstff.csb.app/