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

@victorzimnikov/number-to-words

v0.0.9

Published

Число прописью

Downloads

160

Readme

number-to-words

Написание числа прописью
yarn add @victorzimnikov/number-to-words
Словарь
/**
 * words - массив слов для единиц, десяктов и сотен
 * cent - массив или строка для ниписания слова "копейка"
 * million - массив или строка для ниписания слова "миллион"
 * billion - массив или строка для ниписания слова "миллиард"
 * currency - массив или строка для ниписания валюты
 * thousand - массив или строка для ниписания слова "тысяча"
 * declinationOfThousands - функция для форматирования префикса для тысяч
 */

interface DictionaryProps {
  readonly words: string[][];
  readonly cent: string | string[];
  readonly million: string | string[];
  readonly billion: string | string[];
  readonly currency: string | string[];
  readonly thousand: string | string[];
  readonly declinationOfThousands?: (word: string) => string;
}
Доступные языки
export enum Language {
  Uzbek = "uz",
  Russian = "ru",
  English = "en",
}
Доступные валюты
export enum CurrencyCode {
  RussianRuble = "RUR",
  UzbekistanSum = "UZS",
  UnitedStatesDollar = "USD",
}
Настройки преобразования
/**
 * language - Язык преобразования
 * withStartZero - флаг, разрешающий добавлять ноль для перед единичными копейками. По-умолчанию - true
 * showZeroCents - флаг, разрешающий показывать "00 копеек". По-умолчанию - true
 * dictionary - словари
 * currencyCode - Валюта преобразования
 */

interface FormatNumberToWordOptionProps {
  readonly language: Language;
  readonly withStartZero?: boolean;
  readonly showZeroCents?: boolean;
  readonly dictionary: DictionaryType;
  readonly currencyCode: CurrencyCode;
}
Функция для преобразования
function formatNumberToWord(
  number: number | string,
  {
    currencyCode,
    language,
    dictionary,
    showZeroCents,
    withStartZero,
  }: FormatNumberToWordOptionProps,
): string {}
Пример использования
import {
  CurrencyCode,
  DictionaryType,
  formatNumberToWord,
  Language,
} from "@victorzimnikov/number-to-words";

export const NUMBER_TO_WORDS_DICTIONARY: DictionaryType = {
  [CurrencyCode.RussianRuble]: {
    [Language.Russian]: {
      cent: ["копейка", "копейки", "копеек"],
      currency: ["рубль", "рубля", "рублей"],
      thousand: ["тысяча", "тысячи", "тысяч"],
      million: ["миллион", "миллиона", "миллионов"],
      billion: ["миллиард", "миллиарда", "миллиардов"],
      declinationOfThousands: x => x.replace("один ", "одна ").replace("два ", "две "),
      words: [
        [
          "один",
          "два",
          "три",
          "четыре",
          "пять",
          "шесть",
          "семь",
          "восемь",
          "девять",
          "десять",
          "одиннадцать",
          "двенадцать",
          "тринадцать",
          "четырнадцать",
          "пятнадцать",
          "шестнадцать",
          "семнадцать",
          "восемнадцать",
          "девятнадцать",
        ],
        [
          "двадцать",
          "тридцать",
          "сорок",
          "пятьдесят",
          "шестьдесят",
          "семьдесят",
          "восемьдесят",
          "девяносто",
        ],
        [
          "сто",
          "двести",
          "триста",
          "четыреста",
          "пятьсот",
          "шестьсот",
          "семьсот",
          "восемьсот",
          "девятьсот",
        ],
      ],
    },
  },
};

function numberToWords(number: string | number, options?: FormatNumberToWordOptionProps): string {
  return formatNumberToWord(number, {
    dictionary: NUMBER_TO_WORDS_DICTIONARY,

    ...options,
  });
}

const amountDetails = numberToWords(123, {
  language: Language.Russian,
  currencyCode: CurrencyCode.RussianRuble,
});

console.log(amountDetails); //  Сто двадцать три рубля 00 копеек