there repository

This commit is contained in:
IDONTSUDO 2023-12-10 21:44:41 +03:00
parent 71cd1061cb
commit 5d0e5f7f1c
10 changed files with 257 additions and 2 deletions

View file

@ -45,4 +45,10 @@ export const ArrayExtensions = () => {
return this.length !== 0;
};
}
if ([].hasIncludeElement === undefined) {
// eslint-disable-next-line no-extend-native
Array.prototype.hasIncludeElement = function (element) {
return this.indexOf(element) !== -1;
};
}
};

View file

@ -1,19 +1,27 @@
import { ArrayExtensions } from "./array";
import { MapExtensions } from "./map";
import { StringExtensions } from "./string";
export type CallBackFunction = <T>(value: T) => void;
declare global {
interface Array<T> {
// @strict: The parameter is determined whether the arrays must be exactly the same in content and order of this relationship or simply follow the same requirements.
equals(array: Array<T>, strict: boolean): boolean;
lastElement(): T | undefined;
isEmpty(): boolean;
isNotEmpty():boolean;
isNotEmpty(): boolean;
hasIncludeElement(element: T): boolean;
}
interface String {
isEmpty(): boolean;
}
interface Map<K, V> {
addValueOrMakeCallback(key: K, value: V, callBack: CallBackFunction): void;
}
}
export const extensions = () => {
ArrayExtensions();
StringExtensions();
MapExtensions();
};

View file

@ -0,0 +1,15 @@
export const MapExtensions = () => {
if (Map.prototype.addValueOrMakeCallback === undefined) {
// eslint-disable-next-line no-extend-native
Map.prototype.addValueOrMakeCallback = function (key, value, fn) {
if (this.has(key)) {
this.set(key, value);
fn(this);
return;
} else {
this.set(key, value);
}
};
}
};
Object();