Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .tsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@
"strictPropertyInitialization": true,
"experimentalDecorators": true,
"noImplicitOverride": true
}
},
"typeAcquisition": {
"exclude": ["node"]
},
"exclude": [
"dist",
"config",
"node_modules"
]
}
35 changes: 25 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ interface ObjectConstructor {
* ```
*/
Result<A1, A extends any[], R>(value: (a1: A1, ...a: A) => R):
(a1: Maybe<A1> | Either<A1>, ...rest: A) => Either<R>;
(a1: A1 | Maybe<A1> | Either<A1>, ...rest: A) => Either<R>;

/**
* Wraps the specified value into the Either structure
Expand Down Expand Up @@ -2510,7 +2510,7 @@ interface NumberConstructor {
* Returns a curried version of `Number.pad`
* @param opts - additional options
*/
pad(opts: NumberPadOptions): (value: string) => string;
pad(opts: NumberPadOptions): (value: number) => string;

/**
* Returns a string from a number with adding extra zeros to the start, if necessary
Expand Down Expand Up @@ -2757,7 +2757,7 @@ interface Number {
* @param targetLength - length of the resulting string once the current string has been padded
* @param [opts] - additional options
*/
pad(targetLength?: number, opts?: NumberPadOptions): string;
pad(targetLength?: number | NumberPadOptions, opts?: NumberPadOptions): string;

/**
* Returns a string representation of the number by the specified pattern.
Expand Down Expand Up @@ -2825,7 +2825,8 @@ interface Number {
ceil(precision?: number): number;
}

type RegExpFlag = '' | 'g' | 'i' | 'm' | 'u' | 'y' | 's';
type RegExpSingleFlag = '' | 'g' | 'i' | 'm' | 'u' | 'y' | 's';
type RegExpFlag = `${RegExpSingleFlag}${RegExpSingleFlag}${RegExpSingleFlag}${RegExpSingleFlag}${RegExpSingleFlag}`;

interface RegExp {
/**
Expand Down Expand Up @@ -2881,7 +2882,7 @@ interface RegExpConstructor {
* @param rgxp
* @param flags
*/
addFlags(rgxp: RegExp, ...flags: RegExpFlag[]): RegExp;
addFlags(rgxp: RegExp, ...flags: [RegExpFlag, ...RegExpFlag[]]): RegExp;

/**
* Returns a curried version of `RegExp.addFlags`
Expand All @@ -2901,7 +2902,7 @@ interface RegExpConstructor {
* @param rgxp
* @param flags
*/
removeFlags(rgxp: RegExp, ...flags: RegExpFlag[]): RegExp;
removeFlags(rgxp: RegExp, ...flags: [RegExpFlag, ...RegExpFlag[]]): RegExp;

/**
* Returns a curried version of `RegExp.removeFlags`
Expand All @@ -2921,7 +2922,7 @@ interface RegExpConstructor {
* @param rgxp
* @param flags
*/
setFlags(rgxp: RegExp, ...flags: RegExpFlag[]): RegExp;
setFlags(rgxp: RegExp, ...flags: [RegExpFlag, ...RegExpFlag[]]): RegExp;

/**
* Returns a curried version of `RegExp.setFlags`
Expand Down Expand Up @@ -3083,6 +3084,20 @@ interface DateConstructor {
*/
isBetween(date: Date, left: DateCreateValue, right: DateCreateValue, margin?: number): boolean;

/**
* Returns true if the date is less than the now date
*
* @param date - date that will be checked
*/
isPast(date: Date): boolean;

/**
* Returns true if the date is greater than the now date
*
* @param date - date that will be checked
*/
isFuture(date: Date): boolean;

/**
* Returns a new date based on the current so that it starts at the beginning of a day
* @param date
Expand Down Expand Up @@ -3205,7 +3220,7 @@ interface DateConstructor {
* @param opts
* @param locale
*/
format(opts: Intl.NumberFormatOptions, locale?: CanArray<string>): (date: Date) => string;
format(opts: Intl.DateTimeFormatOptions, locale?: CanArray<string>): (date: Date) => string;

/**
* Returns a string representation of the date by the specified pattern.
Expand Down Expand Up @@ -3294,7 +3309,7 @@ interface DateConstructor {
* Returns a curried version of `Date.toHTMLTimeString`
* @param opts - additional options
*/
toHTMLTimeString(opts: DateHTMLDateStringOptions): (date: Date) => string;
toHTMLTimeString(opts: DateHTMLTimeStringOptions): (date: Date) => string;

/**
* Returns an HTML string representation of a timestamp from the date.
Expand Down Expand Up @@ -4020,7 +4035,7 @@ interface Function {
* ```
*/
result<A1, A extends any[], R>(this: (a1: A1, ...rest: A) => R):
(a1: Maybe<A1> | Either<A1>, ...rest: A) => Either<R>;
(a1: A1 | Maybe<A1> | Either<A1>, ...rest: A) => Either<R>;

/**
* Returns a curried equivalent of the function.
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/** @type {import('ts-jest').InitialOptionsTsJest} */
export default {
projects: ['<rootDir>'],
testMatch: ['<rootDir>/dist/server/**/*[sS]pec.js', '<rootDir>/src/**/*[sS]pec.ts'],
testMatch: ['<rootDir>/dist/server/**/*[sS]pec.js'],
rootDir: './',
testTimeout: 20000,
testEnvironment: 'node',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"upath": "2.0.1"
},
"devDependencies": {
"@types/express": "4.17.14",
"@types/fs-extra-promise": "1.0.10",
"@types/got": "9.6.12",
"@types/gulp": "4.0.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ const
$$ = symbolGenerator();

describe('core/async/modules/base `label`', () => {
const onResolve = (res, label) => (v = label) => {
res.push(v);
const onResolve = (res: string[], label?: string) => (v = label) => {
if (v != null) {
res.push(v);
}

return label;
};

Expand Down Expand Up @@ -42,7 +45,7 @@ describe('core/async/modules/base `label`', () => {
const
$a = new Async(),
spy = jest.fn(),
res = [];
res: string[] = [];

$a.promise(Promise.resolve('first'), {label: $$.foo}).then(onResolve(res), onReject(spy));
$a.promise(Promise.resolve('second'), {label: $$.foo}).then(onResolve(res), onReject(spy));
Expand Down Expand Up @@ -73,7 +76,7 @@ describe('core/async/modules/base `label`', () => {
it('label collision with promises and joining', (done) => {
const
$a = new Async(),
res = [];
res: string[] = [];

$a.promise(Promise.resolve('first'), {label: $$.foo, join: true})
.then(onResolve(res));
Expand All @@ -91,7 +94,7 @@ describe('core/async/modules/base `label`', () => {
const
$a = new Async(),
spy = jest.fn(),
res = [];
res: string[] = [];

$a.setTimeout(onResolve(res, 'first'), 10, {label: $$.foo, join: 'replace', onClear: onReject(spy)});
$a.setTimeout(onResolve(res, 'second'), 10, {label: $$.foo, join: 'replace', onClear: onReject(spy)});
Expand All @@ -107,7 +110,7 @@ describe('core/async/modules/base `label`', () => {
const
$a = new Async(),
spy = jest.fn(),
res = [];
res: string[] = [];

$a.promise(Promise.resolve('first'), {label: $$.foo, join: 'replace'}).then(onResolve(res), onReject(spy));
$a.promise(Promise.resolve('second'), {label: $$.foo, join: 'replace'}).then(onResolve(res), onReject(spy));
Expand All @@ -121,7 +124,7 @@ describe('core/async/modules/base `label`', () => {
it('label collision with iterables and replacing', async () => {
const $a = new Async();

const result = [];
const result: number[] = [];

await Promise.all([
(async () => {
Expand Down Expand Up @@ -149,7 +152,7 @@ describe('core/async/modules/base `label`', () => {
it('label collision with iterables and join', async () => {
const $a = new Async();

const result = [];
const result: number[] = [];

await Promise.all([
(async () => {
Expand Down
14 changes: 7 additions & 7 deletions src/core/async/modules/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
events: CanArray<string>,
handler: ProxyCb<E, R, CTX>,
...args: unknown[]
): Nullable<EventId>;
): CanUndef<EventId>;

/**
* Attaches an event listener from the specified event emitter.
Expand All @@ -78,15 +78,15 @@ export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
handler: ProxyCb<E, R, CTX>,
opts: AsyncOnOptions<CTX>,
...args: unknown[]
): Nullable<EventId>;
): CanUndef<EventId>;

on<E, R>(
emitter: EventEmitterLikeP,
events: CanArray<string>,
handler: ProxyCb<E, R, CTX>,
opts?: AsyncOnOptions<CTX> | unknown[],
...args: unknown[]
): Nullable<EventId> {
): CanUndef<EventId> {
let
p: AsyncOnOptions<CTX>;

Expand Down Expand Up @@ -197,7 +197,7 @@ export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
}
}

return events.length <= 1 ? links[0] ?? null : links;
return events.length <= 1 ? links[0] ?? undefined : links;
}

/**
Expand All @@ -215,7 +215,7 @@ export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
events: CanArray<string>,
handler: ProxyCb<E, R, CTX>,
...args: unknown[]
): Nullable<EventId>;
): CanUndef<EventId>;

/**
* Attaches an event listener from the specified event emitter, but the event is listened only once.
Expand All @@ -234,15 +234,15 @@ export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
handler: ProxyCb<E, R, CTX>,
opts: AsyncOnceOptions<CTX>,
...args: unknown[]
): Nullable<EventId>;
): CanUndef<EventId>;

once<E, R>(
emitter: EventEmitterLikeP,
events: CanArray<string>,
handler: ProxyCb<E, R, CTX>,
opts?: AsyncOnceOptions<CTX> | unknown[],
...args: unknown[]
): Nullable<EventId> {
): CanUndef<EventId> {
let
p: AsyncOnceOptions<CTX>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('core/async/modules/proxy `iterable`', () => {
});
});

function expectToBePending(promise) {
function expectToBePending(promise: PromiseLike<any>) {
const want = {};

return SyncPromise.race([promise, SyncPromise.resolve(want)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('core/async/modules/timers', () => {
clear = clear || `clear-${method}`.camelize(false);

const
args = [];
args: number[] = [];

if (method === 'timeout' || method === 'interval') {
args.push(10);
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('core/async/modules/timers', () => {
it(`\`${method}\``, (done) => {
const
$a = new Async(),
args = [];
args: Array<number | (() => boolean)> = [];

let
i = 0;
Expand Down
Loading