Skip to content

Commit

Permalink
Merge pull request #40 from michaelcoxon/eslint
Browse files Browse the repository at this point in the history
init
  • Loading branch information
michaelcoxon committed Feb 13, 2024
2 parents 2a3f6c1 + 2f1aec1 commit 1f3a6b8
Show file tree
Hide file tree
Showing 98 changed files with 2,998 additions and 699 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
};
2,756 changes: 2,458 additions & 298 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"build:docs:typedoc": "typedoc --logLevel Verbose --out docs/api src",
"build:lib": "npm-run-all -s clean:lib build:lib:typescript",
"build:lib:debug": "npm-run-all -s clean:lib build:lib:typescript:debug",
"build:lib:typescript": "tsc",
"build:lib:typescript:debug": "tsc --sourceMap",
"build:lib:typescript": "tsc -p ./tsconfig.build.json",
"build:lib:typescript:debug": "tsc --sourceMap -p ./tsconfig.build.json",
"build": "npm-run-all -s build:lib -p build:dist",
"clean:lib": "rimraf lib",
"clean:dist": "rimraf dist",
Expand Down Expand Up @@ -65,10 +65,13 @@
"@types/prop-types": "^15.7.9",
"@types/shelljs": "^0.8.14",
"@types/webpack-env": "^1.18.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"ajv": "^8.12.0",
"browserslist": "^4.22.1",
"copyfiles": "^2.4.1",
"dts-bundle": "^0.7.3",
"eslint": "^8.56.0",
"file-loader": "^6.2.0",
"jest": "^29.7.0",
"json-loader": "^0.5.7",
Expand Down
4 changes: 0 additions & 4 deletions src/Arrays/utils/_Array.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import all from './all';
import any from './any';
import average from './average';
import contains from './contains';
import count from "./count";
import distinct from './distinct';
import first from './first';
import firstOrDefault from './firstOrDefault';
import forEach from './forEach';
import groupBy from './groupBy';
import item from './item';
import last from './last';
Expand All @@ -16,8 +14,6 @@ import min from './min';
import ofType from './ofType';
import select from './select';
import selectMany from './selectMany';
import single from './single';
import singleOrDefault from './singleOrDefault';
import take from './take';
import where from './where';
import orderBy from './orderBy';
Expand Down
5 changes: 0 additions & 5 deletions src/Arrays/utils/groupBy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Selector } from '../../Types';
import distinct from './distinct';
import select from './select';
import where from './where';



