@allthings/sdk 6.6.0 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.cjs.js CHANGED
@@ -12,7 +12,7 @@ var require$$4 = require('https');
12
12
  var require$$5 = require('url');
13
13
  var require$$6 = require('fs');
14
14
 
15
- const version = "6.6.0";
15
+ const version = "6.7.0";
16
16
 
17
17
  const REST_API_URL = 'https://api.allthings.me';
18
18
  const OAUTH_URL = 'https://accounts.allthings.me';
@@ -920,322 +920,338 @@ function getDefaultExportFromCjs (x) {
920
920
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
921
921
  }
922
922
 
923
- var Stream$2 = require$$0$1.Stream;
924
- var util$2 = require$$1;
925
-
926
- var delayed_stream = DelayedStream$1;
927
- function DelayedStream$1() {
928
- this.source = null;
929
- this.dataSize = 0;
930
- this.maxDataSize = 1024 * 1024;
931
- this.pauseStream = true;
932
-
933
- this._maxDataSizeExceeded = false;
934
- this._released = false;
935
- this._bufferedEvents = [];
936
- }
937
- util$2.inherits(DelayedStream$1, Stream$2);
938
-
939
- DelayedStream$1.create = function(source, options) {
940
- var delayedStream = new this();
923
+ var delayed_stream;
924
+ var hasRequiredDelayed_stream;
925
+
926
+ function requireDelayed_stream () {
927
+ if (hasRequiredDelayed_stream) return delayed_stream;
928
+ hasRequiredDelayed_stream = 1;
929
+ var Stream = require$$0$1.Stream;
930
+ var util = require$$1;
931
+
932
+ delayed_stream = DelayedStream;
933
+ function DelayedStream() {
934
+ this.source = null;
935
+ this.dataSize = 0;
936
+ this.maxDataSize = 1024 * 1024;
937
+ this.pauseStream = true;
938
+
939
+ this._maxDataSizeExceeded = false;
940
+ this._released = false;
941
+ this._bufferedEvents = [];
942
+ }
943
+ util.inherits(DelayedStream, Stream);
941
944
 
942
- options = options || {};
943
- for (var option in options) {
944
- delayedStream[option] = options[option];
945
- }
945
+ DelayedStream.create = function(source, options) {
946
+ var delayedStream = new this();
946
947
 
947
- delayedStream.source = source;
948
+ options = options || {};
949
+ for (var option in options) {
950
+ delayedStream[option] = options[option];
951
+ }
948
952
 
949
- var realEmit = source.emit;
950
- source.emit = function() {
951
- delayedStream._handleEmit(arguments);
952
- return realEmit.apply(source, arguments);
953
- };
953
+ delayedStream.source = source;
954
954
 
955
- source.on('error', function() {});
956
- if (delayedStream.pauseStream) {
957
- source.pause();
958
- }
955
+ var realEmit = source.emit;
956
+ source.emit = function() {
957
+ delayedStream._handleEmit(arguments);
958
+ return realEmit.apply(source, arguments);
959
+ };
959
960
 
960
- return delayedStream;
961
- };
961
+ source.on('error', function() {});
962
+ if (delayedStream.pauseStream) {
963
+ source.pause();
964
+ }
962
965
 
963
- Object.defineProperty(DelayedStream$1.prototype, 'readable', {
964
- configurable: true,
965
- enumerable: true,
966
- get: function() {
967
- return this.source.readable;
968
- }
969
- });
966
+ return delayedStream;
967
+ };
970
968
 
971
- DelayedStream$1.prototype.setEncoding = function() {
972
- return this.source.setEncoding.apply(this.source, arguments);
973
- };
969
+ Object.defineProperty(DelayedStream.prototype, 'readable', {
970
+ configurable: true,
971
+ enumerable: true,
972
+ get: function() {
973
+ return this.source.readable;
974
+ }
975
+ });
974
976
 
975
- DelayedStream$1.prototype.resume = function() {
976
- if (!this._released) {
977
- this.release();
978
- }
977
+ DelayedStream.prototype.setEncoding = function() {
978
+ return this.source.setEncoding.apply(this.source, arguments);
979
+ };
979
980
 
980
- this.source.resume();
981
- };
981
+ DelayedStream.prototype.resume = function() {
982
+ if (!this._released) {
983
+ this.release();
984
+ }
982
985
 
983
- DelayedStream$1.prototype.pause = function() {
984
- this.source.pause();
985
- };
986
+ this.source.resume();
987
+ };
986
988
 
987
- DelayedStream$1.prototype.release = function() {
988
- this._released = true;
989
+ DelayedStream.prototype.pause = function() {
990
+ this.source.pause();
991
+ };
989
992
 
990
- this._bufferedEvents.forEach(function(args) {
991
- this.emit.apply(this, args);
992
- }.bind(this));
993
- this._bufferedEvents = [];
994
- };
993
+ DelayedStream.prototype.release = function() {
994
+ this._released = true;
995
995
 
996
- DelayedStream$1.prototype.pipe = function() {
997
- var r = Stream$2.prototype.pipe.apply(this, arguments);
998
- this.resume();
999
- return r;
1000
- };
996
+ this._bufferedEvents.forEach(function(args) {
997
+ this.emit.apply(this, args);
998
+ }.bind(this));
999
+ this._bufferedEvents = [];
1000
+ };
1001
1001
 
1002
- DelayedStream$1.prototype._handleEmit = function(args) {
1003
- if (this._released) {
1004
- this.emit.apply(this, args);
1005
- return;
1006
- }
1002
+ DelayedStream.prototype.pipe = function() {
1003
+ var r = Stream.prototype.pipe.apply(this, arguments);
1004
+ this.resume();
1005
+ return r;
1006
+ };
1007
1007
 
1008
- if (args[0] === 'data') {
1009
- this.dataSize += args[1].length;
1010
- this._checkIfMaxDataSizeExceeded();
1011
- }
1008
+ DelayedStream.prototype._handleEmit = function(args) {
1009
+ if (this._released) {
1010
+ this.emit.apply(this, args);
1011
+ return;
1012
+ }
1012
1013
 
1013
- this._bufferedEvents.push(args);
1014
- };
1014
+ if (args[0] === 'data') {
1015
+ this.dataSize += args[1].length;
1016
+ this._checkIfMaxDataSizeExceeded();
1017
+ }
1015
1018
 
1016
- DelayedStream$1.prototype._checkIfMaxDataSizeExceeded = function() {
1017
- if (this._maxDataSizeExceeded) {
1018
- return;
1019
- }
1019
+ this._bufferedEvents.push(args);
1020
+ };
1020
1021
 
1021
- if (this.dataSize <= this.maxDataSize) {
1022
- return;
1023
- }
1022
+ DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
1023
+ if (this._maxDataSizeExceeded) {
1024
+ return;
1025
+ }
1024
1026
 
1025
- this._maxDataSizeExceeded = true;
1026
- var message =
1027
- 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
1028
- this.emit('error', new Error(message));
1029
- };
1027
+ if (this.dataSize <= this.maxDataSize) {
1028
+ return;
1029
+ }
1030
1030
 
1031
- var util$1 = require$$1;
1032
- var Stream$1 = require$$0$1.Stream;
1033
- var DelayedStream = delayed_stream;
1034
-
1035
- var combined_stream = CombinedStream$1;
1036
- function CombinedStream$1() {
1037
- this.writable = false;
1038
- this.readable = true;
1039
- this.dataSize = 0;
1040
- this.maxDataSize = 2 * 1024 * 1024;
1041
- this.pauseStreams = true;
1042
-
1043
- this._released = false;
1044
- this._streams = [];
1045
- this._currentStream = null;
1046
- this._insideLoop = false;
1047
- this._pendingNext = false;
1031
+ this._maxDataSizeExceeded = true;
1032
+ var message =
1033
+ 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
1034
+ this.emit('error', new Error(message));
1035
+ };
1036
+ return delayed_stream;
1048
1037
  }
1049
- util$1.inherits(CombinedStream$1, Stream$1);
1050
1038
 
