@plumtreesystems/utils
TypeScript icon, indicating that this package has built-in type declarations

1.1.7 • Public • Published

Plum tree systems utils

Instalation

Add module

    yarn add @plumtreesystems/utils

Add types definition to tsconfig.json file if necessary

    "typeRoots": [
      "./node_modules/@plumtreesystems/utils/dist/esm/@types"
    ],

For Jest to understand modules add to jest.config.js file

    transformIgnorePatterns: ['/node_modules/(?!@plumtreesystems)'],

Utils

Browser detector

Initiated BrowserDetector class.

import BrowserDetector from '@plumtreesystems/utils';

Currency prefix

CurrencyPrefix uninitiated class.

import CurrencyPrefix from '@plumtreesystems/utils';

new CurrencyPrefix(countryOptions);

Params:

  • countryOptions: Object<{key: value}>

Date manager

DateManager uninitiated class.

import { DateManager } from '@plumtreesystems/utils';

new DateManager(dateFormat, timeFormat);

Params:

  • dateFormat: string = 'YYYY-MM-DD'
  • timeFormat: string = 'HH:mm'

Functions:

// normalize date string to contain T separator between date and time
formatDate(val: string)

// get time zone RegExp e.g. +02:00
getRegExp(): RegExp

// get short time zone RegExp e.g. +0200
getShortRegExp(): RegExp

// get time RegExp
getTimeRegExp(): RegExp

// get default date format
getDateFormat(): string

// get default date with time format
getDayTimeFormat(): string

// get default date with time and time zone format
getDayTimeFormatUtc(): string

// get uk date format
getDateFormatUK(): string

// get uk date with time format
getDayTimeFormatUK(): string

// get uk date with time and time zone format
getDayTimeFormatUtcUK(): string

// returns current date with time
getCurrentDateTime(options: Partial<DateManagerOptionsType> = {}): string

options = {
    returnFormat: string // response format.
}

// returns current date
getCurrentDate(options: Partial<DateManagerOptionsType> = {}): string

options = {
    returnFormat: string // response format.
}

// returns date with time.
getDateTime(date: any, options: Partial<DateManagerOptionsType> = {}): string

options = {
    inputFormat: OptionType|undefined // provided date parameter format.
    returnFormat: string // response format.
}

// returns current date with time and time zone
getCurrentDateTimeUtc(): string

// returns date and time with one day offset to the future
getDefaultToDateTime(): string

// returns current date and time with offset from parameters
getCurrentDateWithOffset(offset: number, options: Partial<DateManagerOptionsType> = {}): string

options = {
    type // type of offset value. Day, week, etc...
    returnFormat: string // response format.
}

// returns date and time with offset from parameters
getDateWithOffset(offset: number, date: any, options: Partial<DateManagerOptionsType> = {}): string

options = {
    type // type of offset value. Day, week, etc...
    returnFormat: string // response format.
    inputFormat: string // input format
}

// execute time zone regexp on value and return RegExp result
getTimeZoneRegex(val: string): RegExpExecArray | null

// returns date and time without time zone
getDateTimeWithoutTimezone(val: string): string

// returns first day of the month
getFirstDayOfMonth(options: Partial<DateManagerOptionsType> = {}): string

options = {
    date: any, // starting date to determine first day of the month. Default value is current date
    offset: number, // offset in months
    returnFormat: string // response format
    inputFormat: string // input format
}

// returns last day of the month
getLastDayOfMonth(options: Partial<DateManagerOptionsType> = {}): string

options = {
    date: any, // starting date to determine last day of the month. Default value is current date
    offset: number, // offset in months
    returnFormat: string // response format
    inputFormat: string // input format
}

// check if date matches iso standard
isIsoDate(str: string): boolean

// returns date in unix time format
getUnixTime(date: string, options: Partial<DateManagerOptionsType> = {}): number

options = {
    inputFormat: string // input format
}

// execute time regexp on value and return RegExp result
getTime(val: string): RegExpExecArray | null

// returns difference between two dates.
getDifference(from: string, to: string, format?: QUnitType | OpUnitType, options: Partial<DateManagerOptionsType> = {}): number

options = {
    inputFormat: string // input format
}

// check if provided date option is before before option
isBefore(date, before, options: Partial<DateManagerOptionsType> = {}): boolean

options = {
    inputFormat: string // input format
}

// check if provided date option is after after option
isAfter(date, after, options: Partial<DateManagerOptionsType> = {}): boolean

options = {
    inputFormat: string // input format
}

// returns week of the year from provided date
getWeekOfYear(date: string, options: Partial<DateManagerOptionsType> = {}): number

options = {
    inputFormat: string // input format
}

// returns week day from provided date
getWeekDay(date: string, options: Partial<DateManagerOptionsType> = {}): number

options = {
    firstDayMonday: boolean, // define if week starts from monday. Default value is true
    inputFormat: string // input format
}

// returns number of days in month from provided date
getDaysInMonth(date: string, options: Partial<DateManagerOptionsType> = {}): number