export default function groupBy<T, TKey>(array: T[], keySelector: Selector<T, TKey>): Map<TKey, T[]>
{
Expand Down
4 changes: 0 additions & 4 deletions src/Assertions/ArrayLikeArgumentAssertionBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import ArgumentAssertionBuilder from './ArgumentAssertionBuilder';
import ArgumentException from '../Exceptions/ArgumentException';
import ArgumentNullException from '../Exceptions/ArgumentNullException';
import ArgumentUndefinedException from '../Exceptions/ArgumentUndefinedException';
import NotSupportedException from '../Exceptions/NotSupportedException';


export default class ArrayLikeArgumentAssertionBuilder<T> extends ArgumentAssertionBuilder<ArrayLike<T>>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Assertions/GuidArgumentAssertionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class GuidArgumentAssertionBuilder extends ArgumentAssertionBuild
{
let matched = false;

for (let option of options)
for (const option of options)
{
matched = option.toString() === this.argument.toString();

Expand Down
36 changes: 18 additions & 18 deletions src/Cache/AsyncCacheItem.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Awaitable } from '../Types';
import { IAsyncCacheItem, IExpiryPolicyDelegate } from './_types';
import CacheExpiredException from './CacheExpiredException';
import isFunction from '../TypeHelpers/isFunction';
import { cat } from 'shelljs';
import { Promises } from '..';
import { error } from 'console';


export default class AsyncCacheItem<T> implements IAsyncCacheItem<T>
export default class AsyncCacheItem<T> implements IAsyncCacheItem
{
readonly #promiseOrValue: Awaitable<T>;
readonly #expiryPolicy: IExpiryPolicyDelegate<T>;
Expand All @@ -25,26 +22,29 @@ export default class AsyncCacheItem<T> implements IAsyncCacheItem<T>
this.#expiryPolicy = expiryPolicy;
}

public getValueAsync(): Promise<T>
{
return new Promise<T>(async (resolve, reject) =>
public getValueAsync<T1 = T>(): Promise<T1>
{
return new Promise<T1>((resolve, reject) =>
{
try
(async () =>
{
const value = await Promises.ensurePromise(this.#promiseOrValue);
if (this.#expiryPolicy(value))
try
{
reject();
const value = await Promises.ensurePromise(this.#promiseOrValue);
if (this.#expiryPolicy(value))
{
reject();
}
else
{
resolve(value as T1);
}
}
else
catch (error)
{
resolve(value);
reject(error);
}
}
catch (error)
{
reject(error);
}
})();
});
}
}
2 changes: 1 addition & 1 deletion src/Cache/MemoryCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("MemoryCache + expire", () =>
}
catch (err)
{
;
//
}
});

Expand Down
14 changes: 7 additions & 7 deletions src/Cache/MemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { isUndefinedOrNull } from '../TypeHelpers';
*/
export default class MemoryCache<TKey = string> implements ICache<TKey>
{
readonly #internalCache: Map<TKey, IAsyncCacheItem<any>>;
readonly #internalCache: Map<TKey, IAsyncCacheItem>;

constructor()
{
this.#internalCache = new Map<TKey, IAsyncCacheItem<any>>();
this.#internalCache = new Map<TKey, IAsyncCacheItem>();
}

add<T>(key: TKey, value: Awaitable<T>, expiryPolicy: IExpiryPolicyDelegate<T>): void
Expand All @@ -29,8 +29,8 @@ export default class MemoryCache<TKey = string> implements ICache<TKey>

async addOrGetAsync<T>(key: TKey, factory: (key: TKey) => Awaitable<T>, expiryPolicy: IExpiryPolicyDelegate<T>): Promise<T>
{
const cacheItem = this.#internalCache.get(key) as IAsyncCacheItem<T> | undefined;
let value = await cacheItem?.getValueAsync();
const cacheItem = this.#internalCache.get(key) as IAsyncCacheItem | undefined;
const value = await cacheItem?.getValueAsync<T>();

if (!isUndefinedOrNull(value))
{
Expand All @@ -51,7 +51,7 @@ export default class MemoryCache<TKey = string> implements ICache<TKey>

async cleanAsync(): Promise<void>
{
for (var item of this.#internalCache)
for (const item of this.#internalCache)
{
const value = item[1];
const key = item[0];
Expand All @@ -72,7 +72,7 @@ export default class MemoryCache<TKey = string> implements ICache<TKey>
throw new KeyNotFoundException(key);
}

const value = await cacheItem.getValueAsync();
const value = await cacheItem.getValueAsync<T>();
if (isUndefinedOrNull(value))
{
this.#internalCache.delete(key);
Expand All @@ -91,7 +91,7 @@ export default class MemoryCache<TKey = string> implements ICache<TKey>
return { success: false };
}

const value = await cacheItem.getValueAsync();
const value = await cacheItem.getValueAsync<T>();
if (isUndefinedOrNull(value))
{
this.#internalCache.delete(key);
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
export type IExpiryPolicyDelegate<T> = (value?: T) => boolean;


export interface IAsyncCacheItem<T>
export interface IAsyncCacheItem
{
getValueAsync(): Promise<T>;
getValueAsync<T>(): Promise<T>;
}

export interface ICache<TKey>
Expand Down
21 changes: 10 additions & 11 deletions src/Cache/expire.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { any } from '../Arrays';
import { ArgumentNullException, NullReferenceException } from '../Exceptions';
import { ArgumentNullException } from '../Exceptions';
import { IExpiryPolicyDelegate } from './_types';


Expand Down Expand Up @@ -37,58 +36,58 @@ expire.inYears = expireInYears;
function expireAt(date: Date)
{
return expire(() => date <= new Date());
};
}

function expireIn(time: number)
{
const expires = new Date();
expires.setTime(expires.getTime() + time);
return expireAt(expires);
};
}

function expireTomorrow()
{
return expireInDays(1);
};
}

function expireInSeconds(seconds: number)
{
const expires = new Date();
expires.setSeconds(expires.getSeconds() + seconds);
return expireAt(expires);
};
}

function expireInMinutes(minutes: number)
{
const expires = new Date();
expires.setMinutes(expires.getMinutes() + minutes);
return expireAt(expires);
};
}

function expireInHours(hours: number)
{
const expires = new Date();
expires.setHours(expires.getHours() + hours);
return expireAt(expires);
};
}

function expireInDays(days: number)
{
const expires = new Date();
expires.setDate(expires.getDate() + days);
return expireAt(expires);
};
}

function expireInMonths(months: number)
{
const expires = new Date();
expires.setMonth(expires.getMonth() + months);
return expireAt(expires);
};
}

function expireInYears(years: number)
{
const expires = new Date();
expires.setFullYear(expires.getFullYear() + years);
return expireAt(expires);
};
}
4 changes: 2 additions & 2 deletions src/Comparers/CustomComparer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class CustomComparer<T> implements IComparer<T>, IEqualityCompare
}
else
{
throw new ArgumentUndefinedException("The comparer");
throw new ArgumentUndefinedException("you must specify the comparer in the constructor to use compare.");
}
}

