diff --git a/src/util/support/Pipe.ts b/src/util/support/Pipe.ts index 599994e..faf9779 100644 --- a/src/util/support/Pipe.ts +++ b/src/util/support/Pipe.ts @@ -96,7 +96,9 @@ export class Pipe { * @param op */ when(check: PipeCondition, op: ReflexivePipeOperator): Pipe { - if ( (typeof check === 'function' && check(this.subject)) || check ) { + if ( + (typeof check === 'function' && check(this.subject)) + || (typeof check !== 'function' && check) ) { return Pipe.wrap(op(this.subject)) } @@ -111,7 +113,9 @@ export class Pipe { * @param op */ unless(check: PipeCondition, op: ReflexivePipeOperator): Pipe { - if ( (typeof check === 'function' && check(this.subject)) || check ) { + if ( + (typeof check === 'function' && check(this.subject)) + || (typeof check !== 'function' && check) ) { return this } diff --git a/src/util/support/string.ts b/src/util/support/string.ts index 3123012..e3a41a4 100644 --- a/src/util/support/string.ts +++ b/src/util/support/string.ts @@ -36,13 +36,15 @@ export function padLeft(string: string, length: number, padWith = ' '): string { * @param padWith */ export function padCenter(string: string, length: number, padWith = ' '): string { - const bit = false + let bit = false while ( string.length < length ) { if ( bit ) { string = `${padWith}${string}` } else { string += padWith } + + bit = !bit } return string @@ -53,7 +55,7 @@ export function padCenter(string: string, length: number, padWith = ' '): string * @param input */ export function stringToPascal(input: string): string { - return input.split(/[\s_]+/i) + return input.split(/[\s_-]+/i) .map(part => { return part[0].toUpperCase() + part.substr(1) }) diff --git a/src/util/support/types.ts b/src/util/support/types.ts index 9c99599..39533f2 100644 --- a/src/util/support/types.ts +++ b/src/util/support/types.ts @@ -18,3 +18,8 @@ export function isKeyof(key: unknown, obj: T): key is keyof T { return key in obj } + +/** A typescript-compatible version of Object.hasOwnProperty. */ +export function hasOwnProperty(obj: X, prop: Y): obj is X & Record { // eslint-disable-line @typescript-eslint/ban-types + return Object.hasOwnProperty.call(obj, prop) +}