Skip to content

Commit

Permalink
fix: tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
westeezy committed Nov 23, 2022
1 parent 8e26cda commit 6e70ebb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export function request({
},
false
);
// open of a dynamic url
// eslint-disable-next-line security/detect-non-literal-fs-filename
xhr.open(method, url, true);

for (const key in normalizedHeaders) {
Expand Down
92 changes: 46 additions & 46 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function base64encode(str: string): string {
export function base64decode(str: string): string {
if (typeof atob === "function") {
return decodeURIComponent(
// $FlowFixMe[method-unbinding]
Array.prototype.map
.call(atob(str), (c) => {
// eslint-disable-next-line prefer-template, @typescript-eslint/restrict-plus-operands
Expand Down Expand Up @@ -153,7 +152,6 @@ export function getObjectID(obj: Record<string, any>): string {

function serializeArgs<T>(args: readonly T[]): string {
try {
// $FlowFixMe[method-unbinding]
return JSON.stringify(Array.prototype.slice.call(args), (_subkey, val) => {
// Treat each distinct function as unique for purposes of memoization
// e.g. even if someFunction.stringify() is the same, we may use a different memoize cache
Expand Down Expand Up @@ -226,7 +224,8 @@ export function memoize<F extends (...args: any[]) => any>(
try {
cacheKey = serializeArgs(args);
} catch {
// @ts-expect-error
// @ts-expect-error use rest parameter over arguments
// eslint-disable-next-line prefer-rest-params
return method.apply(this, arguments);
}

Expand All @@ -244,7 +243,8 @@ export function memoize<F extends (...args: any[]) => any>(
}

const time = Date.now();
// @ts-expect-error
// @ts-expect-error use rest parameter over arguments
// eslint-disable-next-line prefer-rest-params
const value = method.apply(this, arguments);
// @ts-expect-error need to use a generic for cache later
cache[cacheKey] = {
Expand All @@ -259,8 +259,7 @@ export function memoize<F extends (...args: any[]) => any>(
thisCache = null;
};

// @ts-expect-error
const result: F = memoizedFunction;
const result = memoizedFunction;
// @ts-expect-error memoized function vs function
return setFunctionName(
result,
Expand Down Expand Up @@ -291,7 +290,8 @@ export function memoizePromise<R>(
return cache[key];
}

// @ts-expect-error
// @ts-expect-error this line just has all sorts of problems
// eslint-disable-next-line prefer-rest-params
cache[key] = ZalgoPromise.try(() => method.apply(this, arguments)).finally(
() => {
// @ts-expect-error need to use a generic for cache later
Expand Down Expand Up @@ -327,7 +327,8 @@ export function promisify<R>(
options: PromisifyOptions = getDefaultPromisifyOptions()
): (...args: readonly any[]) => ZalgoPromise<R> {
function promisifiedFunction(): ZalgoPromise<R | undefined> {
// @ts-expect-error Argument of type 'IArguments' is not assignable to parameter of type 'readonly any[]'.
// @ts-expect-error use rest parameter over arguments also something with this
// eslint-disable-next-line prefer-rest-params
return ZalgoPromise.try(method, this, arguments);
}

Expand All @@ -349,9 +350,9 @@ export function inlineMemoize<R>(
logic: (...args: readonly any[]) => R,
args: readonly any[] = []
): R {
// @ts-expect-error
// @ts-expect-error __inline_memoize_cache__ does not exist
const cache: Record<string, R> = (method.__inline_memoize_cache__ =
// @ts-expect-error
// @ts-expect-error __inline_memoize_cache__ does not exist
method.__inline_memoize_cache__ || {});
const key = serializeArgs(args);

Expand All @@ -374,7 +375,8 @@ export function once(method: (...args: any[]) => any): (...args: any[]) => any {
const onceFunction = function (): unknown {
if (!called) {
called = true;
// @ts-expect-error
// @ts-expect-error use rest parameter over arguments
// eslint-disable-next-line prefer-rest-params
return method.apply(this, arguments);
}
};
Expand Down Expand Up @@ -458,7 +460,6 @@ export function stringifyError(err: unknown, level = 1): string {

try {
if (!err) {
// $FlowFixMe[method-unbinding]
return `<unknown error: ${Object.prototype.toString.call(err)}>`;
}

Expand Down Expand Up @@ -488,10 +489,11 @@ export function stringifyError(err: unknown, level = 1): string {
(err as Error).toString &&
typeof (err as Error).toString === "function"
) {
// stringify of err will be [object Object]
// eslint-disable-next-line @typescript-eslint/no-base-to-string
return err.toString();
}

// $FlowFixMe[method-unbinding]
return Object.prototype.toString.call(err);
} catch (newErr) {
return `Error while stringifying error: ${stringifyError(
Expand All @@ -502,7 +504,6 @@ export function stringifyError(err: unknown, level = 1): string {
}

export function stringifyErrorMessage(err: unknown): string {
// $FlowFixMe[method-unbinding]
const defaultMessage = `<unknown error: ${Object.prototype.toString.call(
err
)}>`;
Expand All @@ -528,10 +529,11 @@ export function stringify(item: unknown): string {
}

if (item && item.toString && typeof item.toString === "function") {
// stringify of item will be [object Object]
// eslint-disable-next-line @typescript-eslint/no-base-to-string
return item.toString();
}

// $FlowFixMe[method-unbinding]
return Object.prototype.toString.call(item);
}

Expand All @@ -551,9 +553,11 @@ export function patchMethod(
obj[name] = function patchedMethod(): unknown {
return handler({
context: this,
// eslint-disable-next-line prefer-rest-params
args: Array.prototype.slice.call(arguments),
original,
// @ts-expect-error arguments in an arrow function
// eslint-disable-next-line prefer-rest-params
callOriginal: () => original.apply(this, arguments),
});
};
Expand Down Expand Up @@ -582,20 +586,17 @@ export function extend<

export function values<T>(obj: Record<string, T>): readonly T[] {
if (Object.values) {
// $FlowFixMe
return Object.values(obj);
}

const result: T[] = [];

for (const key in obj) {
if (obj.hasOwnProperty(key)) {
// $FlowFixMe[escaped-generic]
result.push(obj[key]);
}
}

// $FlowFixMe
return result;
}

Expand Down Expand Up @@ -625,12 +626,14 @@ export function regexMap<T>(
handler?: () => T
): readonly T[] {
const results: T[] | Array<string | T> = [];
// @ts-expect-error
// @ts-expect-error no overload matches the cal of regexMapMatcher
str.replace(regexp, function regexMapMatcher(item) {
// @ts-expect-error
// @ts-expect-error use rest parameter over arguments
// eslint-disable-next-line
results.push(handler ? handler.apply(null, arguments) : item);
});
// @ts-expect-error

// @ts-expect-error results doesnt match return value
return results;
}

Expand All @@ -649,7 +652,7 @@ export function objFilter<T, R>(
continue;
}

// @ts-expect-error
// @ts-expect-error string indexer
result[key] = obj[key];
}

Expand Down Expand Up @@ -824,10 +827,10 @@ export function undotify(obj: Record<string, unknown>): Record<string, any> {
}

if (isLast) {
// @ts-expect-error
// @ts-expect-error string indexer
keyResult[part] = value;
} else {
// @ts-expect-error
// @ts-expect-error string indexer
keyResult = keyResult[part] = keyResult[part] || (isIndex ? [] : {});
}
}
Expand Down Expand Up @@ -989,17 +992,17 @@ export function defineLazyProp<T>(
configurable: true,
enumerable: true,
get: () => {
// @ts-expect-error
// @ts-expect-error delete on a dynamic key
delete obj[key];
const value = getter();
// @ts-expect-error
// @ts-expect-error string indexer
obj[key] = value;
return value;
},
set: (value: T) => {
// @ts-expect-error
// @ts-expect-error delete on a dynamic key
delete obj[key];
// @ts-expect-error
// @ts-expect-error string indexer
obj[key] = value;
},
});
Expand All @@ -1015,7 +1018,6 @@ export function isObject(item: unknown): boolean {

export function isObjectObject(obj: unknown): boolean {
return (
// $FlowFixMe[method-unbinding]
isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]"
);
}
Expand All @@ -1025,7 +1027,7 @@ export function isPlainObject(obj: unknown): boolean {
return false;
}

// @ts-expect-error
// @ts-expect-error obj is unknown
const constructor = obj.constructor;

if (typeof constructor !== "function") {
Expand Down Expand Up @@ -1063,15 +1065,15 @@ export function replaceObject<
let child = replacer(el, i, itemKey);

if (isPlainObject(child) || Array.isArray(child)) {
// @ts-expect-error
// @ts-expect-error child is unknown type
child = replaceObject(child, replacer, itemKey);
}

return child;
});
}

// @ts-expect-error
// @ts-expect-error unknown[] is not assignable to T
return result;
} else if (isPlainObject(item)) {
const result = {};
Expand All @@ -1083,20 +1085,19 @@ export function replaceObject<

defineLazyProp(result, key, () => {
const itemKey = fullKey ? `${fullKey}.${key}` : `${key}`;
// $FlowFixMe
const el = item[key];
let child = replacer(el, key, itemKey);

if (isPlainObject(child) || Array.isArray(child)) {
// @ts-expect-error
// @ts-expect-error child is unknown type
child = replaceObject(child, replacer, itemKey);
}

return child;
});
}

// @ts-expect-error
// @ts-expect-error unknown[] is not assignable to T
return result;
} else {
throw new Error(`Pass an object or array`);
Expand Down Expand Up @@ -1139,12 +1140,11 @@ export function regex(

const result = string.slice(start).match(pattern);

if (!result) {
if (!result || result.index === undefined) {
return;
}

// @ts-expect-error
const index: number = result.index;
const index = result.index;
const regmatch = result[0];
return {
text: regmatch,
Expand Down Expand Up @@ -1188,7 +1188,7 @@ export function regexAll(
return matches;
}

export function isDefined(value: unknown | undefined | undefined): boolean {
export function isDefined(value: unknown): boolean {
return value !== null && value !== undefined;
}

Expand All @@ -1206,20 +1206,20 @@ export function debounce<T>(
const debounceWrapper = function () {
clearTimeout(timeout);
timeout = setTimeout(() => {
// @ts-expect-error
// @ts-expect-error use rest parameter over arguments
// eslint-disable-next-line
return method.apply(this, arguments);
}, time);
};

// @ts-expect-error
// @ts-expect-error this is a problematic helper
return setFunctionName(
debounceWrapper,
`${getFunctionName(method)}::debounced`
);
}

export function isRegex(item: unknown): boolean {
// $FlowFixMe[method-unbinding]
return Object.prototype.toString.call(item) === "[object RegExp]";
}

Expand All @@ -1231,7 +1231,7 @@ export const weakMapMemoize: FunctionProxy<any> = <R>(
const weakmap = new WeakMap();

return function weakmapMemoized(arg: any): R {
// @ts-expect-error
// @ts-expect-error unknown is not assignable to R
return weakmap.getOrSet(arg, () => method.call(this, arg));
};
};
Expand All @@ -1249,7 +1249,7 @@ export const weakMapMemoizePromise: FunctionPromiseProxy<any, any> = <R>(
return function weakmapMemoizedPromise(arg: any): ZalgoPromise<R> {
// @ts-expect-error unknown is not assignable to ZalgoPromise<R>
return weakmap.getOrSet(arg, () =>
// @ts-expect-error
// @ts-expect-error this has no type annotation
method.call(this, arg).finally(() => {
weakmap.delete(arg);
})
Expand All @@ -1267,7 +1267,7 @@ export function getOrSet<O extends Record<string, any>, T>(
}

const val = getter();
// @ts-expect-error
// @ts-expect-error string indexer
obj[key] = val;
return val;
}
Expand Down Expand Up @@ -1339,7 +1339,7 @@ export function cleanup(obj: Record<string, any>): CleanupType {
export function tryCatch<T>(fn: () => T):
| {
result: T;
error: Error | unknown;
error: Error;
}
| {
result: unknown;
Expand Down

0 comments on commit 6e70ebb

Please sign in to comment.