This commit is contained in:
IDONTSUDO 2023-11-10 21:43:57 +03:00
parent 6446da7e76
commit 6f86377685
18 changed files with 274 additions and 107 deletions

View file

@ -1,13 +1,3 @@
export {};
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;
}
}
export const ArrayExtensions = () => {
if ([].equals === undefined) {
// eslint-disable-next-line no-extend-native
@ -42,4 +32,10 @@ export const ArrayExtensions = () => {
}
};
}
if ([].isEmpty === undefined) {
// eslint-disable-next-line no-extend-native
Array.prototype.isEmpty = function () {
return this.length === 0;
};
}
};

View file

@ -1,6 +1,18 @@
import { ArrayExtensions } from "./array";
import { StringExtensions } from "./string";
export const extensions = () =>{
ArrayExtensions()
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;
}
interface String {
isEmpty(): boolean;
}
}
export const extensions = () => {
ArrayExtensions();
StringExtensions();
};

View file

@ -0,0 +1,8 @@
export const StringExtensions = () => {
if ("".isEmpty === undefined) {
// eslint-disable-next-line no-extend-native
String.prototype.isEmpty = function () {
return this.length === 0;
};
}
};