https://github.com/fl3xice/humanity
Humanizer for Deno & NodeJS
https://github.com/fl3xice/humanity
deno humanizer nodejs
Last synced: 27 days ago
JSON representation
Humanizer for Deno & NodeJS
- Host: GitHub
- URL: https://github.com/fl3xice/humanity
- Owner: fl3xice
- License: agpl-3.0
- Created: 2022-07-01T22:27:09.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-05T00:28:26.000Z (almost 4 years ago)
- Last Synced: 2025-06-17T09:06:16.673Z (12 months ago)
- Topics: deno, humanizer, nodejs
- Language: TypeScript
- Homepage:
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Humanity
[](https://github.com/fl3xice/humanity/actions/workflows/deno.yml)


[](https://www.npmjs.com/package/humanity-deno)
[](https://deno.land/x/humanity)

Humanity is a library for humanizing data in a human-readable form.
## How to use
### Deno
```typescript
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
```
```javascript
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
```typescript
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
```
## Disable spaces between number and word
```typescript
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`
- 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"`
## Supported languages by default
_You can customize defaults the language and create yourself language_
- `en_US`
- `de_DE`
- `ru_RU`