diff options
| author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2025-03-11 17:43:05 +0100 |
|---|---|---|
| committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2025-03-11 17:43:05 +0100 |
| commit | fa937182bc93aa2c6faadda80ea998cdfd479b4e (patch) | |
| tree | cba8e16edcccc6fd2932173484ac444cb79abea2 /src/extensions | |
| parent | cf91c46cfec6e3e36b9184764016f9c1b5c997d4 (diff) | |
| parent | 04669ffeb163688c7aefd7b5face7998252abdca (diff) | |
Merge branch 'master' of https://github.com/brown-dash/Dash-Web into DocCreatorMenu-work
Diffstat (limited to 'src/extensions')
| -rw-r--r-- | src/extensions/ExtensionsTypings.ts | 8 | ||||
| -rw-r--r-- | src/extensions/Extensions_Array.ts | 10 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/extensions/ExtensionsTypings.ts b/src/extensions/ExtensionsTypings.ts index d6ffd3be3..fa8851bb3 100644 --- a/src/extensions/ExtensionsTypings.ts +++ b/src/extensions/ExtensionsTypings.ts @@ -1,6 +1,14 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ interface Array<T> { + /** + * returns the last element of the array or undefined + */ lastElement(): T; + /** + * if val is in the list, it returns its index, otherwise undefined; + * @param val + */ + getIndex(val: T): number | undefined; } interface String { diff --git a/src/extensions/Extensions_Array.ts b/src/extensions/Extensions_Array.ts index a50fb330f..d61585e28 100644 --- a/src/extensions/Extensions_Array.ts +++ b/src/extensions/Extensions_Array.ts @@ -1,14 +1,13 @@ export default class ArrayExtension { private readonly property: string; - private readonly body: <T>(this: Array<T>) => any; + private readonly body: <T>(this: Array<T>, args: unknown) => unknown; - constructor(property: string, body: <T>(this: Array<T>) => any) { + constructor(property: string, body: <T>(this: Array<T>, args: unknown) => unknown) { this.property = property; this.body = body; } assign() { - // eslint-disable-next-line no-extend-native Object.defineProperty(Array.prototype, this.property, { value: this.body, enumerable: false, @@ -28,6 +27,11 @@ const extensions = [ } return this[this.length - 1]; }), + // eslint-disable-next-line @typescript-eslint/no-explicit-any + new ArrayExtension('getIndex', function (val: any) { + const index = this.indexOf(val); + return index === -1 ? undefined : index; + }), ]; function Assign() { |
