Options
All
  • Public
  • Public/Protected
  • All
Menu

@damenor/js-tools

Index

Variables

ARRAY: { flat: (array: []) => any[]; removeDuplicates: <T>(array: T[]) => T[]; removeFalsy: <T>(array: T[]) => T[] } = ...

Type declaration

  • flat: (array: []) => any[]
      • (array: []): any[]
      • Convert array in simple array Example: const arrayFlated = ARRAY.flat([0, [1, 2, 3]]) // [0, 1, 2, 3]

        Parameters

        • array: []

          []

        Returns any[]

        the array without false values

  • removeDuplicates: <T>(array: T[]) => T[]
      • <T>(array: T[]): T[]
      • Remove duplicates values in arrays

        Type parameters

        • T

        Parameters

        • array: T[]

          []

        Returns T[]

        the array without duplicates

  • removeFalsy: <T>(array: T[]) => T[]
      • <T>(array: T[]): T[]
      • Remove false values in arrays (include 0)

        Example: ARRAY.removeFalsy([0, 'a string', '', NaN, true, 5, undefined, false]) // ['a string', true, 5]

        Type parameters

        • T

        Parameters

        • array: T[]

          []

        Returns T[]

        the array without false values

COLOR: { random: () => string; rgbToHex: (r: number, g: number, b: number) => string } = ...

Type declaration

  • random: () => string
      • (): string
      • Get a random hexadecimal color

        Returns string

        hexadecimal color

  • rgbToHex: (r: number, g: number, b: number) => string
      • (r: number, g: number, b: number): string
      • Convert rgb color to hexadecimal

        Example: const colorHex = COLOR.rgbToHex(255, 255, 255) // #ffffff

        Parameters

        • r: number

          number between 0 and 255

        • g: number

          number between 0 and 255

        • b: number

          number between 0 and 255

        Returns string

        hexadecimal color

COOKIES: { clear: () => void } = ...

Type declaration

  • clear: () => void
      • (): void
      • Clean all cookies

        Returns void

CSS: { isDarkMode: () => boolean } = ...

Type declaration

  • isDarkMode: () => boolean
      • (): boolean
      • Check is user prefers dark mode

        Returns boolean

        boolean

DATE: { dayOfYear: (date: Date) => number; daysDiff: (startDate: Date, endDate: Date) => number } = ...

Type declaration

  • dayOfYear: (date: Date) => number
      • (date: Date): number
      • Calculate the number of the day of the year

        Example: const day = DATE.dayOfYear(new Date())

        Parameters

        • date: Date

          Date

        Returns number

        number of day of year

  • daysDiff: (startDate: Date, endDate: Date) => number
      • (startDate: Date, endDate: Date): number
      • Calculate days difference between 2 dates

        Example: const startDate = new Date("1986-03-05") const endDate = new Date() const daysDiff = DATE.daysDiff(startDate, endDate)

        Parameters

        • startDate: Date

          Date

        • endDate: Date

          Date

        Returns number

        number of days difference

NUMBER: { average: (...args: number[]) => number; isEven: (num: number) => boolean; randomMinMax: (min: number, max: number) => number; roundDecimal: (num: number, maxDecimal: number) => number } = ...

Type declaration

  • average: (...args: number[]) => number
      • (...args: number[]): number
      • Calculate average of numbers

        Example: const day = NUMBER.average(1, 2, 3, 4, 5, ...) // 3

        Parameters

        • Rest ...args: number[]

          Numbers of calculate (1, 2, ...)

        Returns number

        number average

  • isEven: (num: number) => boolean
      • (num: number): boolean
      • Calculate is even

        Parameters

        • num: number

          number

        Returns boolean

        boolean

  • randomMinMax: (min: number, max: number) => number
      • (min: number, max: number): number
      • Calculate random number by min and max

        Example: const numberBetween1and100 = NUMBER.randomMinMax(1, 100)

        Parameters

        • min: number

          minimum number

        • max: number

          maximum number

        Returns number

        random number

  • roundDecimal: (num: number, maxDecimal: number) => number
      • (num: number, maxDecimal: number): number
      • Round a decimal to the indicated amount

        Example: const numberRounded = NUMBER.roundDecimal(1.0135, 2) // 1.01 const numberRounded = NUMBER.roundDecimal(1.0185, 2) // 1.02

        Parameters

        • num: number

          number with decimals

        • maxDecimal: number

          number of decimal

        Returns number

        random number

