Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace localisationService

Helper functions for handling all things locale.

import { localisationService } from '@oneblink/apps'

Index

Functions

  • formatCurrency(value: number): string
  • Format a number as a string represented as a currency e.g. $123.31

    Example

    const amount = 123.321
    const text = localisationService.formatCurrency(amount)
    // Display text

    Parameters

    • value: number

    Returns string

  • formatDate(value: Date): string
  • Format a Date as a string that just contains the date portion e.g. 31/01/2020

    Example

    const date = new Date()
    const text = localisationService.formatDate(date)
    // Display text

    Parameters

    • value: Date

    Returns string

  • formatDateLong(value: Date): string
  • Format a Date as a string that just contains the date portion in a long format e.g. Thursday, 2 January 2020

    Example

    const date = new Date()
    const text = localisationService.formatDateLong(date)
    // Display text

    Parameters

    • value: Date

    Returns string

  • formatDatetime(value: Date): string
  • Format a Date as a string that contains the date and time portions e.g. 31/01/2020 5:31 pm

    Example

    const date = new Date()
    const text = localisationService.formatDatetime(date)
    // Display text

    Parameters

    • value: Date

    Returns string

  • formatDatetimeLong(value: Date): string
  • Format a Date as a string that contains the date and time portions in a long format e.g. Thursday, 2 January 2020 5:31 pm

    Example

    const date = new Date()
    const text = localisationService.formatDatetime(date)
    // Display text

    Parameters

    • value: Date

    Returns string

  • formatNumber(value: number): string
  • Format a number as a string represented as a readable number e.g. 123,321.123

    Example

    const amount = 1234.4321
    const text = localisationService.formatCurrency(amount)
    // Display text

    Parameters

    • value: number

    Returns string

  • formatTime(value: Date): string
  • Format a Date as a string that just contains the time portion e.g. 5:31 pm

    Example

    const date = new Date()
    const text = localisationService.formatTime(date)
    // Display text

    Parameters

    • value: Date

    Returns string

  • generateDate(options: { dateOnly: boolean; daysOffset: undefined | number; value: string }): Date | undefined
  • Generate a Date based a string while adding/subtracting a number of days. Use this function to generate a date with the correct time if only the date part is required to be formatted for display purposes. Also supports passing 'NOW' as the value to get the current date with an offset.

    Example

    const dateOnly = localisationService.generateDate({
    value: '2023-05-04',
    dateOnly: true,
    daysOffset: undefined,
    })

    const date = localisationService.generateDate({
    value: '2023-05-04T02:49:23.616Z',
    dateOnly: false,
    daysOffset: undefined,
    })

    const now = localisationService.generateDate({
    value: 'NOW',
    dateOnly: false,
    daysOffset: undefined,
    })

    Parameters

    • options: { dateOnly: boolean; daysOffset: undefined | number; value: string }
      • dateOnly: boolean
      • daysOffset: undefined | number
      • value: string

    Returns Date | undefined

  • getDateFnsFormats(): { longDate: string; longDateTime: string; longYearlessDate: string; shortDate: string; shortDateTime: string; shortYearlessDate: string; time: string }
  • Returns { longDate: string; longDateTime: string; longYearlessDate: string; shortDate: string; shortDateTime: string; shortYearlessDate: string; time: string }

    • longDate: string
    • longDateTime: string
    • longYearlessDate: string
    • shortDate: string
    • shortDateTime: string
    • shortYearlessDate: string
    • time: string
  • getFlatpickrFormats(): { longDate: string; longDateTime: string; longYearlessDate: string; shortDate: string; shortDateTime: string; shortYearlessDate: string; time: string }
  • Returns { longDate: string; longDateTime: string; longYearlessDate: string; shortDate: string; shortDateTime: string; shortYearlessDate: string; time: string }

    • longDate: string
    • longDateTime: string
    • longYearlessDate: string
    • shortDate: string
    • shortDateTime: string
    • shortYearlessDate: string
    • time: string
  • getLocale(): "en-US" | "en-AU"
  • replaceInjectablesWithElementValues(text: string, options: Omit<{ formElements: FormElement[] } & ReplaceInjectablesFormatters & { excludeNestedElements?: boolean; submission: {}; task: undefined | Task; taskGroup: undefined | TaskGroup; taskGroupInstance: undefined | TaskGroupInstance; userProfile: undefined | UserProfile }, keyof ReplaceInjectablesFormatters>): ReturnType<typeof submissionService.replaceInjectablesWithElementValues>
  • Replace the {ELEMENT:<elementName>} values in text while a form is being filled out. The replacements are suppose to be user friendly and for display purposes, e.g. dates should be displayed in the user's desired format and timezone.

    Parameters

    • text: string
    • options: Omit<{ formElements: FormElement[] } & ReplaceInjectablesFormatters & { excludeNestedElements?: boolean; submission: {}; task: undefined | Task; taskGroup: undefined | TaskGroup; taskGroupInstance: undefined | TaskGroupInstance; userProfile: undefined | UserProfile }, keyof ReplaceInjectablesFormatters>

    Returns ReturnType<typeof submissionService.replaceInjectablesWithElementValues>

  • replaceInjectablesWithSubmissionValues(text: string, options: Omit<ReplaceInjectablesOptions, keyof ReplaceInjectablesFormatters>): ReturnType<typeof submissionService.replaceInjectablesWithSubmissionValues>
  • Replace the {ELEMENT:<elementName>} values in text after a successful form submission as well as other replaceable parameters e.g. submissionId. The replacements are suppose to be user friendly and for display purposes, e.g. dates should be displayed in the user's desired format and timezone.

    Parameters

    • text: string
    • options: Omit<ReplaceInjectablesOptions, keyof ReplaceInjectablesFormatters>

    Returns ReturnType<typeof submissionService.replaceInjectablesWithSubmissionValues>