@idot-digital/generic-helpers
TypeScript icon, indicating that this package has built-in type declarations

0.17.0 • Public • Published

@idot-digital/generic-helpers

This package/repo provides a collection of useful helper functions for various tasks.

Installation

You can install this package via npm or yarn.

npm install @idot-digital/generic-helpers

or

yarn add @idot-digital/generic-helpers

Features

General Helper

  • wait(ms: number): Promise<void>: A helper function that returns a promise that resolves after a given amount of time in milliseconds.

Array Helpers

  • Arrays.filterNull<T>(array: (T | null | undefined)[]): T[]: A static method that filters out null and undefined values from an array.

Color Helpers

The Colors class provides several color-related helper methods, including:

  • hexToRgba(hex: HEX): RGBA | null: Converts a hex color to rgba values.
  • rgbaToHex(color: RGB | RGBA): HEX: Converts rgb values to hex color format.
  • getContrastColor(color: Color, settings?: {...}): string: Calculates a contrast text color for a given background color.
  • And many more!

Date Helpers

The Dates class provides date-related helper methods, such as:

  • getRelativeTimeString(date: Date, date2: Date = new Date(), short: boolean = false, roundToDate = false): string: Represents the difference between two dates as a string.
  • onSameDay(date1: Date, date2?: Date): boolean: Checks if two dates are on the same day.
  • And more!

Iterator Helpers

The Iterators class provides helper methods for working with iterators, such as:

  • toArray<T>(iterator: AsyncGenerator<T> | Generator<T> | IterableIterator<T> | AsyncIterableIterator<T>, limit?: number): Promise<T[]>: Converts an iterator to an array.
  • fromArray<T>(array: (T | Promise<T>)[]): AsyncGenerator<T>: Converts an array with promise items to an async iterator.
  • And more!

Object Helpers

The Objects class provides object-related helper methods:

  • deepEqual<T>(a: T, b: T): boolean: Deeply compares two objects and returns true if they are equal.
  • deepClone<T>(obj: T): T: Deeply clones an object and returns the cloned object.

Text Helpers

The Text class provides text-related helper methods:

  • bigNumbers(num: number): string: Formats big numbers to a more readable format.
  • grades(percentage: number): string: Converts a percent value to a corresponding letter grade.

Conclusion

This package offers various functionalities, including array manipulation, color conversion, date handling, iterator operations, object comparison/cloning, and text formatting.

Contributing

If you are an employee of idot digital or one of its subsidiaries, you can create issues or pull/merge requests. They will regularly be reviewed and merged. The code standards are your default company standards.

If you are someone who just found the package on npm and you have feedback or additional functions you want to see in the package, please send us an email to contact@idot-digital.de with "[generic-helpers]" in the subject.

License

The package is licensed under the ISC License or MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i @idot-digital/generic-helpers

Weekly Downloads

0

Version

0.17.0

License

ISC

Unpacked Size

122 kB

Total Files

73

Last publish

Collaborators

  • der-grosse
  • luiskugel