Gathering detailed insights and metrics for @visulima/humanizer
Gathering detailed insights and metrics for @visulima/humanizer
Gathering detailed insights and metrics for @visulima/humanizer
Gathering detailed insights and metrics for @visulima/humanizer
Visulima is the next-gen JavaScript framework for JAMStack blogs, sites & apps.
npm install @visulima/humanizer
Typescript
Module System
Min. Node Version
Node Version
NPM Version
@visulima/cerebro@1.1.46
Updated on Jun 04, 2025
@visulima/boxen@2.0.2
Updated on Jun 04, 2025
@visulima/pail@2.1.25
Updated on Jun 04, 2025
@visulima/api-platform@3.0.44
Updated on Jun 04, 2025
@visulima/jsdoc-open-api@2.0.81
Updated on Jun 04, 2025
@visulima/find-cache-dir@1.0.31
Updated on Jun 04, 2025
TypeScript (93.51%)
JavaScript (5.17%)
MDX (1.02%)
Handlebars (0.14%)
Shell (0.08%)
CSS (0.08%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
16 Stars
2,703 Commits
3 Forks
2 Watchers
17 Branches
2 Contributors
Updated on Jun 10, 2025
Latest Version
1.2.2
Package Id
@visulima/humanizer@1.2.2
Unpacked Size
296.03 kB
Size
63.88 kB
File Count
352
NPM Version
10.9.2
Node Version
18.20.8
Published on
Jun 04, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
Humanizer is a library for humanizing data in a human-readable form.
[][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
Daniel Bannert's open source work is supported by the community on GitHub Sponsors
1npm install @visulima/humanizer
1yarn add @visulima/humanizer
1pnpm add @visulima/humanizer
Convert bytes to human-readable strings and vice versa: 1024 → 1KB and 1KB → 1024
1import { formatBytes, parseBytes } from "@visulima/humanizer"; 2 3console.log(formatBytes(123412341, { decimals: 2 })); // "117.70 MB" 4console.log(parseBytes("117.70 MB")); // 123417395.2 5 6// Localization support in both directions 7console.log(formatBytes(123412341, { decimals: 2, locale: "de" })); // "117,70 MB" 8console.log(parseBytes("117,70 MB", { locale: "de" })); // 123417395.2 9 10// Use a specified unit 11console.log(formatBytes(123412341, { decimals: 2, unit: "KB" })); // "120,519.86 KB" 12 13// Use a long unit 14console.log(formatBytes(123412341, { decimals: 2, unit: "GB", long: true })); // "0.11 Gigabytes" 15 16// Use a differnet base 17console.log(formatBytes(123412341, { decimals: 2, base: 10 })); // "123.41 MB"
Default: "en".
formatBytes
and parseBytes
supports the following locales:
duration
andparseDuration
functionality is based on a modified version of HumanizeDuration.
Format time in milliseconds into a human-readable string like "30 minutes" or "3 days, 1 hour". Parse various human-readable duration strings back into milliseconds.
1import { duration, parseDuration } from "@visulima/humanizer"; 2import { durationLanguage as fr } from "@visulima/humanizer/language/fr"; // Example language import 3 4// --- Formatting --- 5console.log(duration(3000)); 6// => "3 seconds" 7 8console.log(duration(2250)); 9// => "2.25 seconds" 10 11console.log(duration(97320000)); 12// => "1 day, 3 hours, 2 minutes" 13 14// --- Parsing --- 15console.log(parseDuration("1 day, 3 hours, 2 minutes")); 16// => 97320000 17 18console.log(parseDuration("2h 30 min")); 19// => 9000000 20 21console.log(parseDuration("-3 weeks")); 22// => -1814400000 23 24console.log(parseDuration("1.5 years")); 25// => 47335428000 26 27// Parsing with different languages (requires language object with unitMap) 28console.log(parseDuration("2 jours et 5 heures", { language: fr })); 29// => 190800000 30 31// Parsing colon format (H:MM:SS or MM:SS) 32console.log(parseDuration("1:25:05")); 33// => 5105000 34 35console.log(parseDuration("15:30")); 36// => 930000 37 38// Parsing ISO 8601 duration format (PT#H#M#S) 39console.log(parseDuration("PT2H30M5S")); 40// => 9005000 41 42// Parsing just numbers (uses defaultUnit) 43console.log(parseDuration("1500")); // Default unit is 'ms' 44// => 1500
duration
You can change the formatting settings by passing options as the second argument to duration
.
Array of possible units to use. Units are y
, mo
, w
, d
, h
, m
, s
, and ms
.
Units are skipped if their count is zero. For example, if you pass a duration of 1000
and units ["h", "m", "s"]
, the output will be "1 second".
Must be in descending order of unit size. For example, ["h", "m"]
is valid but ["m", "h"]
is not.
Default: ["y", "mo", "w", "d", "h", "m", "s"]
1duration(69000, { units: ["h", "m", "s", "ms"] }); 2// => "1 minute, 9 seconds" 3 4duration(3600000, { units: ["h"] }); 5// => "1 hour" 6 7duration(3600000, { units: ["m"] }); 8// => "60 minutes" 9 10duration(3600000, { units: ["d", "h"] }); 11// => "1 hour"
Integer representing the maximum number of units to use.
Default: Infinity
1duration(1000000000000); 2// => "31 years, 8 months, 1 week, 19 hours, 46 minutes, 40 seconds" 3 4duration(1000000000000, { largest: 2 }); 5// => "31 years, 8 months"
A boolean that, if true
, rounds the smallest unit.
Default: false
1duration(1200); 2// => "1.2 seconds" 3 4duration(1200, { round: true }); 5// => "1 second" 6 7duration(1600, { round: true }); 8// => "2 seconds"
String to display between units.
Default: ", "
in most languages, " ﻭ "
for Arabic
1duration(22140000); 2// => "6 hours, 9 minutes" 3 4duration(22140000, { delimiter: " and " }); 5// => "6 hours and 9 minutes"
String to display between the count and the word.
Default: " "
1duration(260040000); 2// => "3 days, 14 minutes" 3 4duration(260040000, { spacer: " whole " }); 5// => "3 whole days, 14 whole minutes"
String to display between the integer and decimal parts of a count, if relevant.
Default depends on the language.
1duration(1200); 2// => "1.2 seconds" 3 4duration(1200, { decimal: " point " }); 5// => "1 point 2 seconds"
String to include before the final unit.
You can also set serialComma
to false
to eliminate the final comma.
Default: ""
1duration(22140000, { conjunction: " and " }); 2// => "6 hours and 9 minutes" 3 4duration(22141000, { conjunction: " and " }); 5// => "6 hours, 9 minutes, and 1 second" 6 7duration(22140000, { conjunction: " and ", serialComma: false }); 8// => "6 hours and 9 minutes" 9 10duration(22141000, { conjunction: " and ", serialComma: false }); 11// => "6 hours, 9 minutes and 1 second"
Integer that defines the maximum number of decimal points to show, if relevant. If undefined
, the count will be converted to a string using Number.prototype.toString()
.
This does not round any numbers. See the round
option.
Default: undefined
1duration(8123.456789); 2// => "8.123456789 seconds" 3 4duration(8123.456789, { maxDecimalPoints: 3 }); 5// => "8.123 seconds" 6 7duration(8100, { maxDecimalPoints: 99 }); 8// => "8.1 seconds" 9 10duration(8000, { maxDecimalPoints: 99 }); 11// => "8 seconds" 12 13duration(7999, { maxDecimalPoints: 2 }); 14// => "7.99 seconds"
Array of ten strings to which will replace the numerals 0-9. Useful if a language uses different numerals.
Default: undefined
for most languages, ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
for Arabic
1duration(1234); 2// => "1.234 seconds" 3 4duration(1234, { 5 digitReplacements: ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"], 6}); 7// => "One.TwoThreeFour seconds"
Use this option with care. It is an advanced feature.
Object used to customize the value used to calculate each unit of time. Most useful when you want to update the length of years or months, which have ambiguous lengths.
Default: { y: 31557600000, mo: 2629800000, w: 604800000, d: 86400000, h: 3600000, m: 60000, s: 1000, ms: 1 }
1duration(2629800000); 2// => "1 month" 3 4duration(2629800000, { 5 unitMeasures: { 6 y: 31557600000, 7 mo: 30 * 86400000, 8 w: 604800000, 9 d: 86400000, 10 h: 3600000, 11 m: 60000, 12 s: 1000, 13 ms: 1, 14 }, 15}); 16// => "1 month, 10 hours, 30 minutes"
Language for unit display. Accepts an ISO 639-1 code from one of the supported languages, or a custom language object.
Default: en
(English language object).
1import { duration } from "@visulima/humanizer"; 2import { durationLanguage as es } from "@visulima/humanizer/language/es"; 3import { durationLanguage as ko } from "@visulima/humanizer/language/ko"; 4 5duration(3000, { language: es }); 6// => "3 segundos" 7 8duration(5000, { language: ko }); 9// => "5 초"
parseDuration
You can pass options as the second argument to parseDuration
.
Language object containing the unitMap
for parsing localized strings. See the language
option for the duration
function for details on how to import language objects.
If omitted or if the language object doesn't have a unitMap
, parsing will only recognize standard English units (like "hour", "min", "d", "ms" etc.).
Default: English units.
1import { parseDuration } from "@visulima/humanizer"; 2import { durationLanguage as de } from "@visulima/humanizer/language/de"; 3import { durationLanguage as ru } from "@visulima/humanizer/language/ru"; 4 5// Without language option (or if unitMap is missing) 6parseDuration("3 Stunden"); // => undefined 7parseDuration("5 часов"); // => undefined 8 9// With language option containing a unitMap 10parseDuration("3 Stunden", { language: de }); 11// => 10800000 12 13parseDuration("5 часов, 10 минут", { language: ru }); 14// => 18600000
Specifies the unit to assume if the input string is just a number (without any units).
Possible values: y
, mo
, w
, d
, h
, m
, s
, ms
.
Default: "ms"
1parseDuration("1500"); 2// => 1500 (interpreted as 1500 ms) 3 4parseDuration("1500", { defaultUnit: "s" }); 5// => 1500000 (interpreted as 1500 s) 6 7parseDuration("-10", { defaultUnit: "d" }); 8// => -864000000 (interpreted as -10 days)
duration
and parseDuration
(when provided with a language object containing a unitMap
) support the following languages:
Language | Code |
---|---|
Afrikaans | af |
Albanian | sq |
Amharic | am |
Arabic | ar |
Basque | eu |
Bengali | bn |
Bulgarian | bg |
Catalan | ca |
Central Kurdish | ckb |
Chinese, simplified | zh_CN |
Chinese, traditional | zh_TW |
Croatian | hr |
Czech | cs |
Danish | da |
Dutch | nl |
English | en |
Esperanto | eo |
Estonian | et |
Faroese | fo |
Farsi/Persian | fa |
Finnish | fi |
French | fr |
German | de |
Greek | el |
Hebrew | he |
Hindi | hi |
Hungarian | hu |
Icelandic | is |
Indonesian | id |
Italian | it |
Japanese | ja |
Kannada | kn |
Khmer | km |
Korean | ko |
Kurdish | ku |
Lao | lo |
Latvian | lv |
Lithuanian | lt |
Macedonian | mk |
Mongolian | mn |
Malay | ms |
Marathi | mr |
Norwegian | no |
Polish | pl |
Portuguese | pt |
Romanian | ro |
Russian | ru |
Serbian | sr |
Slovak | sk |
Slovenian | sl |
Spanish | es |
Swahili | sw |
Swedish | sv |
Tamil | ta |
Telugu | te |
Thai | th |
Turkish | tr |
Ukrainian | uk |
Urdu | ur |
Uzbek | uz |
Uzbek (Cyrillic) | uz_CYR |
Vietnamese | vi |
Welsh | cy |
1337
→ 1.34 kB
1337000000
→ 15d 11h 23m 20s
Libraries in this ecosystem make the best effort to track Node.js' release schedule. Here's a post on why we think this is important.
If you would like to help take a look at the list of issues and check our Contributing guidelines.
Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
The visulima humanizer is open-sourced software licensed under the [MIT][license-url]
[typescript-url]: https://www.typescriptlang.org/ "TypeScript" "typescript" [license-image]: https://img.shields.io/npm/l/@visulima/humanizer?color=blueviolet&style=for-the-badge [license-url]: LICENSE.md "license" [npm-image]: https://img.shields.io/npm/v/@visulima/humanizer/latest.svg?style=for-the-badge&logo=npm [npm-url]: https://www.npmjs.com/package/@visulima/humanizer/v/latest "npm"
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
project has 4 contributing companies or organizations
Details
Reason
no dangerous workflow patterns detected
Reason
update tool detected
Details
Reason
license file detected
Details
Reason
30 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
SAST tool detected: CodeQL
Details
Reason
dependency not pinned by hash detected -- score normalized to 8
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Score
Last Scanned on 2025-07-15T07:35:33Z
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More