Skip to content

Commit

Permalink
Change exports usage
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Oct 13, 2017
1 parent 0e838da commit 6f0586f
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lib/utils.js
Expand Up @@ -34,7 +34,7 @@ var compactQueue = function compactQueue(queue) {
return obj;
};

exports.arrayToObject = function arrayToObject(source, options) {
var arrayToObject = function arrayToObject(source, options) {
var obj = options && options.plainObjects ? Object.create(null) : {};
for (var i = 0; i < source.length; ++i) {
if (typeof source[i] !== 'undefined') {
Expand All @@ -45,7 +45,7 @@ exports.arrayToObject = function arrayToObject(source, options) {
return obj;
};

exports.merge = function merge(target, source, options) {
var merge = function merge(target, source, options) {
if (!source) {
return target;
}
Expand All @@ -70,14 +70,14 @@ exports.merge = function merge(target, source, options) {

var mergeTarget = target;
if (Array.isArray(target) && !Array.isArray(source)) {
mergeTarget = exports.arrayToObject(target, options);
mergeTarget = arrayToObject(target, options);
}

if (Array.isArray(target) && Array.isArray(source)) {
source.forEach(function (item, i) {
if (has.call(target, i)) {
if (target[i] && typeof target[i] === 'object') {
target[i] = exports.merge(target[i], item, options);
target[i] = merge(target[i], item, options);
} else {
target.push(item);
}
Expand All @@ -92,30 +92,30 @@ exports.merge = function merge(target, source, options) {
var value = source[key];

if (has.call(acc, key)) {
acc[key] = exports.merge(acc[key], value, options);
acc[key] = merge(acc[key], value, options);
} else {
acc[key] = value;
}
return acc;
}, mergeTarget);
};

exports.assign = function assignSingleSource(target, source) {
var assign = function assignSingleSource(target, source) {
return Object.keys(source).reduce(function (acc, key) {
acc[key] = source[key];
return acc;
}, target);
};

exports.decode = function (str) {
var decode = function (str) {
try {
return decodeURIComponent(str.replace(/\+/g, ' '));
} catch (e) {
return str;
}
};

exports.encode = function encode(str) {
var encode = function encode(str) {
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
// It has been adapted here for stricter adherence to RFC 3986
if (str.length === 0) {
Expand Down Expand Up @@ -167,7 +167,7 @@ exports.encode = function encode(str) {
return out;
};

exports.compact = function compact(value) {
var compact = function compact(value) {
var queue = [{ obj: { o: value }, prop: 'o' }];
var refs = [];

Expand All @@ -189,14 +189,25 @@ exports.compact = function compact(value) {
return compactQueue(queue);
};

exports.isRegExp = function isRegExp(obj) {
var isRegExp = function isRegExp(obj) {
return Object.prototype.toString.call(obj) === '[object RegExp]';
};

exports.isBuffer = function isBuffer(obj) {
var isBuffer = function isBuffer(obj) {
if (obj === null || typeof obj === 'undefined') {
return false;
}

return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
};

module.exports = {
arrayToObject: arrayToObject,
assign: assign,
compact: compact,
decode: decode,
encode: encode,
isBuffer: isBuffer,
isRegExp: isRegExp,
merge: merge
};

0 comments on commit 6f0586f

Please sign in to comment.