@plumtreesystems/utils
v1.1.0
Published
Utils for Plum Tree System app's
Downloads
293
Readme
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.
}
// 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
offset: number, // offset in months
returnFormat: string // response format
}
// returns last day of the month
getLastDayOfMonth(options: Partial<DateManagerOptionsType> = {}): string
options = {
date: any, // starting date to determine last day of the month
offset: number, // offset in months
returnFormat: string // response format
}
// check if date matches iso standard
isIsoDate(str: string): boolean
// returns date in unix time format
getUnixTime(date: string): number
// 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): number
// check if provided date option is before before option
isBefore(date, before): boolean
// check if provided date option is after after option
isAfter(date, after): boolean
// returns week of the year from provided date
getWeekOfYear(date: string): number
// 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
}
// returns number of days in month from provided date
getDaysInMonth(date: string): number
// check if both provided dates ar the same day
isSameDay(first: string, second: string): boolean
// return utc offset
getUTCOffset(date: string): number
// 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
}
// 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
}
// 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';