1.1.2 • Published 5 months ago

@elzazo/main-utils v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

JavaScript Utility Functions

A collection of JavaScript utility functions for common tasks.

Installation

npm install @elzazo/main-utils

Usage

const utils = require("@elzazo/main-utils");

// Format a date
const formattedDate = utils.getFormattedDateTime();
console.log(formattedDate.datetime); // "DD/MM/YYYY HH:MM:SS"

// Convert seconds to duration
const duration = utils.secondsToDuration(175);
console.log(duration); // "00:02:55"

// Check if an element exists in an array (loose equality)
const exists = utils.arrayIncludes([1, 2, 3], "3");
console.log(exists); // true

Available Functions

Date and Time

  • datetimeToDuration(datetime) - Converts a datetime to a human-readable duration (e.g., "2 years ago")
  • getFormattedDateTime(seconds) - Returns formatted date and time strings
  • secondsToDuration(seconds) - Converts seconds to a formatted duration string (HH:MM:SS)

String and Number Formatting

  • separateNumbers(number) - Formats a number with space separators (e.g., "1 000 000")
  • setLenByCaracter(text, options) - Sets the length of a string by adding characters
  • setLenByZero(num, len) - Adds leading zeros to a number
  • setLenBySpace(text, len) - Adds trailing spaces to a string

Object Utilities

  • getKeys(obj) - Extracts all keys from an object, including nested keys using dot notation
  • isObject(value) - Checks if a value is a plain JavaScript object

Array Utilities

  • arrayIncludes(list, element) - Checks if an element exists in an array using loose equality (==)

Random Utilities

  • getRandomNumber(max) - Generates a random integer between 0 and the specified maximum value

Error Handling

All functions include proper error handling and will return appropriate fallback values if errors occur.

License

ISC

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago