김시환

test

Showing 537 changed files with 4824 additions and 0 deletions
1 +const { response } = require('express');
2 +const fetch = require('node-fetch')
3 +
4 +globalThis.fetch = fetch.fetch;
5 +
6 +var AddressList = new Array();
7 +
8 +
9 +function getAddress(currQuery) {
10 + fetch('https://dapi.kakao.com/v2/local/search/address.json?' + new URLSearchParams({
11 + query: currQuery
12 + }), {
13 + method: "GET",
14 + headers: {"Authorization": "KakaoAK c14234ba46c574c73715276c5644f397"}
15 + })
16 + .then(response => response.json())
17 + .then(data => {
18 + console.log(response)
19 + AddressList = data.documents.map(({road_address})=>({road_address}));
20 + console.log(AddressList)
21 + return AddressList
22 + })
23 +}
24 +
25 +
26 +
27 +
28 +/*
29 +
30 + move to Line
31 +
32 +var x; var y;
33 +var regions = new Array();
34 +
35 +
36 +// addressArray <- return value from function getAddress
37 +
38 +function selectAddress(addressArray, number) {
39 + x = addressArray[number].road_address.x
40 + y = addressArray[number].road_address.y
41 + regions.region_1depth_name = addressArray[number].road_address.region_1depth_name;
42 + regions.region_2depth_name = addressArray[number].road_address.region_2depth_name;
43 + regions.region_3depth_name = addressArray[number].road_address.region_3depth_name;
44 +
45 +}
46 +
47 +*/
48 +
49 +
50 +// hospitals: array from hospital API
51 +// addNum: index of addressArray
52 +
53 +function getXY(hospitals, addNum) {
54 + var hospitals_xy = new Array();
55 + hospitals_xy.my_x = AddressList[addNum].road_address.x;
56 + hospitals_xy.my_y = AddressList[addNum].road_address.y;
57 + // hopsitals_keyword[i] : name, x, y
58 +
59 + for (let i = 0; i < hospitals.length; i++) { // iterate through available hospitals...
60 +
61 + fetch('https://dapi.kakao.com/v2/local/search/keyword.json?' + new URLSearchParams({
62 + query: hospitals.name,
63 + category_group_code: "HP8"
64 + }), {
65 + method: "GET",
66 + headers: {"Authorization": "KakaoAK c14234ba46c574c73715276c5644f397"}
67 + })
68 + .then(response => response.json())
69 + .then(data => {
70 + for (let j = 0; j < data.length; j++) {
71 + if ((data.documents[j].category_name === "의료,건강 > 병원 > 종합병원") || (data.documents[j].category_name === "의료,건강 > 병원 > 대학병원")) {
72 + hospitals_xy[i].name = data.documents[j].place_name;
73 + hospitals_xy[i].x = data.documents[j].x;
74 + hospitals_xy[i].y = data.documents[j].y;
75 + break;
76 + }
77 + }
78 +
79 + })
80 +
81 + }
82 + AddressList = null;
83 + return hospitals_xy;
84 + /*
85 + hospitals_xy:
86 + .my_x, .my_y: user's coordinates (to some precision..)
87 + [i].name: name of ith hospital
88 + [i].x, [i].y: coordinates of ith hospital
89 +
90 + */
91 +
92 + // for loop 다 돈 다음에 return하도록 수정해야함 (하실수 있는분?)
93 +}
94 +
95 +module.exports = {getAddress, getXY};
...\ No newline at end of file ...\ No newline at end of file
1 +var request = require('request');
2 +var options = {
3 + 'method': 'GET',
4 + 'url': 'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start=127.1058342,37.359708&goal=129.075986,35.179470&option=trafast',
5 + 'headers': {
6 + 'X-NCP-APIGW-API-KEY-ID': '12rhzhzq7g',
7 + 'X-NCP-APIGW-API-KEY': 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI'
8 + }
9 +};
10 +request(options, function (error, response) {
11 + if (error) throw new Error(error);
12 + console.log(response.body);
13 +});
1 +const Address = require('./Address.js');
2 +const express = require('express');
3 +const app = express();
4 +
5 +
6 +console.log(Address.getAddress('석수동길'));
7 +
8 +app.use(express.urlencoded({ extended: false }));
9 +app.use(express.json());
10 +
11 +app.get('',(req,res)=> {
12 + res.send('tset')
13 +})
14 +
15 +app.post('/hook', function(request,response){
16 + var eventObj = request.body.events[0];
17 +
18 + console.log("---------------",new Date(),"-----------------");
19 + response.sendStatus(200);
20 +
21 +
22 +
23 +})
24 +
25 +
26 +app.get('/keyboard', (req, res) => {
27 + const data = {'type': 'text'}
28 + res.json(data);
29 +});
30 +
31 +app.post('/message', (req, res) => {
32 + const question = req.body.userRequest.utterance;
33 + const goMain = '처음으로';
34 +
35 + if (question === '테스트') {
36 + const data = {
37 + 'version': '2.0',
38 + 'template': {
39 + 'outputs': [{
40 + 'simpleText': {
41 + 'text': '테스트'
42 + }
43 + }],
44 + 'quickReplies': [{
45 + 'label': goMain,
46 + 'action': 'message',
47 + 'messageText': goMain
48 + }]
49 + }
50 + }
51 + }
52 + res.json(data);
53 +});
54 +
55 +app.listen(3000, () => console.log('node on 3000'));
...\ No newline at end of file ...\ No newline at end of file
1 +const request = require('request');
2 +const convert = require("xml-js");
3 +
4 +var url = 'http://apis.data.go.kr/B552657/ErmctInfoInqireService/getEmrrmRltmUsefulSckbdInfoInqire';
5 +var queryParams = '?' + encodeURIComponent('serviceKey') + '=52tXHgaW46YUpGn9k0r3IQrduIl6kBOl3Ta8Idra1%2BpPMYhL4qVCDu9itW8FVbDtMF4f9LAT9NJXEx7pvEJv%2FQ%3D%3D'; /* Service Key*/
6 +queryParams += '&' + encodeURIComponent('STAGE1') + '=' + encodeURIComponent('¼­¿ïƯº°½Ã'); /* */
7 +queryParams += '&' + encodeURIComponent('STAGE2') + '=' + encodeURIComponent('°­³²±¸'); /* */
8 +queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
9 +queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10'); /* */
10 +
11 +request({
12 + url: url + queryParams,
13 + method: 'GET'
14 +}, function (err, res, body) {
15 + if(err){
16 + console.log(`err => ${err}`)
17 + }
18 + console.log(convert.xml2js(body));
19 +});
...\ No newline at end of file ...\ No newline at end of file
1 +Subproject commit 02cdaa89d8a001ae3a0c9c0aac13495c558b1305
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../mime/cli.js" "$@"
10 +else
11 + exec node "$basedir/../mime/cli.js" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mime\cli.js" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../mime/cli.js" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../mime/cli.js" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../mime/cli.js" $args
23 + } else {
24 + & "node$exe" "$basedir/../mime/cli.js" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../xml-js/bin/cli.js" "$@"
10 +else
11 + exec node "$basedir/../xml-js/bin/cli.js" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\xml-js\bin\cli.js" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../xml-js/bin/cli.js" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../xml-js/bin/cli.js" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../xml-js/bin/cli.js" $args
23 + } else {
24 + & "node$exe" "$basedir/../xml-js/bin/cli.js" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
This diff is collapsed. Click to expand it.
1 +1.3.8 / 2022-02-02
2 +==================
3 +
4 + * deps: mime-types@~2.1.34
5 + - deps: mime-db@~1.51.0
6 + * deps: negotiator@0.6.3
7 +
8 +1.3.7 / 2019-04-29
9 +==================
10 +
11 + * deps: negotiator@0.6.2
12 + - Fix sorting charset, encoding, and language with extra parameters
13 +
14 +1.3.6 / 2019-04-28
15 +==================
16 +
17 + * deps: mime-types@~2.1.24
18 + - deps: mime-db@~1.40.0
19 +
20 +1.3.5 / 2018-02-28
21 +==================
22 +
23 + * deps: mime-types@~2.1.18
24 + - deps: mime-db@~1.33.0
25 +
26 +1.3.4 / 2017-08-22
27 +==================
28 +
29 + * deps: mime-types@~2.1.16
30 + - deps: mime-db@~1.29.0
31 +
32 +1.3.3 / 2016-05-02
33 +==================
34 +
35 + * deps: mime-types@~2.1.11
36 + - deps: mime-db@~1.23.0
37 + * deps: negotiator@0.6.1
38 + - perf: improve `Accept` parsing speed
39 + - perf: improve `Accept-Charset` parsing speed
40 + - perf: improve `Accept-Encoding` parsing speed
41 + - perf: improve `Accept-Language` parsing speed
42 +
43 +1.3.2 / 2016-03-08
44 +==================
45 +
46 + * deps: mime-types@~2.1.10
47 + - Fix extension of `application/dash+xml`
48 + - Update primary extension for `audio/mp4`
49 + - deps: mime-db@~1.22.0
50 +
51 +1.3.1 / 2016-01-19
52 +==================
53 +
54 + * deps: mime-types@~2.1.9
55 + - deps: mime-db@~1.21.0
56 +
57 +1.3.0 / 2015-09-29
58 +==================
59 +
60 + * deps: mime-types@~2.1.7
61 + - deps: mime-db@~1.19.0
62 + * deps: negotiator@0.6.0
63 + - Fix including type extensions in parameters in `Accept` parsing
64 + - Fix parsing `Accept` parameters with quoted equals
65 + - Fix parsing `Accept` parameters with quoted semicolons
66 + - Lazy-load modules from main entry point
67 + - perf: delay type concatenation until needed
68 + - perf: enable strict mode
69 + - perf: hoist regular expressions
70 + - perf: remove closures getting spec properties
71 + - perf: remove a closure from media type parsing
72 + - perf: remove property delete from media type parsing
73 +
74 +1.2.13 / 2015-09-06
75 +===================
76 +
77 + * deps: mime-types@~2.1.6
78 + - deps: mime-db@~1.18.0
79 +
80 +1.2.12 / 2015-07-30
81 +===================
82 +
83 + * deps: mime-types@~2.1.4
84 + - deps: mime-db@~1.16.0
85 +
86 +1.2.11 / 2015-07-16
87 +===================
88 +
89 + * deps: mime-types@~2.1.3
90 + - deps: mime-db@~1.15.0
91 +
92 +1.2.10 / 2015-07-01
93 +===================
94 +
95 + * deps: mime-types@~2.1.2
96 + - deps: mime-db@~1.14.0
97 +
98 +1.2.9 / 2015-06-08
99 +==================
100 +
101 + * deps: mime-types@~2.1.1
102 + - perf: fix deopt during mapping
103 +
104 +1.2.8 / 2015-06-07
105 +==================
106 +
107 + * deps: mime-types@~2.1.0
108 + - deps: mime-db@~1.13.0
109 + * perf: avoid argument reassignment & argument slice
110 + * perf: avoid negotiator recursive construction
111 + * perf: enable strict mode
112 + * perf: remove unnecessary bitwise operator
113 +
114 +1.2.7 / 2015-05-10
115 +==================
116 +
117 + * deps: negotiator@0.5.3
118 + - Fix media type parameter matching to be case-insensitive
119 +
120 +1.2.6 / 2015-05-07
121 +==================
122 +
123 + * deps: mime-types@~2.0.11
124 + - deps: mime-db@~1.9.1
125 + * deps: negotiator@0.5.2
126 + - Fix comparing media types with quoted values
127 + - Fix splitting media types with quoted commas
128 +
129 +1.2.5 / 2015-03-13
130 +==================
131 +
132 + * deps: mime-types@~2.0.10
133 + - deps: mime-db@~1.8.0
134 +
135 +1.2.4 / 2015-02-14
136 +==================
137 +
138 + * Support Node.js 0.6
139 + * deps: mime-types@~2.0.9
140 + - deps: mime-db@~1.7.0
141 + * deps: negotiator@0.5.1
142 + - Fix preference sorting to be stable for long acceptable lists
143 +
144 +1.2.3 / 2015-01-31
145 +==================
146 +
147 + * deps: mime-types@~2.0.8
148 + - deps: mime-db@~1.6.0
149 +
150 +1.2.2 / 2014-12-30
151 +==================
152 +
153 + * deps: mime-types@~2.0.7
154 + - deps: mime-db@~1.5.0
155 +
156 +1.2.1 / 2014-12-30
157 +==================
158 +
159 + * deps: mime-types@~2.0.5
160 + - deps: mime-db@~1.3.1
161 +
162 +1.2.0 / 2014-12-19
163 +==================
164 +
165 + * deps: negotiator@0.5.0
166 + - Fix list return order when large accepted list
167 + - Fix missing identity encoding when q=0 exists
168 + - Remove dynamic building of Negotiator class
169 +
170 +1.1.4 / 2014-12-10
171 +==================
172 +
173 + * deps: mime-types@~2.0.4
174 + - deps: mime-db@~1.3.0
175 +
176 +1.1.3 / 2014-11-09
177 +==================
178 +
179 + * deps: mime-types@~2.0.3
180 + - deps: mime-db@~1.2.0
181 +
182 +1.1.2 / 2014-10-14
183 +==================
184 +
185 + * deps: negotiator@0.4.9
186 + - Fix error when media type has invalid parameter
187 +
188 +1.1.1 / 2014-09-28
189 +==================
190 +
191 + * deps: mime-types@~2.0.2
192 + - deps: mime-db@~1.1.0
193 + * deps: negotiator@0.4.8
194 + - Fix all negotiations to be case-insensitive
195 + - Stable sort preferences of same quality according to client order
196 +
197 +1.1.0 / 2014-09-02
198 +==================
199 +
200 + * update `mime-types`
201 +
202 +1.0.7 / 2014-07-04
203 +==================
204 +
205 + * Fix wrong type returned from `type` when match after unknown extension
206 +
207 +1.0.6 / 2014-06-24
208 +==================
209 +
210 + * deps: negotiator@0.4.7
211 +
212 +1.0.5 / 2014-06-20
213 +==================
214 +
215 + * fix crash when unknown extension given
216 +
217 +1.0.4 / 2014-06-19
218 +==================
219 +
220 + * use `mime-types`
221 +
222 +1.0.3 / 2014-06-11
223 +==================
224 +
225 + * deps: negotiator@0.4.6
226 + - Order by specificity when quality is the same
227 +
228 +1.0.2 / 2014-05-29
229 +==================
230 +
231 + * Fix interpretation when header not in request
232 + * deps: pin negotiator@0.4.5
233 +
234 +1.0.1 / 2014-01-18
235 +==================
236 +
237 + * Identity encoding isn't always acceptable
238 + * deps: negotiator@~0.4.0
239 +
240 +1.0.0 / 2013-12-27
241 +==================
242 +
243 + * Genesis
1 +(The MIT License)
2 +
3 +Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
4 +Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining
7 +a copy of this software and associated documentation files (the
8 +'Software'), to deal in the Software without restriction, including
9 +without limitation the rights to use, copy, modify, merge, publish,
10 +distribute, sublicense, and/or sell copies of the Software, and to
11 +permit persons to whom the Software is furnished to do so, subject to
12 +the following conditions:
13 +
14 +The above copyright notice and this permission notice shall be
15 +included in all copies or substantial portions of the Software.
16 +
17 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# accepts
2 +
3 +[![NPM Version][npm-version-image]][npm-url]
4 +[![NPM Downloads][npm-downloads-image]][npm-url]
5 +[![Node.js Version][node-version-image]][node-version-url]
6 +[![Build Status][github-actions-ci-image]][github-actions-ci-url]
7 +[![Test Coverage][coveralls-image]][coveralls-url]
8 +
9 +Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator).
10 +Extracted from [koa](https://www.npmjs.com/package/koa) for general use.
11 +
12 +In addition to negotiator, it allows:
13 +
14 +- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])`
15 + as well as `('text/html', 'application/json')`.
16 +- Allows type shorthands such as `json`.
17 +- Returns `false` when no types match
18 +- Treats non-existent headers as `*`
19 +
20 +## Installation
21 +
22 +This is a [Node.js](https://nodejs.org/en/) module available through the
23 +[npm registry](https://www.npmjs.com/). Installation is done using the
24 +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
25 +
26 +```sh
27 +$ npm install accepts
28 +```
29 +
30 +## API
31 +
32 +```js
33 +var accepts = require('accepts')
34 +```
35 +
36 +### accepts(req)
37 +
38 +Create a new `Accepts` object for the given `req`.
39 +
40 +#### .charset(charsets)
41 +
42 +Return the first accepted charset. If nothing in `charsets` is accepted,
43 +then `false` is returned.
44 +
45 +#### .charsets()
46 +
47 +Return the charsets that the request accepts, in the order of the client's
48 +preference (most preferred first).
49 +
50 +#### .encoding(encodings)
51 +
52 +Return the first accepted encoding. If nothing in `encodings` is accepted,
53 +then `false` is returned.
54 +
55 +#### .encodings()
56 +
57 +Return the encodings that the request accepts, in the order of the client's
58 +preference (most preferred first).
59 +
60 +#### .language(languages)
61 +
62 +Return the first accepted language. If nothing in `languages` is accepted,
63 +then `false` is returned.
64 +
65 +#### .languages()
66 +
67 +Return the languages that the request accepts, in the order of the client's
68 +preference (most preferred first).
69 +
70 +#### .type(types)
71 +
72 +Return the first accepted type (and it is returned as the same text as what
73 +appears in the `types` array). If nothing in `types` is accepted, then `false`
74 +is returned.
75 +
76 +The `types` array can contain full MIME types or file extensions. Any value
77 +that is not a full MIME types is passed to `require('mime-types').lookup`.
78 +
79 +#### .types()
80 +
81 +Return the types that the request accepts, in the order of the client's
82 +preference (most preferred first).
83 +
84 +## Examples
85 +
86 +### Simple type negotiation
87 +
88 +This simple example shows how to use `accepts` to return a different typed
89 +respond body based on what the client wants to accept. The server lists it's
90 +preferences in order and will get back the best match between the client and
91 +server.
92 +
93 +```js
94 +var accepts = require('accepts')
95 +var http = require('http')
96 +
97 +function app (req, res) {
98 + var accept = accepts(req)
99 +
100 + // the order of this list is significant; should be server preferred order
101 + switch (accept.type(['json', 'html'])) {
102 + case 'json':
103 + res.setHeader('Content-Type', 'application/json')
104 + res.write('{"hello":"world!"}')
105 + break
106 + case 'html':
107 + res.setHeader('Content-Type', 'text/html')
108 + res.write('<b>hello, world!</b>')
109 + break
110 + default:
111 + // the fallback is text/plain, so no need to specify it above
112 + res.setHeader('Content-Type', 'text/plain')
113 + res.write('hello, world!')
114 + break
115 + }
116 +
117 + res.end()
118 +}
119 +
120 +http.createServer(app).listen(3000)
121 +```
122 +
123 +You can test this out with the cURL program:
124 +```sh
125 +curl -I -H'Accept: text/html' http://localhost:3000/
126 +```
127 +
128 +## License
129 +
130 +[MIT](LICENSE)
131 +
132 +[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master
133 +[coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master
134 +[github-actions-ci-image]: https://badgen.net/github/checks/jshttp/accepts/master?label=ci
135 +[github-actions-ci-url]: https://github.com/jshttp/accepts/actions/workflows/ci.yml
136 +[node-version-image]: https://badgen.net/npm/node/accepts
137 +[node-version-url]: https://nodejs.org/en/download
138 +[npm-downloads-image]: https://badgen.net/npm/dm/accepts
139 +[npm-url]: https://npmjs.org/package/accepts
140 +[npm-version-image]: https://badgen.net/npm/v/accepts
1 +/*!
2 + * accepts
3 + * Copyright(c) 2014 Jonathan Ong
4 + * Copyright(c) 2015 Douglas Christopher Wilson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict'
9 +
10 +/**
11 + * Module dependencies.
12 + * @private
13 + */
14 +
15 +var Negotiator = require('negotiator')
16 +var mime = require('mime-types')
17 +
18 +/**
19 + * Module exports.
20 + * @public
21 + */
22 +
23 +module.exports = Accepts
24 +
25 +/**
26 + * Create a new Accepts object for the given req.
27 + *
28 + * @param {object} req
29 + * @public
30 + */
31 +
32 +function Accepts (req) {
33 + if (!(this instanceof Accepts)) {
34 + return new Accepts(req)
35 + }
36 +
37 + this.headers = req.headers
38 + this.negotiator = new Negotiator(req)
39 +}
40 +
41 +/**
42 + * Check if the given `type(s)` is acceptable, returning
43 + * the best match when true, otherwise `undefined`, in which
44 + * case you should respond with 406 "Not Acceptable".
45 + *
46 + * The `type` value may be a single mime type string
47 + * such as "application/json", the extension name
48 + * such as "json" or an array `["json", "html", "text/plain"]`. When a list
49 + * or array is given the _best_ match, if any is returned.
50 + *
51 + * Examples:
52 + *
53 + * // Accept: text/html
54 + * this.types('html');
55 + * // => "html"
56 + *
57 + * // Accept: text/*, application/json
58 + * this.types('html');
59 + * // => "html"
60 + * this.types('text/html');
61 + * // => "text/html"
62 + * this.types('json', 'text');
63 + * // => "json"
64 + * this.types('application/json');
65 + * // => "application/json"
66 + *
67 + * // Accept: text/*, application/json
68 + * this.types('image/png');
69 + * this.types('png');
70 + * // => undefined
71 + *
72 + * // Accept: text/*;q=.5, application/json
73 + * this.types(['html', 'json']);
74 + * this.types('html', 'json');
75 + * // => "json"
76 + *
77 + * @param {String|Array} types...
78 + * @return {String|Array|Boolean}
79 + * @public
80 + */
81 +
82 +Accepts.prototype.type =
83 +Accepts.prototype.types = function (types_) {
84 + var types = types_
85 +
86 + // support flattened arguments
87 + if (types && !Array.isArray(types)) {
88 + types = new Array(arguments.length)
89 + for (var i = 0; i < types.length; i++) {
90 + types[i] = arguments[i]
91 + }
92 + }
93 +
94 + // no types, return all requested types
95 + if (!types || types.length === 0) {
96 + return this.negotiator.mediaTypes()
97 + }
98 +
99 + // no accept header, return first given type
100 + if (!this.headers.accept) {
101 + return types[0]
102 + }
103 +
104 + var mimes = types.map(extToMime)
105 + var accepts = this.negotiator.mediaTypes(mimes.filter(validMime))
106 + var first = accepts[0]
107 +
108 + return first
109 + ? types[mimes.indexOf(first)]
110 + : false
111 +}
112 +
113 +/**
114 + * Return accepted encodings or best fit based on `encodings`.
115 + *
116 + * Given `Accept-Encoding: gzip, deflate`
117 + * an array sorted by quality is returned:
118 + *
119 + * ['gzip', 'deflate']
120 + *
121 + * @param {String|Array} encodings...
122 + * @return {String|Array}
123 + * @public
124 + */
125 +
126 +Accepts.prototype.encoding =
127 +Accepts.prototype.encodings = function (encodings_) {
128 + var encodings = encodings_
129 +
130 + // support flattened arguments
131 + if (encodings && !Array.isArray(encodings)) {
132 + encodings = new Array(arguments.length)
133 + for (var i = 0; i < encodings.length; i++) {
134 + encodings[i] = arguments[i]
135 + }
136 + }
137 +
138 + // no encodings, return all requested encodings
139 + if (!encodings || encodings.length === 0) {
140 + return this.negotiator.encodings()
141 + }
142 +
143 + return this.negotiator.encodings(encodings)[0] || false
144 +}
145 +
146 +/**
147 + * Return accepted charsets or best fit based on `charsets`.
148 + *
149 + * Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
150 + * an array sorted by quality is returned:
151 + *
152 + * ['utf-8', 'utf-7', 'iso-8859-1']
153 + *
154 + * @param {String|Array} charsets...
155 + * @return {String|Array}
156 + * @public
157 + */
158 +
159 +Accepts.prototype.charset =
160 +Accepts.prototype.charsets = function (charsets_) {
161 + var charsets = charsets_
162 +
163 + // support flattened arguments
164 + if (charsets && !Array.isArray(charsets)) {
165 + charsets = new Array(arguments.length)
166 + for (var i = 0; i < charsets.length; i++) {
167 + charsets[i] = arguments[i]
168 + }
169 + }
170 +
171 + // no charsets, return all requested charsets
172 + if (!charsets || charsets.length === 0) {
173 + return this.negotiator.charsets()
174 + }
175 +
176 + return this.negotiator.charsets(charsets)[0] || false
177 +}
178 +
179 +/**
180 + * Return accepted languages or best fit based on `langs`.
181 + *
182 + * Given `Accept-Language: en;q=0.8, es, pt`
183 + * an array sorted by quality is returned:
184 + *
185 + * ['es', 'pt', 'en']
186 + *
187 + * @param {String|Array} langs...
188 + * @return {Array|String}
189 + * @public
190 + */
191 +
192 +Accepts.prototype.lang =
193 +Accepts.prototype.langs =
194 +Accepts.prototype.language =
195 +Accepts.prototype.languages = function (languages_) {
196 + var languages = languages_
197 +
198 + // support flattened arguments
199 + if (languages && !Array.isArray(languages)) {
200 + languages = new Array(arguments.length)
201 + for (var i = 0; i < languages.length; i++) {
202 + languages[i] = arguments[i]
203 + }
204 + }
205 +
206 + // no languages, return all requested languages
207 + if (!languages || languages.length === 0) {
208 + return this.negotiator.languages()
209 + }
210 +
211 + return this.negotiator.languages(languages)[0] || false
212 +}
213 +
214 +/**
215 + * Convert extnames to mime.
216 + *
217 + * @param {String} type
218 + * @return {String}
219 + * @private
220 + */
221 +
222 +function extToMime (type) {
223 + return type.indexOf('/') === -1
224 + ? mime.lookup(type)
225 + : type
226 +}
227 +
228 +/**
229 + * Check if mime is valid.
230 + *
231 + * @param {String} type
232 + * @return {String}
233 + * @private
234 + */
235 +
236 +function validMime (type) {
237 + return typeof type === 'string'
238 +}
1 +{
2 + "name": "accepts",
3 + "description": "Higher-level content negotiation",
4 + "version": "1.3.8",
5 + "contributors": [
6 + "Douglas Christopher Wilson <doug@somethingdoug.com>",
7 + "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
8 + ],
9 + "license": "MIT",
10 + "repository": "jshttp/accepts",
11 + "dependencies": {
12 + "mime-types": "~2.1.34",
13 + "negotiator": "0.6.3"
14 + },
15 + "devDependencies": {
16 + "deep-equal": "1.0.1",
17 + "eslint": "7.32.0",
18 + "eslint-config-standard": "14.1.1",
19 + "eslint-plugin-import": "2.25.4",
20 + "eslint-plugin-markdown": "2.2.1",
21 + "eslint-plugin-node": "11.1.0",
22 + "eslint-plugin-promise": "4.3.1",
23 + "eslint-plugin-standard": "4.1.0",
24 + "mocha": "9.2.0",
25 + "nyc": "15.1.0"
26 + },
27 + "files": [
28 + "LICENSE",
29 + "HISTORY.md",
30 + "index.js"
31 + ],
32 + "engines": {
33 + "node": ">= 0.6"
34 + },
35 + "scripts": {
36 + "lint": "eslint .",
37 + "test": "mocha --reporter spec --check-leaks --bail test/",
38 + "test-ci": "nyc --reporter=lcov --reporter=text npm test",
39 + "test-cov": "nyc --reporter=html --reporter=text npm test"
40 + },
41 + "keywords": [
42 + "content",
43 + "negotiation",
44 + "accept",
45 + "accepts"
46 + ]
47 +}
1 +The MIT License (MIT)
2 +
3 +Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in
13 +all copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 +THE SOFTWARE.
1 +# Array Flatten
2 +
3 +[![NPM version][npm-image]][npm-url]
4 +[![NPM downloads][downloads-image]][downloads-url]
5 +[![Build status][travis-image]][travis-url]
6 +[![Test coverage][coveralls-image]][coveralls-url]
7 +
8 +> Flatten an array of nested arrays into a single flat array. Accepts an optional depth.
9 +
10 +## Installation
11 +
12 +```
13 +npm install array-flatten --save
14 +```
15 +
16 +## Usage
17 +
18 +```javascript
19 +var flatten = require('array-flatten')
20 +
21 +flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
22 +//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
23 +
24 +flatten([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
25 +//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
26 +
27 +(function () {
28 + flatten(arguments) //=> [1, 2, 3]
29 +})(1, [2, 3])
30 +```
31 +
32 +## License
33 +
34 +MIT
35 +
36 +[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat
37 +[npm-url]: https://npmjs.org/package/array-flatten
38 +[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat
39 +[downloads-url]: https://npmjs.org/package/array-flatten
40 +[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat
41 +[travis-url]: https://travis-ci.org/blakeembrey/array-flatten
42 +[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
43 +[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master
1 +'use strict'
2 +
3 +/**
4 + * Expose `arrayFlatten`.
5 + */
6 +module.exports = arrayFlatten
7 +
8 +/**
9 + * Recursive flatten function with depth.
10 + *
11 + * @param {Array} array
12 + * @param {Array} result
13 + * @param {Number} depth
14 + * @return {Array}
15 + */
16 +function flattenWithDepth (array, result, depth) {
17 + for (var i = 0; i < array.length; i++) {
18 + var value = array[i]
19 +
20 + if (depth > 0 && Array.isArray(value)) {
21 + flattenWithDepth(value, result, depth - 1)
22 + } else {
23 + result.push(value)
24 + }
25 + }
26 +
27 + return result
28 +}
29 +
30 +/**
31 + * Recursive flatten function. Omitting depth is slightly faster.
32 + *
33 + * @param {Array} array
34 + * @param {Array} result
35 + * @return {Array}
36 + */
37 +function flattenForever (array, result) {
38 + for (var i = 0; i < array.length; i++) {
39 + var value = array[i]
40 +
41 + if (Array.isArray(value)) {
42 + flattenForever(value, result)
43 + } else {
44 + result.push(value)
45 + }
46 + }
47 +
48 + return result
49 +}
50 +
51 +/**
52 + * Flatten an array, with the ability to define a depth.
53 + *
54 + * @param {Array} array
55 + * @param {Number} depth
56 + * @return {Array}
57 + */
58 +function arrayFlatten (array, depth) {
59 + if (depth == null) {
60 + return flattenForever(array, [])
61 + }
62 +
63 + return flattenWithDepth(array, [], depth)
64 +}
1 +{
2 + "name": "array-flatten",
3 + "version": "1.1.1",
4 + "description": "Flatten an array of nested arrays into a single flat array",
5 + "main": "array-flatten.js",
6 + "files": [
7 + "array-flatten.js",
8 + "LICENSE"
9 + ],
10 + "scripts": {
11 + "test": "istanbul cover _mocha -- -R spec"
12 + },
13 + "repository": {
14 + "type": "git",
15 + "url": "git://github.com/blakeembrey/array-flatten.git"
16 + },
17 + "keywords": [
18 + "array",
19 + "flatten",
20 + "arguments",
21 + "depth"
22 + ],
23 + "author": {
24 + "name": "Blake Embrey",
25 + "email": "hello@blakeembrey.com",
26 + "url": "http://blakeembrey.me"
27 + },
28 + "license": "MIT",
29 + "bugs": {
30 + "url": "https://github.com/blakeembrey/array-flatten/issues"
31 + },
32 + "homepage": "https://github.com/blakeembrey/array-flatten",
33 + "devDependencies": {
34 + "istanbul": "^0.3.13",
35 + "mocha": "^2.2.4",
36 + "pre-commit": "^1.0.7",
37 + "standard": "^3.7.3"
38 + }
39 +}
This diff is collapsed. Click to expand it.
1 +(The MIT License)
2 +
3 +Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
4 +Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining
7 +a copy of this software and associated documentation files (the
8 +'Software'), to deal in the Software without restriction, including
9 +without limitation the rights to use, copy, modify, merge, publish,
10 +distribute, sublicense, and/or sell copies of the Software, and to
11 +permit persons to whom the Software is furnished to do so, subject to
12 +the following conditions:
13 +
14 +The above copyright notice and this permission notice shall be
15 +included in all copies or substantial portions of the Software.
16 +
17 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This diff is collapsed. Click to expand it.
1 +# Security Policies and Procedures
2 +
3 +## Reporting a Bug
4 +
5 +The Express team and community take all security bugs seriously. Thank you
6 +for improving the security of Express. We appreciate your efforts and
7 +responsible disclosure and will make every effort to acknowledge your
8 +contributions.
9 +
10 +Report security bugs by emailing the current owner(s) of `body-parser`. This
11 +information can be found in the npm registry using the command
12 +`npm owner ls body-parser`.
13 +If unsure or unable to get the information from the above, open an issue
14 +in the [project issue tracker](https://github.com/expressjs/body-parser/issues)
15 +asking for the current contact information.
16 +
17 +To ensure the timely response to your report, please ensure that the entirety
18 +of the report is contained within the email body and not solely behind a web
19 +link or an attachment.
20 +
21 +At least one owner will acknowledge your email within 48 hours, and will send a
22 +more detailed response within 48 hours indicating the next steps in handling
23 +your report. After the initial reply to your report, the owners will
24 +endeavor to keep you informed of the progress towards a fix and full
25 +announcement, and may ask for additional information or guidance.
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module dependencies.
11 + * @private
12 + */
13 +
14 +var deprecate = require('depd')('body-parser')
15 +
16 +/**
17 + * Cache of loaded parsers.
18 + * @private
19 + */
20 +
21 +var parsers = Object.create(null)
22 +
23 +/**
24 + * @typedef Parsers
25 + * @type {function}
26 + * @property {function} json
27 + * @property {function} raw
28 + * @property {function} text
29 + * @property {function} urlencoded
30 + */
31 +
32 +/**
33 + * Module exports.
34 + * @type {Parsers}
35 + */
36 +
37 +exports = module.exports = deprecate.function(bodyParser,
38 + 'bodyParser: use individual json/urlencoded middlewares')
39 +
40 +/**
41 + * JSON parser.
42 + * @public
43 + */
44 +
45 +Object.defineProperty(exports, 'json', {
46 + configurable: true,
47 + enumerable: true,
48 + get: createParserGetter('json')
49 +})
50 +
51 +/**
52 + * Raw parser.
53 + * @public
54 + */
55 +
56 +Object.defineProperty(exports, 'raw', {
57 + configurable: true,
58 + enumerable: true,
59 + get: createParserGetter('raw')
60 +})
61 +
62 +/**
63 + * Text parser.
64 + * @public
65 + */
66 +
67 +Object.defineProperty(exports, 'text', {
68 + configurable: true,
69 + enumerable: true,
70 + get: createParserGetter('text')
71 +})
72 +
73 +/**
74 + * URL-encoded parser.
75 + * @public
76 + */
77 +
78 +Object.defineProperty(exports, 'urlencoded', {
79 + configurable: true,
80 + enumerable: true,
81 + get: createParserGetter('urlencoded')
82 +})
83 +
84 +/**
85 + * Create a middleware to parse json and urlencoded bodies.
86 + *
87 + * @param {object} [options]
88 + * @return {function}
89 + * @deprecated
90 + * @public
91 + */
92 +
93 +function bodyParser (options) {
94 + // use default type for parsers
95 + var opts = Object.create(options || null, {
96 + type: {
97 + configurable: true,
98 + enumerable: true,
99 + value: undefined,
100 + writable: true
101 + }
102 + })
103 +
104 + var _urlencoded = exports.urlencoded(opts)
105 + var _json = exports.json(opts)
106 +
107 + return function bodyParser (req, res, next) {
108 + _json(req, res, function (err) {
109 + if (err) return next(err)
110 + _urlencoded(req, res, next)
111 + })
112 + }
113 +}
114 +
115 +/**
116 + * Create a getter for loading a parser.
117 + * @private
118 + */
119 +
120 +function createParserGetter (name) {
121 + return function get () {
122 + return loadParser(name)
123 + }
124 +}
125 +
126 +/**
127 + * Load a parser module.
128 + * @private
129 + */
130 +
131 +function loadParser (parserName) {
132 + var parser = parsers[parserName]
133 +
134 + if (parser !== undefined) {
135 + return parser
136 + }
137 +
138 + // this uses a switch for static require analysis
139 + switch (parserName) {
140 + case 'json':
141 + parser = require('./lib/types/json')
142 + break
143 + case 'raw':
144 + parser = require('./lib/types/raw')
145 + break
146 + case 'text':
147 + parser = require('./lib/types/text')
148 + break
149 + case 'urlencoded':
150 + parser = require('./lib/types/urlencoded')
151 + break
152 + }
153 +
154 + // store to prevent invoking require()
155 + return (parsers[parserName] = parser)
156 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module dependencies.
11 + * @private
12 + */
13 +
14 +var createError = require('http-errors')
15 +var destroy = require('destroy')
16 +var getBody = require('raw-body')
17 +var iconv = require('iconv-lite')
18 +var onFinished = require('on-finished')
19 +var unpipe = require('unpipe')
20 +var zlib = require('zlib')
21 +
22 +/**
23 + * Module exports.
24 + */
25 +
26 +module.exports = read
27 +
28 +/**
29 + * Read a request into a buffer and parse.
30 + *
31 + * @param {object} req
32 + * @param {object} res
33 + * @param {function} next
34 + * @param {function} parse
35 + * @param {function} debug
36 + * @param {object} options
37 + * @private
38 + */
39 +
40 +function read (req, res, next, parse, debug, options) {
41 + var length
42 + var opts = options
43 + var stream
44 +
45 + // flag as parsed
46 + req._body = true
47 +
48 + // read options
49 + var encoding = opts.encoding !== null
50 + ? opts.encoding
51 + : null
52 + var verify = opts.verify
53 +
54 + try {
55 + // get the content stream
56 + stream = contentstream(req, debug, opts.inflate)
57 + length = stream.length
58 + stream.length = undefined
59 + } catch (err) {
60 + return next(err)
61 + }
62 +
63 + // set raw-body options
64 + opts.length = length
65 + opts.encoding = verify
66 + ? null
67 + : encoding
68 +
69 + // assert charset is supported
70 + if (opts.encoding === null && encoding !== null && !iconv.encodingExists(encoding)) {
71 + return next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
72 + charset: encoding.toLowerCase(),
73 + type: 'charset.unsupported'
74 + }))
75 + }
76 +
77 + // read body
78 + debug('read body')
79 + getBody(stream, opts, function (error, body) {
80 + if (error) {
81 + var _error
82 +
83 + if (error.type === 'encoding.unsupported') {
84 + // echo back charset
85 + _error = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
86 + charset: encoding.toLowerCase(),
87 + type: 'charset.unsupported'
88 + })
89 + } else {
90 + // set status code on error
91 + _error = createError(400, error)
92 + }
93 +
94 + // unpipe from stream and destroy
95 + if (stream !== req) {
96 + unpipe(req)
97 + destroy(stream, true)
98 + }
99 +
100 + // read off entire request
101 + dump(req, function onfinished () {
102 + next(createError(400, _error))
103 + })
104 + return
105 + }
106 +
107 + // verify
108 + if (verify) {
109 + try {
110 + debug('verify body')
111 + verify(req, res, body, encoding)
112 + } catch (err) {
113 + next(createError(403, err, {
114 + body: body,
115 + type: err.type || 'entity.verify.failed'
116 + }))
117 + return
118 + }
119 + }
120 +
121 + // parse
122 + var str = body
123 + try {
124 + debug('parse body')
125 + str = typeof body !== 'string' && encoding !== null
126 + ? iconv.decode(body, encoding)
127 + : body
128 + req.body = parse(str)
129 + } catch (err) {
130 + next(createError(400, err, {
131 + body: str,
132 + type: err.type || 'entity.parse.failed'
133 + }))
134 + return
135 + }
136 +
137 + next()
138 + })
139 +}
140 +
141 +/**
142 + * Get the content stream of the request.
143 + *
144 + * @param {object} req
145 + * @param {function} debug
146 + * @param {boolean} [inflate=true]
147 + * @return {object}
148 + * @api private
149 + */
150 +
151 +function contentstream (req, debug, inflate) {
152 + var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase()
153 + var length = req.headers['content-length']
154 + var stream
155 +
156 + debug('content-encoding "%s"', encoding)
157 +
158 + if (inflate === false && encoding !== 'identity') {
159 + throw createError(415, 'content encoding unsupported', {
160 + encoding: encoding,
161 + type: 'encoding.unsupported'
162 + })
163 + }
164 +
165 + switch (encoding) {
166 + case 'deflate':
167 + stream = zlib.createInflate()
168 + debug('inflate body')
169 + req.pipe(stream)
170 + break
171 + case 'gzip':
172 + stream = zlib.createGunzip()
173 + debug('gunzip body')
174 + req.pipe(stream)
175 + break
176 + case 'identity':
177 + stream = req
178 + stream.length = length
179 + break
180 + default:
181 + throw createError(415, 'unsupported content encoding "' + encoding + '"', {
182 + encoding: encoding,
183 + type: 'encoding.unsupported'
184 + })
185 + }
186 +
187 + return stream
188 +}
189 +
190 +/**
191 + * Dump the contents of a request.
192 + *
193 + * @param {object} req
194 + * @param {function} callback
195 + * @api private
196 + */
197 +
198 +function dump (req, callback) {
199 + if (onFinished.isFinished(req)) {
200 + callback(null)
201 + } else {
202 + onFinished(req, callback)
203 + req.resume()
204 + }
205 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014 Jonathan Ong
4 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict'
9 +
10 +/**
11 + * Module dependencies.
12 + * @private
13 + */
14 +
15 +var bytes = require('bytes')
16 +var contentType = require('content-type')
17 +var createError = require('http-errors')
18 +var debug = require('debug')('body-parser:json')
19 +var read = require('../read')
20 +var typeis = require('type-is')
21 +
22 +/**
23 + * Module exports.
24 + */
25 +
26 +module.exports = json
27 +
28 +/**
29 + * RegExp to match the first non-space in a string.
30 + *
31 + * Allowed whitespace is defined in RFC 7159:
32 + *
33 + * ws = *(
34 + * %x20 / ; Space
35 + * %x09 / ; Horizontal tab
36 + * %x0A / ; Line feed or New line
37 + * %x0D ) ; Carriage return
38 + */
39 +
40 +var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/ // eslint-disable-line no-control-regex
41 +
42 +/**
43 + * Create a middleware to parse JSON bodies.
44 + *
45 + * @param {object} [options]
46 + * @return {function}
47 + * @public
48 + */
49 +
50 +function json (options) {
51 + var opts = options || {}
52 +
53 + var limit = typeof opts.limit !== 'number'
54 + ? bytes.parse(opts.limit || '100kb')
55 + : opts.limit
56 + var inflate = opts.inflate !== false
57 + var reviver = opts.reviver
58 + var strict = opts.strict !== false
59 + var type = opts.type || 'application/json'
60 + var verify = opts.verify || false
61 +
62 + if (verify !== false && typeof verify !== 'function') {
63 + throw new TypeError('option verify must be function')
64 + }
65 +
66 + // create the appropriate type checking function
67 + var shouldParse = typeof type !== 'function'
68 + ? typeChecker(type)
69 + : type
70 +
71 + function parse (body) {
72 + if (body.length === 0) {
73 + // special-case empty json body, as it's a common client-side mistake
74 + // TODO: maybe make this configurable or part of "strict" option
75 + return {}
76 + }
77 +
78 + if (strict) {
79 + var first = firstchar(body)
80 +
81 + if (first !== '{' && first !== '[') {
82 + debug('strict violation')
83 + throw createStrictSyntaxError(body, first)
84 + }
85 + }
86 +
87 + try {
88 + debug('parse json')
89 + return JSON.parse(body, reviver)
90 + } catch (e) {
91 + throw normalizeJsonSyntaxError(e, {
92 + message: e.message,
93 + stack: e.stack
94 + })
95 + }
96 + }
97 +
98 + return function jsonParser (req, res, next) {
99 + if (req._body) {
100 + debug('body already parsed')
101 + next()
102 + return
103 + }
104 +
105 + req.body = req.body || {}
106 +
107 + // skip requests without bodies
108 + if (!typeis.hasBody(req)) {
109 + debug('skip empty body')
110 + next()
111 + return
112 + }
113 +
114 + debug('content-type %j', req.headers['content-type'])
115 +
116 + // determine if request should be parsed
117 + if (!shouldParse(req)) {
118 + debug('skip parsing')
119 + next()
120 + return
121 + }
122 +
123 + // assert charset per RFC 7159 sec 8.1
124 + var charset = getCharset(req) || 'utf-8'
125 + if (charset.slice(0, 4) !== 'utf-') {
126 + debug('invalid charset')
127 + next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
128 + charset: charset,
129 + type: 'charset.unsupported'
130 + }))
131 + return
132 + }
133 +
134 + // read
135 + read(req, res, next, parse, debug, {
136 + encoding: charset,
137 + inflate: inflate,
138 + limit: limit,
139 + verify: verify
140 + })
141 + }
142 +}
143 +
144 +/**
145 + * Create strict violation syntax error matching native error.
146 + *
147 + * @param {string} str
148 + * @param {string} char
149 + * @return {Error}
150 + * @private
151 + */
152 +
153 +function createStrictSyntaxError (str, char) {
154 + var index = str.indexOf(char)
155 + var partial = index !== -1
156 + ? str.substring(0, index) + '#'
157 + : ''
158 +
159 + try {
160 + JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
161 + } catch (e) {
162 + return normalizeJsonSyntaxError(e, {
163 + message: e.message.replace('#', char),
164 + stack: e.stack
165 + })
166 + }
167 +}
168 +
169 +/**
170 + * Get the first non-whitespace character in a string.
171 + *
172 + * @param {string} str
173 + * @return {function}
174 + * @private
175 + */
176 +
177 +function firstchar (str) {
178 + var match = FIRST_CHAR_REGEXP.exec(str)
179 +
180 + return match
181 + ? match[1]
182 + : undefined
183 +}
184 +
185 +/**
186 + * Get the charset of a request.
187 + *
188 + * @param {object} req
189 + * @api private
190 + */
191 +
192 +function getCharset (req) {
193 + try {
194 + return (contentType.parse(req).parameters.charset || '').toLowerCase()
195 + } catch (e) {
196 + return undefined
197 + }
198 +}
199 +
200 +/**
201 + * Normalize a SyntaxError for JSON.parse.
202 + *
203 + * @param {SyntaxError} error
204 + * @param {object} obj
205 + * @return {SyntaxError}
206 + */
207 +
208 +function normalizeJsonSyntaxError (error, obj) {
209 + var keys = Object.getOwnPropertyNames(error)
210 +
211 + for (var i = 0; i < keys.length; i++) {
212 + var key = keys[i]
213 + if (key !== 'stack' && key !== 'message') {
214 + delete error[key]
215 + }
216 + }
217 +
218 + // replace stack before message for Node.js 0.10 and below
219 + error.stack = obj.stack.replace(error.message, obj.message)
220 + error.message = obj.message
221 +
222 + return error
223 +}
224 +
225 +/**
226 + * Get the simple type checker.
227 + *
228 + * @param {string} type
229 + * @return {function}
230 + */
231 +
232 +function typeChecker (type) {
233 + return function checkType (req) {
234 + return Boolean(typeis(req, type))
235 + }
236 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module dependencies.
11 + */
12 +
13 +var bytes = require('bytes')
14 +var debug = require('debug')('body-parser:raw')
15 +var read = require('../read')
16 +var typeis = require('type-is')
17 +
18 +/**
19 + * Module exports.
20 + */
21 +
22 +module.exports = raw
23 +
24 +/**
25 + * Create a middleware to parse raw bodies.
26 + *
27 + * @param {object} [options]
28 + * @return {function}
29 + * @api public
30 + */
31 +
32 +function raw (options) {
33 + var opts = options || {}
34 +
35 + var inflate = opts.inflate !== false
36 + var limit = typeof opts.limit !== 'number'
37 + ? bytes.parse(opts.limit || '100kb')
38 + : opts.limit
39 + var type = opts.type || 'application/octet-stream'
40 + var verify = opts.verify || false
41 +
42 + if (verify !== false && typeof verify !== 'function') {
43 + throw new TypeError('option verify must be function')
44 + }
45 +
46 + // create the appropriate type checking function
47 + var shouldParse = typeof type !== 'function'
48 + ? typeChecker(type)
49 + : type
50 +
51 + function parse (buf) {
52 + return buf
53 + }
54 +
55 + return function rawParser (req, res, next) {
56 + if (req._body) {
57 + debug('body already parsed')
58 + next()
59 + return
60 + }
61 +
62 + req.body = req.body || {}
63 +
64 + // skip requests without bodies
65 + if (!typeis.hasBody(req)) {
66 + debug('skip empty body')
67 + next()
68 + return
69 + }
70 +
71 + debug('content-type %j', req.headers['content-type'])
72 +
73 + // determine if request should be parsed
74 + if (!shouldParse(req)) {
75 + debug('skip parsing')
76 + next()
77 + return
78 + }
79 +
80 + // read
81 + read(req, res, next, parse, debug, {
82 + encoding: null,
83 + inflate: inflate,
84 + limit: limit,
85 + verify: verify
86 + })
87 + }
88 +}
89 +
90 +/**
91 + * Get the simple type checker.
92 + *
93 + * @param {string} type
94 + * @return {function}
95 + */
96 +
97 +function typeChecker (type) {
98 + return function checkType (req) {
99 + return Boolean(typeis(req, type))
100 + }
101 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module dependencies.
11 + */
12 +
13 +var bytes = require('bytes')
14 +var contentType = require('content-type')
15 +var debug = require('debug')('body-parser:text')
16 +var read = require('../read')
17 +var typeis = require('type-is')
18 +
19 +/**
20 + * Module exports.
21 + */
22 +
23 +module.exports = text
24 +
25 +/**
26 + * Create a middleware to parse text bodies.
27 + *
28 + * @param {object} [options]
29 + * @return {function}
30 + * @api public
31 + */
32 +
33 +function text (options) {
34 + var opts = options || {}
35 +
36 + var defaultCharset = opts.defaultCharset || 'utf-8'
37 + var inflate = opts.inflate !== false
38 + var limit = typeof opts.limit !== 'number'
39 + ? bytes.parse(opts.limit || '100kb')
40 + : opts.limit
41 + var type = opts.type || 'text/plain'
42 + var verify = opts.verify || false
43 +
44 + if (verify !== false && typeof verify !== 'function') {
45 + throw new TypeError('option verify must be function')
46 + }
47 +
48 + // create the appropriate type checking function
49 + var shouldParse = typeof type !== 'function'
50 + ? typeChecker(type)
51 + : type
52 +
53 + function parse (buf) {
54 + return buf
55 + }
56 +
57 + return function textParser (req, res, next) {
58 + if (req._body) {
59 + debug('body already parsed')
60 + next()
61 + return
62 + }
63 +
64 + req.body = req.body || {}
65 +
66 + // skip requests without bodies
67 + if (!typeis.hasBody(req)) {
68 + debug('skip empty body')
69 + next()
70 + return
71 + }
72 +
73 + debug('content-type %j', req.headers['content-type'])
74 +
75 + // determine if request should be parsed
76 + if (!shouldParse(req)) {
77 + debug('skip parsing')
78 + next()
79 + return
80 + }
81 +
82 + // get charset
83 + var charset = getCharset(req) || defaultCharset
84 +
85 + // read
86 + read(req, res, next, parse, debug, {
87 + encoding: charset,
88 + inflate: inflate,
89 + limit: limit,
90 + verify: verify
91 + })
92 + }
93 +}
94 +
95 +/**
96 + * Get the charset of a request.
97 + *
98 + * @param {object} req
99 + * @api private
100 + */
101 +
102 +function getCharset (req) {
103 + try {
104 + return (contentType.parse(req).parameters.charset || '').toLowerCase()
105 + } catch (e) {
106 + return undefined
107 + }
108 +}
109 +
110 +/**
111 + * Get the simple type checker.
112 + *
113 + * @param {string} type
114 + * @return {function}
115 + */
116 +
117 +function typeChecker (type) {
118 + return function checkType (req) {
119 + return Boolean(typeis(req, type))
120 + }
121 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014 Jonathan Ong
4 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict'
9 +
10 +/**
11 + * Module dependencies.
12 + * @private
13 + */
14 +
15 +var bytes = require('bytes')
16 +var contentType = require('content-type')
17 +var createError = require('http-errors')
18 +var debug = require('debug')('body-parser:urlencoded')
19 +var deprecate = require('depd')('body-parser')
20 +var read = require('../read')
21 +var typeis = require('type-is')
22 +
23 +/**
24 + * Module exports.
25 + */
26 +
27 +module.exports = urlencoded
28 +
29 +/**
30 + * Cache of parser modules.
31 + */
32 +
33 +var parsers = Object.create(null)
34 +
35 +/**
36 + * Create a middleware to parse urlencoded bodies.
37 + *
38 + * @param {object} [options]
39 + * @return {function}
40 + * @public
41 + */
42 +
43 +function urlencoded (options) {
44 + var opts = options || {}
45 +
46 + // notice because option default will flip in next major
47 + if (opts.extended === undefined) {
48 + deprecate('undefined extended: provide extended option')
49 + }
50 +
51 + var extended = opts.extended !== false
52 + var inflate = opts.inflate !== false
53 + var limit = typeof opts.limit !== 'number'
54 + ? bytes.parse(opts.limit || '100kb')
55 + : opts.limit
56 + var type = opts.type || 'application/x-www-form-urlencoded'
57 + var verify = opts.verify || false
58 +
59 + if (verify !== false && typeof verify !== 'function') {
60 + throw new TypeError('option verify must be function')
61 + }
62 +
63 + // create the appropriate query parser
64 + var queryparse = extended
65 + ? extendedparser(opts)
66 + : simpleparser(opts)
67 +
68 + // create the appropriate type checking function
69 + var shouldParse = typeof type !== 'function'
70 + ? typeChecker(type)
71 + : type
72 +
73 + function parse (body) {
74 + return body.length
75 + ? queryparse(body)
76 + : {}
77 + }
78 +
79 + return function urlencodedParser (req, res, next) {
80 + if (req._body) {
81 + debug('body already parsed')
82 + next()
83 + return
84 + }
85 +
86 + req.body = req.body || {}
87 +
88 + // skip requests without bodies
89 + if (!typeis.hasBody(req)) {
90 + debug('skip empty body')
91 + next()
92 + return
93 + }
94 +
95 + debug('content-type %j', req.headers['content-type'])
96 +
97 + // determine if request should be parsed
98 + if (!shouldParse(req)) {
99 + debug('skip parsing')
100 + next()
101 + return
102 + }
103 +
104 + // assert charset
105 + var charset = getCharset(req) || 'utf-8'
106 + if (charset !== 'utf-8') {
107 + debug('invalid charset')
108 + next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
109 + charset: charset,
110 + type: 'charset.unsupported'
111 + }))
112 + return
113 + }
114 +
115 + // read
116 + read(req, res, next, parse, debug, {
117 + debug: debug,
118 + encoding: charset,
119 + inflate: inflate,
120 + limit: limit,
121 + verify: verify
122 + })
123 + }
124 +}
125 +
126 +/**
127 + * Get the extended query parser.
128 + *
129 + * @param {object} options
130 + */
131 +
132 +function extendedparser (options) {
133 + var parameterLimit = options.parameterLimit !== undefined
134 + ? options.parameterLimit
135 + : 1000
136 + var parse = parser('qs')
137 +
138 + if (isNaN(parameterLimit) || parameterLimit < 1) {
139 + throw new TypeError('option parameterLimit must be a positive number')
140 + }
141 +
142 + if (isFinite(parameterLimit)) {
143 + parameterLimit = parameterLimit | 0
144 + }
145 +
146 + return function queryparse (body) {
147 + var paramCount = parameterCount(body, parameterLimit)
148 +
149 + if (paramCount === undefined) {
150 + debug('too many parameters')
151 + throw createError(413, 'too many parameters', {
152 + type: 'parameters.too.many'
153 + })
154 + }
155 +
156 + var arrayLimit = Math.max(100, paramCount)
157 +
158 + debug('parse extended urlencoding')
159 + return parse(body, {
160 + allowPrototypes: true,
161 + arrayLimit: arrayLimit,
162 + depth: Infinity,
163 + parameterLimit: parameterLimit
164 + })
165 + }
166 +}
167 +
168 +/**
169 + * Get the charset of a request.
170 + *
171 + * @param {object} req
172 + * @api private
173 + */
174 +
175 +function getCharset (req) {
176 + try {
177 + return (contentType.parse(req).parameters.charset || '').toLowerCase()
178 + } catch (e) {
179 + return undefined
180 + }
181 +}
182 +
183 +/**
184 + * Count the number of parameters, stopping once limit reached
185 + *
186 + * @param {string} body
187 + * @param {number} limit
188 + * @api private
189 + */
190 +
191 +function parameterCount (body, limit) {
192 + var count = 0
193 + var index = 0
194 +
195 + while ((index = body.indexOf('&', index)) !== -1) {
196 + count++
197 + index++
198 +
199 + if (count === limit) {
200 + return undefined
201 + }
202 + }
203 +
204 + return count
205 +}
206 +
207 +/**
208 + * Get parser for module name dynamically.
209 + *
210 + * @param {string} name
211 + * @return {function}
212 + * @api private
213 + */
214 +
215 +function parser (name) {
216 + var mod = parsers[name]
217 +
218 + if (mod !== undefined) {
219 + return mod.parse
220 + }
221 +
222 + // this uses a switch for static require analysis
223 + switch (name) {
224 + case 'qs':
225 + mod = require('qs')
226 + break
227 + case 'querystring':
228 + mod = require('querystring')
229 + break
230 + }
231 +
232 + // store to prevent invoking require()
233 + parsers[name] = mod
234 +
235 + return mod.parse
236 +}
237 +
238 +/**
239 + * Get the simple query parser.
240 + *
241 + * @param {object} options
242 + */
243 +
244 +function simpleparser (options) {
245 + var parameterLimit = options.parameterLimit !== undefined
246 + ? options.parameterLimit
247 + : 1000
248 + var parse = parser('querystring')
249 +
250 + if (isNaN(parameterLimit) || parameterLimit < 1) {
251 + throw new TypeError('option parameterLimit must be a positive number')
252 + }
253 +
254 + if (isFinite(parameterLimit)) {
255 + parameterLimit = parameterLimit | 0
256 + }
257 +
258 + return function queryparse (body) {
259 + var paramCount = parameterCount(body, parameterLimit)
260 +
261 + if (paramCount === undefined) {
262 + debug('too many parameters')
263 + throw createError(413, 'too many parameters', {
264 + type: 'parameters.too.many'
265 + })
266 + }
267 +
268 + debug('parse urlencoding')
269 + return parse(body, undefined, undefined, { maxKeys: parameterLimit })
270 + }
271 +}
272 +
273 +/**
274 + * Get the simple type checker.
275 + *
276 + * @param {string} type
277 + * @return {function}
278 + */
279 +
280 +function typeChecker (type) {
281 + return function checkType (req) {
282 + return Boolean(typeis(req, type))
283 + }
284 +}
1 +root = true
2 +
3 +[*]
4 +indent_style = space
5 +indent_size = 4
6 +end_of_line = lf
7 +charset = utf-8
8 +trim_trailing_whitespace = true
9 +insert_final_newline = true
10 +max_line_length = 160
11 +quote_type = single
12 +
13 +[test/*]
14 +max_line_length = off
15 +
16 +[LICENSE.md]
17 +indent_size = off
18 +
19 +[*.md]
20 +max_line_length = off
21 +
22 +[*.json]
23 +max_line_length = off
24 +
25 +[Makefile]
26 +max_line_length = off
27 +
28 +[CHANGELOG.md]
29 +indent_style = space
30 +indent_size = 2
31 +
32 +[LICENSE]
33 +indent_size = 2
34 +max_line_length = off
35 +
36 +[coverage/**/*]
37 +indent_size = off
38 +indent_style = off
39 +indent = off
40 +max_line_length = off
41 +
42 +[.nycrc]
43 +indent_style = tab
1 +{
2 + "root": true,
3 +
4 + "extends": "@ljharb",
5 +
6 + "ignorePatterns": [
7 + "dist/",
8 + ],
9 +
10 + "rules": {
11 + "complexity": 0,
12 + "consistent-return": 1,
13 + "func-name-matching": 0,
14 + "id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
15 + "indent": [2, 4],
16 + "max-lines-per-function": [2, { "max": 150 }],
17 + "max-params": [2, 16],
18 + "max-statements": [2, 53],
19 + "multiline-comment-style": 0,
20 + "no-continue": 1,
21 + "no-magic-numbers": 0,
22 + "no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
23 + },
24 +
25 + "overrides": [
26 + {
27 + "files": "test/**",
28 + "rules": {
29 + "function-paren-newline": 0,
30 + "max-lines-per-function": 0,
31 + "max-statements": 0,
32 + "no-buffer-constructor": 0,
33 + "no-extend-native": 0,
34 + "no-throw-literal": 0,
35 + },
36 + },
37 + ],
38 +}
1 +# These are supported funding model platforms
2 +
3 +github: [ljharb]
4 +patreon: # Replace with a single Patreon username
5 +open_collective: # Replace with a single Open Collective username
6 +ko_fi: # Replace with a single Ko-fi username
7 +tidelift: npm/qs
8 +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 +liberapay: # Replace with a single Liberapay username
10 +issuehunt: # Replace with a single IssueHunt username
11 +otechie: # Replace with a single Otechie username
12 +custom: # Replace with a single custom sponsorship URL
1 +{
2 + "all": true,
3 + "check-coverage": false,
4 + "reporter": ["text-summary", "text", "html", "json"],
5 + "lines": 86,
6 + "statements": 85.93,
7 + "functions": 82.43,
8 + "branches": 76.06,
9 + "exclude": [
10 + "coverage",
11 + "dist"
12 + ]
13 +}
This diff is collapsed. Click to expand it.
1 +BSD 3-Clause License
2 +
3 +Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/ljharb/qs/graphs/contributors)
4 +All rights reserved.
5 +
6 +Redistribution and use in source and binary forms, with or without
7 +modification, are permitted provided that the following conditions are met:
8 +
9 +1. Redistributions of source code must retain the above copyright notice, this
10 + list of conditions and the following disclaimer.
11 +
12 +2. Redistributions in binary form must reproduce the above copyright notice,
13 + this list of conditions and the following disclaimer in the documentation
14 + and/or other materials provided with the distribution.
15 +
16 +3. Neither the name of the copyright holder nor the names of its
17 + contributors may be used to endorse or promote products derived from
18 + this software without specific prior written permission.
19 +
20 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +'use strict';
2 +
3 +var replace = String.prototype.replace;
4 +var percentTwenties = /%20/g;
5 +
6 +var Format = {
7 + RFC1738: 'RFC1738',
8 + RFC3986: 'RFC3986'
9 +};
10 +
11 +module.exports = {
12 + 'default': Format.RFC3986,
13 + formatters: {
14 + RFC1738: function (value) {
15 + return replace.call(value, percentTwenties, '+');
16 + },
17 + RFC3986: function (value) {
18 + return String(value);
19 + }
20 + },
21 + RFC1738: Format.RFC1738,
22 + RFC3986: Format.RFC3986
23 +};
1 +'use strict';
2 +
3 +var stringify = require('./stringify');
4 +var parse = require('./parse');
5 +var formats = require('./formats');
6 +
7 +module.exports = {
8 + formats: formats,
9 + parse: parse,
10 + stringify: stringify
11 +};
1 +'use strict';
2 +
3 +var utils = require('./utils');
4 +
5 +var has = Object.prototype.hasOwnProperty;
6 +var isArray = Array.isArray;
7 +
8 +var defaults = {
9 + allowDots: false,
10 + allowPrototypes: false,
11 + allowSparse: false,
12 + arrayLimit: 20,
13 + charset: 'utf-8',
14 + charsetSentinel: false,
15 + comma: false,
16 + decoder: utils.decode,
17 + delimiter: '&',
18 + depth: 5,
19 + ignoreQueryPrefix: false,
20 + interpretNumericEntities: false,
21 + parameterLimit: 1000,
22 + parseArrays: true,
23 + plainObjects: false,
24 + strictNullHandling: false
25 +};
26 +
27 +var interpretNumericEntities = function (str) {
28 + return str.replace(/&#(\d+);/g, function ($0, numberStr) {
29 + return String.fromCharCode(parseInt(numberStr, 10));
30 + });
31 +};
32 +
33 +var parseArrayValue = function (val, options) {
34 + if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
35 + return val.split(',');
36 + }
37 +
38 + return val;
39 +};
40 +
41 +// This is what browsers will submit when the ✓ character occurs in an
42 +// application/x-www-form-urlencoded body and the encoding of the page containing
43 +// the form is iso-8859-1, or when the submitted form has an accept-charset
44 +// attribute of iso-8859-1. Presumably also with other charsets that do not contain
45 +// the ✓ character, such as us-ascii.
46 +var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('&#10003;')
47 +
48 +// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
49 +var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
50 +
51 +var parseValues = function parseQueryStringValues(str, options) {
52 + var obj = {};
53 + var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
54 + var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
55 + var parts = cleanStr.split(options.delimiter, limit);
56 + var skipIndex = -1; // Keep track of where the utf8 sentinel was found
57 + var i;
58 +
59 + var charset = options.charset;
60 + if (options.charsetSentinel) {
61 + for (i = 0; i < parts.length; ++i) {
62 + if (parts[i].indexOf('utf8=') === 0) {
63 + if (parts[i] === charsetSentinel) {
64 + charset = 'utf-8';
65 + } else if (parts[i] === isoSentinel) {
66 + charset = 'iso-8859-1';
67 + }
68 + skipIndex = i;
69 + i = parts.length; // The eslint settings do not allow break;
70 + }
71 + }
72 + }
73 +
74 + for (i = 0; i < parts.length; ++i) {
75 + if (i === skipIndex) {
76 + continue;
77 + }
78 + var part = parts[i];
79 +
80 + var bracketEqualsPos = part.indexOf(']=');
81 + var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
82 +
83 + var key, val;
84 + if (pos === -1) {
85 + key = options.decoder(part, defaults.decoder, charset, 'key');
86 + val = options.strictNullHandling ? null : '';
87 + } else {
88 + key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
89 + val = utils.maybeMap(
90 + parseArrayValue(part.slice(pos + 1), options),
91 + function (encodedVal) {
92 + return options.decoder(encodedVal, defaults.decoder, charset, 'value');
93 + }
94 + );
95 + }
96 +
97 + if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
98 + val = interpretNumericEntities(val);
99 + }
100 +
101 + if (part.indexOf('[]=') > -1) {
102 + val = isArray(val) ? [val] : val;
103 + }
104 +
105 + if (has.call(obj, key)) {
106 + obj[key] = utils.combine(obj[key], val);
107 + } else {
108 + obj[key] = val;
109 + }
110 + }
111 +
112 + return obj;
113 +};
114 +
115 +var parseObject = function (chain, val, options, valuesParsed) {
116 + var leaf = valuesParsed ? val : parseArrayValue(val, options);
117 +
118 + for (var i = chain.length - 1; i >= 0; --i) {
119 + var obj;
120 + var root = chain[i];
121 +
122 + if (root === '[]' && options.parseArrays) {
123 + obj = [].concat(leaf);
124 + } else {
125 + obj = options.plainObjects ? Object.create(null) : {};
126 + var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
127 + var index = parseInt(cleanRoot, 10);
128 + if (!options.parseArrays && cleanRoot === '') {
129 + obj = { 0: leaf };
130 + } else if (
131 + !isNaN(index)
132 + && root !== cleanRoot
133 + && String(index) === cleanRoot
134 + && index >= 0
135 + && (options.parseArrays && index <= options.arrayLimit)
136 + ) {
137 + obj = [];
138 + obj[index] = leaf;
139 + } else if (cleanRoot !== '__proto__') {
140 + obj[cleanRoot] = leaf;
141 + }
142 + }
143 +
144 + leaf = obj;
145 + }
146 +
147 + return leaf;
148 +};
149 +
150 +var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
151 + if (!givenKey) {
152 + return;
153 + }
154 +
155 + // Transform dot notation to bracket notation
156 + var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
157 +
158 + // The regex chunks
159 +
160 + var brackets = /(\[[^[\]]*])/;
161 + var child = /(\[[^[\]]*])/g;
162 +
163 + // Get the parent
164 +
165 + var segment = options.depth > 0 && brackets.exec(key);
166 + var parent = segment ? key.slice(0, segment.index) : key;
167 +
168 + // Stash the parent if it exists
169 +
170 + var keys = [];
171 + if (parent) {
172 + // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
173 + if (!options.plainObjects && has.call(Object.prototype, parent)) {
174 + if (!options.allowPrototypes) {
175 + return;
176 + }
177 + }
178 +
179 + keys.push(parent);
180 + }
181 +
182 + // Loop through children appending to the array until we hit depth
183 +
184 + var i = 0;
185 + while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
186 + i += 1;
187 + if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
188 + if (!options.allowPrototypes) {
189 + return;
190 + }
191 + }
192 + keys.push(segment[1]);
193 + }
194 +
195 + // If there's a remainder, just add whatever is left
196 +
197 + if (segment) {
198 + keys.push('[' + key.slice(segment.index) + ']');
199 + }
200 +
201 + return parseObject(keys, val, options, valuesParsed);
202 +};
203 +
204 +var normalizeParseOptions = function normalizeParseOptions(opts) {
205 + if (!opts) {
206 + return defaults;
207 + }
208 +
209 + if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
210 + throw new TypeError('Decoder has to be a function.');
211 + }
212 +
213 + if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
214 + throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
215 + }
216 + var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
217 +
218 + return {
219 + allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
220 + allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
221 + allowSparse: typeof opts.allowSparse === 'boolean' ? opts.allowSparse : defaults.allowSparse,
222 + arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
223 + charset: charset,
224 + charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
225 + comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
226 + decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
227 + delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
228 + // eslint-disable-next-line no-implicit-coercion, no-extra-parens
229 + depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth,
230 + ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
231 + interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
232 + parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
233 + parseArrays: opts.parseArrays !== false,
234 + plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
235 + strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
236 + };
237 +};
238 +
239 +module.exports = function (str, opts) {
240 + var options = normalizeParseOptions(opts);
241 +
242 + if (str === '' || str === null || typeof str === 'undefined') {
243 + return options.plainObjects ? Object.create(null) : {};
244 + }
245 +
246 + var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
247 + var obj = options.plainObjects ? Object.create(null) : {};
248 +
249 + // Iterate over the keys and setup the new object
250 +
251 + var keys = Object.keys(tempObj);
252 + for (var i = 0; i < keys.length; ++i) {
253 + var key = keys[i];
254 + var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string');
255 + obj = utils.merge(obj, newObj, options);
256 + }
257 +
258 + if (options.allowSparse === true) {
259 + return obj;
260 + }
261 +
262 + return utils.compact(obj);
263 +};
This diff is collapsed. Click to expand it.
1 +'use strict';
2 +
3 +var formats = require('./formats');
4 +
5 +var has = Object.prototype.hasOwnProperty;
6 +var isArray = Array.isArray;
7 +
8 +var hexTable = (function () {
9 + var array = [];
10 + for (var i = 0; i < 256; ++i) {
11 + array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
12 + }
13 +
14 + return array;
15 +}());
16 +
17 +var compactQueue = function compactQueue(queue) {
18 + while (queue.length > 1) {
19 + var item = queue.pop();
20 + var obj = item.obj[item.prop];
21 +
22 + if (isArray(obj)) {
23 + var compacted = [];
24 +
25 + for (var j = 0; j < obj.length; ++j) {
26 + if (typeof obj[j] !== 'undefined') {
27 + compacted.push(obj[j]);
28 + }
29 + }
30 +
31 + item.obj[item.prop] = compacted;
32 + }
33 + }
34 +};
35 +
36 +var arrayToObject = function arrayToObject(source, options) {
37 + var obj = options && options.plainObjects ? Object.create(null) : {};
38 + for (var i = 0; i < source.length; ++i) {
39 + if (typeof source[i] !== 'undefined') {
40 + obj[i] = source[i];
41 + }
42 + }
43 +
44 + return obj;
45 +};
46 +
47 +var merge = function merge(target, source, options) {
48 + /* eslint no-param-reassign: 0 */
49 + if (!source) {
50 + return target;
51 + }
52 +
53 + if (typeof source !== 'object') {
54 + if (isArray(target)) {
55 + target.push(source);
56 + } else if (target && typeof target === 'object') {
57 + if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
58 + target[source] = true;
59 + }
60 + } else {
61 + return [target, source];
62 + }
63 +
64 + return target;
65 + }
66 +
67 + if (!target || typeof target !== 'object') {
68 + return [target].concat(source);
69 + }
70 +
71 + var mergeTarget = target;
72 + if (isArray(target) && !isArray(source)) {
73 + mergeTarget = arrayToObject(target, options);
74 + }
75 +
76 + if (isArray(target) && isArray(source)) {
77 + source.forEach(function (item, i) {
78 + if (has.call(target, i)) {
79 + var targetItem = target[i];
80 + if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
81 + target[i] = merge(targetItem, item, options);
82 + } else {
83 + target.push(item);
84 + }
85 + } else {
86 + target[i] = item;
87 + }
88 + });
89 + return target;
90 + }
91 +
92 + return Object.keys(source).reduce(function (acc, key) {
93 + var value = source[key];
94 +
95 + if (has.call(acc, key)) {
96 + acc[key] = merge(acc[key], value, options);
97 + } else {
98 + acc[key] = value;
99 + }
100 + return acc;
101 + }, mergeTarget);
102 +};
103 +
104 +var assign = function assignSingleSource(target, source) {
105 + return Object.keys(source).reduce(function (acc, key) {
106 + acc[key] = source[key];
107 + return acc;
108 + }, target);
109 +};
110 +
111 +var decode = function (str, decoder, charset) {
112 + var strWithoutPlus = str.replace(/\+/g, ' ');
113 + if (charset === 'iso-8859-1') {
114 + // unescape never throws, no try...catch needed:
115 + return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
116 + }
117 + // utf-8
118 + try {
119 + return decodeURIComponent(strWithoutPlus);
120 + } catch (e) {
121 + return strWithoutPlus;
122 + }
123 +};
124 +
125 +var encode = function encode(str, defaultEncoder, charset, kind, format) {
126 + // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
127 + // It has been adapted here for stricter adherence to RFC 3986
128 + if (str.length === 0) {
129 + return str;
130 + }
131 +
132 + var string = str;
133 + if (typeof str === 'symbol') {
134 + string = Symbol.prototype.toString.call(str);
135 + } else if (typeof str !== 'string') {
136 + string = String(str);
137 + }
138 +
139 + if (charset === 'iso-8859-1') {
140 + return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
141 + return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
142 + });
143 + }
144 +
145 + var out = '';
146 + for (var i = 0; i < string.length; ++i) {
147 + var c = string.charCodeAt(i);
148 +
149 + if (
150 + c === 0x2D // -
151 + || c === 0x2E // .
152 + || c === 0x5F // _
153 + || c === 0x7E // ~
154 + || (c >= 0x30 && c <= 0x39) // 0-9
155 + || (c >= 0x41 && c <= 0x5A) // a-z
156 + || (c >= 0x61 && c <= 0x7A) // A-Z
157 + || (format === formats.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
158 + ) {
159 + out += string.charAt(i);
160 + continue;
161 + }
162 +
163 + if (c < 0x80) {
164 + out = out + hexTable[c];
165 + continue;
166 + }
167 +
168 + if (c < 0x800) {
169 + out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
170 + continue;
171 + }
172 +
173 + if (c < 0xD800 || c >= 0xE000) {
174 + out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
175 + continue;
176 + }
177 +
178 + i += 1;
179 + c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
180 + /* eslint operator-linebreak: [2, "before"] */
181 + out += hexTable[0xF0 | (c >> 18)]
182 + + hexTable[0x80 | ((c >> 12) & 0x3F)]
183 + + hexTable[0x80 | ((c >> 6) & 0x3F)]
184 + + hexTable[0x80 | (c & 0x3F)];
185 + }
186 +
187 + return out;
188 +};
189 +
190 +var compact = function compact(value) {
191 + var queue = [{ obj: { o: value }, prop: 'o' }];
192 + var refs = [];
193 +
194 + for (var i = 0; i < queue.length; ++i) {
195 + var item = queue[i];
196 + var obj = item.obj[item.prop];
197 +
198 + var keys = Object.keys(obj);
199 + for (var j = 0; j < keys.length; ++j) {
200 + var key = keys[j];
201 + var val = obj[key];
202 + if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
203 + queue.push({ obj: obj, prop: key });
204 + refs.push(val);
205 + }
206 + }
207 + }
208 +
209 + compactQueue(queue);
210 +
211 + return value;
212 +};
213 +
214 +var isRegExp = function isRegExp(obj) {
215 + return Object.prototype.toString.call(obj) === '[object RegExp]';
216 +};
217 +
218 +var isBuffer = function isBuffer(obj) {
219 + if (!obj || typeof obj !== 'object') {
220 + return false;
221 + }
222 +
223 + return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
224 +};
225 +
226 +var combine = function combine(a, b) {
227 + return [].concat(a, b);
228 +};
229 +
230 +var maybeMap = function maybeMap(val, fn) {
231 + if (isArray(val)) {
232 + var mapped = [];
233 + for (var i = 0; i < val.length; i += 1) {
234 + mapped.push(fn(val[i]));
235 + }
236 + return mapped;
237 + }
238 + return fn(val);
239 +};
240 +
241 +module.exports = {
242 + arrayToObject: arrayToObject,
243 + assign: assign,
244 + combine: combine,
245 + compact: compact,
246 + decode: decode,
247 + encode: encode,
248 + isBuffer: isBuffer,
249 + isRegExp: isRegExp,
250 + maybeMap: maybeMap,
251 + merge: merge
252 +};
1 +{
2 + "name": "qs",
3 + "description": "A querystring parser that supports nesting and arrays, with a depth limit",
4 + "homepage": "https://github.com/ljharb/qs",
5 + "version": "6.11.0",
6 + "repository": {
7 + "type": "git",
8 + "url": "https://github.com/ljharb/qs.git"
9 + },
10 + "funding": {
11 + "url": "https://github.com/sponsors/ljharb"
12 + },
13 + "main": "lib/index.js",
14 + "contributors": [
15 + {
16 + "name": "Jordan Harband",
17 + "email": "ljharb@gmail.com",
18 + "url": "http://ljharb.codes"
19 + }
20 + ],
21 + "keywords": [
22 + "querystring",
23 + "qs",
24 + "query",
25 + "url",
26 + "parse",
27 + "stringify"
28 + ],
29 + "engines": {
30 + "node": ">=0.6"
31 + },
32 + "dependencies": {
33 + "side-channel": "^1.0.4"
34 + },
35 + "devDependencies": {
36 + "@ljharb/eslint-config": "^21.0.0",
37 + "aud": "^2.0.0",
38 + "browserify": "^16.5.2",
39 + "eclint": "^2.8.1",
40 + "eslint": "=8.8.0",
41 + "evalmd": "^0.0.19",
42 + "for-each": "^0.3.3",
43 + "has-symbols": "^1.0.3",
44 + "iconv-lite": "^0.5.1",
45 + "in-publish": "^2.0.1",
46 + "mkdirp": "^0.5.5",
47 + "npmignore": "^0.3.0",
48 + "nyc": "^10.3.2",
49 + "object-inspect": "^1.12.2",
50 + "qs-iconv": "^1.0.4",
51 + "safe-publish-latest": "^2.0.0",
52 + "safer-buffer": "^2.1.2",
53 + "tape": "^5.5.3"
54 + },
55 + "scripts": {
56 + "prepack": "npmignore --auto --commentLines=autogenerated",
57 + "prepublishOnly": "safe-publish-latest && npm run dist",
58 + "prepublish": "not-in-publish || npm run prepublishOnly",
59 + "pretest": "npm run --silent readme && npm run --silent lint",
60 + "test": "npm run tests-only",
61 + "tests-only": "nyc tape 'test/**/*.js'",
62 + "posttest": "aud --production",
63 + "readme": "evalmd README.md",
64 + "postlint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)",
65 + "lint": "eslint --ext=js,mjs .",
66 + "dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js"
67 + },
68 + "license": "BSD-3-Clause",
69 + "publishConfig": {
70 + "ignore": [
71 + "!dist/*",
72 + "bower.json",
73 + "component.json",
74 + ".github/workflows"
75 + ]
76 + }
77 +}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +'use strict';
2 +
3 +var test = require('tape');
4 +var inspect = require('object-inspect');
5 +var SaferBuffer = require('safer-buffer').Buffer;
6 +var forEach = require('for-each');
7 +var utils = require('../lib/utils');
8 +
9 +test('merge()', function (t) {
10 + t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null');
11 +
12 + t.deepEqual(utils.merge(null, [42]), [null, 42], 'merges null into an array');
13 +
14 + t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
15 +
16 + var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });
17 + t.deepEqual(oneMerged, { foo: ['bar', { first: '123' }] }, 'merges a standalone and an object into an array');
18 +
19 + var twoMerged = utils.merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } });
20 + t.deepEqual(twoMerged, { foo: { 0: 'bar', 1: { first: '123' }, second: '456' } }, 'merges a standalone and two objects into an array');
21 +
22 + var sandwiched = utils.merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' });
23 + t.deepEqual(sandwiched, { foo: ['bar', { first: '123', second: '456' }, 'baz'] }, 'merges an object sandwiched by two standalones into an array');
24 +
25 + var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
26 + t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });
27 +
28 + var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
29 + t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
30 +
31 + t.test(
32 + 'avoids invoking array setters unnecessarily',
33 + { skip: typeof Object.defineProperty !== 'function' },
34 + function (st) {
35 + var setCount = 0;
36 + var getCount = 0;
37 + var observed = [];
38 + Object.defineProperty(observed, 0, {
39 + get: function () {
40 + getCount += 1;
41 + return { bar: 'baz' };
42 + },
43 + set: function () { setCount += 1; }
44 + });
45 + utils.merge(observed, [null]);
46 + st.equal(setCount, 0);
47 + st.equal(getCount, 1);
48 + observed[0] = observed[0]; // eslint-disable-line no-self-assign
49 + st.equal(setCount, 1);
50 + st.equal(getCount, 2);
51 + st.end();
52 + }
53 + );
54 +
55 + t.end();
56 +});
57 +
58 +test('assign()', function (t) {
59 + var target = { a: 1, b: 2 };
60 + var source = { b: 3, c: 4 };
61 + var result = utils.assign(target, source);
62 +
63 + t.equal(result, target, 'returns the target');
64 + t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged');
65 + t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched');
66 +
67 + t.end();
68 +});
69 +
70 +test('combine()', function (t) {
71 + t.test('both arrays', function (st) {
72 + var a = [1];
73 + var b = [2];
74 + var combined = utils.combine(a, b);
75 +
76 + st.deepEqual(a, [1], 'a is not mutated');
77 + st.deepEqual(b, [2], 'b is not mutated');
78 + st.notEqual(a, combined, 'a !== combined');
79 + st.notEqual(b, combined, 'b !== combined');
80 + st.deepEqual(combined, [1, 2], 'combined is a + b');
81 +
82 + st.end();
83 + });
84 +
85 + t.test('one array, one non-array', function (st) {
86 + var aN = 1;
87 + var a = [aN];
88 + var bN = 2;
89 + var b = [bN];
90 +
91 + var combinedAnB = utils.combine(aN, b);
92 + st.deepEqual(b, [bN], 'b is not mutated');
93 + st.notEqual(aN, combinedAnB, 'aN + b !== aN');
94 + st.notEqual(a, combinedAnB, 'aN + b !== a');
95 + st.notEqual(bN, combinedAnB, 'aN + b !== bN');
96 + st.notEqual(b, combinedAnB, 'aN + b !== b');
97 + st.deepEqual([1, 2], combinedAnB, 'first argument is array-wrapped when not an array');
98 +
99 + var combinedABn = utils.combine(a, bN);
100 + st.deepEqual(a, [aN], 'a is not mutated');
101 + st.notEqual(aN, combinedABn, 'a + bN !== aN');
102 + st.notEqual(a, combinedABn, 'a + bN !== a');
103 + st.notEqual(bN, combinedABn, 'a + bN !== bN');
104 + st.notEqual(b, combinedABn, 'a + bN !== b');
105 + st.deepEqual([1, 2], combinedABn, 'second argument is array-wrapped when not an array');
106 +
107 + st.end();
108 + });
109 +
110 + t.test('neither is an array', function (st) {
111 + var combined = utils.combine(1, 2);
112 + st.notEqual(1, combined, '1 + 2 !== 1');
113 + st.notEqual(2, combined, '1 + 2 !== 2');
114 + st.deepEqual([1, 2], combined, 'both arguments are array-wrapped when not an array');
115 +
116 + st.end();
117 + });
118 +
119 + t.end();
120 +});
121 +
122 +test('isBuffer()', function (t) {
123 + forEach([null, undefined, true, false, '', 'abc', 42, 0, NaN, {}, [], function () {}, /a/g], function (x) {
124 + t.equal(utils.isBuffer(x), false, inspect(x) + ' is not a buffer');
125 + });
126 +
127 + var fakeBuffer = { constructor: Buffer };
128 + t.equal(utils.isBuffer(fakeBuffer), false, 'fake buffer is not a buffer');
129 +
130 + var saferBuffer = SaferBuffer.from('abc');
131 + t.equal(utils.isBuffer(saferBuffer), true, 'SaferBuffer instance is a buffer');
132 +
133 + var buffer = Buffer.from && Buffer.alloc ? Buffer.from('abc') : new Buffer('abc');
134 + t.equal(utils.isBuffer(buffer), true, 'real Buffer instance is a buffer');
135 + t.end();
136 +});
1 +{
2 + "name": "body-parser",
3 + "description": "Node.js body parsing middleware",
4 + "version": "1.20.1",
5 + "contributors": [
6 + "Douglas Christopher Wilson <doug@somethingdoug.com>",
7 + "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
8 + ],
9 + "license": "MIT",
10 + "repository": "expressjs/body-parser",
11 + "dependencies": {
12 + "bytes": "3.1.2",
13 + "content-type": "~1.0.4",
14 + "debug": "2.6.9",
15 + "depd": "2.0.0",
16 + "destroy": "1.2.0",
17 + "http-errors": "2.0.0",
18 + "iconv-lite": "0.4.24",
19 + "on-finished": "2.4.1",
20 + "qs": "6.11.0",
21 + "raw-body": "2.5.1",
22 + "type-is": "~1.6.18",
23 + "unpipe": "1.0.0"
24 + },
25 + "devDependencies": {
26 + "eslint": "8.24.0",
27 + "eslint-config-standard": "14.1.1",
28 + "eslint-plugin-import": "2.26.0",
29 + "eslint-plugin-markdown": "3.0.0",
30 + "eslint-plugin-node": "11.1.0",
31 + "eslint-plugin-promise": "6.0.1",
32 + "eslint-plugin-standard": "4.1.0",
33 + "methods": "1.1.2",
34 + "mocha": "10.0.0",
35 + "nyc": "15.1.0",
36 + "safe-buffer": "5.2.1",
37 + "supertest": "6.3.0"
38 + },
39 + "files": [
40 + "lib/",
41 + "LICENSE",
42 + "HISTORY.md",
43 + "SECURITY.md",
44 + "index.js"
45 + ],
46 + "engines": {
47 + "node": ">= 0.8",
48 + "npm": "1.2.8000 || >= 1.4.16"
49 + },
50 + "scripts": {
51 + "lint": "eslint .",
52 + "test": "mocha --require test/support/env --reporter spec --check-leaks --bail test/",
53 + "test-ci": "nyc --reporter=lcov --reporter=text npm test",
54 + "test-cov": "nyc --reporter=html --reporter=text npm test"
55 + }
56 +}
1 +3.1.2 / 2022-01-27
2 +==================
3 +
4 + * Fix return value for un-parsable strings
5 +
6 +3.1.1 / 2021-11-15
7 +==================
8 +
9 + * Fix "thousandsSeparator" incorrecting formatting fractional part
10 +
11 +3.1.0 / 2019-01-22
12 +==================
13 +
14 + * Add petabyte (`pb`) support
15 +
16 +3.0.0 / 2017-08-31
17 +==================
18 +
19 + * Change "kB" to "KB" in format output
20 + * Remove support for Node.js 0.6
21 + * Remove support for ComponentJS
22 +
23 +2.5.0 / 2017-03-24
24 +==================
25 +
26 + * Add option "unit"
27 +
28 +2.4.0 / 2016-06-01
29 +==================
30 +
31 + * Add option "unitSeparator"
32 +
33 +2.3.0 / 2016-02-15
34 +==================
35 +
36 + * Drop partial bytes on all parsed units
37 + * Fix non-finite numbers to `.format` to return `null`
38 + * Fix parsing byte string that looks like hex
39 + * perf: hoist regular expressions
40 +
41 +2.2.0 / 2015-11-13
42 +==================
43 +
44 + * add option "decimalPlaces"
45 + * add option "fixedDecimals"
46 +
47 +2.1.0 / 2015-05-21
48 +==================
49 +
50 + * add `.format` export
51 + * add `.parse` export
52 +
53 +2.0.2 / 2015-05-20
54 +==================
55 +
56 + * remove map recreation
57 + * remove unnecessary object construction
58 +
59 +2.0.1 / 2015-05-07
60 +==================
61 +
62 + * fix browserify require
63 + * remove node.extend dependency
64 +
65 +2.0.0 / 2015-04-12
66 +==================
67 +
68 + * add option "case"
69 + * add option "thousandsSeparator"
70 + * return "null" on invalid parse input
71 + * support proper round-trip: bytes(bytes(num)) === num
72 + * units no longer case sensitive when parsing
73 +
74 +1.0.0 / 2014-05-05
75 +==================
76 +
77 + * add negative support. fixes #6
78 +
79 +0.3.0 / 2014-03-19
80 +==================
81 +
82 + * added terabyte support
83 +
84 +0.2.1 / 2013-04-01
85 +==================
86 +
87 + * add .component
88 +
89 +0.2.0 / 2012-10-28
90 +==================
91 +
92 + * bytes(200).should.eql('200b')
93 +
94 +0.1.0 / 2012-07-04
95 +==================
96 +
97 + * add bytes to string conversion [yields]
1 +(The MIT License)
2 +
3 +Copyright (c) 2012-2014 TJ Holowaychuk <tj@vision-media.ca>
4 +Copyright (c) 2015 Jed Watson <jed.watson@me.com>
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining
7 +a copy of this software and associated documentation files (the
8 +'Software'), to deal in the Software without restriction, including
9 +without limitation the rights to use, copy, modify, merge, publish,
10 +distribute, sublicense, and/or sell copies of the Software, and to
11 +permit persons to whom the Software is furnished to do so, subject to
12 +the following conditions:
13 +
14 +The above copyright notice and this permission notice shall be
15 +included in all copies or substantial portions of the Software.
16 +
17 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# Bytes utility
2 +
3 +[![NPM Version][npm-image]][npm-url]
4 +[![NPM Downloads][downloads-image]][downloads-url]
5 +[![Build Status][ci-image]][ci-url]
6 +[![Test Coverage][coveralls-image]][coveralls-url]
7 +
8 +Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
9 +
10 +## Installation
11 +
12 +This is a [Node.js](https://nodejs.org/en/) module available through the
13 +[npm registry](https://www.npmjs.com/). Installation is done using the
14 +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
15 +
16 +```bash
17 +$ npm install bytes
18 +```
19 +
20 +## Usage
21 +
22 +```js
23 +var bytes = require('bytes');
24 +```
25 +
26 +#### bytes(number|string value, [options]): number|string|null
27 +
28 +Default export function. Delegates to either `bytes.format` or `bytes.parse` based on the type of `value`.
29 +
30 +**Arguments**
31 +
32 +| Name | Type | Description |
33 +|---------|----------|--------------------|
34 +| value | `number``string` | Number value to format or string value to parse |
35 +| options | `Object` | Conversion options for `format` |
36 +
37 +**Returns**
38 +
39 +| Name | Type | Description |
40 +|---------|------------------|-------------------------------------------------|
41 +| results | `string``number``null` | Return null upon error. Numeric value in bytes, or string value otherwise. |
42 +
43 +**Example**
44 +
45 +```js
46 +bytes(1024);
47 +// output: '1KB'
48 +
49 +bytes('1KB');
50 +// output: 1024
51 +```
52 +
53 +#### bytes.format(number value, [options]): string|null
54 +
55 +Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is
56 + rounded.
57 +
58 +**Arguments**
59 +
60 +| Name | Type | Description |
61 +|---------|----------|--------------------|
62 +| value | `number` | Value in bytes |
63 +| options | `Object` | Conversion options |
64 +
65 +**Options**
66 +
67 +| Property | Type | Description |
68 +|-------------------|--------|-----------------------------------------------------------------------------------------|
69 +| decimalPlaces | `number``null` | Maximum number of decimal places to include in output. Default value to `2`. |
70 +| fixedDecimals | `boolean``null` | Whether to always display the maximum number of decimal places. Default value to `false` |
71 +| thousandsSeparator | `string``null` | Example of values: `' '`, `','` and `'.'`... Default value to `''`. |
72 +| unit | `string``null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |
73 +| unitSeparator | `string``null` | Separator to use between number and unit. Default value to `''`. |
74 +
75 +**Returns**
76 +
77 +| Name | Type | Description |
78 +|---------|------------------|-------------------------------------------------|
79 +| results | `string``null` | Return null upon error. String value otherwise. |
80 +
81 +**Example**
82 +
83 +```js
84 +bytes.format(1024);
85 +// output: '1KB'
86 +
87 +bytes.format(1000);
88 +// output: '1000B'
89 +
90 +bytes.format(1000, {thousandsSeparator: ' '});
91 +// output: '1 000B'
92 +
93 +bytes.format(1024 * 1.7, {decimalPlaces: 0});
94 +// output: '2KB'
95 +
96 +bytes.format(1024, {unitSeparator: ' '});
97 +// output: '1 KB'
98 +```
99 +
100 +#### bytes.parse(string|number value): number|null
101 +
102 +Parse the string value into an integer in bytes. If no unit is given, or `value`
103 +is a number, it is assumed the value is in bytes.
104 +
105 +Supported units and abbreviations are as follows and are case-insensitive:
106 +
107 + * `b` for bytes
108 + * `kb` for kilobytes
109 + * `mb` for megabytes
110 + * `gb` for gigabytes
111 + * `tb` for terabytes
112 + * `pb` for petabytes
113 +
114 +The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
115 +
116 +**Arguments**
117 +
118 +| Name | Type | Description |
119 +|---------------|--------|--------------------|
120 +| value | `string``number` | String to parse, or number in bytes. |
121 +
122 +**Returns**
123 +
124 +| Name | Type | Description |
125 +|---------|-------------|-------------------------|
126 +| results | `number``null` | Return null upon error. Value in bytes otherwise. |
127 +
128 +**Example**
129 +
130 +```js
131 +bytes.parse('1KB');
132 +// output: 1024
133 +
134 +bytes.parse('1024');
135 +// output: 1024
136 +
137 +bytes.parse(1024);
138 +// output: 1024
139 +```
140 +
141 +## License
142 +
143 +[MIT](LICENSE)
144 +
145 +[ci-image]: https://badgen.net/github/checks/visionmedia/bytes.js/master?label=ci
146 +[ci-url]: https://github.com/visionmedia/bytes.js/actions?query=workflow%3Aci
147 +[coveralls-image]: https://badgen.net/coveralls/c/github/visionmedia/bytes.js/master
148 +[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master
149 +[downloads-image]: https://badgen.net/npm/dm/bytes
150 +[downloads-url]: https://npmjs.org/package/bytes
151 +[npm-image]: https://badgen.net/npm/v/bytes
152 +[npm-url]: https://npmjs.org/package/bytes
1 +/*!
2 + * bytes
3 + * Copyright(c) 2012-2014 TJ Holowaychuk
4 + * Copyright(c) 2015 Jed Watson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict';
9 +
10 +/**
11 + * Module exports.
12 + * @public
13 + */
14 +
15 +module.exports = bytes;
16 +module.exports.format = format;
17 +module.exports.parse = parse;
18 +
19 +/**
20 + * Module variables.
21 + * @private
22 + */
23 +
24 +var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g;
25 +
26 +var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/;
27 +
28 +var map = {
29 + b: 1,
30 + kb: 1 << 10,
31 + mb: 1 << 20,
32 + gb: 1 << 30,
33 + tb: Math.pow(1024, 4),
34 + pb: Math.pow(1024, 5),
35 +};
36 +
37 +var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i;
38 +
39 +/**
40 + * Convert the given value in bytes into a string or parse to string to an integer in bytes.
41 + *
42 + * @param {string|number} value
43 + * @param {{
44 + * case: [string],
45 + * decimalPlaces: [number]
46 + * fixedDecimals: [boolean]
47 + * thousandsSeparator: [string]
48 + * unitSeparator: [string]
49 + * }} [options] bytes options.
50 + *
51 + * @returns {string|number|null}
52 + */
53 +
54 +function bytes(value, options) {
55 + if (typeof value === 'string') {
56 + return parse(value);
57 + }
58 +
59 + if (typeof value === 'number') {
60 + return format(value, options);
61 + }
62 +
63 + return null;
64 +}
65 +
66 +/**
67 + * Format the given value in bytes into a string.
68 + *
69 + * If the value is negative, it is kept as such. If it is a float,
70 + * it is rounded.
71 + *
72 + * @param {number} value
73 + * @param {object} [options]
74 + * @param {number} [options.decimalPlaces=2]
75 + * @param {number} [options.fixedDecimals=false]
76 + * @param {string} [options.thousandsSeparator=]
77 + * @param {string} [options.unit=]
78 + * @param {string} [options.unitSeparator=]
79 + *
80 + * @returns {string|null}
81 + * @public
82 + */
83 +
84 +function format(value, options) {
85 + if (!Number.isFinite(value)) {
86 + return null;
87 + }
88 +
89 + var mag = Math.abs(value);
90 + var thousandsSeparator = (options && options.thousandsSeparator) || '';
91 + var unitSeparator = (options && options.unitSeparator) || '';
92 + var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;
93 + var fixedDecimals = Boolean(options && options.fixedDecimals);
94 + var unit = (options && options.unit) || '';
95 +
96 + if (!unit || !map[unit.toLowerCase()]) {
97 + if (mag >= map.pb) {
98 + unit = 'PB';
99 + } else if (mag >= map.tb) {
100 + unit = 'TB';
101 + } else if (mag >= map.gb) {
102 + unit = 'GB';
103 + } else if (mag >= map.mb) {
104 + unit = 'MB';
105 + } else if (mag >= map.kb) {
106 + unit = 'KB';
107 + } else {
108 + unit = 'B';
109 + }
110 + }
111 +
112 + var val = value / map[unit.toLowerCase()];
113 + var str = val.toFixed(decimalPlaces);
114 +
115 + if (!fixedDecimals) {
116 + str = str.replace(formatDecimalsRegExp, '$1');
117 + }
118 +
119 + if (thousandsSeparator) {
120 + str = str.split('.').map(function (s, i) {
121 + return i === 0
122 + ? s.replace(formatThousandsRegExp, thousandsSeparator)
123 + : s
124 + }).join('.');
125 + }
126 +
127 + return str + unitSeparator + unit;
128 +}
129 +
130 +/**
131 + * Parse the string value into an integer in bytes.
132 + *
133 + * If no unit is given, it is assumed the value is in bytes.
134 + *
135 + * @param {number|string} val
136 + *
137 + * @returns {number|null}
138 + * @public
139 + */
140 +
141 +function parse(val) {
142 + if (typeof val === 'number' && !isNaN(val)) {
143 + return val;
144 + }
145 +
146 + if (typeof val !== 'string') {
147 + return null;
148 + }
149 +
150 + // Test if the string passed is valid
151 + var results = parseRegExp.exec(val);
152 + var floatValue;
153 + var unit = 'b';
154 +
155 + if (!results) {
156 + // Nothing could be extracted from the given string
157 + floatValue = parseInt(val, 10);
158 + unit = 'b'
159 + } else {
160 + // Retrieve the value and the unit
161 + floatValue = parseFloat(results[1]);
162 + unit = results[4].toLowerCase();
163 + }
164 +
165 + if (isNaN(floatValue)) {
166 + return null;
167 + }
168 +
169 + return Math.floor(map[unit] * floatValue);
170 +}
1 +{
2 + "name": "bytes",
3 + "description": "Utility to parse a string bytes to bytes and vice-versa",
4 + "version": "3.1.2",
5 + "author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
6 + "contributors": [
7 + "Jed Watson <jed.watson@me.com>",
8 + "Théo FIDRY <theo.fidry@gmail.com>"
9 + ],
10 + "license": "MIT",
11 + "keywords": [
12 + "byte",
13 + "bytes",
14 + "utility",
15 + "parse",
16 + "parser",
17 + "convert",
18 + "converter"
19 + ],
20 + "repository": "visionmedia/bytes.js",
21 + "devDependencies": {
22 + "eslint": "7.32.0",
23 + "eslint-plugin-markdown": "2.2.1",
24 + "mocha": "9.2.0",
25 + "nyc": "15.1.0"
26 + },
27 + "files": [
28 + "History.md",
29 + "LICENSE",
30 + "Readme.md",
31 + "index.js"
32 + ],
33 + "engines": {
34 + "node": ">= 0.8"
35 + },
36 + "scripts": {
37 + "lint": "eslint .",
38 + "test": "mocha --check-leaks --reporter spec",
39 + "test-ci": "nyc --reporter=lcov --reporter=text npm test",
40 + "test-cov": "nyc --reporter=html --reporter=text npm test"
41 + }
42 +}
1 +{
2 + "root": true,
3 +
4 + "extends": "@ljharb",
5 +
6 + "rules": {
7 + "func-name-matching": 0,
8 + "id-length": 0,
9 + "new-cap": [2, {
10 + "capIsNewExceptions": [
11 + "GetIntrinsic",
12 + ],
13 + }],
14 + "no-magic-numbers": 0,
15 + "operator-linebreak": [2, "before"],
16 + },
17 +}
1 +# These are supported funding model platforms
2 +
3 +github: [ljharb]
4 +patreon: # Replace with a single Patreon username
5 +open_collective: # Replace with a single Open Collective username
6 +ko_fi: # Replace with a single Ko-fi username
7 +tidelift: npm/call-bind
8 +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 +liberapay: # Replace with a single Liberapay username
10 +issuehunt: # Replace with a single IssueHunt username
11 +otechie: # Replace with a single Otechie username
12 +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1 +{
2 + "all": true,
3 + "check-coverage": false,
4 + "reporter": ["text-summary", "text", "html", "json"],
5 + "lines": 86,
6 + "statements": 85.93,
7 + "functions": 82.43,
8 + "branches": 76.06,
9 + "exclude": [
10 + "coverage",
11 + "test"
12 + ]
13 +}
1 +# Changelog
2 +
3 +All notable changes to this project will be documented in this file.
4 +
5 +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6 +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 +
8 +## [v1.0.2](https://github.com/ljharb/call-bind/compare/v1.0.1...v1.0.2) - 2021-01-11
9 +
10 +### Commits
11 +
12 +- [Fix] properly include the receiver in the bound length [`dbae7bc`](https://github.com/ljharb/call-bind/commit/dbae7bc676c079a0d33c0a43e9ef92cb7b01345d)
13 +
14 +## [v1.0.1](https://github.com/ljharb/call-bind/compare/v1.0.0...v1.0.1) - 2021-01-08
15 +
16 +### Commits
17 +
18 +- [Tests] migrate tests to Github Actions [`b6db284`](https://github.com/ljharb/call-bind/commit/b6db284c36f8ccd195b88a6764fe84b7223a0da1)
19 +- [meta] do not publish github action workflow files [`ec7fe46`](https://github.com/ljharb/call-bind/commit/ec7fe46e60cfa4764ee943d2755f5e5a366e578e)
20 +- [Fix] preserve original function’s length when possible [`adbceaa`](https://github.com/ljharb/call-bind/commit/adbceaa3cac4b41ea78bb19d7ccdbaaf7e0bdadb)
21 +- [Tests] gather coverage data on every job [`d69e23c`](https://github.com/ljharb/call-bind/commit/d69e23cc65f101ba1d4c19bb07fa8eb0ec624be8)
22 +- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`2fd3586`](https://github.com/ljharb/call-bind/commit/2fd3586c5d47b335364c14293114c6b625ae1f71)
23 +- [Deps] update `get-intrinsic` [`f23e931`](https://github.com/ljharb/call-bind/commit/f23e9318cc271c2add8bb38cfded85ee7baf8eee)
24 +- [Deps] update `get-intrinsic` [`72d9f44`](https://github.com/ljharb/call-bind/commit/72d9f44e184465ba8dd3fb48260bbcff234985f2)
25 +- [meta] fix FUNDING.yml [`e723573`](https://github.com/ljharb/call-bind/commit/e723573438c5a68dcec31fb5d96ea6b7e4a93be8)
26 +- [eslint] ignore coverage output [`15e76d2`](https://github.com/ljharb/call-bind/commit/15e76d28a5f43e504696401e5b31ebb78ee1b532)
27 +- [meta] add Automatic Rebase and Require Allow Edits workflows [`8fa4dab`](https://github.com/ljharb/call-bind/commit/8fa4dabb23ba3dd7bb92c9571c1241c08b56e4b6)
28 +
29 +## v1.0.0 - 2020-10-30
30 +
31 +### Commits
32 +
33 +- Initial commit [`306cf98`](https://github.com/ljharb/call-bind/commit/306cf98c7ec9e7ef66b653ec152277ac1381eb50)
34 +- Tests [`e10d0bb`](https://github.com/ljharb/call-bind/commit/e10d0bbdadc7a10ecedc9a1c035112d3e368b8df)
35 +- Implementation [`43852ed`](https://github.com/ljharb/call-bind/commit/43852eda0f187327b7fad2423ca972149a52bd65)
36 +- npm init [`408f860`](https://github.com/ljharb/call-bind/commit/408f860b773a2f610805fd3613d0d71bac1b6249)
37 +- [meta] add Automatic Rebase and Require Allow Edits workflows [`fb349b2`](https://github.com/ljharb/call-bind/commit/fb349b2e48defbec8b5ec8a8395cc8f69f220b13)
38 +- [meta] add `auto-changelog` [`c4001fc`](https://github.com/ljharb/call-bind/commit/c4001fc43031799ef908211c98d3b0fb2b60fde4)
39 +- [meta] add "funding"; create `FUNDING.yml` [`d4d6d29`](https://github.com/ljharb/call-bind/commit/d4d6d2974a14bc2e98830468eda7fe6d6a776717)
40 +- [Tests] add `npm run lint` [`dedfb98`](https://github.com/ljharb/call-bind/commit/dedfb98bd0ecefb08ddb9a94061bd10cde4332af)
41 +- Only apps should have lockfiles [`54ac776`](https://github.com/ljharb/call-bind/commit/54ac77653db45a7361dc153d2f478e743f110650)
42 +- [meta] add `safe-publish-latest` [`9ea8e43`](https://github.com/ljharb/call-bind/commit/9ea8e435b950ce9b705559cd651039f9bf40140f)
1 +MIT License
2 +
3 +Copyright (c) 2020 Jordan Harband
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in all
13 +copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 +SOFTWARE.
1 +# call-bind
2 +Robustly `.call.bind()` a function.
1 +'use strict';
2 +
3 +var GetIntrinsic = require('get-intrinsic');
4 +
5 +var callBind = require('./');
6 +
7 +var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));
8 +
9 +module.exports = function callBoundIntrinsic(name, allowMissing) {
10 + var intrinsic = GetIntrinsic(name, !!allowMissing);
11 + if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) {
12 + return callBind(intrinsic);
13 + }
14 + return intrinsic;
15 +};
1 +'use strict';
2 +
3 +var bind = require('function-bind');
4 +var GetIntrinsic = require('get-intrinsic');
5 +
6 +var $apply = GetIntrinsic('%Function.prototype.apply%');
7 +var $call = GetIntrinsic('%Function.prototype.call%');
8 +var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
9 +
10 +var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
11 +var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
12 +var $max = GetIntrinsic('%Math.max%');
13 +
14 +if ($defineProperty) {
15 + try {
16 + $defineProperty({}, 'a', { value: 1 });
17 + } catch (e) {
18 + // IE 8 has a broken defineProperty
19 + $defineProperty = null;
20 + }
21 +}
22 +
23 +module.exports = function callBind(originalFunction) {
24 + var func = $reflectApply(bind, $call, arguments);
25 + if ($gOPD && $defineProperty) {
26 + var desc = $gOPD(func, 'length');
27 + if (desc.configurable) {
28 + // original length, plus the receiver, minus any additional arguments (after the receiver)
29 + $defineProperty(
30 + func,
31 + 'length',
32 + { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) }
33 + );
34 + }
35 + }
36 + return func;
37 +};
38 +
39 +var applyBind = function applyBind() {
40 + return $reflectApply(bind, $apply, arguments);
41 +};
42 +
43 +if ($defineProperty) {
44 + $defineProperty(module.exports, 'apply', { value: applyBind });
45 +} else {
46 + module.exports.apply = applyBind;
47 +}
1 +{
2 + "name": "call-bind",
3 + "version": "1.0.2",
4 + "description": "Robustly `.call.bind()` a function",
5 + "main": "index.js",
6 + "exports": {
7 + ".": [
8 + {
9 + "default": "./index.js"
10 + },
11 + "./index.js"
12 + ],
13 + "./callBound": [
14 + {
15 + "default": "./callBound.js"
16 + },
17 + "./callBound.js"
18 + ],
19 + "./package.json": "./package.json"
20 + },
21 + "scripts": {
22 + "prepublish": "safe-publish-latest",
23 + "lint": "eslint --ext=.js,.mjs .",
24 + "pretest": "npm run lint",
25 + "tests-only": "nyc tape 'test/*'",
26 + "test": "npm run tests-only",
27 + "posttest": "aud --production",
28 + "version": "auto-changelog && git add CHANGELOG.md",
29 + "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
30 + },
31 + "repository": {
32 + "type": "git",
33 + "url": "git+https://github.com/ljharb/call-bind.git"
34 + },
35 + "keywords": [
36 + "javascript",
37 + "ecmascript",
38 + "es",
39 + "js",
40 + "callbind",
41 + "callbound",
42 + "call",
43 + "bind",
44 + "bound",
45 + "call-bind",
46 + "call-bound",
47 + "function",
48 + "es-abstract"
49 + ],
50 + "author": "Jordan Harband <ljharb@gmail.com>",
51 + "funding": {
52 + "url": "https://github.com/sponsors/ljharb"
53 + },
54 + "license": "MIT",
55 + "bugs": {
56 + "url": "https://github.com/ljharb/call-bind/issues"
57 + },
58 + "homepage": "https://github.com/ljharb/call-bind#readme",
59 + "devDependencies": {
60 + "@ljharb/eslint-config": "^17.3.0",
61 + "aud": "^1.1.3",
62 + "auto-changelog": "^2.2.1",
63 + "eslint": "^7.17.0",
64 + "nyc": "^10.3.2",
65 + "safe-publish-latest": "^1.1.4",
66 + "tape": "^5.1.1"
67 + },
68 + "dependencies": {
69 + "function-bind": "^1.1.1",
70 + "get-intrinsic": "^1.0.2"
71 + },
72 + "auto-changelog": {
73 + "output": "CHANGELOG.md",
74 + "template": "keepachangelog",
75 + "unreleased": false,
76 + "commitLimit": false,
77 + "backfillLimit": false,
78 + "hideCredit": true
79 + }
80 +}
1 +'use strict';
2 +
3 +var test = require('tape');
4 +
5 +var callBound = require('../callBound');
6 +
7 +test('callBound', function (t) {
8 + // static primitive
9 + t.equal(callBound('Array.length'), Array.length, 'Array.length yields itself');
10 + t.equal(callBound('%Array.length%'), Array.length, '%Array.length% yields itself');
11 +
12 + // static non-function object
13 + t.equal(callBound('Array.prototype'), Array.prototype, 'Array.prototype yields itself');
14 + t.equal(callBound('%Array.prototype%'), Array.prototype, '%Array.prototype% yields itself');
15 + t.equal(callBound('Array.constructor'), Array.constructor, 'Array.constructor yields itself');
16 + t.equal(callBound('%Array.constructor%'), Array.constructor, '%Array.constructor% yields itself');
17 +
18 + // static function
19 + t.equal(callBound('Date.parse'), Date.parse, 'Date.parse yields itself');
20 + t.equal(callBound('%Date.parse%'), Date.parse, '%Date.parse% yields itself');
21 +
22 + // prototype primitive
23 + t.equal(callBound('Error.prototype.message'), Error.prototype.message, 'Error.prototype.message yields itself');
24 + t.equal(callBound('%Error.prototype.message%'), Error.prototype.message, '%Error.prototype.message% yields itself');
25 +
26 + // prototype function
27 + t.notEqual(callBound('Object.prototype.toString'), Object.prototype.toString, 'Object.prototype.toString does not yield itself');
28 + t.notEqual(callBound('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% does not yield itself');
29 + t.equal(callBound('Object.prototype.toString')(true), Object.prototype.toString.call(true), 'call-bound Object.prototype.toString calls into the original');
30 + t.equal(callBound('%Object.prototype.toString%')(true), Object.prototype.toString.call(true), 'call-bound %Object.prototype.toString% calls into the original');
31 +
32 + t['throws'](
33 + function () { callBound('does not exist'); },
34 + SyntaxError,
35 + 'nonexistent intrinsic throws'
36 + );
37 + t['throws'](
38 + function () { callBound('does not exist', true); },
39 + SyntaxError,
40 + 'allowMissing arg still throws for unknown intrinsic'
41 + );
42 +
43 + /* globals WeakRef: false */
44 + t.test('real but absent intrinsic', { skip: typeof WeakRef !== 'undefined' }, function (st) {
45 + st['throws'](
46 + function () { callBound('WeakRef'); },
47 + TypeError,
48 + 'real but absent intrinsic throws'
49 + );
50 + st.equal(callBound('WeakRef', true), undefined, 'allowMissing arg avoids exception');
51 + st.end();
52 + });
53 +
54 + t.end();
55 +});
1 +'use strict';
2 +
3 +var callBind = require('../');
4 +var bind = require('function-bind');
5 +
6 +var test = require('tape');
7 +
8 +/*
9 + * older engines have length nonconfigurable
10 + * in io.js v3, it is configurable except on bound functions, hence the .bind()
11 + */
12 +var functionsHaveConfigurableLengths = !!(
13 + Object.getOwnPropertyDescriptor
14 + && Object.getOwnPropertyDescriptor(bind.call(function () {}), 'length').configurable
15 +);
16 +
17 +test('callBind', function (t) {
18 + var sentinel = { sentinel: true };
19 + var func = function (a, b) {
20 + // eslint-disable-next-line no-invalid-this
21 + return [this, a, b];
22 + };
23 + t.equal(func.length, 2, 'original function length is 2');
24 + t.deepEqual(func(), [undefined, undefined, undefined], 'unbound func with too few args');
25 + t.deepEqual(func(1, 2), [undefined, 1, 2], 'unbound func with right args');
26 + t.deepEqual(func(1, 2, 3), [undefined, 1, 2], 'unbound func with too many args');
27 +
28 + var bound = callBind(func);
29 + t.equal(bound.length, func.length + 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
30 + t.deepEqual(bound(), [undefined, undefined, undefined], 'bound func with too few args');
31 + t.deepEqual(bound(1, 2), [1, 2, undefined], 'bound func with right args');
32 + t.deepEqual(bound(1, 2, 3), [1, 2, 3], 'bound func with too many args');
33 +
34 + var boundR = callBind(func, sentinel);
35 + t.equal(boundR.length, func.length, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
36 + t.deepEqual(boundR(), [sentinel, undefined, undefined], 'bound func with receiver, with too few args');
37 + t.deepEqual(boundR(1, 2), [sentinel, 1, 2], 'bound func with receiver, with right args');
38 + t.deepEqual(boundR(1, 2, 3), [sentinel, 1, 2], 'bound func with receiver, with too many args');
39 +
40 + var boundArg = callBind(func, sentinel, 1);
41 + t.equal(boundArg.length, func.length - 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
42 + t.deepEqual(boundArg(), [sentinel, 1, undefined], 'bound func with receiver and arg, with too few args');
43 + t.deepEqual(boundArg(2), [sentinel, 1, 2], 'bound func with receiver and arg, with right arg');
44 + t.deepEqual(boundArg(2, 3), [sentinel, 1, 2], 'bound func with receiver and arg, with too many args');
45 +
46 + t.test('callBind.apply', function (st) {
47 + var aBound = callBind.apply(func);
48 + st.deepEqual(aBound(sentinel), [sentinel, undefined, undefined], 'apply-bound func with no args');
49 + st.deepEqual(aBound(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
50 + st.deepEqual(aBound(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
51 +
52 + var aBoundArg = callBind.apply(func);
53 + st.deepEqual(aBoundArg(sentinel, [1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with too many args');
54 + st.deepEqual(aBoundArg(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
55 + st.deepEqual(aBoundArg(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
56 +
57 + var aBoundR = callBind.apply(func, sentinel);
58 + st.deepEqual(aBoundR([1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with receiver and too many args');
59 + st.deepEqual(aBoundR([1, 2], 4), [sentinel, 1, 2], 'apply-bound func with receiver and right args');
60 + st.deepEqual(aBoundR([1], 4), [sentinel, 1, undefined], 'apply-bound func with receiver and too few args');
61 +
62 + st.end();
63 + });
64 +
65 + t.end();
66 +});
1 +0.5.4 / 2021-12-10
2 +==================
3 +
4 + * deps: safe-buffer@5.2.1
5 +
6 +0.5.3 / 2018-12-17
7 +==================
8 +
9 + * Use `safe-buffer` for improved Buffer API
10 +
11 +0.5.2 / 2016-12-08
12 +==================
13 +
14 + * Fix `parse` to accept any linear whitespace character
15 +
16 +0.5.1 / 2016-01-17
17 +==================
18 +
19 + * perf: enable strict mode
20 +
21 +0.5.0 / 2014-10-11
22 +==================
23 +
24 + * Add `parse` function
25 +
26 +0.4.0 / 2014-09-21
27 +==================
28 +
29 + * Expand non-Unicode `filename` to the full ISO-8859-1 charset
30 +
31 +0.3.0 / 2014-09-20
32 +==================
33 +
34 + * Add `fallback` option
35 + * Add `type` option
36 +
37 +0.2.0 / 2014-09-19
38 +==================
39 +
40 + * Reduce ambiguity of file names with hex escape in buggy browsers
41 +
42 +0.1.2 / 2014-09-19
43 +==================
44 +
45 + * Fix periodic invalid Unicode filename header
46 +
47 +0.1.1 / 2014-09-19
48 +==================
49 +
50 + * Fix invalid characters appearing in `filename*` parameter
51 +
52 +0.1.0 / 2014-09-18
53 +==================
54 +
55 + * Make the `filename` argument optional
56 +
57 +0.0.0 / 2014-09-18
58 +==================
59 +
60 + * Initial release
1 +(The MIT License)
2 +
3 +Copyright (c) 2014-2017 Douglas Christopher Wilson
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining
6 +a copy of this software and associated documentation files (the
7 +'Software'), to deal in the Software without restriction, including
8 +without limitation the rights to use, copy, modify, merge, publish,
9 +distribute, sublicense, and/or sell copies of the Software, and to
10 +permit persons to whom the Software is furnished to do so, subject to
11 +the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be
14 +included in all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# content-disposition
2 +
3 +[![NPM Version][npm-image]][npm-url]
4 +[![NPM Downloads][downloads-image]][downloads-url]
5 +[![Node.js Version][node-version-image]][node-version-url]
6 +[![Build Status][github-actions-ci-image]][github-actions-ci-url]
7 +[![Test Coverage][coveralls-image]][coveralls-url]
8 +
9 +Create and parse HTTP `Content-Disposition` header
10 +
11 +## Installation
12 +
13 +```sh
14 +$ npm install content-disposition
15 +```
16 +
17 +## API
18 +
19 +```js
20 +var contentDisposition = require('content-disposition')
21 +```
22 +
23 +### contentDisposition(filename, options)
24 +
25 +Create an attachment `Content-Disposition` header value using the given file name,
26 +if supplied. The `filename` is optional and if no file name is desired, but you
27 +want to specify `options`, set `filename` to `undefined`.
28 +
29 +```js
30 +res.setHeader('Content-Disposition', contentDisposition('∫ maths.pdf'))
31 +```
32 +
33 +**note** HTTP headers are of the ISO-8859-1 character set. If you are writing this
34 +header through a means different from `setHeader` in Node.js, you'll want to specify
35 +the `'binary'` encoding in Node.js.
36 +
37 +#### Options
38 +
39 +`contentDisposition` accepts these properties in the options object.
40 +
41 +##### fallback
42 +
43 +If the `filename` option is outside ISO-8859-1, then the file name is actually
44 +stored in a supplemental field for clients that support Unicode file names and
45 +a ISO-8859-1 version of the file name is automatically generated.
46 +
47 +This specifies the ISO-8859-1 file name to override the automatic generation or
48 +disables the generation all together, defaults to `true`.
49 +
50 + - A string will specify the ISO-8859-1 file name to use in place of automatic
51 + generation.
52 + - `false` will disable including a ISO-8859-1 file name and only include the
53 + Unicode version (unless the file name is already ISO-8859-1).
54 + - `true` will enable automatic generation if the file name is outside ISO-8859-1.
55 +
56 +If the `filename` option is ISO-8859-1 and this option is specified and has a
57 +different value, then the `filename` option is encoded in the extended field
58 +and this set as the fallback field, even though they are both ISO-8859-1.
59 +
60 +##### type
61 +
62 +Specifies the disposition type, defaults to `"attachment"`. This can also be
63 +`"inline"`, or any other value (all values except inline are treated like
64 +`attachment`, but can convey additional information if both parties agree to
65 +it). The type is normalized to lower-case.
66 +
67 +### contentDisposition.parse(string)
68 +
69 +```js
70 +var disposition = contentDisposition.parse('attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt')
71 +```
72 +
73 +Parse a `Content-Disposition` header string. This automatically handles extended
74 +("Unicode") parameters by decoding them and providing them under the standard
75 +parameter name. This will return an object with the following properties (examples
76 +are shown for the string `'attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt'`):
77 +
78 + - `type`: The disposition type (always lower case). Example: `'attachment'`
79 +
80 + - `parameters`: An object of the parameters in the disposition (name of parameter
81 + always lower case and extended versions replace non-extended versions). Example:
82 + `{filename: "€ rates.txt"}`
83 +
84 +## Examples
85 +
86 +### Send a file for download
87 +
88 +```js
89 +var contentDisposition = require('content-disposition')
90 +var destroy = require('destroy')
91 +var fs = require('fs')
92 +var http = require('http')
93 +var onFinished = require('on-finished')
94 +
95 +var filePath = '/path/to/public/plans.pdf'
96 +
97 +http.createServer(function onRequest (req, res) {
98 + // set headers
99 + res.setHeader('Content-Type', 'application/pdf')
100 + res.setHeader('Content-Disposition', contentDisposition(filePath))
101 +
102 + // send file
103 + var stream = fs.createReadStream(filePath)
104 + stream.pipe(res)
105 + onFinished(res, function () {
106 + destroy(stream)
107 + })
108 +})
109 +```
110 +
111 +## Testing
112 +
113 +```sh
114 +$ npm test
115 +```
116 +
117 +## References
118 +
119 +- [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1][rfc-2616]
120 +- [RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters][rfc-5987]
121 +- [RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)][rfc-6266]
122 +- [Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987][tc-2231]
123 +
124 +[rfc-2616]: https://tools.ietf.org/html/rfc2616
125 +[rfc-5987]: https://tools.ietf.org/html/rfc5987
126 +[rfc-6266]: https://tools.ietf.org/html/rfc6266
127 +[tc-2231]: http://greenbytes.de/tech/tc2231/
128 +
129 +## License
130 +
131 +[MIT](LICENSE)
132 +
133 +[npm-image]: https://img.shields.io/npm/v/content-disposition.svg
134 +[npm-url]: https://npmjs.org/package/content-disposition
135 +[node-version-image]: https://img.shields.io/node/v/content-disposition.svg
136 +[node-version-url]: https://nodejs.org/en/download
137 +[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-disposition.svg
138 +[coveralls-url]: https://coveralls.io/r/jshttp/content-disposition?branch=master
139 +[downloads-image]: https://img.shields.io/npm/dm/content-disposition.svg
140 +[downloads-url]: https://npmjs.org/package/content-disposition
141 +[github-actions-ci-image]: https://img.shields.io/github/workflow/status/jshttp/content-disposition/ci/master?label=ci
142 +[github-actions-ci-url]: https://github.com/jshttp/content-disposition?query=workflow%3Aci
This diff is collapsed. Click to expand it.
1 +{
2 + "name": "content-disposition",
3 + "description": "Create and parse Content-Disposition header",
4 + "version": "0.5.4",
5 + "author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
6 + "license": "MIT",
7 + "keywords": [
8 + "content-disposition",
9 + "http",
10 + "rfc6266",
11 + "res"
12 + ],
13 + "repository": "jshttp/content-disposition",
14 + "dependencies": {
15 + "safe-buffer": "5.2.1"
16 + },
17 + "devDependencies": {
18 + "deep-equal": "1.0.1",
19 + "eslint": "7.32.0",
20 + "eslint-config-standard": "13.0.1",
21 + "eslint-plugin-import": "2.25.3",
22 + "eslint-plugin-markdown": "2.2.1",
23 + "eslint-plugin-node": "11.1.0",
24 + "eslint-plugin-promise": "5.2.0",
25 + "eslint-plugin-standard": "4.1.0",
26 + "istanbul": "0.4.5",
27 + "mocha": "9.1.3"
28 + },
29 + "files": [
30 + "LICENSE",
31 + "HISTORY.md",
32 + "README.md",
33 + "index.js"
34 + ],
35 + "engines": {
36 + "node": ">= 0.6"
37 + },
38 + "scripts": {
39 + "lint": "eslint .",
40 + "test": "mocha --reporter spec --bail --check-leaks test/",
41 + "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
42 + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
43 + }
44 +}
1 +1.0.4 / 2017-09-11
2 +==================
3 +
4 + * perf: skip parameter parsing when no parameters
5 +
6 +1.0.3 / 2017-09-10
7 +==================
8 +
9 + * perf: remove argument reassignment
10 +
11 +1.0.2 / 2016-05-09
12 +==================
13 +
14 + * perf: enable strict mode
15 +
16 +1.0.1 / 2015-02-13
17 +==================
18 +
19 + * Improve missing `Content-Type` header error message
20 +
21 +1.0.0 / 2015-02-01
22 +==================
23 +
24 + * Initial implementation, derived from `media-typer@0.3.0`
1 +(The MIT License)
2 +
3 +Copyright (c) 2015 Douglas Christopher Wilson
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining
6 +a copy of this software and associated documentation files (the
7 +'Software'), to deal in the Software without restriction, including
8 +without limitation the rights to use, copy, modify, merge, publish,
9 +distribute, sublicense, and/or sell copies of the Software, and to
10 +permit persons to whom the Software is furnished to do so, subject to
11 +the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be
14 +included in all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# content-type
2 +
3 +[![NPM Version][npm-image]][npm-url]
4 +[![NPM Downloads][downloads-image]][downloads-url]
5 +[![Node.js Version][node-version-image]][node-version-url]
6 +[![Build Status][travis-image]][travis-url]
7 +[![Test Coverage][coveralls-image]][coveralls-url]
8 +
9 +Create and parse HTTP Content-Type header according to RFC 7231
10 +
11 +## Installation
12 +
13 +```sh
14 +$ npm install content-type
15 +```
16 +
17 +## API
18 +
19 +```js
20 +var contentType = require('content-type')
21 +```
22 +
23 +### contentType.parse(string)
24 +
25 +```js
26 +var obj = contentType.parse('image/svg+xml; charset=utf-8')
27 +```
28 +
29 +Parse a content type string. This will return an object with the following
30 +properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
31 +
32 + - `type`: The media type (the type and subtype, always lower case).
33 + Example: `'image/svg+xml'`
34 +
35 + - `parameters`: An object of the parameters in the media type (name of parameter
36 + always lower case). Example: `{charset: 'utf-8'}`
37 +
38 +Throws a `TypeError` if the string is missing or invalid.
39 +
40 +### contentType.parse(req)
41 +
42 +```js
43 +var obj = contentType.parse(req)
44 +```
45 +
46 +Parse the `content-type` header from the given `req`. Short-cut for
47 +`contentType.parse(req.headers['content-type'])`.
48 +
49 +Throws a `TypeError` if the `Content-Type` header is missing or invalid.
50 +
51 +### contentType.parse(res)
52 +
53 +```js
54 +var obj = contentType.parse(res)
55 +```
56 +
57 +Parse the `content-type` header set on the given `res`. Short-cut for
58 +`contentType.parse(res.getHeader('content-type'))`.
59 +
60 +Throws a `TypeError` if the `Content-Type` header is missing or invalid.
61 +
62 +### contentType.format(obj)
63 +
64 +```js
65 +var str = contentType.format({type: 'image/svg+xml'})
66 +```
67 +
68 +Format an object into a content type string. This will return a string of the
69 +content type for the given object with the following properties (examples are
70 +shown that produce the string `'image/svg+xml; charset=utf-8'`):
71 +
72 + - `type`: The media type (will be lower-cased). Example: `'image/svg+xml'`
73 +
74 + - `parameters`: An object of the parameters in the media type (name of the
75 + parameter will be lower-cased). Example: `{charset: 'utf-8'}`
76 +
77 +Throws a `TypeError` if the object contains an invalid type or parameter names.
78 +
79 +## License
80 +
81 +[MIT](LICENSE)
82 +
83 +[npm-image]: https://img.shields.io/npm/v/content-type.svg
84 +[npm-url]: https://npmjs.org/package/content-type
85 +[node-version-image]: https://img.shields.io/node/v/content-type.svg
86 +[node-version-url]: http://nodejs.org/download/
87 +[travis-image]: https://img.shields.io/travis/jshttp/content-type/master.svg
88 +[travis-url]: https://travis-ci.org/jshttp/content-type
89 +[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-type/master.svg
90 +[coveralls-url]: https://coveralls.io/r/jshttp/content-type
91 +[downloads-image]: https://img.shields.io/npm/dm/content-type.svg
92 +[downloads-url]: https://npmjs.org/package/content-type
1 +/*!
2 + * content-type
3 + * Copyright(c) 2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1
11 + *
12 + * parameter = token "=" ( token / quoted-string )
13 + * token = 1*tchar
14 + * tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
15 + * / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
16 + * / DIGIT / ALPHA
17 + * ; any VCHAR, except delimiters
18 + * quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
19 + * qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
20 + * obs-text = %x80-FF
21 + * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
22 + */
23 +var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g
24 +var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/
25 +var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
26 +
27 +/**
28 + * RegExp to match quoted-pair in RFC 7230 sec 3.2.6
29 + *
30 + * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
31 + * obs-text = %x80-FF
32 + */
33 +var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g
34 +
35 +/**
36 + * RegExp to match chars that must be quoted-pair in RFC 7230 sec 3.2.6
37 + */
38 +var QUOTE_REGEXP = /([\\"])/g
39 +
40 +/**
41 + * RegExp to match type in RFC 7231 sec 3.1.1.1
42 + *
43 + * media-type = type "/" subtype
44 + * type = token
45 + * subtype = token
46 + */
47 +var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
48 +
49 +/**
50 + * Module exports.
51 + * @public
52 + */
53 +
54 +exports.format = format
55 +exports.parse = parse
56 +
57 +/**
58 + * Format object to media type.
59 + *
60 + * @param {object} obj
61 + * @return {string}
62 + * @public
63 + */
64 +
65 +function format (obj) {
66 + if (!obj || typeof obj !== 'object') {
67 + throw new TypeError('argument obj is required')
68 + }
69 +
70 + var parameters = obj.parameters
71 + var type = obj.type
72 +
73 + if (!type || !TYPE_REGEXP.test(type)) {
74 + throw new TypeError('invalid type')
75 + }
76 +
77 + var string = type
78 +
79 + // append parameters
80 + if (parameters && typeof parameters === 'object') {
81 + var param
82 + var params = Object.keys(parameters).sort()
83 +
84 + for (var i = 0; i < params.length; i++) {
85 + param = params[i]
86 +
87 + if (!TOKEN_REGEXP.test(param)) {
88 + throw new TypeError('invalid parameter name')
89 + }
90 +
91 + string += '; ' + param + '=' + qstring(parameters[param])
92 + }
93 + }
94 +
95 + return string
96 +}
97 +
98 +/**
99 + * Parse media type to object.
100 + *
101 + * @param {string|object} string
102 + * @return {Object}
103 + * @public
104 + */
105 +
106 +function parse (string) {
107 + if (!string) {
108 + throw new TypeError('argument string is required')
109 + }
110 +
111 + // support req/res-like objects as argument
112 + var header = typeof string === 'object'
113 + ? getcontenttype(string)
114 + : string
115 +
116 + if (typeof header !== 'string') {
117 + throw new TypeError('argument string is required to be a string')
118 + }
119 +
120 + var index = header.indexOf(';')
121 + var type = index !== -1
122 + ? header.substr(0, index).trim()
123 + : header.trim()
124 +
125 + if (!TYPE_REGEXP.test(type)) {
126 + throw new TypeError('invalid media type')
127 + }
128 +
129 + var obj = new ContentType(type.toLowerCase())
130 +
131 + // parse parameters
132 + if (index !== -1) {
133 + var key
134 + var match
135 + var value
136 +
137 + PARAM_REGEXP.lastIndex = index
138 +
139 + while ((match = PARAM_REGEXP.exec(header))) {
140 + if (match.index !== index) {
141 + throw new TypeError('invalid parameter format')
142 + }
143 +
144 + index += match[0].length
145 + key = match[1].toLowerCase()
146 + value = match[2]
147 +
148 + if (value[0] === '"') {
149 + // remove quotes and escapes
150 + value = value
151 + .substr(1, value.length - 2)
152 + .replace(QESC_REGEXP, '$1')
153 + }
154 +
155 + obj.parameters[key] = value
156 + }
157 +
158 + if (index !== header.length) {
159 + throw new TypeError('invalid parameter format')
160 + }
161 + }
162 +
163 + return obj
164 +}
165 +
166 +/**
167 + * Get content-type from req/res objects.
168 + *
169 + * @param {object}
170 + * @return {Object}
171 + * @private
172 + */
173 +
174 +function getcontenttype (obj) {
175 + var header
176 +
177 + if (typeof obj.getHeader === 'function') {
178 + // res-like
179 + header = obj.getHeader('content-type')
180 + } else if (typeof obj.headers === 'object') {
181 + // req-like
182 + header = obj.headers && obj.headers['content-type']
183 + }
184 +
185 + if (typeof header !== 'string') {
186 + throw new TypeError('content-type header is missing from object')
187 + }
188 +
189 + return header
190 +}
191 +
192 +/**
193 + * Quote a string if necessary.
194 + *
195 + * @param {string} val
196 + * @return {string}
197 + * @private
198 + */
199 +
200 +function qstring (val) {
201 + var str = String(val)
202 +
203 + // no need to quote tokens
204 + if (TOKEN_REGEXP.test(str)) {
205 + return str
206 + }
207 +
208 + if (str.length > 0 && !TEXT_REGEXP.test(str)) {
209 + throw new TypeError('invalid parameter value')
210 + }
211 +
212 + return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"'
213 +}
214 +
215 +/**
216 + * Class to represent a content type.
217 + * @private
218 + */
219 +function ContentType (type) {
220 + this.parameters = Object.create(null)
221 + this.type = type
222 +}
1 +{
2 + "name": "content-type",
3 + "description": "Create and parse HTTP Content-Type header",
4 + "version": "1.0.4",
5 + "author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
6 + "license": "MIT",
7 + "keywords": [
8 + "content-type",
9 + "http",
10 + "req",
11 + "res",
12 + "rfc7231"
13 + ],
14 + "repository": "jshttp/content-type",
15 + "devDependencies": {
16 + "eslint": "3.19.0",
17 + "eslint-config-standard": "10.2.1",
18 + "eslint-plugin-import": "2.7.0",
19 + "eslint-plugin-node": "5.1.1",
20 + "eslint-plugin-promise": "3.5.0",
21 + "eslint-plugin-standard": "3.0.1",
22 + "istanbul": "0.4.5",
23 + "mocha": "~1.21.5"
24 + },
25 + "files": [
26 + "LICENSE",
27 + "HISTORY.md",
28 + "README.md",
29 + "index.js"
30 + ],
31 + "engines": {
32 + "node": ">= 0.6"
33 + },
34 + "scripts": {
35 + "lint": "eslint .",
36 + "test": "mocha --reporter spec --check-leaks --bail test/",
37 + "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
38 + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
39 + }
40 +}
1 +support
2 +test
3 +examples
4 +*.sock
1 +1.0.6 / 2015-02-03
2 +==================
3 +
4 +* use `npm test` instead of `make test` to run tests
5 +* clearer assertion messages when checking input
6 +
7 +
8 +1.0.5 / 2014-09-05
9 +==================
10 +
11 +* add license to package.json
12 +
13 +1.0.4 / 2014-06-25
14 +==================
15 +
16 + * corrected avoidance of timing attacks (thanks @tenbits!)
17 +
18 +1.0.3 / 2014-01-28
19 +==================
20 +
21 + * [incorrect] fix for timing attacks
22 +
23 +1.0.2 / 2014-01-28
24 +==================
25 +
26 + * fix missing repository warning
27 + * fix typo in test
28 +
29 +1.0.1 / 2013-04-15
30 +==================
31 +
32 + * Revert "Changed underlying HMAC algo. to sha512."
33 + * Revert "Fix for timing attacks on MAC verification."
34 +
35 +0.0.1 / 2010-01-03
36 +==================
37 +
38 + * Initial release
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.