Skip to content

Commit

Permalink
[Refactor] stringify: throw faster with an invalid encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 17, 2016
1 parent 2ca339e commit b041eb9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
module.exports = function (object, opts) {
var obj = object;
var options = opts || {};

if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
throw new TypeError('Encoder has to be a function.');
}

var delimiter = typeof options.delimiter === 'undefined' ? defaults.delimiter : options.delimiter;
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
Expand All @@ -136,10 +141,6 @@ module.exports = function (object, opts) {
var objKeys;
var filter;

if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
throw new TypeError('Encoder has to be a function.');
}

if (typeof options.filter === 'function') {
filter = options.filter;
obj = filter('', obj);
Expand Down

0 comments on commit b041eb9

Please sign in to comment.