OBJECT: { mergeObjects: (target: object, ...sources: object[]) => object } = ...

Type declaration

  • mergeObjects: (target: object, ...sources: object[]) => object
      • (target: object, ...sources: object[]): object
      • Copies one object with another without losing properties

        Example: const objectMerged = mergeObjects({hello: 'World'}, {object: 'toCopy}) // { hello: 'World', object: 'toCopy }

        Parameters

        • target: object

          object to merge

        • Rest ...sources: object[]

          new Values for object

        Returns object

        Object

PROMISE: { pause: (ms: number) => Promise<unknown>; tryCatchWrapper: (promise: Promise<any>, onError?: (error: any) => void) => Promise<any> } = ...

Type declaration

  • pause: (ms: number) => Promise<unknown>
      • (ms: number): Promise<unknown>
      • Create a uses asynchronous pause

        Example: PROMISE.pause(1000).then(...) await PROMISE.pause(1000)

        Parameters

        • ms: number

          pause time in milliseconds

        Returns Promise<unknown>

        Promise

  • tryCatchWrapper: (promise: Promise<any>, onError?: (error: any) => void) => Promise<any>
      • (promise: Promise<any>, onError?: (error: any) => void): Promise<any>
      • Wrapper for a promise including a try catch by default it shows error by console

        Example: const promise = fetch(...) PROMISE.tryCatchWrapper(promise).then(...)

        Parameters

        • promise: Promise<any>

          pause time in milliseconds

        • Optional onError: (error: any) => void

          optional ()

            • (error: any): void
            • Parameters

              • error: any

              Returns void

        Returns Promise<any>

        Promise

STRING: { htmlEscape: (str: string) => string; random: () => string; replaceAll: (str: string, search: string, replace: string) => string; toCamelCase: (str: string) => string; toLowerCase: (str: string, onlyFirst?: boolean) => string; toUpperCase: (str: string, onlyFirst?: boolean) => string } = ...

Type declaration

  • htmlEscape: (str: string) => string
      • (str: string): string
      • Escape html code

        Example: const htmlClean = STRING.htmlEscape('

        hello world
        ')

        Parameters

        • str: string

          string to convert

        Returns string

        string converted

  • random: () => string
      • (): string
      • Get random letters

        Returns string

        string created

  • replaceAll: (str: string, search: string, replace: string) => string
      • (str: string, search: string, replace: string): string
      • replace all text in string

        Example: const textReplaced = STRING.replaceall(text, textToReplace, textReplace)

        Parameters

        • str: string

          string complete

        • search: string

          string to search for replace

        • replace: string

          new string

        Returns string

        string converted

  • toCamelCase: (str: string) => string
      • (str: string): string
      • convert text string to camelCase

        Example: const stringCamelCase = STRING.toCamelCase('background-color') // "backgroundColor"

        Parameters

        • str: string

          string to convert

        Returns string

        string converted

  • toLowerCase: (str: string, onlyFirst?: boolean) => string
      • (str: string, onlyFirst?: boolean): string
      • Lowercase all words

        Example: const wordsConverted = STRING.toLowerCase('Hello World!') // "hello world!" const wordsConverted = STRING.toLowerCase('Hello World!', true) // "hello World!"

        Parameters

        • str: string

          string to convert

        • Optional onlyFirst: boolean

          boolean optional for only change first letter

        Returns string

        string converted

  • toUpperCase: (str: string, onlyFirst?: boolean) => string
      • (str: string, onlyFirst?: boolean): string
      • Capitalize all words

        Example: const wordsConverted = STRING.toUpperCase('hello world!') // "Hello World!" const wordsConverted = STRING.toUpperCase('hello world!', true) // "Hello world!"

        Parameters

        • str: string

          string to convert

        • Optional onlyFirst: boolean

          boolean optional for only change first letter

        Returns string

        string converted

Generated using TypeDoc