1.3.10 • Published 9 months ago

dev-classes v1.3.10

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago
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();
//...
import { HTTPSApi, RequestPayloadHTTPSApi } from "dev-classes";

HTTPSApi.init();

HTTPSApi.on('fetch', (info) => { })
HTTPSApi.request({keyAction: 'action1', request: {url: '...'}})
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;
}
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
}
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>
}
interface NumbersProps {
  randomNumber: () => number;
  getOnlyTheStringNumbers(dirtyString: string): string;
  isNumber(charStr: string | number): boolean;
}
interface NumbersProps {
  randomNumber: () => number;
  getOnlyTheStringNumbers(dirtyString: string): string;
  isNumber(charStr: string | number): boolean;
}
import { File } from 'dev-classes';

File.download({
  name: 'test',
  base64: 'test',
  format: 'pdf',
})
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
}
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();
});
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);
1.3.7

9 months ago

1.3.6

9 months ago

1.3.5

9 months ago

1.3.4

9 months ago

1.3.10

9 months ago

1.3.9

9 months ago

1.3.8

9 months ago

1.3.3

12 months ago

1.2.3

1 year ago

1.2.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.0.16

1 year ago

1.1.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.12

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago