there repository
This commit is contained in:
parent
71cd1061cb
commit
5d0e5f7f1c
10 changed files with 257 additions and 2 deletions
|
@ -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;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
15
ui/src/core/extensions/map.ts
Normal file
15
ui/src/core/extensions/map.ts
Normal 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();
|
Loading…
Add table
Add a link
Reference in a new issue