diff options
author | Minteck <contact@minteck.org> | 2022-08-21 17:31:56 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-08-21 17:31:56 +0200 |
commit | a2df9a69dcc14cb70118cda2ded499055e7ee358 (patch) | |
tree | 6dd283e4e9452d38bce81ddaaae49b5335755842 /together/node_modules/formidable/src/plugins/json.js | |
parent | 84dd0735820b16b60f600284d35183d76547a71f (diff) | |
download | pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.gz pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.bz2 pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.zip |
m. update
Diffstat (limited to 'together/node_modules/formidable/src/plugins/json.js')
-rw-r--r-- | together/node_modules/formidable/src/plugins/json.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/together/node_modules/formidable/src/plugins/json.js b/together/node_modules/formidable/src/plugins/json.js new file mode 100644 index 0000000..20d3b26 --- /dev/null +++ b/together/node_modules/formidable/src/plugins/json.js @@ -0,0 +1,38 @@ +/* eslint-disable no-underscore-dangle */ + +'use strict'; + +const JSONParser = require('../parsers/JSON'); + +// the `options` is also available through the `this.options` / `formidable.options` +module.exports = function plugin(formidable, options) { + // the `this` context is always formidable, as the first argument of a plugin + // but this allows us to customize/test each plugin + + /* istanbul ignore next */ + const self = this || formidable; + + if (/json/i.test(self.headers['content-type'])) { + init.call(self, self, options); + } +}; + +// Note that it's a good practice (but it's up to you) to use the `this.options` instead +// of the passed `options` (second) param, because when you decide +// to test the plugin you can pass custom `this` context to it (and so `this.options`) +function init(_self, _opts) { + this.type = 'json'; + + const parser = new JSONParser(this.options); + + parser.on('data', ({ key, value }) => { + this.emit('field', key, value); + }); + + parser.once('end', () => { + this.ended = true; + this._maybeEnd(); + }); + + this._parser = parser; +} |