Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

maltypart

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

maltypart - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

LICENSE

2

bower.json
{
"name": "maltypart",
"description": "Maltypart is a simple multipart request builder.",
"version": "1.1.2",
"version": "1.2.0",
"authors": [

@@ -6,0 +6,0 @@ "Jason Miller <jasonmiller@synacor.com>"

@@ -107,3 +107,3 @@ /** Maltypart is a simple multipart builder.

if (typeof fields==='string' && arguments.length>=2) {
this.setField(fields, replace, arguments[2]);
this.setField.apply(this, arguments);
}

@@ -129,6 +129,7 @@ else if (isArray(fields)) {

* @param {String|module:maltypart.RequestField|Element|File} value Any of: a {@link module:maltypart.RequestField RequestField}, a simple String value, an HTML5 [File](https://developer.mozilla.org/en/docs/Web/API/File) object, or any form input Element.
* @param {Boolean} [replace=true] By default, any existing field with the same name is replaced. If `replace` is set to `false`, existing values will be left in-place, and the new value will be appended. This results in duplicate keys (which can be useful!).
* @param {Boolean} [replace=true] By default, any existing field with the same name is replaced. If `replace` is set to `false`, existing values will be left in-place, and the new value will be appended. This results in duplicate keys (which can be useful!).
* @param {Object} [headers] If set, headers will be added to the field
* @returns {this}
*/
setField : function(name, value, replace) {
setField : function(name, value, replace, headers) {
var fields = this.fields;

@@ -167,3 +168,3 @@ name = name + '';

*/
setFileField : function(name, file, callback) {
setFileField : function(name, file, callback, headers) {
var self = this,

@@ -175,3 +176,4 @@ reader = new FileReader();

file.type,
file.name
file.name,
headers
));

@@ -178,0 +180,0 @@ if (typeof callback==='function') {

@@ -1,2 +0,2 @@

/*! maltypart 1.1.1 */
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof module&&module.exports?module.exports=b():a.maltypart=b()}(this,function(){function a(a,b){this.fields={},a&&this.append(a),this.setBoundary(b)}function b(a,b,c,d){this.data=a,this.contentType=b,this.filename=c,this.headers=d}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(){return Math.random().toString(36).substring(2)+(++f).toString(36)}function e(a){for(var b="",c=new Uint8Array(a),d=0;d<c.byteLength;d++)b+=String.fromCharCode(c[d]);return b}var f=0;return a.prototype={constructor:a,availableTypes:["multipart","form-encoded"],setType:function(a){return this.typeOverride=-1!==this.availableTypes.indexOf(a)?a:null,this},getType:function(){var a=this.typeOverride;if(-1!==this.availableTypes.indexOf(a))return a;for(var b in this.fields)if(this.fields.hasOwnProperty(b)&&this.fields[b].contentType)return"multipart";return"form-encoded"},append:function(a,b){var d,e;if("string"==typeof a&&arguments.length>=2)this.setField(a,b,arguments[2]);else if(c(a))for(e=0;e<a.length;e++)this.setField(a[e].name,a[e].value,b);else for(d in a)a.hasOwnProperty(d)&&this.setField(d,a[d],b);return this},setField:function(a,d,e){var f=this.fields;return a+="",window.File&&d instanceof window.File||window.Blob&&d instanceof window.Blob?this.setFileField(a,d,"function"==typeof e&&e):(d&&d.nodeType&&d.nodeName&&d.getAttribute?d=d.value:c(d)||d&&(d instanceof b||d.contentType&&d.data)||(d+=""),a.match(/\[\]$/g)&&(e=!1),e===!1&&f.hasOwnProperty(a)?(c(f[a])||(f[a]=[f[a]]),f[a].push(d)):f[a]=d,this)},setFileField:function(a,c,d){var f=this,g=new FileReader;return g.onloadend=function(){f.setField(a,new b(e(g.result),c.type,c.name)),"function"==typeof d&&d(),c=d=f=g=null},g.readAsArrayBuffer(c),this},setBoundary:function(a){return this.boundary=(a||d())+"",this},toString:function(a){var b,d,e,f,g,h,i,j,k,l=this.getType(),m="";this.boundary||this.setBoundary(),a&&this.append(a);for(d in this.fields)if(this.fields.hasOwnProperty(d))for(e=this.fields[d],b=c(e)?e:[e],i=0;i<b.length;i++){if(h=b[i],"multipart"===l){if(j=h.headers,f=null,h.contentType&&(f=h.contentType,h=h.data),g="--"+this.boundary+'\r\nContent-Disposition: form-data; name="'+d+'"',b[i].filename&&(g+='; filename="'+b[i].filename+'"'),g+="\r\n",f&&(g+="Content-type: "+f+"\r\n"),j)for(k in j)j.hasOwnProperty(k)&&(g+=k+": "+j[k]+"\r\n");g+="\r\n"+h+"\r\n"}else"form-encoded"===l&&(g=encodeURIComponent(d)+"="+encodeURIComponent(h)+"&");m+=g}return"multipart"===l?m+="--"+this.boundary+"--\r\n":"form-encoded"===l&&(m=m.substring(0,m.length-1)),m},getData:function(){var a,b,c=this.toString();if("multipart"===this.getType()){a=c.length,b=new Uint8Array(a);for(var d=0;a>d;d++)b[d]=255&c.charCodeAt(d);return b}return c},getContentType:function(a){var b=this.getType();return"multipart"===b?"multipart/form-data; "+(a?"charset=utf-8; ":"")+"boundary="+this.boundary:"application/x-www-form-encoded"}},{RequestBody:a,RequestField:b}});
/*! maltypart 1.1.2 */
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof module&&module.exports?module.exports=b():a.maltypart=b()}(this,function(){function a(a,b){this.fields={},a&&this.append(a),this.setBoundary(b)}function b(a,b,c,d){this.data=a,this.contentType=b,this.filename=c,this.headers=d}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(){return Math.random().toString(36).substring(2)+(++f).toString(36)}function e(a){for(var b="",c=new Uint8Array(a),d=0;d<c.byteLength;d++)b+=String.fromCharCode(c[d]);return b}var f=0;return a.prototype={constructor:a,availableTypes:["multipart","form-encoded"],setType:function(a){return this.typeOverride=-1!==this.availableTypes.indexOf(a)?a:null,this},getType:function(){var a=this.typeOverride;if(-1!==this.availableTypes.indexOf(a))return a;for(var b in this.fields)if(this.fields.hasOwnProperty(b)&&this.fields[b].contentType)return"multipart";return"form-encoded"},append:function(a,b){var d,e;if("string"==typeof a&&arguments.length>=2)this.setField.apply(this,arguments);else if(c(a))for(e=0;e<a.length;e++)this.setField(a[e].name,a[e].value,b);else for(d in a)a.hasOwnProperty(d)&&this.setField(d,a[d],b);return this},setField:function(a,d,e){var f=this.fields;return a+="",window.File&&d instanceof window.File||window.Blob&&d instanceof window.Blob?this.setFileField(a,d,"function"==typeof e&&e):(d&&d.nodeType&&d.nodeName&&d.getAttribute?d=d.value:c(d)||d&&(d instanceof b||d.contentType&&d.data)||(d+=""),a.match(/\[\]$/g)&&(e=!1),e===!1&&f.hasOwnProperty(a)?(c(f[a])||(f[a]=[f[a]]),f[a].push(d)):f[a]=d,this)},setFileField:function(a,c,d,f){var g=this,h=new FileReader;return h.onloadend=function(){g.setField(a,new b(e(h.result),c.type,c.name,f)),"function"==typeof d&&d(),c=d=g=h=null},h.readAsArrayBuffer(c),this},setBoundary:function(a){return this.boundary=(a||d())+"",this},toString:function(a){var b,d,e,f,g,h,i,j,k,l=this.getType(),m="";this.boundary||this.setBoundary(),a&&this.append(a);for(d in this.fields)if(this.fields.hasOwnProperty(d))for(e=this.fields[d],b=c(e)?e:[e],i=0;i<b.length;i++){if(h=b[i],"multipart"===l){if(j=h.headers,f=null,h.contentType&&(f=h.contentType,h=h.data),g="--"+this.boundary+'\r\nContent-Disposition: form-data; name="'+d+'"',b[i].filename&&(g+='; filename="'+b[i].filename+'"'),g+="\r\n",f&&(g+="Content-type: "+f+"\r\n"),j)for(k in j)j.hasOwnProperty(k)&&(g+=k+": "+j[k]+"\r\n");g+="\r\n"+h+"\r\n"}else"form-encoded"===l&&(g=encodeURIComponent(d)+"="+encodeURIComponent(h)+"&");m+=g}return"multipart"===l?m+="--"+this.boundary+"--\r\n":"form-encoded"===l&&(m=m.substring(0,m.length-1)),m},getData:function(){var a,b,c=this.toString();if("multipart"===this.getType()){a=c.length,b=new Uint8Array(a);for(var d=0;a>d;d++)b[d]=255&c.charCodeAt(d);return b}return c},getContentType:function(a){var b=this.getType();return"multipart"===b?"multipart/form-data; "+(a?"charset=utf-8; ":"")+"boundary="+this.boundary:"application/x-www-form-encoded"}},{RequestBody:a,RequestField:b}});
{
"name": "maltypart",
"version": "1.1.2",
"version": "1.2.0",
"description": "Maltypart is a simple multipart request builder.",

@@ -8,3 +8,3 @@ "main": "maltypart.js",

"build": "grunt",
"pre-start": "grunt",
"prestart": "grunt",
"start": "node server.js",

@@ -31,17 +31,17 @@ "test": "grunt test"

"devDependencies": {
"compression": "^1.3.0",
"express": "^4.10.7",
"serve-static": "^1.8.0",
"compression": "^1.4.3",
"express": "^4.12.3",
"serve-static": "^1.9.2",
"connect-busboy": "0.0.2",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-uglify": "~0.7.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-jshint": "~0.11.1",
"grunt-contrib-uglify": "~0.8.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-jsdoc": "^0.5.7",
"grunt-mocha": "^0.4.11",
"jsdoc": "^3.3.0-alpha13",
"load-grunt-tasks": "^2.0.0"
"grunt-jsdoc": "^0.5.8",
"grunt-mocha": "^0.4.12",
"jsdoc": "^3.3.0-beta3",
"load-grunt-tasks": "^3.1.0"
}
}

@@ -107,3 +107,3 @@ /** Maltypart is a simple multipart builder.

if (typeof fields==='string' && arguments.length>=2) {
this.setField(fields, replace, arguments[2]);
this.setField.apply(this, arguments);
}

@@ -129,6 +129,7 @@ else if (isArray(fields)) {

* @param {String|module:maltypart.RequestField|Element|File} value Any of: a {@link module:maltypart.RequestField RequestField}, a simple String value, an HTML5 [File](https://developer.mozilla.org/en/docs/Web/API/File) object, or any form input Element.
* @param {Boolean} [replace=true] By default, any existing field with the same name is replaced. If `replace` is set to `false`, existing values will be left in-place, and the new value will be appended. This results in duplicate keys (which can be useful!).
* @param {Boolean} [replace=true] By default, any existing field with the same name is replaced. If `replace` is set to `false`, existing values will be left in-place, and the new value will be appended. This results in duplicate keys (which can be useful!).
* @param {Object} [headers] If set, headers will be added to the field
* @returns {this}
*/
setField : function(name, value, replace) {
setField : function(name, value, replace, headers) {
var fields = this.fields;

@@ -167,3 +168,3 @@ name = name + '';

*/
setFileField : function(name, file, callback) {
setFileField : function(name, file, callback, headers) {
var self = this,

@@ -175,3 +176,4 @@ reader = new FileReader();

file.type,
file.name
file.name,
headers
));

@@ -178,0 +180,0 @@ if (typeof callback==='function') {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc