1.0.15 β€’ Published 2 months ago

ldr-utils v1.0.15

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

πŸ”° Ldr-utils package

Ldr-utils is an unlimited utility package designed to provide a wide range of helpful functions for your projects.

βœ…Installation

To install this package, you can use npm or yarn:

yarn add ldr-utils
npm i ldr-utils

❓ Usage

The package offers several functions:

🎈 abbreviate(number)

This function takes a large number and abbreviates it to make it more readable. It returns a string containing the abbreviated number.

Example usage:

const { abbreviate } = require('ldr-utils');

console.log(abbreviate(1500)); // Output: "1.5K"
console.log(abbreviate(2000000)); // Output: "2M"
console.log(abbreviate(5000000000)); // Output: "5B"

🎈 unabbreviate(number)

This function takes an abbreviated number string and expands it to its full numeric value.

Example usage:

const { unabbreviate } = require('ldr-utils');

console.log(unabbreviate('1.5K')); // Output: 1500
console.log(unabbreviate('100k', { format: true }));  // Output: '100.000'
console.log(unabbreviate('5B'));   // Output: 5000000000

🎈 average(...numbers)

The average function calculates the average of a set of numbers passed as arguments. It returns the arithmetic mean of the provided numbers.

Example Usage:

const { average } = require('ldr-utils');

console.log(average(5, 10, 15)); // Output: 10 (average of 5, 10, and 15)
console.log(average(12, 24, 36, 64)); // Output: 34 (average of 12, 24, 36 and 64)

🎈 ms(duration, options)

This function takes a duration string and formats it into a human-readable format. It supports various units such as 'w' (weeks), 'd' (days), 'h' (hours), 'm' (minutes), 's' (seconds), and 'y' (years).

Example Usage:

const { ms } = require('ldr-utils');

console.log(ms('5d')); // Output: 432000000
console.log(ms('2w', { detailed: true })); // Output: "2 weeks"
console.log(ms('40d', { detailed: true })); // Output: "5 weeks, 5 days"

🎈 formatTime(milliseconds)

This function takes a duration in milliseconds and formats it into a human-readable format with days, hours, minutes, and seconds.

Example Usage:

const { formatTime } = require('ldr-utils');

console.log(formatTime(86400000)); // Output: "1d"
console.log(formatTime(3600000)); // Output: "1h"
console.log(formatTime(179191000)); // Output: "2d, 1h, 59m, 51s"
1.0.11

2 months ago

1.0.10

2 months ago

1.0.15

2 months ago

1.0.14

2 months ago

1.0.13

2 months ago

1.0.12

2 months ago

1.0.9

2 months ago

1.0.8

2 months ago

1.0.7

2 months ago

1.0.6

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago