mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Prevent negated conditions
This commit is contained in:
@@ -88,14 +88,14 @@ function emitStoredErrors(this: Guarded, event: string, func: (error: Error) =>
|
||||
*/
|
||||
export function guardStream<T extends NodeJS.EventEmitter>(stream: T): Guarded<T> {
|
||||
const guarded = stream as Guarded<T>;
|
||||
if (!isGuarded(stream)) {
|
||||
guarded[guardedErrors] = [];
|
||||
guarded.on('error', guardingErrorListener);
|
||||
guarded.on('newListener', emitStoredErrors);
|
||||
} else {
|
||||
if (isGuarded(stream)) {
|
||||
// This makes sure the guarding error listener is the last one in the list again
|
||||
guarded.removeListener('error', guardingErrorListener);
|
||||
guarded.on('error', guardingErrorListener);
|
||||
} else {
|
||||
guarded[guardedErrors] = [];
|
||||
guarded.on('error', guardingErrorListener);
|
||||
guarded.on('newListener', emitStoredErrors);
|
||||
}
|
||||
return guarded;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ function transformPathComponents(path: string, transform: (part: string) => stri
|
||||
.map((part, index): string =>
|
||||
index % 2 === 0 ? transform(part) : part.toUpperCase())
|
||||
.join('');
|
||||
return !queryString ? transformed : `${transformed}${queryString}`;
|
||||
return queryString ? `${transformed}${queryString}` : transformed;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,8 +72,8 @@ export class FilterPattern {
|
||||
* @param object - Optionally filter based on a specific object.
|
||||
*/
|
||||
public constructor(subject?: string, predicate?: string, object?: string) {
|
||||
this.subject = typeof subject !== 'undefined' ? toNamedTerm(subject) : null;
|
||||
this.predicate = typeof predicate !== 'undefined' ? toNamedTerm(predicate) : null;
|
||||
this.object = typeof object !== 'undefined' ? toNamedTerm(object) : null;
|
||||
this.subject = typeof subject === 'string' ? toNamedTerm(subject) : null;
|
||||
this.predicate = typeof predicate === 'string' ? toNamedTerm(predicate) : null;
|
||||
this.object = typeof object === 'string' ? toNamedTerm(object) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ export class SliceStream extends Transform {
|
||||
let start = options.start;
|
||||
const end = options.end ?? Number.POSITIVE_INFINITY;
|
||||
if (options.start < 0) {
|
||||
if (typeof options.size !== 'number') {
|
||||
throw new RangeNotSatisfiedHttpError('Slicing data at the end of a stream requires a known size.');
|
||||
} else {
|
||||
if (typeof options.size === 'number') {
|
||||
// `start` is a negative number here so need to add
|
||||
start = options.size + start;
|
||||
} else {
|
||||
throw new RangeNotSatisfiedHttpError('Slicing data at the end of a stream requires a known size.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user