diff --git a/source/lib/predicates/predicate.ts b/source/lib/predicates/predicate.ts index 3871ffa..db8a6d9 100644 --- a/source/lib/predicates/predicate.ts +++ b/source/lib/predicates/predicate.ts @@ -9,6 +9,8 @@ export interface Context { validators: Validator[]; } +export const validatorSymbol = Symbol('validators'); + export class Predicate { constructor( type: string, @@ -20,7 +22,7 @@ export class Predicate { }); } - get validators() { + get [validatorSymbol]() { return this.context.validators; } diff --git a/source/ow.ts b/source/ow.ts index a83d456..1d13c08 100644 --- a/source/ow.ts +++ b/source/ow.ts @@ -1,6 +1,6 @@ import * as is from '@sindresorhus/is'; import { ArgumentError } from './lib/argument-error'; -import { Predicate } from './lib/predicates/predicate'; +import { Predicate, validatorSymbol } from './lib/predicates/predicate'; import { StringPredicate } from './lib/predicates/string'; export interface Ow { @@ -12,7 +12,7 @@ export interface Ow { } export const ow: Ow = (value: any, predicate: Predicate) => { - for (const { validator, message } of predicate.validators) { + for (const { validator, message } of predicate[validatorSymbol]) { if (!validator(value)) { // TODO: Modify the stack output to show the original `ow()` call instead of this `throw` statement throw new ArgumentError(message(value), ow);