From bce3cd2b8ba61a72a8e1bbd34ec87dcc17d49bb0 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Tue, 30 Aug 2016 13:20:20 -0400 Subject: [PATCH] Add key/value validation to Collection.find/findAll (#569) * Add key/value validation to Collection.find/findAll * Fix ESLint errors --- src/util/Collection.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/Collection.js b/src/util/Collection.js index f33053a33..67168cb24 100644 --- a/src/util/Collection.js +++ b/src/util/Collection.js @@ -77,6 +77,8 @@ class Collection extends Map { * collection.getAll('username', 'Bob'); */ findAll(key, value) { + if (typeof key !== 'string') throw new TypeError('key must be a string'); + if (typeof value === 'undefined') throw new Error('value must be specified'); const results = []; for (const item of this.values()) { if (item[key] === value) { @@ -95,6 +97,8 @@ class Collection extends Map { * collection.get('id', '123123...'); */ find(key, value) { + if (typeof key !== 'string') throw new TypeError('key must be a string'); + if (typeof value === 'undefined') throw new Error('value must be specified'); for (const item of this.values()) { if (item[key] === value) { return item;