Package Exports
- dev-classes
- dev-classes/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dev-classes) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
SocketApi
import { SocketApi } from 'dev-classes';
SocketApi.init({
url: 'wss://...',
timeReConnect: 5000,
numberOfRepit: 5,
isReConnectNetworkOnline: true
});
SocketApi.on('status', (status) => { console.log('onStatus', status); });
SocketApi.on('msg', (messages) => { console.log('onMessages', messages); });
SocketApi.on('reConnect', (status) => { console.log('reConnect', status); });
SocketApi.on('timeOffReConnect', (data) => { console.log('timeOffReConnect', data); });
SocketApi.connect();
//...
HTTPSApi
import { HTTPSApi, RequestPayloadHTTPSApi } from "dev-classes";
HTTPSApi.init();
HTTPSApi.on('fetch', (info) => { })
HTTPSApi.request({keyAction: 'action1', request: {url: '...'}})
Color
type ColorRgb = [number, number, number];
interface Color_P{
ColorRgb: ColorRgb;
ColorRgba: [...ColorRgb, number];
ColorHsla: Record<"h" | "s" | "l" | "a", number>;
TypeBrightness_OR:"BT601" | "BT709" | "BT2020"
}
interface ColorProps{
componentToHex: (c: number) => string;
rgbToHex(r: number, g: number, b: number): string;
rgbToHsv(r: number, g: number, b: number): Color_P['ColorRgb'];
hsvToRgb(h: number, s: number, v: number): Color_P['ColorRgb'];
rgbaToHsla(r: number, g: number, b: number, a: number): Color_P['ColorHsla'];
hslaToRgba(h: number, s: number, l: number, a: number): Color_P['ColorRgba'];
hslaStringToRgba(hsla: string): Color_P['ColorRgba'];
hexaToRgba(hexa: string): Color_P['ColorRgba'];
hexToRgb(hex: string): Color_P['ColorRgb'];
hexaToHsla(hexa: string): Color_P['ColorHsla'];
rgbaToHexa(rgba: Color_P['ColorRgba'] | Color_P['ColorRgb'] ): string;
hslaStringToHexa(hsla: string): string;
hslaStringToHex(hsla: string): string;
mixColors(color1: Color_P['ColorRgb'] , color2: Color_P['ColorRgb'], weight: number): Color_P['ColorRgb'];
getRgbByTypeBrightness(type: Color_P['TypeBrightness_OR']): Color_P['ColorRgb'];
getAverageColor(color1: Color_P['ColorRgb'], color2: Color_P['ColorRgb']): Color_P['ColorRgb'];
getAccentColor(baseHsv: number[], baseColor: Color_P['ColorRgb'], elementColor: Color_P['ColorRgb']): Color_P['ColorRgb']
changeColorAccent(baseHsv: number[], accentHsv: number[], color: Color_P['ColorRgb'], isDarkTheme: boolean): Color_P['ColorRgb'];
changeBrightness(color: Color_P['ColorRgb'], amount: number): Color_P['ColorRgb'];
hexBrightness(hex:string, amount: number):string;
getHexColorFromTelegramColor(color: number): string;
getRgbColorFromTelegramColor(color: number): Color_P['ColorRgb'];
rgbaToRgb(rgba: Color_P['ColorRgba'], bg: Color_P['ColorRgb']): Color_P['ColorRgb'];
calculateBrightness(rgb: Color_P['ColorRgb'], type?:Color_P['TypeBrightness_OR']): number;
getTextColor(luminance: number): Color_P['ColorRgb']
calculateOpacity(luminance: number, targetContrast: number): number;
clamp(v: number, min: number, max: number): number;
}
DateProcessing
interface DateProcessingProps{
getActiveColorClassInDiffDate(a:string, b:string, c:string):string
getClassByDifferenceDay(a:string, b:{className:string, diffDay:number}[]):string
getMinMaxDate(a:string, b:string, c:string):Record<'minDate' | 'maxDate' | 'minMaxMonth', string >
splitDateFromTime(a:string):string[]
getCorrectDateAndTime(a:string):[string, string]
reverseDate(a:string):string
correctionDataISO8601(a:string):string
isDateDMY(a:string):boolean
correctionDateAndRemoveYear(a:string, b?:Partial<{isYear:boolean}>):string
correctionDateWithOutCurrentYear(a:string, b?:Partial<{shortYear:boolean}>):string
correctionShortYear(a:string):string
correctionDate(a:string, b?:Partial<Record<'isRemoveYear'| 'shortYear' | 'withOutCurrentYear', boolean>>):string
hasDateLessPeriod(a:string, b: string, c?:{dateMinMax: '<=' | '>=' | '<' | '>'}):boolean
hasDateLessPeriods(a:string, b: string, c:string, d?:{dateMinMax: '<=' | '>=' | '<' | '>'}):Record<'one' | 'two', boolean>
getDi(a:string, b: string):number
getDifferenceDates(a:string, b: string):number
hasDateLessInNumber(a:string, b: string, c:number):boolean
correctionCurrentYear(a:[string], b?:number):string[]
getChunkFromDate(a:string, b:'day' | 'month' | 'year', c?:{isBeforeZero:boolean}):string
getNameMonthByNumber(a:number):(typeof itemsMonths)[number]
minMaxMountStr(a:Record<'minDate' | 'maxDate', string>): {minMaxMonth: string}
getDatesToCurrentDate(a:string[]):string[]
getDayOfWeek(a:string):(typeof itemsWeek)[number] | null
cropSecond(a:string):string
getRenderDate(a:string, b?:{withOutCurrentYear: boolean} ):'Сегодня' | 'Вчера' | 'Позавчера' | string
getCurrentDate():string
getDaysInMonth(a: number, b: number):number
getCurrentYear():number
getDateDeviation(date: string, config: Partial<Record<"day" | "month" | "year", number>>): string
}
DelaysPromise
interface ControlAction{
stop(status?: boolean):void;
getIsActiveEvent():boolean;
}
interface StartActionEveryConfigI {
interval: number,
cutoffTime?: number;//4000
countAction?:number;//example 5
watchIdInterval?(id:number | null):void;
controlAction?(control:ControlAction):void
}
interface OneOfPromiseReject{
status: boolean;
msg: string;
}
interface DelaysPromiseProps{
startActionEvery: (cb: () => boolean, config: StartActionEveryConfigI) => Promise<{status: boolean, msg: string}>
oneOf: (watchPromise: () => Promise<any>, potentialCaseCB: () => void, config: {second: number}) => void
oneOfPromise:(watchPromise: () => Promise<any>, cbPotentialReject: (p:OneOfPromiseReject) => OneOfPromiseReject, config: {second: number}) => Promise<any>
}
Number
interface NumbersProps {
randomNumber: () => number;
getOnlyTheStringNumbers(dirtyString: string): string;
isNumber(charStr: string | number): boolean;
}
Number
interface NumbersProps {
randomNumber: () => number;
getOnlyTheStringNumbers(dirtyString: string): string;
isNumber(charStr: string | number): boolean;
}
Number
import { File } from 'dev-classes';
File.download({
name: 'test',
base64: 'test',
format: 'pdf',
})
Utils
interface UtilsProps {
events (status: 'add' | 'remove', who:EventTarget, entriesEvents, msg: string): Promise<string>;
sortDataByAlphabet(arrData: {[key: string]: any}[], sortKey: string): {[key: string]: any}[] ;
sortDataByDate(data:any[], keyDate: string): string[];
sortDataByDateAndTime(data:any[], keyDate: string): string[];
reverseDate(datePPR:string):string;
correctionDataISO8601(date:string):string;
hasDateLessPeriod(date: string, period: string, option?:{ dateMinMax: '<=' | '>=' | '<' | '>'; } ): boolean;
getEndsWithArr(arr: any[], countEnd: number): any[];
deepMerge<T extends object = object>(...itemsOb: T[]): T
}
NetworkInformation
import { NetworkInformation, NetworkInformationPC, NetworkInformationCordova } from 'dev-classes';
const internet = new NetworkInformation([new NetworkInformationPC(), new NetworkInformationCordova()]);
const online = () => {}
const offline = () => {}
internet.run((status) => {
status ? online() : offline();
});
EventSubscribers
interface EventSubscribersProps<EventsProps>{
getSubscribers: () => {[K in keyof EventsProps]?: EventsProps[K][]}
subscribe: <K extends keyof EventsProps>(name: K, cb: EventsProps[K]) => void
unsubscribe: <K extends keyof EventsProps>(name: K, cb: EventsProps[K]) => void
publish: <K extends keyof EventsProps>(name: K, data: EventsProps[K] extends (...args: any[]) => any ? Parameters<EventsProps[K]>[0] : any) => void
resetSubscribers: () => void
}
import { EventSubscribers } from 'dev-classes';
interface CustomEvents{
myEvent(status: boolean): void;
}
class MyClass{
private static events = new EventSubscribers<CustomEvents>(["myEvent"]);
static on = MyClass.events.subscribe;
static off = MyClass.events.unsubscribe;
static runTime(num: number){
const id = setTimeout(() => {
let status = true;
//...
// if(/*.... */) { status = false; }
MyClass.events.publish('myEvent', status);
clearTimeout(id);
}, num * 1000)
}
}
MyClass.on('myEvent', (status) => {
console.log(status)
})
MyClass.runTime(2);