Expand All @@ -38,7 +38,7 @@ export default class CustomComparer<T> implements IComparer<T>, IEqualityCompare
}
else
{
throw new ArgumentUndefinedException("The equality comparer");
throw new ArgumentUndefinedException("you must specify The equality comparer in the constructor to use equals.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Comparers/DefaultComparers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class DefaultComparer<T> implements IComparer<T>, IEqualityComparer<T> {


const DefaultComparers = {
DefaultComparer: new DefaultComparer<any>(),
DefaultComparer: new DefaultComparer<unknown>(),
StringComparer: new DefaultStringComparer(),
NumberComparer: new DefaultNumberComparer(),
ObjectComparer: new DefaultObjectComparer(),
Expand Down
2 changes: 1 addition & 1 deletion src/Comparers/DefaultObjectComparer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IComparer, IEqualityComparer } from './_types';
/**
* Default implementation
*/
export default class DefaultObjectComparer<T extends any = any> implements IComparer<T>, IEqualityComparer<T> {
export default class DefaultObjectComparer<T = unknown> implements IComparer<T>, IEqualityComparer<T> {
public compare(x: T, y: T): number
{
const toStringMethodName = 'toString';
Expand Down
2 changes: 1 addition & 1 deletion src/Comparers/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

export interface IComparable
{
valueOf(): any;
valueOf(): unknown;
}

export interface IComparer<T>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IEvent, Event } from '../Events';
import { INotifyPropertyChanged, INotifyComponentPropertyChangedEventArgs, INotifyPropertyChangedEventArgs } from '../INotifyPropertyChanged';
import { Collection, Enumerable } from '../Enumerables';

type Props = Undefinable<{}>;
type Props = Undefinable<unknown>;

export interface IComponent<TProps extends Props = undefined> extends INotifyPropertyChanged, IDisposable
{
Expand Down Expand Up @@ -57,7 +57,7 @@ export default abstract class Component<TProps extends Props> implements ICompon
{
component.propertyChanged.addHandler((s, e) =>
{
this.#propertyChanged.invoke(this, {...e, instance: s });
this.#propertyChanged.invoke(this, {...e, instance: s as INotifyPropertyChanged });
});
component.init();
}
Expand Down
1 change: 0 additions & 1 deletion src/Components/ListComponent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import Component from './Component';
import { List } from '../Enumerables';

interface IListComponentProps
{
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Json/Json.types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

export type ConfigValue<T = {}> = T[] | T | string | number | boolean;
export type ConfigValue<T = NonNullable<unknown>> = ConfigValue<T>[] | T | string | number | boolean;
Loading

0 comments on commit 1f3a6b8

Please sign in to comment.