1051
- CombinedStream$1.create = function(options) {
1052
- var combinedStream = new this();
1039
+ var combined_stream;
1040
+ var hasRequiredCombined_stream;
1041
+
1042
+ function requireCombined_stream () {
1043
+ if (hasRequiredCombined_stream) return combined_stream;
1044
+ hasRequiredCombined_stream = 1;
1045
+ var util = require$$1;
1046
+ var Stream = require$$0$1.Stream;
1047
+ var DelayedStream = requireDelayed_stream();
1048
+
1049
+ combined_stream = CombinedStream;
1050
+ function CombinedStream() {
1051
+ this.writable = false;
1052
+ this.readable = true;
1053
+ this.dataSize = 0;
1054
+ this.maxDataSize = 2 * 1024 * 1024;
1055
+ this.pauseStreams = true;
1056
+
1057
+ this._released = false;
1058
+ this._streams = [];
1059
+ this._currentStream = null;
1060
+ this._insideLoop = false;
1061
+ this._pendingNext = false;
1062
+ }
1063
+ util.inherits(CombinedStream, Stream);
1053
1064
 
1054
- options = options || {};
1055
- for (var option in options) {
1056
- combinedStream[option] = options[option];
1057
- }
1065
+ CombinedStream.create = function(options) {
1066
+ var combinedStream = new this();
1058
1067
 
1059
- return combinedStream;
1060
- };
1061
-
1062
- CombinedStream$1.isStreamLike = function(stream) {
1063
- return (typeof stream !== 'function')
1064
- && (typeof stream !== 'string')
1065
- && (typeof stream !== 'boolean')
1066
- && (typeof stream !== 'number')
1067
- && (!Buffer.isBuffer(stream));
1068
- };
1068
+ options = options || {};
1069
+ for (var option in options) {
1070
+ combinedStream[option] = options[option];
1071
+ }
1069
1072
 
1070
- CombinedStream$1.prototype.append = function(stream) {
1071
- var isStreamLike = CombinedStream$1.isStreamLike(stream);
1072
-
1073
- if (isStreamLike) {
1074
- if (!(stream instanceof DelayedStream)) {
1075
- var newStream = DelayedStream.create(stream, {
1076
- maxDataSize: Infinity,
1077
- pauseStream: this.pauseStreams,
1078
- });
1079
- stream.on('data', this._checkDataSize.bind(this));
1080
- stream = newStream;
1081
- }
1073
+ return combinedStream;
1074
+ };
1075
+
1076
+ CombinedStream.isStreamLike = function(stream) {
1077
+ return (typeof stream !== 'function')
1078
+ && (typeof stream !== 'string')
1079
+ && (typeof stream !== 'boolean')
1080
+ && (typeof stream !== 'number')
1081
+ && (!Buffer.isBuffer(stream));
1082
+ };
1083
+
1084
+ CombinedStream.prototype.append = function(stream) {
1085
+ var isStreamLike = CombinedStream.isStreamLike(stream);
1086
+
1087
+ if (isStreamLike) {
1088
+ if (!(stream instanceof DelayedStream)) {
1089
+ var newStream = DelayedStream.create(stream, {
1090
+ maxDataSize: Infinity,
1091
+ pauseStream: this.pauseStreams,
1092
+ });
1093
+ stream.on('data', this._checkDataSize.bind(this));
1094
+ stream = newStream;
1095
+ }
1082
1096
 
1083
- this._handleErrors(stream);
1097
+ this._handleErrors(stream);
1084
1098
 
1085
- if (this.pauseStreams) {
1086
- stream.pause();
1087
- }
1088
- }
1099
+ if (this.pauseStreams) {
1100
+ stream.pause();
1101
+ }
1102
+ }
1089
1103
 
1090
- this._streams.push(stream);
1091
- return this;
1092
- };
1104
+ this._streams.push(stream);
1105
+ return this;
1106
+ };
1093
1107
 
1094
- CombinedStream$1.prototype.pipe = function(dest, options) {
1095
- Stream$1.prototype.pipe.call(this, dest, options);
1096
- this.resume();
1097
- return dest;
1098
- };
1108
+ CombinedStream.prototype.pipe = function(dest, options) {
1109
+ Stream.prototype.pipe.call(this, dest, options);
1110
+ this.resume();
1111
+ return dest;
1112
+ };
1099
1113
 
1100
- CombinedStream$1.prototype._getNext = function() {
1101
- this._currentStream = null;
1102
-
1103
- if (this._insideLoop) {
1104
- this._pendingNext = true;
1105
- return; // defer call
1106
- }
1107
-
1108
- this._insideLoop = true;
1109
- try {
1110
- do {
1111
- this._pendingNext = false;
1112
- this._realGetNext();
1113
- } while (this._pendingNext);
1114
- } finally {
1115
- this._insideLoop = false;
1116
- }
1117
- };
1118
-
1119
- CombinedStream$1.prototype._realGetNext = function() {
1120
- var stream = this._streams.shift();
1114
+ CombinedStream.prototype._getNext = function() {
1115
+ this._currentStream = null;
1121
1116
 
1117
+ if (this._insideLoop) {
1118
+ this._pendingNext = true;
1119
+ return; // defer call
1120
+ }
1122
1121
 
1123
- if (typeof stream == 'undefined') {
1124
- this.end();
1125
- return;
1126
- }
1122
+ this._insideLoop = true;
1123
+ try {
1124
+ do {
1125
+ this._pendingNext = false;
1126
+ this._realGetNext();
1127
+ } while (this._pendingNext);
1128
+ } finally {
1129
+ this._insideLoop = false;
1130
+ }
1131
+ };
1127
1132
 
1128
- if (typeof stream !== 'function') {
1129
- this._pipeNext(stream);
1130
- return;
1131
- }
1132
-
1133
- var getStream = stream;
1134
- getStream(function(stream) {
1135
- var isStreamLike = CombinedStream$1.isStreamLike(stream);
1136
- if (isStreamLike) {
1137
- stream.on('data', this._checkDataSize.bind(this));
1138
- this._handleErrors(stream);
1139
- }
1133
+ CombinedStream.prototype._realGetNext = function() {
1134
+ var stream = this._streams.shift();
1140
1135
 
1141
- this._pipeNext(stream);
1142
- }.bind(this));
1143
- };
1144
1136
 
1145
- CombinedStream$1.prototype._pipeNext = function(stream) {
1146
- this._currentStream = stream;
1137
+ if (typeof stream == 'undefined') {
1138
+ this.end();
1139
+ return;
1140
+ }
1147
1141
 
1148
- var isStreamLike = CombinedStream$1.isStreamLike(stream);
1149
- if (isStreamLike) {
1150
- stream.on('end', this._getNext.bind(this));
1151
- stream.pipe(this, {end: false});
1152
- return;
1153
- }
1142
+ if (typeof stream !== 'function') {
1143
+ this._pipeNext(stream);
1144
+ return;
1145
+ }
1154
1146
 
1155
- var value = stream;
1156
- this.write(value);
1157
- this._getNext();
1158
- };
1147
+ var getStream = stream;
1148
+ getStream(function(stream) {
1149
+ var isStreamLike = CombinedStream.isStreamLike(stream);
1150
+ if (isStreamLike) {
1151
+ stream.on('data', this._checkDataSize.bind(this));
1152
+ this._handleErrors(stream);
1153
+ }
1159
1154
 
1160
- CombinedStream$1.prototype._handleErrors = function(stream) {
1161
- var self = this;
1162
- stream.on('error', function(err) {
1163
- self._emitError(err);
1164
- });
1165
- };
1155
+ this._pipeNext(stream);
1156
+ }.bind(this));
1157
+ };
1166
1158
 
1167
- CombinedStream$1.prototype.write = function(data) {
1168
- this.emit('data', data);
1169
- };
1159
+ CombinedStream.prototype._pipeNext = function(stream) {
1160
+ this._currentStream = stream;
1170
1161
 
1171
- CombinedStream$1.prototype.pause = function() {
1172
- if (!this.pauseStreams) {
1173
- return;
1174
- }
1162
+ var isStreamLike = CombinedStream.isStreamLike(stream);
1163
+ if (isStreamLike) {
1164
+ stream.on('end', this._getNext.bind(this));
1165
+ stream.pipe(this, {end: false});
1166
+ return;
1167
+ }
1175
1168
 
1176
- if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
1177
- this.emit('pause');
1178
- };
1169
+ var value = stream;
1170
+ this.write(value);
1171
+ this._getNext();
1172
+ };
1179
1173
 
1180
- CombinedStream$1.prototype.resume = function() {
1181
- if (!this._released) {
1182
- this._released = true;
1183
- this.writable = true;
1184
- this._getNext();
1185
- }
1174
+ CombinedStream.prototype._handleErrors = function(stream) {
1175
+ var self = this;
1176
+ stream.on('error', function(err) {
1177
+ self._emitError(err);
1178
+ });
1179
+ };
1186
1180
 
1187
- if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
1188
- this.emit('resume');
1189
- };
1181
+ CombinedStream.prototype.write = function(data) {
1182
+ this.emit('data', data);
1183
+ };
1190
1184
 
1191
- CombinedStream$1.prototype.end = function() {
1192
- this._reset();
1193
- this.emit('end');
1194
- };
1185
+ CombinedStream.prototype.pause = function() {
1186
+ if (!this.pauseStreams) {
1187
+ return;
1188
+ }
1195
1189
 
1196
- CombinedStream$1.prototype.destroy = function() {
1197
- this._reset();
1198
- this.emit('close');
1199
- };
1190
+ if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
1191
+ this.emit('pause');
1192
+ };
1200
1193
 
1201
- CombinedStream$1.prototype._reset = function() {
1202
- this.writable = false;
1203
- this._streams = [];
1204
- this._currentStream = null;
1205
- };
1194
+ CombinedStream.prototype.resume = function() {
1195
+ if (!this._released) {
1196
+ this._released = true;
1197
+ this.writable = true;
1198
+ this._getNext();
1199
+ }
1206
1200
 
1207
- CombinedStream$1.prototype._checkDataSize = function() {
1208
- this._updateDataSize();
1209
- if (this.dataSize <= this.maxDataSize) {
1210
- return;
1211
- }
1201
+ if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
1202
+ this.emit('resume');
1203
+ };
1204
+
1205
+ CombinedStream.prototype.end = function() {
1206
+ this._reset();
1207
+ this.emit('end');
1208
+ };
1209
+
1210
+ CombinedStream.prototype.destroy = function() {
1211
+ this._reset();
1212
+ this.emit('close');
1213
+ };
1214
+
1215
+ CombinedStream.prototype._reset = function() {
1216
+ this.writable = false;
1217
+ this._streams = [];
1218
+ this._currentStream = null;
1219
+ };
1220
+
1221
+ CombinedStream.prototype._checkDataSize = function() {
1222
+ this._updateDataSize();
1223
+ if (this.dataSize <= this.maxDataSize) {
1224
+ return;
1225
+ }
1212
1226
 
1213
- var message =
1214
- 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
1215
- this._emitError(new Error(message));
1216
- };
1227
+ var message =
1228
+ 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
1229
+ this._emitError(new Error(message));
1230
+ };
1217
1231
 
1218
- CombinedStream$1.prototype._updateDataSize = function() {
1219
- this.dataSize = 0;
1232
+ CombinedStream.prototype._updateDataSize = function() {
1233
+ this.dataSize = 0;
1220
1234
 
1221
- var self = this;
1222
- this._streams.forEach(function(stream) {
1223
- if (!stream.dataSize) {
1224
- return;
1225
- }
1235
+ var self = this;
1236
+ this._streams.forEach(function(stream) {
1237
+ if (!stream.dataSize) {
1238
+ return;
1239
+ }
1226
1240
 
1227
- self.dataSize += stream.dataSize;
1228
- });
1241
+ self.dataSize += stream.dataSize;
1242
+ });
1229
1243
 
1230
- if (this._currentStream && this._currentStream.dataSize) {
1231
- this.dataSize += this._currentStream.dataSize;
1232
- }
1233
- };
1244
+ if (this._currentStream && this._currentStream.dataSize) {
1245
+ this.dataSize += this._currentStream.dataSize;
1246
+ }
1247
+ };
1234
1248
 
1235
- CombinedStream$1.prototype._emitError = function(err) {
1236
- this._reset();
1237
- this.emit('error', err);
1238
- };
1249
+ CombinedStream.prototype._emitError = function(err) {
1250
+ this._reset();
1251
+ this.emit('error', err);
1252
+ };
1253
+ return combined_stream;
1254
+ }
1239
1255
 
1240
1256
  var mimeTypes = {};
1241
1257
 
