Skip to content

fl3xice/humanity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Humanity

Deno GitHub GitHub release (latest SemVer) npm

GitHub Repo stars

Humanity is a library for humanizing data in a human-readable form.

How to use

Deno

import { createHumanity } from "https://deno.land/x/humanity/mod.ts";

const Humanity = createHumanity("en_US");

console.log(Humanity.number(500000)); // 500 000
// Output: 500 thousand

NodeJS

You can use it library with NodeJS

npm i humanity-deno
const { createHumanity } = require("humanity-deno");

const Humanity = createHumanity("en_US");

console.log(Humanity.number(500000)); // 500 000
// Output: 500 thousand

You can use custom language

import { createCustomHumanity } from "https://deno.land/x/humanity/mod.ts";
const Humanity = createCustomHumanity({
    locale: "custom",
    numbers: {
        thousand: "th",
        million: "m",
        billion: "b",
        trillion: "t",
        quadrillion: "q",
        quintillion: "qui",
    },
});

console.log(Humanity.number(500000)); // 500 th

Disable spaces between number and word

Humanity.disableFeature("spacing");
console.log(Humanity.number(500000)); // 500thousand

Available functions

  • number(n: number | bigint): string
    Humanity.number(500000) // 500 thousand
  • truncate(n: string | number | bigint, lengthMax: number): string
    Humanity.truncate("Humanity is a library for humanizing data in a human-readable form.", 24) // "Humanity is a library fo..."
  • toRoman(n: number): string
    Humanity.toRoman(505) // DV
  • binarySuffix(n: number, fixed = 2): string
    Humanity.binarySuffix(500, 0) // 500 B

Supported languages by default

You can customize defaults the language and create yourself language

  • en_US
  • de_DE
  • ru_RU