diff options
-rw-r--r-- | src/find.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/find.js b/src/find.js index 2c97142f..238abda8 100644 --- a/src/find.js +++ b/src/find.js @@ -112,7 +112,10 @@ function findHelper({ // 'quiet' both return null, with 'warn' logging details directly to the // console. return (fullRef, data, {mode = 'warn'} = {}) => { + // TODO: Factor out this validation + if (!fullRef) return null; + if (typeof fullRef !== 'string') { throw new TypeError(`Expected a string, got ${typeAppearance(fullRef)}`); } @@ -268,6 +271,18 @@ function findMixedHelper(config) { specs = specKeys.map(specKey => findFindSpec(specKey)); return (fullRef, data, {mode = 'warn'} = {}) => { + // TODO: Factor out this validation + + if (!fullRef) return null; + + if (typeof fullRef !== 'string') { + throw new TypeError(`Expected a string, got ${typeAppearance(fullRef)}`); + } + + if (!data) { + throw new TypeError(`Expected data to be present`); + } + // TODO: Cache stuff below by identity of data const byName = Object.create(null); |