options = {
    inputFormat: string // input format
}

// check if both provided dates ar the same day
isSameDay(first: string, second: string, options: Partial<DateManagerOptionsType> = {}): boolean

options = {
    inputFormat: string // input format
}

// return utc offset
getUTCOffset(date: string, options: Partial<DateManagerOptionsType> = {}): number

options = {
    inputFormat: string // input format
}

// summer time utc offset
stdTimezoneOffset(): number

// is winter time observed
isDstObserved(date: string): boolean

// checks if date value is valid
isValid(date, format = this.dateFormat, strict = true): boolean

// returns displayable time string from provided now date to date x. e.g. 5 minutes ago
from(now, options: Partial<DateManagerOptionsType> = {})

options = {
    withoutSuffix, // remove suffix from result e.g 5 minutes / 5 minutes ago. Default is false
    to, // end point of interval from now date. Default is current date
    inputFormat: string // input format
}

// returns displayable time string from now to provided date . e.g. 5 minutes ago
fromNow(options: Partial<DateManagerOptionsType> = {})

options = {
    withoutSuffix, // remove suffix from result e.g 5 minutes / 5 minutes ago. Default is false
    to, // date for measuring interval from now. Default is current date
    inputFormat: string // input format
}

// returns displayable time string to provided date from date x. e.g. 5 minutes ago
to(to, options: Partial<DateManagerOptionsType> = {})

options = {
    withoutSuffix, // remove suffix from result e.g 5 minutes / 5 minutes ago. Default is false
    from, // starting point for measuring interval to x date. Default is current date
}

// returns displayable time string from provided date to now. e.g. 5 minutes ago
toNow(options: Partial<DateManagerOptionsType> = {})

options = {
    withoutSuffix, // remove suffix from result e.g 5 minutes / 5 minutes ago. Default is false
    from, // starting point for measuring interval to now. Default is current date
}

File downloader

Function for file downloading

import { fileDownload } from '@plumtreesystems/utils';

File helper

FilesHelper initiated class.

import { FilesHelper, AssetCategoryType, AssetStatsType, AssetType } from '@plumtreesystems/utils';

Functionality manager

FunctionalityManager uninitiated class.

import { FunctionalityManager } from '@plumtreesystems/utils';

new FunctionalityManager(versionObject, dateManager);

Params:

  • versionObject: object
  • dateManager: DateManager

versionObject - Object. Example: {featureName: {type: boolean, value: true}}.

supported version types: boolean, dateFrom, dateTo

Hydra

Uninitiated Hydra pagination object and types.

import { Hydra, HydraObjectType, HydraPaginationType, HydraViewObjectType, PageFilterType } from '@plumtreesystems/utils';

new Hydra(hydraObject);

Params:

  • hydraObject: HydraObjectType

Image tools

ImageTools initiated class.

import ImageTools from '@plumtreesystems/utils';

Impersonator

Impersonator initiated class. Handle impersonation token actions with local storage.

import Impersonator from '@plumtreesystems/utils';

Local storage manager

LocalStorageManager uninitiated class.

import LocalStorageManager from '@plumtreesystems/utils';

new LocalStorageManager(storeVersion, excludedModules);

Params:

  • storeVersion: string
  • excludedModules: string[]

Mocked date manager

MockedDateManager uninitiated class.

import MockedDateManager from '@plumtreesystems/utils';

new MockedDateManager(currentDate);

Params:

  • currentDate: string = '2020-08-08 08:00'

Object processor

ObjectProcessor initiated class.

import ObjectProcessor from '@plumtreesystems/utils';

Pagination helper

PaginationHelper initiated class.

import PaginationHelper from '@plumtreesystems/utils';

Request cache

RequestCache initiated class and types.

import { RequestCache, RequestCacheFormatType, SetCachedRequestParametersType } from '@plumtreesystems/utils';

Response error processor

ResponseErrorsProcessor uninitiated class, errorsFormatter function and error types.

import { ResponseErrorsProcessor, errorsFormatter, ErrorType, ErrorsObjectType } from '@plumtreesystems/utils';

new ResponseErrorsProcessor(registerError)

Params:

  • registerError: (e: any) => any

Scroll to top

scrollToTop function.

import scrollToTop from '@plumtreesystems/utils';

Types overwrite

OverwriteType type to overwrite existing types.

import OverwriteType from '@plumtreesystems/utils';

Url tools

UrlTools initiated class.

import UrlTools from '@plumtreesystems/utils/src/url-tools';

Vuex module decorators

CustomAction function witch overrides default action parameters.

import { CustomAction } from '@plumtreesystems/utils';

/@plumtreesystems/utils/

    Package Sidebar

    Install

    npm i @plumtreesystems/utils

    Weekly Downloads

    5

    Version

    1.1.7

    License

    MIT

    Unpacked Size

    129 kB

    Total Files

    154

    Last publish

    Collaborators

    • matval
    • martynask
    • duru_stakta