Humanity is a library for humanizing data in a human-readable form.
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
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
import { createCustomHumanity } from "https://deno.land/x/humanity/mod.ts";
const Humanity = createCustomHumanity({
locale: "custom",
words: {
...DefaultLocales.en_US.words,
},
numbers: {
thousand: "th",
million: "m",
billion: "b",
trillion: "t",
quadrillion: "q",
quintillion: "qui",
},
});
console.log(Humanity.number(500000)); // 500 th
Humanity.disableFeature("spacing");
console.log(Humanity.number(500000)); // 500thousand
- 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
- arrayToText(arr: any[], n = 2): string
Humanity.arrayToText(["Dustin", "Leda", "Tristin", "Maybelle", "Dee", "Stephon"], 3) // Dustin, Leda, Tristin and 3 others
- dateTime.difference(dateFirst: Date, dateAfter: Date): string
Humanity.dateTime.difference(1656532800000, 1659211200000); // 4 weeks ago
- Humanity.humanCase(data: string): string
Humanity.humanCase("mainField") // "Main field"
You can customize defaults the language and create yourself language
en_US
de_DE
ru_RU