This commit is contained in:
IDONTSUDO 2024-02-27 18:48:35 +03:00
parent c43c192a3e
commit dffc73c30f
18 changed files with 525 additions and 134 deletions

View file

@ -4,8 +4,12 @@ import { NumberExtensions } from "./number";
import { StringExtensions } from "./string";
export type CallBackVoidFunction = <T>(value: T) => void;
export type CallBackStringVoidFunction = (value: string) => void;
export type CallBackEventTarget = (value: EventTarget) => void;
export type OptionalProperties<T> = {
[P in keyof T]?: T[P];
};
declare global {
interface Array<T> {
@ -25,8 +29,12 @@ declare global {
}
interface Map<K, V> {
addValueOrMakeCallback(key: K, value: V, callBack: CallBackVoidFunction): void;
getKeyFromValueIsExists(value: V): K | undefined;
overrideValue(key: K, value: OptionalProperties<V>): void;
keysToJson(): string;
toArray(): V[];
getPredicateValue(callBack: (value: V) => boolean): K[];
}
interface Vector3 {}
}
export const extensions = () => {
ArrayExtensions();

View file

@ -11,5 +11,51 @@ export const MapExtensions = () => {
}
};
}
if (Map.prototype.getKeyFromValueIsExists === undefined) {
// eslint-disable-next-line no-extend-native
Map.prototype.getKeyFromValueIsExists = function (value) {
let result;
this.forEach((el, key) => {
if (el === value) {
result = key;
}
});
return result;
};
}
if (Map.prototype.overrideValue === undefined) {
// eslint-disable-next-line no-extend-native
Map.prototype.overrideValue = function (key, value) {
const result = this.get(key);
this.set(key, Object.assign(result, value));
};
}
if (Map.prototype.keysToJson === undefined) {
// eslint-disable-next-line no-extend-native
Map.prototype.keysToJson = function () {
const result: any[] = [];
this.forEach((el) => result.push(el));
return JSON.stringify(result);
};
}
if (Map.prototype.toArray === undefined) {
// eslint-disable-next-line no-extend-native
Map.prototype.toArray = function () {
return Array.from(this.values());
};
}
if (Map.prototype.getPredicateValue === undefined) {
// eslint-disable-next-line no-extend-native
Map.prototype.getPredicateValue = function (callBack) {
const result: any[] = [];
this.forEach((el, key) => {
const callBackExecute = callBack(el);
if (callBackExecute) {
result.push(key);
}
});
return result;
};
}
};
Object();