@@ -11949,11 +11965,19 @@ var require$$0 = {
11949
11965
  * MIT Licensed
11950
11966
  */
11951
11967
 
11952
- /**
11953
- * Module exports.
11954
- */
11968
+ var mimeDb;
11969
+ var hasRequiredMimeDb;
11970
+
11971
+ function requireMimeDb () {
11972
+ if (hasRequiredMimeDb) return mimeDb;
11973
+ hasRequiredMimeDb = 1;
11974
+ /**
11975
+ * Module exports.
11976
+ */
11955
11977
 
11956
- var mimeDb = require$$0;
11978
+ mimeDb = require$$0;
11979
+ return mimeDb;
11980
+ }
11957
11981
 
11958
11982
  /*!
11959
11983
  * mime-types
@@ -11962,1088 +11986,1189 @@ var mimeDb = require$$0;
11962
11986
  * MIT Licensed
11963
11987
  */
11964
11988
 
11965
- (function (exports) {
11989
+ var hasRequiredMimeTypes;
11990
+
11991
+ function requireMimeTypes () {
11992
+ if (hasRequiredMimeTypes) return mimeTypes;
11993
+ hasRequiredMimeTypes = 1;
11994
+ (function (exports) {
11995
+
11996
+ /**
11997
+ * Module dependencies.
11998
+ * @private
11999
+ */
12000
+
12001
+ var db = requireMimeDb();
12002
+ var extname = require$$1$1.extname;
12003
+
12004
+ /**
12005
+ * Module variables.
12006
+ * @private
12007
+ */
12008
+
12009
+ var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
12010
+ var TEXT_TYPE_REGEXP = /^text\//i;
12011
+
12012
+ /**
12013
+ * Module exports.
12014
+ * @public
12015
+ */
12016
+
12017
+ exports.charset = charset;
12018
+ exports.charsets = { lookup: charset };
12019
+ exports.contentType = contentType;
12020
+ exports.extension = extension;
12021
+ exports.extensions = Object.create(null);
12022
+ exports.lookup = lookup;
12023
+ exports.types = Object.create(null);
12024
+
12025
+ // Populate the extensions/types maps
12026
+ populateMaps(exports.extensions, exports.types);
12027
+
12028
+ /**
12029
+ * Get the default charset for a MIME type.
12030
+ *
12031
+ * @param {string} type
12032
+ * @return {boolean|string}
12033
+ */
12034
+
12035
+ function charset (type) {
12036
+ if (!type || typeof type !== 'string') {
12037
+ return false
12038
+ }
12039
+
12040
+ // TODO: use media-typer
12041
+ var match = EXTRACT_TYPE_REGEXP.exec(type);
12042
+ var mime = match && db[match[1].toLowerCase()];
12043
+
12044
+ if (mime && mime.charset) {
12045
+ return mime.charset
12046
+ }
12047
+
12048
+ // default text/* to utf-8
12049
+ if (match && TEXT_TYPE_REGEXP.test(match[1])) {
12050
+ return 'UTF-8'
12051
+ }
12052
+
12053
+ return false
12054
+ }
12055
+
12056
+ /**
12057
+ * Create a full Content-Type header given a MIME type or extension.
12058
+ *
12059
+ * @param {string} str
12060
+ * @return {boolean|string}
12061
+ */
12062
+
12063
+ function contentType (str) {
12064
+ // TODO: should this even be in this module?
12065
+ if (!str || typeof str !== 'string') {
12066
+ return false
12067
+ }
12068
+
12069
+ var mime = str.indexOf('/') === -1
12070
+ ? exports.lookup(str)
12071
+ : str;
12072
+
12073
+ if (!mime) {
12074
+ return false
12075
+ }
12076
+
12077
+ // TODO: use content-type or other module
12078
+ if (mime.indexOf('charset') === -1) {
12079
+ var charset = exports.charset(mime);
12080
+ if (charset) mime += '; charset=' + charset.toLowerCase();
12081
+ }
12082
+
12083
+ return mime
12084
+ }
12085
+
12086
+ /**
12087
+ * Get the default extension for a MIME type.
12088
+ *
12089
+ * @param {string} type
12090
+ * @return {boolean|string}
12091
+ */
12092
+
12093
+ function extension (type) {
12094
+ if (!type || typeof type !== 'string') {
12095
+ return false
12096
+ }
12097
+
12098
+ // TODO: use media-typer
12099
+ var match = EXTRACT_TYPE_REGEXP.exec(type);
12100
+
12101
+ // get extensions
12102
+ var exts = match && exports.extensions[match[1].toLowerCase()];
12103
+
12104
+ if (!exts || !exts.length) {
12105
+ return false
12106
+ }
12107
+
12108
+ return exts[0]
12109
+ }
12110
+
12111
+ /**
12112
+ * Lookup the MIME type for a file path/extension.
12113
+ *
12114
+ * @param {string} path
12115
+ * @return {boolean|string}
12116
+ */
12117
+
12118
+ function lookup (path) {
12119
+ if (!path || typeof path !== 'string') {
12120
+ return false
12121
+ }
12122
+
12123
+ // get the extension ("ext" or ".ext" or full path)
12124
+ var extension = extname('x.' + path)
12125
+ .toLowerCase()
12126
+ .substr(1);
12127
+
12128
+ if (!extension) {
12129
+ return false
12130
+ }
12131
+
12132
+ return exports.types[extension] || false
12133
+ }
12134
+
12135
+ /**
12136
+ * Populate the extensions and types maps.
12137
+ * @private
12138
+ */
12139
+
12140
+ function populateMaps (extensions, types) {
12141
+ // source preference (least -> most)
12142
+ var preference = ['nginx', 'apache', undefined, 'iana'];
12143
+
12144
+ Object.keys(db).forEach(function forEachMimeType (type) {
12145
+ var mime = db[type];
12146
+ var exts = mime.extensions;
12147
+
12148
+ if (!exts || !exts.length) {
12149
+ return
12150
+ }
12151
+
12152
+ // mime -> extensions
12153
+ extensions[type] = exts;
12154
+
12155
+ // extension -> mime
12156
+ for (var i = 0; i < exts.length; i++) {
12157
+ var extension = exts[i];
12158
+
12159
+ if (types[extension]) {
12160
+ var from = preference.indexOf(db[types[extension]].source);
12161
+ var to = preference.indexOf(mime.source);
12162
+
12163
+ if (types[extension] !== 'application/octet-stream' &&
12164
+ (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
12165
+ // skip the remapping
12166
+ continue
12167
+ }
12168
+ }
12169
+
12170
+ // set the extension -> mime
12171
+ types[extension] = type;
12172
+ }
12173
+ });
12174
+ }
12175
+ } (mimeTypes));
12176
+ return mimeTypes;
12177
+ }
11966
12178
 
11967
- /**
11968
- * Module dependencies.
11969
- * @private
11970
- */
12179
+ var defer_1;
12180
+ var hasRequiredDefer;
11971
12181
 
11972
- var db = mimeDb;
11973
- var extname = require$$1$1.extname;
12182
+ function requireDefer () {
12183
+ if (hasRequiredDefer) return defer_1;
12184
+ hasRequiredDefer = 1;
12185
+ defer_1 = defer;
11974
12186
 
11975
12187
  /**
11976
- * Module variables.
11977
- * @private
12188
+ * Runs provided function on next iteration of the event loop
12189
+ *
12190
+ * @param {function} fn - function to run
11978
12191
  */
12192
+ function defer(fn)
12193
+ {
12194
+ var nextTick = typeof setImmediate == 'function'
12195
+ ? setImmediate
12196
+ : (
12197
+ typeof process == 'object' && typeof process.nextTick == 'function'
12198
+ ? process.nextTick
12199
+ : null
12200
+ );
12201
+
12202
+ if (nextTick)
12203
+ {
12204
+ nextTick(fn);
12205
+ }
12206
+ else
12207
+ {
12208
+ setTimeout(fn, 0);
12209
+ }
12210
+ }
12211
+ return defer_1;
12212
+ }
11979
12213
 
11980
- var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
11981
- var TEXT_TYPE_REGEXP = /^text\//i;
11982
-
11983
- /**
11984
- * Module exports.
11985
- * @public
11986
- */
12214
+ var async_1;
12215
+ var hasRequiredAsync;
11987
12216
 
11988
- exports.charset = charset;
11989
- exports.charsets = { lookup: charset };
11990
- exports.contentType = contentType;
11991
- exports.extension = extension;
11992
- exports.extensions = Object.create(null);
11993
- exports.lookup = lookup;
11994
- exports.types = Object.create(null);
12217
+ function requireAsync () {
12218
+ if (hasRequiredAsync) return async_1;
12219
+ hasRequiredAsync = 1;
12220
+ var defer = requireDefer();
11995
12221
 
11996
- // Populate the extensions/types maps
11997
- populateMaps(exports.extensions, exports.types);
12222
+ // API
12223
+ async_1 = async;
11998
12224
 
11999
12225
  /**
12000
- * Get the default charset for a MIME type.
12226
+ * Runs provided callback asynchronously
12227
+ * even if callback itself is not
12001
12228
  *
12002
- * @param {string} type
12003
- * @return {boolean|string}
12229
+ * @param {function} callback - callback to invoke
12230
+ * @returns {function} - augmented callback
12004
12231
  */
12232
+ function async(callback)
12233
+ {
12234
+ var isAsync = false;
12235
+
12236
+ // check if async happened
12237
+ defer(function() { isAsync = true; });
12238
+
12239
+ return function async_callback(err, result)
12240
+ {
12241
+ if (isAsync)
12242
+ {
12243
+ callback(err, result);
12244
+ }
12245
+ else
12246
+ {
12247
+ defer(function nextTick_callback()
12248
+ {
12249
+ callback(err, result);
12250
+ });
12251
+ }
12252
+ };
12253
+ }
12254
+ return async_1;
12255
+ }
12005
12256
 
12006
- function charset (type) {
12007
- if (!type || typeof type !== 'string') {
12008
- return false
12009
- }
12010
-
12011
- // TODO: use media-typer
12012
- var match = EXTRACT_TYPE_REGEXP.exec(type);
12013
- var mime = match && db[match[1].toLowerCase()];
12257
+ var abort_1;
12258
+ var hasRequiredAbort;
12014
12259
 
12015
- if (mime && mime.charset) {
12016
- return mime.charset
12017
- }
12260
+ function requireAbort () {
12261
+ if (hasRequiredAbort) return abort_1;
12262
+ hasRequiredAbort = 1;
12263
+ // API
12264
+ abort_1 = abort;
12018
12265
 
12019
- // default text/* to utf-8
12020
- if (match && TEXT_TYPE_REGEXP.test(match[1])) {
12021
- return 'UTF-8'
12022
- }
12266
+ /**
12267
+ * Aborts leftover active jobs
12268
+ *
12269
+ * @param {object} state - current state object
12270
+ */
12271
+ function abort(state)
12272
+ {
12273
+ Object.keys(state.jobs).forEach(clean.bind(state));
12023
12274
 
12024
- return false
12275
+ // reset leftover jobs
12276
+ state.jobs = {};
12025
12277
  }
12026
12278
 
12027
12279
  /**
12028
- * Create a full Content-Type header given a MIME type or extension.
12280
+ * Cleans up leftover job by invoking abort function for the provided job id
12029
12281
  *
12030
- * @param {string} str
12031
- * @return {boolean|string}
12282
+ * @this state
12283
+ * @param {string|number} key - job id to abort
12032
12284
  */
12033
-
12034
- function contentType (str) {
12035
- // TODO: should this even be in this module?
12036
- if (!str || typeof str !== 'string') {
12037
- return false
12285
+ function clean(key)
12286
+ {
12287
+ if (typeof this.jobs[key] == 'function')
12288
+ {
12289
+ this.jobs[key]();
12038
12290
  }
12291
+ }
12292
+ return abort_1;
12293
+ }
12039
12294
 
12040
- var mime = str.indexOf('/') === -1
12041
- ? exports.lookup(str)
12042
- : str;
12043
-
12044
- if (!mime) {
12045
- return false
12046
- }
12295
+ var iterate_1;
12296
+ var hasRequiredIterate;
12047
12297
 
12048
- // TODO: use content-type or other module
12049
- if (mime.indexOf('charset') === -1) {
12050
- var charset = exports.charset(mime);
12051
- if (charset) mime += '; charset=' + charset.toLowerCase();
12052
- }
12298
+ function requireIterate () {
12299
+ if (hasRequiredIterate) return iterate_1;
12300
+ hasRequiredIterate = 1;
12301
+ var async = requireAsync()
12302
+ , abort = requireAbort()
12303
+ ;
12053
12304
 
12054
- return mime
12055
- }
12305
+ // API
12306
+ iterate_1 = iterate;
12056
12307
 
12057
12308
  /**
12058
- * Get the default extension for a MIME type.
12309
+ * Iterates over each job object
12059
12310
  *
12060
- * @param {string} type
12061
- * @return {boolean|string}
12311
+ * @param {array|object} list - array or object (named list) to iterate over
12312
+ * @param {function} iterator - iterator to run
12313
+ * @param {object} state - current job status
12314
+ * @param {function} callback - invoked when all elements processed
12062
12315
  */
12316
+ function iterate(list, iterator, state, callback)
12317
+ {
12318
+ // store current index
12319
+ var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
12320
+
12321
+ state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
12322
+ {
12323
+ // don't repeat yourself
12324
+ // skip secondary callbacks
12325
+ if (!(key in state.jobs))
12326
+ {
12327
+ return;
12328
+ }
12063
12329
 
12064
- function extension (type) {
12065
- if (!type || typeof type !== 'string') {
12066
- return false
12067
- }
12068
-
12069
- // TODO: use media-typer
12070
- var match = EXTRACT_TYPE_REGEXP.exec(type);
12071
-
12072
- // get extensions
12073
- var exts = match && exports.extensions[match[1].toLowerCase()];
12330
+ // clean up jobs
12331
+ delete state.jobs[key];
12074
12332
 
12075
- if (!exts || !exts.length) {
12076
- return false
12077
- }
12333
+ if (error)
12334
+ {
12335
+ // don't process rest of the results
12336
+ // stop still active jobs
12337
+ // and reset the list
12338
+ abort(state);
12339
+ }
12340
+ else
12341
+ {
12342
+ state.results[key] = output;
12343
+ }
12078
12344
 
12079
- return exts[0]
12345
+ // return salvaged results
12346
+ callback(error, state.results);
12347
+ });
12080
12348
  }
12081
12349
 
12082
12350
  /**
12083
- * Lookup the MIME type for a file path/extension.
12351
+ * Runs iterator over provided job element
12084
12352
  *
12085
- * @param {string} path
12086
- * @return {boolean|string}
12353
+ * @param {function} iterator - iterator to invoke
12354
+ * @param {string|number} key - key/index of the element in the list of jobs
12355
+ * @param {mixed} item - job description
12356
+ * @param {function} callback - invoked after iterator is done with the job
12357
+ * @returns {function|mixed} - job abort function or something else
12087
12358
  */
12088
-
12089
- function lookup (path) {
12090
- if (!path || typeof path !== 'string') {
12091
- return false
12359
+ function runJob(iterator, key, item, callback)
12360
+ {
12361
+ var aborter;
12362
+
12363
+ // allow shortcut if iterator expects only two arguments
12364
+ if (iterator.length == 2)
12365
+ {
12366
+ aborter = iterator(item, async(callback));
12092
12367
  }
12093
-
12094
- // get the extension ("ext" or ".ext" or full path)
12095
- var extension = extname('x.' + path)
12096
- .toLowerCase()
12097
- .substr(1);
12098
-
12099
- if (!extension) {
12100
- return false
12368
+ // otherwise go with full three arguments
12369
+ else
12370
+ {
12371
+ aborter = iterator(item, key, async(callback));
12101
12372
  }
12102
12373
 
12103
- return exports.types[extension] || false
12374
+ return aborter;
12104
12375
  }
12376
+ return iterate_1;
12377
+ }
12105
12378
 
12106
- /**
12107
- * Populate the extensions and types maps.
12108
- * @private
12109
- */
12110
-
12111
- function populateMaps (extensions, types) {
12112
- // source preference (least -> most)
12113
- var preference = ['nginx', 'apache', undefined, 'iana'];
12379
+ var state_1;
12380
+ var hasRequiredState;
12114
12381
 
12115
- Object.keys(db).forEach(function forEachMimeType (type) {
12116
- var mime = db[type];
12117
- var exts = mime.extensions;
12382
+ function requireState () {
12383
+ if (hasRequiredState) return state_1;
12384
+ hasRequiredState = 1;
12385
+ // API
12386
+ state_1 = state;
12118
12387
 
12119
- if (!exts || !exts.length) {
12120
- return
12388
+ /**
12389
+ * Creates initial state object
12390
+ * for iteration over list
12391
+ *
12392
+ * @param {array|object} list - list to iterate over
12393
+ * @param {function|null} sortMethod - function to use for keys sort,
12394
+ * or `null` to keep them as is
12395
+ * @returns {object} - initial state object
12396
+ */
12397
+ function state(list, sortMethod)
12398
+ {
12399
+ var isNamedList = !Array.isArray(list)
12400
+ , initState =
12401
+ {
12402
+ index : 0,
12403
+ keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
12404
+ jobs : {},
12405
+ results : isNamedList ? {} : [],
12406
+ size : isNamedList ? Object.keys(list).length : list.length
12121
12407
  }
12408
+ ;
12409
+
12410
+ if (sortMethod)
12411
+ {
12412
+ // sort array keys based on it's values
12413
+ // sort object's keys just on own merit
12414
+ initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
12415
+ {
12416
+ return sortMethod(list[a], list[b]);
12417
+ });
12418
+ }
12122
12419
 
12123
- // mime -> extensions
12124
- extensions[type] = exts;
12420
+ return initState;
12421
+ }
12422
+ return state_1;
12423
+ }
12125
12424
 
12126
- // extension -> mime
12127
- for (var i = 0; i < exts.length; i++) {
12128
- var extension = exts[i];
12425
+ var terminator_1;
12426
+ var hasRequiredTerminator;
12129
12427
 
12130
- if (types[extension]) {
12131
- var from = preference.indexOf(db[types[extension]].source);
12132
- var to = preference.indexOf(mime.source);
12428
+ function requireTerminator () {
12429
+ if (hasRequiredTerminator) return terminator_1;
12430
+ hasRequiredTerminator = 1;
12431
+ var abort = requireAbort()
12432
+ , async = requireAsync()
12433
+ ;
12133
12434
 
12134
- if (types[extension] !== 'application/octet-stream' &&
12135
- (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
12136
- // skip the remapping
12137
- continue
12138
- }
12139
- }
12435
+ // API
12436
+ terminator_1 = terminator;
12140
12437
 
12141
- // set the extension -> mime
12142
- types[extension] = type;
12143
- }
12144
- });
12145
- }
12146
- } (mimeTypes));
12147
-
12148
- var defer_1 = defer$1;
12149
-
12150
- /**
12151
- * Runs provided function on next iteration of the event loop
12152
- *
12153
- * @param {function} fn - function to run
12154
- */
12155
- function defer$1(fn)
12156
- {
12157
- var nextTick = typeof setImmediate == 'function'
12158
- ? setImmediate
12159
- : (
12160
- typeof process == 'object' && typeof process.nextTick == 'function'
12161
- ? process.nextTick
12162
- : null
12163
- );
12164
-
12165
- if (nextTick)
12166
- {
12167
- nextTick(fn);
12168
- }
12169
- else
12170
- {
12171
- setTimeout(fn, 0);
12172
- }
12173
- }
12438
+ /**
12439
+ * Terminates jobs in the attached state context
12440
+ *
12441
+ * @this AsyncKitState#
12442
+ * @param {function} callback - final callback to invoke after termination
12443
+ */
12444
+ function terminator(callback)
12445
+ {
12446
+ if (!Object.keys(this.jobs).length)
12447
+ {
12448
+ return;
12449
+ }
12174
12450
 
12175
- var defer = defer_1;
12451
+ // fast forward iteration index
12452
+ this.index = this.size;
12176
12453
 
12177
- // API
12178
- var async_1 = async$2;
12454
+ // abort jobs
12455
+ abort(this);
12179
12456
 
12180
- /**
12181
- * Runs provided callback asynchronously
12182
- * even if callback itself is not
12183
- *
12184
- * @param {function} callback - callback to invoke
12185
- * @returns {function} - augmented callback
12186
- */
12187
- function async$2(callback)
12188
- {
12189
- var isAsync = false;
12190
-
12191
- // check if async happened
12192
- defer(function() { isAsync = true; });
12193
-
12194
- return function async_callback(err, result)
12195
- {
12196
- if (isAsync)
12197
- {
12198
- callback(err, result);
12199
- }
12200
- else
12201
- {
12202
- defer(function nextTick_callback()
12203
- {
12204
- callback(err, result);
12205
- });
12206
- }
12207
- };
12457
+ // send back results we have so far
12458
+ async(callback)(null, this.results);
12459
+ }
12460
+ return terminator_1;
12208
12461
  }
12209
12462
 
12210
- // API
12211
- var abort_1 = abort$2;
12463
+ var parallel_1;
12464
+ var hasRequiredParallel;
12212
12465
 
12213
- /**
12214
- * Aborts leftover active jobs
12215
- *
12216
- * @param {object} state - current state object
12217
- */
12218
- function abort$2(state)
12219
- {
12220
- Object.keys(state.jobs).forEach(clean.bind(state));
12466
+ function requireParallel () {
12467
+ if (hasRequiredParallel) return parallel_1;
12468
+ hasRequiredParallel = 1;
12469
+ var iterate = requireIterate()
12470
+ , initState = requireState()
12471
+ , terminator = requireTerminator()
12472
+ ;
12221
12473
 
12222
- // reset leftover jobs
12223
- state.jobs = {};
12224
- }
12474
+ // Public API
12475
+ parallel_1 = parallel;
12225
12476
 
12226
- /**
12227
- * Cleans up leftover job by invoking abort function for the provided job id
12228
- *
12229
- * @this state
12230
- * @param {string|number} key - job id to abort
12231
- */
12232
- function clean(key)
12233
- {
12234
- if (typeof this.jobs[key] == 'function')
12235
- {
12236
- this.jobs[key]();
12237
- }
12238
- }
12477
+ /**
12478
+ * Runs iterator over provided array elements in parallel
12479
+ *
12480
+ * @param {array|object} list - array or object (named list) to iterate over
12481
+ * @param {function} iterator - iterator to run
12482
+ * @param {function} callback - invoked when all elements processed
12483
+ * @returns {function} - jobs terminator
12484
+ */
12485
+ function parallel(list, iterator, callback)
12486
+ {
12487
+ var state = initState(list);
12488
+
12489
+ while (state.index < (state['keyedList'] || list).length)
12490
+ {
12491
+ iterate(list, iterator, state, function(error, result)
12492
+ {
12493
+ if (error)
12494
+ {
12495
+ callback(error, result);
12496
+ return;
12497
+ }
12239
12498
 
12240
- var async$1 = async_1
12241
- , abort$1 = abort_1
12242
- ;
12499
+ // looks like it's the last one
12500
+ if (Object.keys(state.jobs).length === 0)
12501
+ {
12502
+ callback(null, state.results);
12503
+ return;
12504
+ }
12505
+ });
12243
12506
 
12244
- // API
12245
- var iterate_1 = iterate$2;
12507
+ state.index++;
12508
+ }
12246
12509
 
12247
- /**
12248
- * Iterates over each job object
12249
- *
12250
- * @param {array|object} list - array or object (named list) to iterate over
12251
- * @param {function} iterator - iterator to run
12252
- * @param {object} state - current job status
12253
- * @param {function} callback - invoked when all elements processed
12254
- */
12255
- function iterate$2(list, iterator, state, callback)
12256
- {
12257
- // store current index
12258
- var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
12259
-
12260
- state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
12261
- {
12262
- // don't repeat yourself
12263
- // skip secondary callbacks
12264
- if (!(key in state.jobs))
12265
- {
12266
- return;
12267
- }
12510
+ return terminator.bind(state, callback);
12511
+ }
12512
+ return parallel_1;
12513
+ }
12268
12514
 
12269
- // clean up jobs
12270
- delete state.jobs[key];
12515
+ var serialOrdered = {exports: {}};
12271
12516
 
12272
- if (error)
12273
- {
12274
- // don't process rest of the results
12275
- // stop still active jobs
12276
- // and reset the list
12277
- abort$1(state);
12278
- }
12279
- else
12280
- {
12281
- state.results[key] = output;
12282
- }
12517
+ var hasRequiredSerialOrdered;
12283
12518
 
12284
- // return salvaged results
12285
- callback(error, state.results);
12286
- });
12287
- }
12519
+ function requireSerialOrdered () {
12520
+ if (hasRequiredSerialOrdered) return serialOrdered.exports;
12521
+ hasRequiredSerialOrdered = 1;
12522
+ var iterate = requireIterate()
12523
+ , initState = requireState()
12524
+ , terminator = requireTerminator()
12525
+ ;
12288
12526
 
12289
- /**
12290
- * Runs iterator over provided job element
12291
- *
12292
- * @param {function} iterator - iterator to invoke
12293
- * @param {string|number} key - key/index of the element in the list of jobs
12294
- * @param {mixed} item - job description
12295
- * @param {function} callback - invoked after iterator is done with the job
12296
- * @returns {function|mixed} - job abort function or something else
12297
- */
12298
- function runJob(iterator, key, item, callback)
12299
- {
12300
- var aborter;
12301
-
12302
- // allow shortcut if iterator expects only two arguments
12303
- if (iterator.length == 2)
12304
- {
12305
- aborter = iterator(item, async$1(callback));
12306
- }
12307
- // otherwise go with full three arguments
12308
- else
12309
- {
12310
- aborter = iterator(item, key, async$1(callback));
12311
- }
12312
-
12313
- return aborter;
12314
- }
12527
+ // Public API
12528
+ serialOrdered.exports = serialOrdered$1;
12529
+ // sorting helpers
12530
+ serialOrdered.exports.ascending = ascending;
12531
+ serialOrdered.exports.descending = descending;
12315
12532
 
12316
- // API
12317
- var state_1 = state;
12318
-
12319
- /**
12320
- * Creates initial state object
12321
- * for iteration over list
12322
- *
12323
- * @param {array|object} list - list to iterate over
12324
- * @param {function|null} sortMethod - function to use for keys sort,
12325
- * or `null` to keep them as is
12326
- * @returns {object} - initial state object
12327
- */
12328
- function state(list, sortMethod)
12329
- {
12330
- var isNamedList = !Array.isArray(list)
12331
- , initState =
12332
- {
12333
- index : 0,
12334
- keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
12335
- jobs : {},
12336
- results : isNamedList ? {} : [],
12337
- size : isNamedList ? Object.keys(list).length : list.length
12338
- }
12339
- ;
12340
-
12341
- if (sortMethod)
12342
- {
12343
- // sort array keys based on it's values
12344
- // sort object's keys just on own merit
12345
- initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
12346
- {
12347
- return sortMethod(list[a], list[b]);
12348
- });
12349
- }
12533
+ /**
12534
+ * Runs iterator over provided sorted array elements in series
12535
+ *
12536
+ * @param {array|object} list - array or object (named list) to iterate over
12537
+ * @param {function} iterator - iterator to run
12538
+ * @param {function} sortMethod - custom sort function
12539
+ * @param {function} callback - invoked when all elements processed
12540
+ * @returns {function} - jobs terminator
12541
+ */
12542
+ function serialOrdered$1(list, iterator, sortMethod, callback)
12543
+ {
12544
+ var state = initState(list, sortMethod);
12545
+
12546
+ iterate(list, iterator, state, function iteratorHandler(error, result)
12547
+ {
12548
+ if (error)
12549
+ {
12550
+ callback(error, result);
12551
+ return;
12552
+ }
12350
12553
 
12351
- return initState;
12352
- }
12554
+ state.index++;
12353
12555
 
12354
- var abort = abort_1
12355
- , async = async_1
12356
- ;
12556
+ // are we there yet?
12557
+ if (state.index < (state['keyedList'] || list).length)
12558
+ {
12559
+ iterate(list, iterator, state, iteratorHandler);
12560
+ return;
12561
+ }
12357
12562
 
12358
- // API
12359
- var terminator_1 = terminator$2;
12563
+ // done here
12564
+ callback(null, state.results);
12565
+ });
12360
12566
 
12361
- /**
12362
- * Terminates jobs in the attached state context
12363
- *
12364
- * @this AsyncKitState#
12365
- * @param {function} callback - final callback to invoke after termination
12366
- */
12367
- function terminator$2(callback)
12368
- {
12369
- if (!Object.keys(this.jobs).length)
12370
- {
12371
- return;
12372
- }
12567
+ return terminator.bind(state, callback);
12568
+ }
12373
12569
 
12374
- // fast forward iteration index
12375
- this.index = this.size;
12570
+ /*
12571
+ * -- Sort methods
12572
+ */
12376
12573
 
12377
- // abort jobs
12378
- abort(this);
12574
+ /**
12575
+ * sort helper to sort array elements in ascending order
12576
+ *
12577
+ * @param {mixed} a - an item to compare
12578
+ * @param {mixed} b - an item to compare
12579
+ * @returns {number} - comparison result
12580
+ */
12581
+ function ascending(a, b)
12582
+ {
12583
+ return a < b ? -1 : a > b ? 1 : 0;
12584
+ }
12379
12585
 
12380
- // send back results we have so far
12381
- async(callback)(null, this.results);
12586
+ /**
12587
+ * sort helper to sort array elements in descending order
12588
+ *
12589
+ * @param {mixed} a - an item to compare
12590
+ * @param {mixed} b - an item to compare
12591
+ * @returns {number} - comparison result
12592
+ */
12593
+ function descending(a, b)
12594
+ {
12595
+ return -1 * ascending(a, b);
12596
+ }
12597
+ return serialOrdered.exports;
12382
12598
  }
12383
12599
 
12384
- var iterate$1 = iterate_1
12385
- , initState$1 = state_1
12386
- , terminator$1 = terminator_1
12387
- ;
12388
-
12389
- // Public API
12390
- var parallel_1 = parallel;
12391
-
12392
- /**
12393
- * Runs iterator over provided array elements in parallel
12394
- *
12395
- * @param {array|object} list - array or object (named list) to iterate over
12396
- * @param {function} iterator - iterator to run
12397
- * @param {function} callback - invoked when all elements processed
12398
- * @returns {function} - jobs terminator
12399
- */
12400
- function parallel(list, iterator, callback)
12401
- {
12402
- var state = initState$1(list);
12403
-
12404
- while (state.index < (state['keyedList'] || list).length)
12405
- {
12406
- iterate$1(list, iterator, state, function(error, result)
12407
- {
12408
- if (error)
12409
- {
12410
- callback(error, result);
12411
- return;
12412
- }
12600
+ var serial_1;
12601
+ var hasRequiredSerial;
12413
12602
 
12414
- // looks like it's the last one
12415
- if (Object.keys(state.jobs).length === 0)
12416
- {
12417
- callback(null, state.results);
12418
- return;
12419
- }
12420
- });
12603
+ function requireSerial () {
12604
+ if (hasRequiredSerial) return serial_1;
12605
+ hasRequiredSerial = 1;
12606
+ var serialOrdered = requireSerialOrdered();
12421
12607
 
12422
- state.index++;
12423
- }
12608
+ // Public API
12609
+ serial_1 = serial;
12424
12610
 
12425
- return terminator$1.bind(state, callback);
12611
+ /**
12612
+ * Runs iterator over provided array elements in series
12613
+ *
12614
+ * @param {array|object} list - array or object (named list) to iterate over
12615
+ * @param {function} iterator - iterator to run
12616
+ * @param {function} callback - invoked when all elements processed
12617
+ * @returns {function} - jobs terminator
12618
+ */
12619
+ function serial(list, iterator, callback)
12620
+ {
12621
+ return serialOrdered(list, iterator, null, callback);
12622
+ }
12623
+ return serial_1;
12426
12624
  }
12427
12625
 
12428
- var serialOrdered$2 = {exports: {}};
12429
-
12430
- var iterate = iterate_1
12431
- , initState = state_1
12432
- , terminator = terminator_1
12433
- ;
12434
-
12435
- // Public API
12436
- serialOrdered$2.exports = serialOrdered$1;
12437
- // sorting helpers
12438
- serialOrdered$2.exports.ascending = ascending;
12439
- serialOrdered$2.exports.descending = descending;
12440
-
12441
- /**
12442
- * Runs iterator over provided sorted array elements in series
12443
- *
12444
- * @param {array|object} list - array or object (named list) to iterate over
12445
- * @param {function} iterator - iterator to run
12446
- * @param {function} sortMethod - custom sort function
12447
- * @param {function} callback - invoked when all elements processed
12448
- * @returns {function} - jobs terminator
12449
- */
12450
- function serialOrdered$1(list, iterator, sortMethod, callback)
12451
- {
12452
- var state = initState(list, sortMethod);
12453
-
12454
- iterate(list, iterator, state, function iteratorHandler(error, result)
12455
- {
12456
- if (error)
12457
- {
12458
- callback(error, result);
12459
- return;
12460
- }
12626
+ var asynckit;
12627
+ var hasRequiredAsynckit;
12628
+
12629
+ function requireAsynckit () {
12630
+ if (hasRequiredAsynckit) return asynckit;
12631
+ hasRequiredAsynckit = 1;
12632
+ asynckit =
12633
+ {
12634
+ parallel : requireParallel(),
12635
+ serial : requireSerial(),
12636
+ serialOrdered : requireSerialOrdered()
12637
+ };
12638
+ return asynckit;
12639
+ }
12461
12640
 
12462
- state.index++;
12641
+ var populate;
12642
+ var hasRequiredPopulate;
12463
12643
 
12464
- // are we there yet?
12465
- if (state.index < (state['keyedList'] || list).length)
12466
- {
12467
- iterate(list, iterator, state, iteratorHandler);
12468
- return;
12469
- }
12644
+ function requirePopulate () {
12645
+ if (hasRequiredPopulate) return populate;
12646
+ hasRequiredPopulate = 1;
12647
+ // populates missing values
12648
+ populate = function(dst, src) {
12470
12649
 
12471
- // done here
12472
- callback(null, state.results);
12473
- });
12650
+ Object.keys(src).forEach(function(prop)
12651
+ {
12652
+ dst[prop] = dst[prop] || src[prop];
12653
+ });
12474
12654
 
12475
- return terminator.bind(state, callback);
12655
+ return dst;
12656
+ };
12657
+ return populate;
12476
12658
  }
12477
12659
 
12478
- /*
12479
- * -- Sort methods
12480
- */
12660
+ var form_data;
12661
+ var hasRequiredForm_data;
12662
+
12663
+ function requireForm_data () {
12664
+ if (hasRequiredForm_data) return form_data;
12665
+ hasRequiredForm_data = 1;
12666
+ var CombinedStream = requireCombined_stream();
12667
+ var util = require$$1;
12668
+ var path = require$$1$1;
12669
+ var http = require$$3;
12670
+ var https = require$$4;
12671
+ var parseUrl = require$$5.parse;
12672
+ var fs = require$$6;
12673
+ var Stream = require$$0$1.Stream;
12674
+ var mime = requireMimeTypes();
12675
+ var asynckit = requireAsynckit();
12676
+ var populate = requirePopulate();
12677
+
12678
+ // Public API
12679
+ form_data = FormData;
12680
+
12681
+ // make it a Stream
12682
+ util.inherits(FormData, CombinedStream);
12481
12683
 
12482
- /**
12483
- * sort helper to sort array elements in ascending order
12484
- *
12485
- * @param {mixed} a - an item to compare
12486
- * @param {mixed} b - an item to compare
12487
- * @returns {number} - comparison result
12488
- */
12489
- function ascending(a, b)
12490
- {
12491
- return a < b ? -1 : a > b ? 1 : 0;
12492
- }
12684
+ /**
12685
+ * Create readable "multipart/form-data" streams.
12686
+ * Can be used to submit forms
12687
+ * and file uploads to other web applications.
12688
+ *
12689
+ * @constructor
12690
+ * @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
12691
+ */
12692
+ function FormData(options) {
12693
+ if (!(this instanceof FormData)) {
12694
+ return new FormData(options);
12695
+ }
12493
12696
 
12494
- /**
12495
- * sort helper to sort array elements in descending order
12496
- *
12497
- * @param {mixed} a - an item to compare
12498
- * @param {mixed} b - an item to compare
12499
- * @returns {number} - comparison result
12500
- */
12501
- function descending(a, b)
12502
- {
12503
- return -1 * ascending(a, b);
12504
- }
12697
+ this._overheadLength = 0;
12698
+ this._valueLength = 0;
12699
+ this._valuesToMeasure = [];
12505
12700
 
12506
- var serialOrderedExports = serialOrdered$2.exports;
12701
+ CombinedStream.call(this);
12507
12702
 
12508
- var serialOrdered = serialOrderedExports;
12703
+ options = options || {};
12704
+ for (var option in options) {
12705
+ this[option] = options[option];
12706
+ }
12707
+ }
12509
12708
 
12510
- // Public API
12511
- var serial_1 = serial;
12709
+ FormData.LINE_BREAK = '\r\n';
12710
+ FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
12512
12711
 
12513
- /**
12514
- * Runs iterator over provided array elements in series
12515
- *
12516
- * @param {array|object} list - array or object (named list) to iterate over
12517
- * @param {function} iterator - iterator to run
12518
- * @param {function} callback - invoked when all elements processed
12519
- * @returns {function} - jobs terminator
12520
- */
12521
- function serial(list, iterator, callback)
12522
- {
12523
- return serialOrdered(list, iterator, null, callback);
12524
- }
12712
+ FormData.prototype.append = function(field, value, options) {
12525
12713
 
12526
- var asynckit$1 =
12527
- {
12528
- parallel : parallel_1,
12529
- serial : serial_1,
12530
- serialOrdered : serialOrderedExports
12531
- };
12714
+ options = options || {};
12532
12715
 
12533
- // populates missing values
12534
- var populate$1 = function(dst, src) {
12716
+ // allow filename as single option
12717
+ if (typeof options == 'string') {
12718
+ options = {filename: options};
12719
+ }
12535
12720
 
12536
- Object.keys(src).forEach(function(prop)
12537
- {
12538
- dst[prop] = dst[prop] || src[prop];
12539
- });
12721
+ var append = CombinedStream.prototype.append.bind(this);
12540
12722
 
12541
- return dst;
12542
- };
12723
+ // all that streamy business can't handle numbers
12724
+ if (typeof value == 'number') {
12725
+ value = '' + value;
12726
+ }
12543
12727
 
12544
- var CombinedStream = combined_stream;
12545
- var util = require$$1;
12546
- var path = require$$1$1;
12547
- var http = require$$3;
12548
- var https = require$$4;
12549
- var parseUrl = require$$5.parse;
12550
- var fs = require$$6;
12551
- var Stream = require$$0$1.Stream;
12552
- var mime = mimeTypes;
12553
- var asynckit = asynckit$1;
12554
- var populate = populate$1;
12555
-
12556
- // Public API
12557
- var form_data = FormData;
12558
-
12559
- // make it a Stream
12560
- util.inherits(FormData, CombinedStream);
12561
-
12562
- /**
12563
- * Create readable "multipart/form-data" streams.
12564
- * Can be used to submit forms
12565
- * and file uploads to other web applications.
12566
- *
12567
- * @constructor
12568
- * @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
12569
- */
12570
- function FormData(options) {
12571
- if (!(this instanceof FormData)) {
12572
- return new FormData(options);
12573
- }
12728
+ // https://github.com/felixge/node-form-data/issues/38
12729
+ if (util.isArray(value)) {
12730
+ // Please convert your array into string
12731
+ // the way web server expects it
12732
+ this._error(new Error('Arrays are not supported.'));
12733
+ return;
12734
+ }
12574
12735
 
12575
- this._overheadLength = 0;
12576
- this._valueLength = 0;
12577
- this._valuesToMeasure = [];
12736
+ var header = this._multiPartHeader(field, value, options);
12737
+ var footer = this._multiPartFooter();
12738
+
12739
+ append(header);
12740
+ append(value);
12741
+ append(footer);
12742
+
12743
+ // pass along options.knownLength
12744
+ this._trackLength(header, value, options);
12745
+ };
12746
+
12747
+ FormData.prototype._trackLength = function(header, value, options) {
12748
+ var valueLength = 0;
12749
+
12750
+ // used w/ getLengthSync(), when length is known.
12751
+ // e.g. for streaming directly from a remote server,
12752
+ // w/ a known file a size, and not wanting to wait for
12753
+ // incoming file to finish to get its size.
12754
+ if (options.knownLength != null) {
12755
+ valueLength += +options.knownLength;
12756
+ } else if (Buffer.isBuffer(value)) {
12757
+ valueLength = value.length;
12758
+ } else if (typeof value === 'string') {
12759
+ valueLength = Buffer.byteLength(value);
12760
+ }
12578
12761
 
12579
- CombinedStream.call(this);
12762
+ this._valueLength += valueLength;
12580
12763
 
12581
- options = options || {};
12582
- for (var option in options) {
12583
- this[option] = options[option];
12584
- }
12585
- }
12764
+ // @check why add CRLF? does this account for custom/multiple CRLFs?
12765
+ this._overheadLength +=
12766
+ Buffer.byteLength(header) +
12767
+ FormData.LINE_BREAK.length;
12586
12768
 
12587
- FormData.LINE_BREAK = '\r\n';
12588
- FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
12769
+ // empty or either doesn't have path or not an http response or not a stream
12770
+ if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) {
12771
+ return;
12772
+ }
12589
12773
 
12590
- FormData.prototype.append = function(field, value, options) {
12774
+ // no need to bother with the length
12775
+ if (!options.knownLength) {
12776
+ this._valuesToMeasure.push(value);
12777
+ }
12778
+ };
12591
12779
 
12592
- options = options || {};
12780
+ FormData.prototype._lengthRetriever = function(value, callback) {
12593
12781
 
12594
- // allow filename as single option
12595
- if (typeof options == 'string') {
12596
- options = {filename: options};
12597
- }
12782
+ if (value.hasOwnProperty('fd')) {
12598
12783
 
12599
- var append = CombinedStream.prototype.append.bind(this);
12784
+ // take read range into a account
12785
+ // `end` = Infinity –> read file till the end
12786
+ //
12787
+ // TODO: Looks like there is bug in Node fs.createReadStream
12788
+ // it doesn't respect `end` options without `start` options
12789
+ // Fix it when node fixes it.
12790
+ // https://github.com/joyent/node/issues/7819
12791
+ if (value.end != undefined && value.end != Infinity && value.start != undefined) {
12600
12792
 
12601
- // all that streamy business can't handle numbers
12602
- if (typeof value == 'number') {
12603
- value = '' + value;
12604
- }
12793
+ // when end specified
12794
+ // no need to calculate range
12795
+ // inclusive, starts with 0
12796
+ callback(null, value.end + 1 - (value.start ? value.start : 0));
12605
12797
 
12606
- // https://github.com/felixge/node-form-data/issues/38
12607
- if (util.isArray(value)) {
12608
- // Please convert your array into string
12609
- // the way web server expects it
12610
- this._error(new Error('Arrays are not supported.'));
12611
- return;
12612
- }
12798
+ // not that fast snoopy
12799
+ } else {
12800
+ // still need to fetch file size from fs
12801
+ fs.stat(value.path, function(err, stat) {
12613
12802
 
12614
- var header = this._multiPartHeader(field, value, options);
12615
- var footer = this._multiPartFooter();
12803
+ var fileSize;
12616
12804
 
12617
- append(header);
12618
- append(value);
12619
- append(footer);
12805
+ if (err) {
12806
+ callback(err);
12807
+ return;
12808
+ }
12620
12809
 
12621
- // pass along options.knownLength
12622
- this._trackLength(header, value, options);
12623
- };
12810
+ // update final size based on the range options
12811
+ fileSize = stat.size - (value.start ? value.start : 0);
12812
+ callback(null, fileSize);
12813
+ });
12814
+ }
12624
12815
 
12625
- FormData.prototype._trackLength = function(header, value, options) {
12626
- var valueLength = 0;
12627
-
12628
- // used w/ getLengthSync(), when length is known.
12629
- // e.g. for streaming directly from a remote server,
12630
- // w/ a known file a size, and not wanting to wait for
12631
- // incoming file to finish to get its size.
12632
- if (options.knownLength != null) {
12633
- valueLength += +options.knownLength;
12634
- } else if (Buffer.isBuffer(value)) {
12635
- valueLength = value.length;
12636
- } else if (typeof value === 'string') {
12637
- valueLength = Buffer.byteLength(value);
12638
- }
12639
-
12640
- this._valueLength += valueLength;
12641
-
12642
- // @check why add CRLF? does this account for custom/multiple CRLFs?
12643
- this._overheadLength +=
12644
- Buffer.byteLength(header) +
12645
- FormData.LINE_BREAK.length;
12646
-
12647
- // empty or either doesn't have path or not an http response or not a stream
12648
- if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) {
12649
- return;
12650
- }
12816
+ // or http response
12817
+ } else if (value.hasOwnProperty('httpVersion')) {
12818
+ callback(null, +value.headers['content-length']);
12819
+
12820
+ // or request stream http://github.com/mikeal/request
12821
+ } else if (value.hasOwnProperty('httpModule')) {
12822
+ // wait till response come back
12823
+ value.on('response', function(response) {
12824
+ value.pause();
12825
+ callback(null, +response.headers['content-length']);
12826
+ });
12827
+ value.resume();
12828
+
12829
+ // something else
12830
+ } else {
12831
+ callback('Unknown stream');
12832
+ }
12833
+ };
12834
+
12835
+ FormData.prototype._multiPartHeader = function(field, value, options) {
12836
+ // custom header specified (as string)?
12837
+ // it becomes responsible for boundary
12838
+ // (e.g. to handle extra CRLFs on .NET servers)
12839
+ if (typeof options.header == 'string') {
12840
+ return options.header;
12841
+ }
12651
12842
 
12652
- // no need to bother with the length
12653
- if (!options.knownLength) {
12654
- this._valuesToMeasure.push(value);
12655
- }
12656
- };
12843
+ var contentDisposition = this._getContentDisposition(value, options);
12844
+ var contentType = this._getContentType(value, options);
12657
12845
 
12658
- FormData.prototype._lengthRetriever = function(value, callback) {
12846
+ var contents = '';
12847
+ var headers = {
12848
+ // add custom disposition as third element or keep it two elements if not
12849
+ 'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
12850
+ // if no content type. allow it to be empty array
12851
+ 'Content-Type': [].concat(contentType || [])
12852
+ };
12659
12853
 
12660
- if (value.hasOwnProperty('fd')) {
12854
+ // allow custom headers.
12855
+ if (typeof options.header == 'object') {
12856
+ populate(headers, options.header);
12857
+ }
12661
12858
 
12662
- // take read range into a account
12663
- // `end` = Infinity –> read file till the end
12664
- //
12665
- // TODO: Looks like there is bug in Node fs.createReadStream
12666
- // it doesn't respect `end` options without `start` options
12667
- // Fix it when node fixes it.
12668
- // https://github.com/joyent/node/issues/7819
12669
- if (value.end != undefined && value.end != Infinity && value.start != undefined) {
12859
+ var header;
12860
+ for (var prop in headers) {
12861
+ if (!headers.hasOwnProperty(prop)) continue;
12862
+ header = headers[prop];
12670
12863
 
12671
- // when end specified
12672
- // no need to calculate range
12673
- // inclusive, starts with 0
12674
- callback(null, value.end + 1 - (value.start ? value.start : 0));
12864
+ // skip nullish headers.
12865
+ if (header == null) {
12866
+ continue;
12867
+ }
12675
12868
 
12676
- // not that fast snoopy
12677
- } else {
12678
- // still need to fetch file size from fs
12679
- fs.stat(value.path, function(err, stat) {
12869
+ // convert all headers to arrays.
12870
+ if (!Array.isArray(header)) {
12871
+ header = [header];
12872
+ }
12680
12873
 
12681
- var fileSize;
12874
+ // add non-empty headers.
12875
+ if (header.length) {
12876
+ contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
12877
+ }
12878
+ }
12682
12879
 
12683
- if (err) {
12684
- callback(err);
12685
- return;
12686
- }
12880
+ return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
12881
+ };
12882
+
12883
+ FormData.prototype._getContentDisposition = function(value, options) {
12884
+
12885
+ var filename
12886
+ , contentDisposition
12887
+ ;
12888
+
12889
+ if (typeof options.filepath === 'string') {
12890
+ // custom filepath for relative paths
12891
+ filename = path.normalize(options.filepath).replace(/\\/g, '/');
12892
+ } else if (options.filename || value.name || value.path) {
12893
+ // custom filename take precedence
12894
+ // formidable and the browser add a name property
12895
+ // fs- and request- streams have path property
12896
+ filename = path.basename(options.filename || value.name || value.path);
12897
+ } else if (value.readable && value.hasOwnProperty('httpVersion')) {
12898
+ // or try http response
12899
+ filename = path.basename(value.client._httpMessage.path || '');
12900
+ }
12687
12901
 
12688
- // update final size based on the range options
12689
- fileSize = stat.size - (value.start ? value.start : 0);
12690
- callback(null, fileSize);
12691
- });
12692
- }
12902
+ if (filename) {
12903
+ contentDisposition = 'filename="' + filename + '"';
12904
+ }
12693
12905
 
12694
- // or http response
12695
- } else if (value.hasOwnProperty('httpVersion')) {
12696
- callback(null, +value.headers['content-length']);
12906
+ return contentDisposition;
12907
+ };
12697
12908
 
12698
- // or request stream http://github.com/mikeal/request
12699
- } else if (value.hasOwnProperty('httpModule')) {
12700
- // wait till response come back
12701
- value.on('response', function(response) {
12702
- value.pause();
12703
- callback(null, +response.headers['content-length']);
12704
- });
12705
- value.resume();
12909
+ FormData.prototype._getContentType = function(value, options) {
12706
12910
 
12707
- // something else
12708
- } else {
12709
- callback('Unknown stream');
12710
- }
12711
- };
12911
+ // use custom content-type above all
12912
+ var contentType = options.contentType;
12712
12913
 
12713
- FormData.prototype._multiPartHeader = function(field, value, options) {
12714
- // custom header specified (as string)?
12715
- // it becomes responsible for boundary
12716
- // (e.g. to handle extra CRLFs on .NET servers)
12717
- if (typeof options.header == 'string') {
12718
- return options.header;
12719
- }
12720
-
12721
- var contentDisposition = this._getContentDisposition(value, options);
12722
- var contentType = this._getContentType(value, options);
12723
-
12724
- var contents = '';
12725
- var headers = {
12726
- // add custom disposition as third element or keep it two elements if not
12727
- 'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
12728
- // if no content type. allow it to be empty array
12729
- 'Content-Type': [].concat(contentType || [])
12730
- };
12731
-
12732
- // allow custom headers.
12733
- if (typeof options.header == 'object') {
12734
- populate(headers, options.header);
12735
- }
12736
-
12737
- var header;
12738
- for (var prop in headers) {
12739
- if (!headers.hasOwnProperty(prop)) continue;
12740
- header = headers[prop];
12741
-
12742
- // skip nullish headers.
12743
- if (header == null) {
12744
- continue;
12745
- }
12914
+ // or try `name` from formidable, browser
12915
+ if (!contentType && value.name) {
12916
+ contentType = mime.lookup(value.name);
12917
+ }
12746
12918
 
12747
- // convert all headers to arrays.
12748
- if (!Array.isArray(header)) {
12749
- header = [header];
12750
- }
12919
+ // or try `path` from fs-, request- streams
12920
+ if (!contentType && value.path) {
12921
+ contentType = mime.lookup(value.path);
12922
+ }
12751
12923
 
12752
- // add non-empty headers.
12753
- if (header.length) {
12754
- contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
12755
- }
12756
- }
12924
+ // or if it's http-reponse
12925
+ if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) {
12926
+ contentType = value.headers['content-type'];
12927
+ }
12757
12928
 
12758
- return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
12759
- };
12929
+ // or guess it from the filepath or filename
12930
+ if (!contentType && (options.filepath || options.filename)) {
12931
+ contentType = mime.lookup(options.filepath || options.filename);
12932
+ }
12760
12933
 
12761
- FormData.prototype._getContentDisposition = function(value, options) {
12762
-
12763
- var filename
12764
- , contentDisposition
12765
- ;
12766
-
12767
- if (typeof options.filepath === 'string') {
12768
- // custom filepath for relative paths
12769
- filename = path.normalize(options.filepath).replace(/\\/g, '/');
12770
- } else if (options.filename || value.name || value.path) {
12771
- // custom filename take precedence
12772
- // formidable and the browser add a name property
12773
- // fs- and request- streams have path property
12774
- filename = path.basename(options.filename || value.name || value.path);
12775
- } else if (value.readable && value.hasOwnProperty('httpVersion')) {
12776
- // or try http response
12777
- filename = path.basename(value.client._httpMessage.path || '');
12778
- }
12779
-
12780
- if (filename) {
12781
- contentDisposition = 'filename="' + filename + '"';
12782
- }
12783
-
12784
- return contentDisposition;
12785
- };
12934
+ // fallback to the default content type if `value` is not simple value
12935
+ if (!contentType && typeof value == 'object') {
12936
+ contentType = FormData.DEFAULT_CONTENT_TYPE;
12937
+ }
12786
12938
 
12787
- FormData.prototype._getContentType = function(value, options) {
12939
+ return contentType;
12940
+ };
12788
12941
 
12789
- // use custom content-type above all
12790
- var contentType = options.contentType;
12942
+ FormData.prototype._multiPartFooter = function() {
12943
+ return function(next) {
12944
+ var footer = FormData.LINE_BREAK;
12791
12945
 
12792
- // or try `name` from formidable, browser
12793
- if (!contentType && value.name) {
12794
- contentType = mime.lookup(value.name);
12795
- }
12946
+ var lastPart = (this._streams.length === 0);
12947
+ if (lastPart) {
12948
+ footer += this._lastBoundary();
12949
+ }
12796
12950
 
12797
- // or try `path` from fs-, request- streams
12798
- if (!contentType && value.path) {
12799
- contentType = mime.lookup(value.path);
12800
- }
12951
+ next(footer);
12952
+ }.bind(this);
12953
+ };
12801
12954
 
12802
- // or if it's http-reponse
12803
- if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) {
12804
- contentType = value.headers['content-type'];
12805
- }
12955
+ FormData.prototype._lastBoundary = function() {
12956
+ return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
12957
+ };
12806
12958
 
12807
- // or guess it from the filepath or filename
12808
- if (!contentType && (options.filepath || options.filename)) {
12809
- contentType = mime.lookup(options.filepath || options.filename);
12810
- }
12959
+ FormData.prototype.getHeaders = function(userHeaders) {
12960
+ var header;
12961
+ var formHeaders = {
12962
+ 'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
12963
+ };
12811
12964
 
12812
- // fallback to the default content type if `value` is not simple value
12813
- if (!contentType && typeof value == 'object') {
12814
- contentType = FormData.DEFAULT_CONTENT_TYPE;
12815
- }
12965
+ for (header in userHeaders) {
12966
+ if (userHeaders.hasOwnProperty(header)) {
12967
+ formHeaders[header.toLowerCase()] = userHeaders[header];
12968
+ }
12969
+ }
12816
12970
 
12817
- return contentType;
12818
- };
12971
+ return formHeaders;
12972
+ };
12819
12973
 
12820
- FormData.prototype._multiPartFooter = function() {
12821
- return function(next) {
12822
- var footer = FormData.LINE_BREAK;
12974
+ FormData.prototype.setBoundary = function(boundary) {
12975
+ this._boundary = boundary;
12976
+ };
12823
12977
 
12824
- var lastPart = (this._streams.length === 0);
12825
- if (lastPart) {
12826
- footer += this._lastBoundary();
12827
- }
12978
+ FormData.prototype.getBoundary = function() {
12979
+ if (!this._boundary) {
12980
+ this._generateBoundary();
12981
+ }
12828
12982
 
12829
- next(footer);
12830
- }.bind(this);
12831
- };
12983
+ return this._boundary;
12984
+ };
12832
12985
 
12833
- FormData.prototype._lastBoundary = function() {
12834
- return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
12835
- };
12986
+ FormData.prototype.getBuffer = function() {
12987
+ var dataBuffer = new Buffer.alloc( 0 );
12988
+ var boundary = this.getBoundary();
12836
12989
 
12837
- FormData.prototype.getHeaders = function(userHeaders) {
12838
- var header;
12839
- var formHeaders = {
12840
- 'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
12841
- };
12990
+ // Create the form content. Add Line breaks to the end of data.
12991
+ for (var i = 0, len = this._streams.length; i < len; i++) {
12992
+ if (typeof this._streams[i] !== 'function') {
12842
12993
 
12843
- for (header in userHeaders) {
12844
- if (userHeaders.hasOwnProperty(header)) {
12845
- formHeaders[header.toLowerCase()] = userHeaders[header];
12846
- }
12847
- }
12994
+ // Add content to the buffer.
12995
+ if(Buffer.isBuffer(this._streams[i])) {
12996
+ dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
12997
+ }else {
12998
+ dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
12999
+ }
12848
13000
 
12849
- return formHeaders;
12850
- };
13001
+ // Add break after content.
13002
+ if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
13003
+ dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
13004
+ }
13005
+ }
13006
+ }
12851
13007
 
12852
- FormData.prototype.setBoundary = function(boundary) {
12853
- this._boundary = boundary;
12854
- };
13008
+ // Add the footer and return the Buffer object.
13009
+ return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
13010
+ };
12855
13011
 
12856
- FormData.prototype.getBoundary = function() {
12857
- if (!this._boundary) {
12858
- this._generateBoundary();
12859
- }
13012
+ FormData.prototype._generateBoundary = function() {
13013
+ // This generates a 50 character boundary similar to those used by Firefox.
13014
+ // They are optimized for boyer-moore parsing.
13015
+ var boundary = '--------------------------';
13016
+ for (var i = 0; i < 24; i++) {
13017
+ boundary += Math.floor(Math.random() * 10).toString(16);
13018
+ }
12860
13019
 
12861
- return this._boundary;
12862
- };
13020
+ this._boundary = boundary;
13021
+ };
12863
13022
 
12864
- FormData.prototype.getBuffer = function() {
12865
- var dataBuffer = new Buffer.alloc( 0 );
12866
- var boundary = this.getBoundary();
12867
-
12868
- // Create the form content. Add Line breaks to the end of data.
12869
- for (var i = 0, len = this._streams.length; i < len; i++) {
12870
- if (typeof this._streams[i] !== 'function') {
12871
-
12872
- // Add content to the buffer.
12873
- if(Buffer.isBuffer(this._streams[i])) {
12874
- dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
12875
- }else {
12876
- dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
12877
- }
12878
-
12879
- // Add break after content.
12880
- if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
12881
- dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
12882
- }
12883
- }
12884
- }
13023
+ // Note: getLengthSync DOESN'T calculate streams length
13024
+ // As workaround one can calculate file size manually
13025
+ // and add it as knownLength option
13026
+ FormData.prototype.getLengthSync = function() {
13027
+ var knownLength = this._overheadLength + this._valueLength;
12885
13028
 
12886
- // Add the footer and return the Buffer object.
12887
- return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
12888
- };
13029
+ // Don't get confused, there are 3 "internal" streams for each keyval pair
13030
+ // so it basically checks if there is any value added to the form
13031
+ if (this._streams.length) {
13032
+ knownLength += this._lastBoundary().length;
13033
+ }
12889
13034
 
12890
- FormData.prototype._generateBoundary = function() {
12891
- // This generates a 50 character boundary similar to those used by Firefox.
12892
- // They are optimized for boyer-moore parsing.
12893
- var boundary = '--------------------------';
12894
- for (var i = 0; i < 24; i++) {
12895
- boundary += Math.floor(Math.random() * 10).toString(16);
12896
- }
13035
+ // https://github.com/form-data/form-data/issues/40
13036
+ if (!this.hasKnownLength()) {
13037
+ // Some async length retrievers are present
13038
+ // therefore synchronous length calculation is false.
13039
+ // Please use getLength(callback) to get proper length
13040
+ this._error(new Error('Cannot calculate proper length in synchronous way.'));
13041
+ }
12897
13042
 
12898
- this._boundary = boundary;
12899
- };
13043
+ return knownLength;
13044
+ };
12900
13045
 
12901
- // Note: getLengthSync DOESN'T calculate streams length
12902
- // As workaround one can calculate file size manually
12903
- // and add it as knownLength option
12904
- FormData.prototype.getLengthSync = function() {
12905
- var knownLength = this._overheadLength + this._valueLength;
12906
-
12907
- // Don't get confused, there are 3 "internal" streams for each keyval pair
12908
- // so it basically checks if there is any value added to the form
12909
- if (this._streams.length) {
12910
- knownLength += this._lastBoundary().length;
12911
- }
12912
-
12913
- // https://github.com/form-data/form-data/issues/40
12914
- if (!this.hasKnownLength()) {
12915
- // Some async length retrievers are present
12916
- // therefore synchronous length calculation is false.
12917
- // Please use getLength(callback) to get proper length
12918
- this._error(new Error('Cannot calculate proper length in synchronous way.'));
12919
- }
12920
-
12921
- return knownLength;
12922
- };
13046
+ // Public API to check if length of added values is known
13047
+ // https://github.com/form-data/form-data/issues/196
13048
+ // https://github.com/form-data/form-data/issues/262
13049
+ FormData.prototype.hasKnownLength = function() {
13050
+ var hasKnownLength = true;
12923
13051
 
12924
- // Public API to check if length of added values is known
12925
- // https://github.com/form-data/form-data/issues/196
12926
- // https://github.com/form-data/form-data/issues/262
12927
- FormData.prototype.hasKnownLength = function() {
12928
- var hasKnownLength = true;
13052
+ if (this._valuesToMeasure.length) {
13053
+ hasKnownLength = false;
13054
+ }
12929
13055
 
12930
- if (this._valuesToMeasure.length) {
12931
- hasKnownLength = false;
12932
- }
13056
+ return hasKnownLength;
13057
+ };
12933
13058
 
12934
- return hasKnownLength;
12935
- };
13059
+ FormData.prototype.getLength = function(cb) {
13060
+ var knownLength = this._overheadLength + this._valueLength;
12936
13061
 
12937
- FormData.prototype.getLength = function(cb) {
12938
- var knownLength = this._overheadLength + this._valueLength;
13062
+ if (this._streams.length) {
13063
+ knownLength += this._lastBoundary().length;
13064
+ }
12939
13065
 
12940
- if (this._streams.length) {
12941
- knownLength += this._lastBoundary().length;
12942
- }
13066
+ if (!this._valuesToMeasure.length) {
13067
+ process.nextTick(cb.bind(this, null, knownLength));
13068
+ return;
13069
+ }
12943
13070
 
12944
- if (!this._valuesToMeasure.length) {
12945
- process.nextTick(cb.bind(this, null, knownLength));
12946
- return;
12947
- }
13071
+ asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
13072
+ if (err) {
13073
+ cb(err);
13074
+ return;
13075
+ }
12948
13076
 
12949
- asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
12950
- if (err) {
12951
- cb(err);
12952
- return;
12953
- }
13077
+ values.forEach(function(length) {
13078
+ knownLength += length;
13079
+ });
12954
13080
 
12955
- values.forEach(function(length) {
12956
- knownLength += length;
12957
- });
13081
+ cb(null, knownLength);
13082
+ });
13083
+ };
13084
+
13085
+ FormData.prototype.submit = function(params, cb) {
13086
+ var request
13087
+ , options
13088
+ , defaults = {method: 'post'}
13089
+ ;
13090
+
13091
+ // parse provided url if it's string
13092
+ // or treat it as options object
13093
+ if (typeof params == 'string') {
13094
+
13095
+ params = parseUrl(params);
13096
+ options = populate({
13097
+ port: params.port,
13098
+ path: params.pathname,
13099
+ host: params.hostname,
13100
+ protocol: params.protocol
13101
+ }, defaults);
13102
+
13103
+ // use custom params
13104
+ } else {
13105
+
13106
+ options = populate(params, defaults);
13107
+ // if no port provided use default one
13108
+ if (!options.port) {
13109
+ options.port = options.protocol == 'https:' ? 443 : 80;
13110
+ }
13111
+ }
12958
13112
 
12959
- cb(null, knownLength);
12960
- });
12961
- };
13113
+ // put that good code in getHeaders to some use
13114
+ options.headers = this.getHeaders(params.headers);
12962
13115
 
12963
- FormData.prototype.submit = function(params, cb) {
12964
- var request
12965
- , options
12966
- , defaults = {method: 'post'}
12967
- ;
12968
-
12969
- // parse provided url if it's string
12970
- // or treat it as options object
12971
- if (typeof params == 'string') {
12972
-
12973
- params = parseUrl(params);
12974
- options = populate({
12975
- port: params.port,
12976
- path: params.pathname,
12977
- host: params.hostname,
12978
- protocol: params.protocol
12979
- }, defaults);
12980
-
12981
- // use custom params
12982
- } else {
12983
-
12984
- options = populate(params, defaults);
12985
- // if no port provided use default one
12986
- if (!options.port) {
12987
- options.port = options.protocol == 'https:' ? 443 : 80;
12988
- }
12989
- }
12990
-
12991
- // put that good code in getHeaders to some use
12992
- options.headers = this.getHeaders(params.headers);
12993
-
12994
- // https if specified, fallback to http in any other case
12995
- if (options.protocol == 'https:') {
12996
- request = https.request(options);
12997
- } else {
12998
- request = http.request(options);
12999
- }
13000
-
13001
- // get content length and fire away
13002
- this.getLength(function(err, length) {
13003
- if (err && err !== 'Unknown stream') {
13004
- this._error(err);
13005
- return;
13006
- }
13116
+ // https if specified, fallback to http in any other case
13117
+ if (options.protocol == 'https:') {
13118
+ request = https.request(options);
13119
+ } else {
13120
+ request = http.request(options);
13121
+ }
13007
13122
 
13008
- // add content length
13009
- if (length) {
13010
- request.setHeader('Content-Length', length);
13011
- }
13123
+ // get content length and fire away
13124
+ this.getLength(function(err, length) {
13125
+ if (err && err !== 'Unknown stream') {
13126
+ this._error(err);
13127
+ return;
13128
+ }
13012
13129
 
13013
- this.pipe(request);
13014
- if (cb) {
13015
- var onResponse;
13130
+ // add content length
13131
+ if (length) {
13132
+ request.setHeader('Content-Length', length);
13133
+ }
13016
13134
 
13017
- var callback = function (error, responce) {
13018
- request.removeListener('error', callback);
13019
- request.removeListener('response', onResponse);
13135
+ this.pipe(request);
13136
+ if (cb) {
13137
+ var onResponse;
13020
13138
 
13021
- return cb.call(this, error, responce);
13022
- };
13139
+ var callback = function (error, responce) {
13140
+ request.removeListener('error', callback);
13141
+ request.removeListener('response', onResponse);
13023
13142
 
13024
- onResponse = callback.bind(this, null);
13143
+ return cb.call(this, error, responce);
13144
+ };
13025
13145
 
13026
- request.on('error', callback);
13027
- request.on('response', onResponse);
13028
- }
13029
- }.bind(this));
13146
+ onResponse = callback.bind(this, null);
13030
13147
 
13031
- return request;
13032
- };
13148
+ request.on('error', callback);
13149
+ request.on('response', onResponse);
13150
+ }
13151
+ }.bind(this));
13033
13152
 
13034
- FormData.prototype._error = function(err) {
13035
- if (!this.error) {
13036
- this.error = err;
13037
- this.pause();
13038
- this.emit('error', err);
13039
- }
13040
- };
13153
+ return request;
13154
+ };
13041
13155
 
13042
- FormData.prototype.toString = function () {
13043
- return '[object FormData]';
13044
- };
13156
+ FormData.prototype._error = function(err) {
13157
+ if (!this.error) {
13158
+ this.error = err;
13159
+ this.pause();
13160
+ this.emit('error', err);
13161
+ }
13162
+ };
13163
+
13164
+ FormData.prototype.toString = function () {
13165
+ return '[object FormData]';
13166
+ };
13167
+ return form_data;
13168
+ }
13045
13169
 
13046
- var FormDataModule = /*@__PURE__*/getDefaultExportFromCjs(form_data);
13170
+ var form_dataExports = requireForm_data();
13171
+ var FormDataModule = /*@__PURE__*/getDefaultExportFromCjs(form_dataExports);
13047
13172
 
13048
13173
  const GRANT_TYPE$1 = 'client_credentials';
13049
13174
  const castClientOptionsToRequestParams = (clientOptions) => {