Showing
207 changed files
with
4634 additions
and
58 deletions
... | @@ -4,9 +4,9 @@ var path = require('path'); | ... | @@ -4,9 +4,9 @@ var path = require('path'); |
4 | var cookieParser = require('cookie-parser'); | 4 | var cookieParser = require('cookie-parser'); |
5 | var logger = require('morgan'); | 5 | var logger = require('morgan'); |
6 | 6 | ||
7 | -var indexRouter = require('./routes/index'); | 7 | +var index = require('./routes/index'); |
8 | -var usersRouter = require('./routes/users'); | 8 | +var users = require('./routes/users'); |
9 | - | 9 | +var calendar = require('./routes/calendar'); |
10 | var app = express(); | 10 | var app = express(); |
11 | 11 | ||
12 | // view engine setup (뷰 폴더 경로 설정) | 12 | // view engine setup (뷰 폴더 경로 설정) |
... | @@ -19,8 +19,9 @@ app.use(express.urlencoded({ extended: false })); | ... | @@ -19,8 +19,9 @@ app.use(express.urlencoded({ extended: false })); |
19 | app.use(cookieParser()); | 19 | app.use(cookieParser()); |
20 | app.use(express.static(path.join(__dirname, 'public'))); | 20 | app.use(express.static(path.join(__dirname, 'public'))); |
21 | 21 | ||
22 | -app.use('/', indexRouter); | 22 | +app.use('/', index); |
23 | -app.use('/users', usersRouter); | 23 | +app.use('/users', users); |
24 | +app.use('/calendar',calendar); | ||
24 | 25 | ||
25 | // catch 404 and forward to error handler | 26 | // catch 404 and forward to error handler |
26 | app.use(function(req, res, next) { | 27 | app.use(function(req, res, next) { | ... | ... |
node_modules/base64url/LICENSE
0 → 100644
1 | +Copyright (c) 2013–2016 Brian J. Brennan | ||
2 | + | ||
3 | +Permission is hereby granted, free of charge, to any person obtaining a | ||
4 | +copy of this software and associated documentation files (the | ||
5 | +"Software"), to deal in the Software without restriction, including | ||
6 | +without limitation the rights to use, copy, modify, merge, publish, | ||
7 | +distribute, sublicense, and/or sell copies of the Software, and to | ||
8 | +permit persons to whom the Software is furnished to do so, subject to | ||
9 | +the following conditions: | ||
10 | + | ||
11 | +The above copyright notice and this permission notice shall be included | ||
12 | +in all copies or substantial portions of the Software. | ||
13 | + | ||
14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
15 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
16 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
17 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
18 | +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
19 | +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
20 | +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
node_modules/base64url/dist/.gitkeep
0 → 100644
File mode changed
node_modules/base64url/dist/base64url.d.ts
0 → 100644
1 | +/// <reference types="node" /> | ||
2 | +export interface Base64Url { | ||
3 | + (input: string | Buffer, encoding?: string): string; | ||
4 | + encode(input: string | Buffer, encoding?: string): string; | ||
5 | + decode(base64url: string, encoding?: string): string; | ||
6 | + toBase64(base64url: string | Buffer): string; | ||
7 | + fromBase64(base64: string): string; | ||
8 | + toBuffer(base64url: string): Buffer; | ||
9 | +} | ||
10 | +declare let base64url: Base64Url; | ||
11 | +export default base64url; |
node_modules/base64url/dist/base64url.js
0 → 100644
1 | +"use strict"; | ||
2 | +Object.defineProperty(exports, "__esModule", { value: true }); | ||
3 | +var pad_string_1 = require("./pad-string"); | ||
4 | +function encode(input, encoding) { | ||
5 | + if (encoding === void 0) { encoding = "utf8"; } | ||
6 | + if (Buffer.isBuffer(input)) { | ||
7 | + return fromBase64(input.toString("base64")); | ||
8 | + } | ||
9 | + return fromBase64(Buffer.from(input, encoding).toString("base64")); | ||
10 | +} | ||
11 | +; | ||
12 | +function decode(base64url, encoding) { | ||
13 | + if (encoding === void 0) { encoding = "utf8"; } | ||
14 | + return Buffer.from(toBase64(base64url), "base64").toString(encoding); | ||
15 | +} | ||
16 | +function toBase64(base64url) { | ||
17 | + base64url = base64url.toString(); | ||
18 | + return pad_string_1.default(base64url) | ||
19 | + .replace(/\-/g, "+") | ||
20 | + .replace(/_/g, "/"); | ||
21 | +} | ||
22 | +function fromBase64(base64) { | ||
23 | + return base64 | ||
24 | + .replace(/=/g, "") | ||
25 | + .replace(/\+/g, "-") | ||
26 | + .replace(/\//g, "_"); | ||
27 | +} | ||
28 | +function toBuffer(base64url) { | ||
29 | + return Buffer.from(toBase64(base64url), "base64"); | ||
30 | +} | ||
31 | +var base64url = encode; | ||
32 | +base64url.encode = encode; | ||
33 | +base64url.decode = decode; | ||
34 | +base64url.toBase64 = toBase64; | ||
35 | +base64url.fromBase64 = fromBase64; | ||
36 | +base64url.toBuffer = toBuffer; | ||
37 | +exports.default = base64url; |
node_modules/base64url/dist/pad-string.d.ts
0 → 100644
1 | +export default function padString(input: string): string; |
node_modules/base64url/dist/pad-string.js
0 → 100644
1 | +"use strict"; | ||
2 | +Object.defineProperty(exports, "__esModule", { value: true }); | ||
3 | +function padString(input) { | ||
4 | + var segmentLength = 4; | ||
5 | + var stringLength = input.length; | ||
6 | + var diff = stringLength % segmentLength; | ||
7 | + if (!diff) { | ||
8 | + return input; | ||
9 | + } | ||
10 | + var position = stringLength; | ||
11 | + var padLength = segmentLength - diff; | ||
12 | + var paddedStringLength = stringLength + padLength; | ||
13 | + var buffer = Buffer.alloc(paddedStringLength); | ||
14 | + buffer.write(input); | ||
15 | + while (padLength--) { | ||
16 | + buffer.write("=", position++); | ||
17 | + } | ||
18 | + return buffer.toString(); | ||
19 | +} | ||
20 | +exports.default = padString; |
node_modules/base64url/index.js
0 → 100644
node_modules/base64url/package.json
0 → 100644
1 | +{ | ||
2 | + "_from": "base64url@3.x.x", | ||
3 | + "_id": "base64url@3.0.1", | ||
4 | + "_inBundle": false, | ||
5 | + "_integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==", | ||
6 | + "_location": "/base64url", | ||
7 | + "_phantomChildren": {}, | ||
8 | + "_requested": { | ||
9 | + "type": "range", | ||
10 | + "registry": true, | ||
11 | + "raw": "base64url@3.x.x", | ||
12 | + "name": "base64url", | ||
13 | + "escapedName": "base64url", | ||
14 | + "rawSpec": "3.x.x", | ||
15 | + "saveSpec": null, | ||
16 | + "fetchSpec": "3.x.x" | ||
17 | + }, | ||
18 | + "_requiredBy": [ | ||
19 | + "/passport-oauth2" | ||
20 | + ], | ||
21 | + "_resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", | ||
22 | + "_shasum": "6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d", | ||
23 | + "_spec": "base64url@3.x.x", | ||
24 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\passport-oauth2", | ||
25 | + "author": { | ||
26 | + "name": "Brian J Brennan" | ||
27 | + }, | ||
28 | + "bugs": { | ||
29 | + "url": "https://github.com/brianloveswords/base64url/issues" | ||
30 | + }, | ||
31 | + "bundleDependencies": false, | ||
32 | + "deprecated": false, | ||
33 | + "description": "For encoding to/from base64urls", | ||
34 | + "devDependencies": { | ||
35 | + "@types/node": "^10.0.0", | ||
36 | + "tap": "^12.1.0" | ||
37 | + }, | ||
38 | + "engines": { | ||
39 | + "node": ">=6.0.0" | ||
40 | + }, | ||
41 | + "files": [ | ||
42 | + "dist/", | ||
43 | + "index.js" | ||
44 | + ], | ||
45 | + "homepage": "https://github.com/brianloveswords/base64url#readme", | ||
46 | + "keywords": [ | ||
47 | + "base64", | ||
48 | + "base64url" | ||
49 | + ], | ||
50 | + "license": "MIT", | ||
51 | + "main": "index.js", | ||
52 | + "name": "base64url", | ||
53 | + "repository": { | ||
54 | + "type": "git", | ||
55 | + "url": "git://github.com/brianloveswords/base64url.git" | ||
56 | + }, | ||
57 | + "scripts": { | ||
58 | + "build": "tsc", | ||
59 | + "clean": "rm -f dist/*", | ||
60 | + "prepublishOnly": "npm run test", | ||
61 | + "test": "npm run clean && npm run build && tap test/*.test.js" | ||
62 | + }, | ||
63 | + "types": "./dist/base64url.d.ts", | ||
64 | + "version": "3.0.1" | ||
65 | +} |
node_modules/base64url/readme.md
0 → 100644
1 | +# base64url [![Build Status](https://secure.travis-ci.org/brianloveswords/base64url.png)](http://travis-ci.org/brianloveswords/base64url) | ||
2 | + | ||
3 | +Converting to, and from, [base64url](http://en.wikipedia.org/wiki/Base64#RFC_4648) | ||
4 | + | ||
5 | +# Install | ||
6 | + | ||
7 | +```bash | ||
8 | +$ npm install base64url | ||
9 | +``` | ||
10 | + | ||
11 | +After installing with `npm` you can require this library from JavaScript or TypeScript: | ||
12 | + | ||
13 | +JavaScript | ||
14 | +```js | ||
15 | +const base64url = require('base64url'); | ||
16 | +``` | ||
17 | + | ||
18 | +TypeScript: | ||
19 | +```typescript | ||
20 | +import base64url from "base64url"; | ||
21 | +``` | ||
22 | + | ||
23 | +# Usage | ||
24 | + | ||
25 | +## CLI | ||
26 | + | ||
27 | +The CLI has been removed. For the time being, please install `base64url@1.0.6` if you need the CLI. | ||
28 | + | ||
29 | +## Library | ||
30 | + | ||
31 | +### base64url(input: string | Buffer, encoding: string = "utf8"): string | ||
32 | + | ||
33 | +### base64url.encode(input: string | Buffer, encoding: string = "utf8"): string | ||
34 | + | ||
35 | +base64url encode `input`. Input should be a `string` or a `Buffer`. | ||
36 | + | ||
37 | + | ||
38 | +Example | ||
39 | + | ||
40 | +```js | ||
41 | +> base64url("ladies and gentlemen we are floating in space") | ||
42 | +'bGFkaWVzIGFuZCBnZW50bGVtYW4sIHdlIGFyZSBmbG9hdGluZyBpbiBzcGFjZQ' | ||
43 | +``` | ||
44 | + | ||
45 | +--- | ||
46 | + | ||
47 | +### base64url.decode(input: string, encoding: string = "utf8"): string | ||
48 | + | ||
49 | +Convert a base64url encoded string into a raw string. The `encoding` argument can be used if the input is a string that's not utf8. | ||
50 | + | ||
51 | +```js | ||
52 | +> base64url.decode("cmlkZTogZHJlYW1zIGJ1cm4gZG93bg") | ||
53 | +'ride: dreams burn down' | ||
54 | +``` | ||
55 | + | ||
56 | +--- | ||
57 | + | ||
58 | +### base64url.fromBase64(input: string): string | ||
59 | + | ||
60 | +Convert a base64 encoded string to a base64url encoded string. | ||
61 | + | ||
62 | +Example | ||
63 | + | ||
64 | +```js | ||
65 | +> base64url.fromBase64('qL8R4QIcQ/ZsRqOAbeRfcZhilN/MksRtDaErMA==') | ||
66 | +'qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA' | ||
67 | +``` | ||
68 | + | ||
69 | +--- | ||
70 | + | ||
71 | + | ||
72 | +### base64url.toBase64(input: string): string | ||
73 | + | ||
74 | +Convert a base64url encoded string to a base64 encoded string. | ||
75 | + | ||
76 | +```js | ||
77 | +> base64url.toBase64('qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA') | ||
78 | +'qL8R4QIcQ/ZsRqOAbeRfcZhilN/MksRtDaErMA==' | ||
79 | +``` | ||
80 | + | ||
81 | +--- | ||
82 | + | ||
83 | + | ||
84 | +### base64url.toBuffer(input: string): Buffer | ||
85 | + | ||
86 | +Convert a base64url encoded string to a Buffer containing the decoded bytes. | ||
87 | + | ||
88 | +```js | ||
89 | +> base64url.toBuffer('c3Bpcml0dWFsaXplZA') | ||
90 | +<Buffer 73 70 69 72 69 74 75 61 6c 69 7a 65 64> | ||
91 | +``` | ||
92 | + | ||
93 | +# Alternatives | ||
94 | + | ||
95 | +- [base64-url](https://github.com/joaquimserafim/base64-url) | ||
96 | + | ||
97 | +# Supported Node.js versions | ||
98 | + | ||
99 | +This library should be used with current versions of the Node.js runtime's long-term stable (LTS) | ||
100 | +schedule. More information can be found [at the Node.js Release Working Group](https://github.com/nodejs/Release) repo. | ||
101 | + | ||
102 | +# License | ||
103 | + | ||
104 | +MIT | ||
105 | + | ||
106 | +``` | ||
107 | +Copyright (c) 2013–2016 Brian J. Brennan | ||
108 | + | ||
109 | +Permission is hereby granted, free of charge, to any person obtaining a | ||
110 | +copy of this software and associated documentation files (the | ||
111 | +"Software"), to deal in the Software without restriction, including | ||
112 | +without limitation the rights to use, copy, modify, merge, publish, | ||
113 | +distribute, sublicense, and/or sell copies of the Software, and to | ||
114 | +permit persons to whom the Software is furnished to do so, subject to | ||
115 | +the following conditions: | ||
116 | + | ||
117 | +The above copyright notice and this permission notice shall be included | ||
118 | +in all copies or substantial portions of the Software. | ||
119 | + | ||
120 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
121 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
122 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
123 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
124 | +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
125 | +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
126 | +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
127 | +``` |
1 | +1.19.0 / 2019-04-25 | ||
2 | +=================== | ||
3 | + | ||
4 | + * deps: bytes@3.1.0 | ||
5 | + - Add petabyte (`pb`) support | ||
6 | + * deps: http-errors@1.7.2 | ||
7 | + - Set constructor name when possible | ||
8 | + - deps: setprototypeof@1.1.1 | ||
9 | + - deps: statuses@'>= 1.5.0 < 2' | ||
10 | + * deps: iconv-lite@0.4.24 | ||
11 | + - Added encoding MIK | ||
12 | + * deps: qs@6.7.0 | ||
13 | + - Fix parsing array brackets after index | ||
14 | + * deps: raw-body@2.4.0 | ||
15 | + - deps: bytes@3.1.0 | ||
16 | + - deps: http-errors@1.7.2 | ||
17 | + - deps: iconv-lite@0.4.24 | ||
18 | + * deps: type-is@~1.6.17 | ||
19 | + - deps: mime-types@~2.1.24 | ||
20 | + - perf: prevent internal `throw` on invalid type | ||
21 | + | ||
1 | 1.18.3 / 2018-05-14 | 22 | 1.18.3 / 2018-05-14 |
2 | =================== | 23 | =================== |
3 | 24 | ... | ... |
... | @@ -399,13 +399,11 @@ var urlencodedParser = bodyParser.urlencoded({ extended: false }) | ... | @@ -399,13 +399,11 @@ var urlencodedParser = bodyParser.urlencoded({ extended: false }) |
399 | 399 | ||
400 | // POST /login gets urlencoded bodies | 400 | // POST /login gets urlencoded bodies |
401 | app.post('/login', urlencodedParser, function (req, res) { | 401 | app.post('/login', urlencodedParser, function (req, res) { |
402 | - if (!req.body) return res.sendStatus(400) | ||
403 | res.send('welcome, ' + req.body.username) | 402 | res.send('welcome, ' + req.body.username) |
404 | }) | 403 | }) |
405 | 404 | ||
406 | // POST /api/users gets JSON bodies | 405 | // POST /api/users gets JSON bodies |
407 | app.post('/api/users', jsonParser, function (req, res) { | 406 | app.post('/api/users', jsonParser, function (req, res) { |
408 | - if (!req.body) return res.sendStatus(400) | ||
409 | // create user in req.body | 407 | // create user in req.body |
410 | }) | 408 | }) |
411 | ``` | 409 | ``` | ... | ... |
... | @@ -266,7 +266,7 @@ function simpleparser (options) { | ... | @@ -266,7 +266,7 @@ function simpleparser (options) { |
266 | } | 266 | } |
267 | 267 | ||
268 | debug('parse urlencoding') | 268 | debug('parse urlencoding') |
269 | - return parse(body, undefined, undefined, {maxKeys: parameterLimit}) | 269 | + return parse(body, undefined, undefined, { maxKeys: parameterLimit }) |
270 | } | 270 | } |
271 | } | 271 | } |
272 | 272 | ... | ... |
1 | +2019-02-18 / 1.7.2 | ||
2 | +================== | ||
3 | + | ||
4 | + * deps: setprototypeof@1.1.1 | ||
5 | + | ||
6 | +2018-09-08 / 1.7.1 | ||
7 | +================== | ||
8 | + | ||
9 | + * Fix error creating objects in some environments | ||
10 | + | ||
11 | +2018-07-30 / 1.7.0 | ||
12 | +================== | ||
13 | + | ||
14 | + * Set constructor name when possible | ||
15 | + * Use `toidentifier` module to make class names | ||
16 | + * deps: statuses@'>= 1.5.0 < 2' | ||
17 | + | ||
18 | +2018-03-29 / 1.6.3 | ||
19 | +================== | ||
20 | + | ||
21 | + * deps: depd@~1.1.2 | ||
22 | + - perf: remove argument reassignment | ||
23 | + * deps: setprototypeof@1.1.0 | ||
24 | + * deps: statuses@'>= 1.4.0 < 2' | ||
25 | + | ||
26 | +2017-08-04 / 1.6.2 | ||
27 | +================== | ||
28 | + | ||
29 | + * deps: depd@1.1.1 | ||
30 | + - Remove unnecessary `Buffer` loading | ||
31 | + | ||
32 | +2017-02-20 / 1.6.1 | ||
33 | +================== | ||
34 | + | ||
35 | + * deps: setprototypeof@1.0.3 | ||
36 | + - Fix shim for old browsers | ||
37 | + | ||
38 | +2017-02-14 / 1.6.0 | ||
39 | +================== | ||
40 | + | ||
41 | + * Accept custom 4xx and 5xx status codes in factory | ||
42 | + * Add deprecation message to `"I'mateapot"` export | ||
43 | + * Deprecate passing status code as anything except first argument in factory | ||
44 | + * Deprecate using non-error status codes | ||
45 | + * Make `message` property enumerable for `HttpError`s | ||
46 | + | ||
47 | +2016-11-16 / 1.5.1 | ||
48 | +================== | ||
49 | + | ||
50 | + * deps: inherits@2.0.3 | ||
51 | + - Fix issue loading in browser | ||
52 | + * deps: setprototypeof@1.0.2 | ||
53 | + * deps: statuses@'>= 1.3.1 < 2' | ||
54 | + | ||
55 | +2016-05-18 / 1.5.0 | ||
56 | +================== | ||
57 | + | ||
58 | + * Support new code `421 Misdirected Request` | ||
59 | + * Use `setprototypeof` module to replace `__proto__` setting | ||
60 | + * deps: statuses@'>= 1.3.0 < 2' | ||
61 | + - Add `421 Misdirected Request` | ||
62 | + - perf: enable strict mode | ||
63 | + * perf: enable strict mode | ||
64 | + | ||
65 | +2016-01-28 / 1.4.0 | ||
66 | +================== | ||
67 | + | ||
68 | + * Add `HttpError` export, for `err instanceof createError.HttpError` | ||
69 | + * deps: inherits@2.0.1 | ||
70 | + * deps: statuses@'>= 1.2.1 < 2' | ||
71 | + - Fix message for status 451 | ||
72 | + - Remove incorrect nginx status code | ||
73 | + | ||
74 | +2015-02-02 / 1.3.1 | ||
75 | +================== | ||
76 | + | ||
77 | + * Fix regression where status can be overwritten in `createError` `props` | ||
78 | + | ||
79 | +2015-02-01 / 1.3.0 | ||
80 | +================== | ||
81 | + | ||
82 | + * Construct errors using defined constructors from `createError` | ||
83 | + * Fix error names that are not identifiers | ||
84 | + - `createError["I'mateapot"]` is now `createError.ImATeapot` | ||
85 | + * Set a meaningful `name` property on constructed errors | ||
86 | + | ||
87 | +2014-12-09 / 1.2.8 | ||
88 | +================== | ||
89 | + | ||
90 | + * Fix stack trace from exported function | ||
91 | + * Remove `arguments.callee` usage | ||
92 | + | ||
93 | +2014-10-14 / 1.2.7 | ||
94 | +================== | ||
95 | + | ||
96 | + * Remove duplicate line | ||
97 | + | ||
98 | +2014-10-02 / 1.2.6 | ||
99 | +================== | ||
100 | + | ||
101 | + * Fix `expose` to be `true` for `ClientError` constructor | ||
102 | + | ||
103 | +2014-09-28 / 1.2.5 | ||
104 | +================== | ||
105 | + | ||
106 | + * deps: statuses@1 | ||
107 | + | ||
108 | +2014-09-21 / 1.2.4 | ||
109 | +================== | ||
110 | + | ||
111 | + * Fix dependency version to work with old `npm`s | ||
112 | + | ||
113 | +2014-09-21 / 1.2.3 | ||
114 | +================== | ||
115 | + | ||
116 | + * deps: statuses@~1.1.0 | ||
117 | + | ||
118 | +2014-09-21 / 1.2.2 | ||
119 | +================== | ||
120 | + | ||
121 | + * Fix publish error | ||
122 | + | ||
123 | +2014-09-21 / 1.2.1 | ||
124 | +================== | ||
125 | + | ||
126 | + * Support Node.js 0.6 | ||
127 | + * Use `inherits` instead of `util` | ||
128 | + | ||
129 | +2014-09-09 / 1.2.0 | ||
130 | +================== | ||
131 | + | ||
132 | + * Fix the way inheriting functions | ||
133 | + * Support `expose` being provided in properties argument | ||
134 | + | ||
135 | +2014-09-08 / 1.1.0 | ||
136 | +================== | ||
137 | + | ||
138 | + * Default status to 500 | ||
139 | + * Support provided `error` to extend | ||
140 | + | ||
141 | +2014-09-08 / 1.0.1 | ||
142 | +================== | ||
143 | + | ||
144 | + * Fix accepting string message | ||
145 | + | ||
146 | +2014-09-08 / 1.0.0 | ||
147 | +================== | ||
148 | + | ||
149 | + * Initial release |
1 | + | ||
2 | +The MIT License (MIT) | ||
3 | + | ||
4 | +Copyright (c) 2014 Jonathan Ong me@jongleberry.com | ||
5 | +Copyright (c) 2016 Douglas Christopher Wilson doug@somethingdoug.com | ||
6 | + | ||
7 | +Permission is hereby granted, free of charge, to any person obtaining a copy | ||
8 | +of this software and associated documentation files (the "Software"), to deal | ||
9 | +in the Software without restriction, including without limitation the rights | ||
10 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
11 | +copies of the Software, and to permit persons to whom the Software is | ||
12 | +furnished to do so, subject to the following conditions: | ||
13 | + | ||
14 | +The above copyright notice and this permission notice shall be included in | ||
15 | +all copies or substantial portions of the Software. | ||
16 | + | ||
17 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
22 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
23 | +THE SOFTWARE. |
1 | +# http-errors | ||
2 | + | ||
3 | +[![NPM Version][npm-version-image]][npm-url] | ||
4 | +[![NPM Downloads][npm-downloads-image]][node-url] | ||
5 | +[![Node.js Version][node-image]][node-url] | ||
6 | +[![Build Status][travis-image]][travis-url] | ||
7 | +[![Test Coverage][coveralls-image]][coveralls-url] | ||
8 | + | ||
9 | +Create HTTP errors for Express, Koa, Connect, etc. with ease. | ||
10 | + | ||
11 | +## Install | ||
12 | + | ||
13 | +This is a [Node.js](https://nodejs.org/en/) module available through the | ||
14 | +[npm registry](https://www.npmjs.com/). Installation is done using the | ||
15 | +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): | ||
16 | + | ||
17 | +```bash | ||
18 | +$ npm install http-errors | ||
19 | +``` | ||
20 | + | ||
21 | +## Example | ||
22 | + | ||
23 | +```js | ||
24 | +var createError = require('http-errors') | ||
25 | +var express = require('express') | ||
26 | +var app = express() | ||
27 | + | ||
28 | +app.use(function (req, res, next) { | ||
29 | + if (!req.user) return next(createError(401, 'Please login to view this page.')) | ||
30 | + next() | ||
31 | +}) | ||
32 | +``` | ||
33 | + | ||
34 | +## API | ||
35 | + | ||
36 | +This is the current API, currently extracted from Koa and subject to change. | ||
37 | + | ||
38 | +### Error Properties | ||
39 | + | ||
40 | +- `expose` - can be used to signal if `message` should be sent to the client, | ||
41 | + defaulting to `false` when `status` >= 500 | ||
42 | +- `headers` - can be an object of header names to values to be sent to the | ||
43 | + client, defaulting to `undefined`. When defined, the key names should all | ||
44 | + be lower-cased | ||
45 | +- `message` - the traditional error message, which should be kept short and all | ||
46 | + single line | ||
47 | +- `status` - the status code of the error, mirroring `statusCode` for general | ||
48 | + compatibility | ||
49 | +- `statusCode` - the status code of the error, defaulting to `500` | ||
50 | + | ||
51 | +### createError([status], [message], [properties]) | ||
52 | + | ||
53 | +Create a new error object with the given message `msg`. | ||
54 | +The error object inherits from `createError.HttpError`. | ||
55 | + | ||
56 | +<!-- eslint-disable no-undef, no-unused-vars --> | ||
57 | + | ||
58 | +```js | ||
59 | +var err = createError(404, 'This video does not exist!') | ||
60 | +``` | ||
61 | + | ||
62 | +- `status: 500` - the status code as a number | ||
63 | +- `message` - the message of the error, defaulting to node's text for that status code. | ||
64 | +- `properties` - custom properties to attach to the object | ||
65 | + | ||
66 | +### createError([status], [error], [properties]) | ||
67 | + | ||
68 | +Extend the given `error` object with `createError.HttpError` | ||
69 | +properties. This will not alter the inheritance of the given | ||
70 | +`error` object, and the modified `error` object is the | ||
71 | +return value. | ||
72 | + | ||
73 | +<!-- eslint-disable no-redeclare, no-undef, no-unused-vars --> | ||
74 | + | ||
75 | +```js | ||
76 | +fs.readFile('foo.txt', function (err, buf) { | ||
77 | + if (err) { | ||
78 | + if (err.code === 'ENOENT') { | ||
79 | + var httpError = createError(404, err, { expose: false }) | ||
80 | + } else { | ||
81 | + var httpError = createError(500, err) | ||
82 | + } | ||
83 | + } | ||
84 | +}) | ||
85 | +``` | ||
86 | + | ||
87 | +- `status` - the status code as a number | ||
88 | +- `error` - the error object to extend | ||
89 | +- `properties` - custom properties to attach to the object | ||
90 | + | ||
91 | +### new createError\[code || name\](\[msg]\)) | ||
92 | + | ||
93 | +Create a new error object with the given message `msg`. | ||
94 | +The error object inherits from `createError.HttpError`. | ||
95 | + | ||
96 | +<!-- eslint-disable no-undef, no-unused-vars --> | ||
97 | + | ||
98 | +```js | ||
99 | +var err = new createError.NotFound() | ||
100 | +``` | ||
101 | + | ||
102 | +- `code` - the status code as a number | ||
103 | +- `name` - the name of the error as a "bumpy case", i.e. `NotFound` or `InternalServerError`. | ||
104 | + | ||
105 | +#### List of all constructors | ||
106 | + | ||
107 | +|Status Code|Constructor Name | | ||
108 | +|-----------|-----------------------------| | ||
109 | +|400 |BadRequest | | ||
110 | +|401 |Unauthorized | | ||
111 | +|402 |PaymentRequired | | ||
112 | +|403 |Forbidden | | ||
113 | +|404 |NotFound | | ||
114 | +|405 |MethodNotAllowed | | ||
115 | +|406 |NotAcceptable | | ||
116 | +|407 |ProxyAuthenticationRequired | | ||
117 | +|408 |RequestTimeout | | ||
118 | +|409 |Conflict | | ||
119 | +|410 |Gone | | ||
120 | +|411 |LengthRequired | | ||
121 | +|412 |PreconditionFailed | | ||
122 | +|413 |PayloadTooLarge | | ||
123 | +|414 |URITooLong | | ||
124 | +|415 |UnsupportedMediaType | | ||
125 | +|416 |RangeNotSatisfiable | | ||
126 | +|417 |ExpectationFailed | | ||
127 | +|418 |ImATeapot | | ||
128 | +|421 |MisdirectedRequest | | ||
129 | +|422 |UnprocessableEntity | | ||
130 | +|423 |Locked | | ||
131 | +|424 |FailedDependency | | ||
132 | +|425 |UnorderedCollection | | ||
133 | +|426 |UpgradeRequired | | ||
134 | +|428 |PreconditionRequired | | ||
135 | +|429 |TooManyRequests | | ||
136 | +|431 |RequestHeaderFieldsTooLarge | | ||
137 | +|451 |UnavailableForLegalReasons | | ||
138 | +|500 |InternalServerError | | ||
139 | +|501 |NotImplemented | | ||
140 | +|502 |BadGateway | | ||
141 | +|503 |ServiceUnavailable | | ||
142 | +|504 |GatewayTimeout | | ||
143 | +|505 |HTTPVersionNotSupported | | ||
144 | +|506 |VariantAlsoNegotiates | | ||
145 | +|507 |InsufficientStorage | | ||
146 | +|508 |LoopDetected | | ||
147 | +|509 |BandwidthLimitExceeded | | ||
148 | +|510 |NotExtended | | ||
149 | +|511 |NetworkAuthenticationRequired| | ||
150 | + | ||
151 | +## License | ||
152 | + | ||
153 | +[MIT](LICENSE) | ||
154 | + | ||
155 | +[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/http-errors/master | ||
156 | +[coveralls-url]: https://coveralls.io/r/jshttp/http-errors?branch=master | ||
157 | +[node-image]: https://badgen.net/npm/node/http-errors | ||
158 | +[node-url]: https://nodejs.org/en/download | ||
159 | +[npm-downloads-image]: https://badgen.net/npm/dm/http-errors | ||
160 | +[npm-url]: https://npmjs.org/package/http-errors | ||
161 | +[npm-version-image]: https://badgen.net/npm/v/http-errors | ||
162 | +[travis-image]: https://badgen.net/travis/jshttp/http-errors/master | ||
163 | +[travis-url]: https://travis-ci.org/jshttp/http-errors |
1 | +/*! | ||
2 | + * http-errors | ||
3 | + * Copyright(c) 2014 Jonathan Ong | ||
4 | + * Copyright(c) 2016 Douglas Christopher Wilson | ||
5 | + * MIT Licensed | ||
6 | + */ | ||
7 | + | ||
8 | +'use strict' | ||
9 | + | ||
10 | +/** | ||
11 | + * Module dependencies. | ||
12 | + * @private | ||
13 | + */ | ||
14 | + | ||
15 | +var deprecate = require('depd')('http-errors') | ||
16 | +var setPrototypeOf = require('setprototypeof') | ||
17 | +var statuses = require('statuses') | ||
18 | +var inherits = require('inherits') | ||
19 | +var toIdentifier = require('toidentifier') | ||
20 | + | ||
21 | +/** | ||
22 | + * Module exports. | ||
23 | + * @public | ||
24 | + */ | ||
25 | + | ||
26 | +module.exports = createError | ||
27 | +module.exports.HttpError = createHttpErrorConstructor() | ||
28 | + | ||
29 | +// Populate exports for all constructors | ||
30 | +populateConstructorExports(module.exports, statuses.codes, module.exports.HttpError) | ||
31 | + | ||
32 | +/** | ||
33 | + * Get the code class of a status code. | ||
34 | + * @private | ||
35 | + */ | ||
36 | + | ||
37 | +function codeClass (status) { | ||
38 | + return Number(String(status).charAt(0) + '00') | ||
39 | +} | ||
40 | + | ||
41 | +/** | ||
42 | + * Create a new HTTP Error. | ||
43 | + * | ||
44 | + * @returns {Error} | ||
45 | + * @public | ||
46 | + */ | ||
47 | + | ||
48 | +function createError () { | ||
49 | + // so much arity going on ~_~ | ||
50 | + var err | ||
51 | + var msg | ||
52 | + var status = 500 | ||
53 | + var props = {} | ||
54 | + for (var i = 0; i < arguments.length; i++) { | ||
55 | + var arg = arguments[i] | ||
56 | + if (arg instanceof Error) { | ||
57 | + err = arg | ||
58 | + status = err.status || err.statusCode || status | ||
59 | + continue | ||
60 | + } | ||
61 | + switch (typeof arg) { | ||
62 | + case 'string': | ||
63 | + msg = arg | ||
64 | + break | ||
65 | + case 'number': | ||
66 | + status = arg | ||
67 | + if (i !== 0) { | ||
68 | + deprecate('non-first-argument status code; replace with createError(' + arg + ', ...)') | ||
69 | + } | ||
70 | + break | ||
71 | + case 'object': | ||
72 | + props = arg | ||
73 | + break | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + if (typeof status === 'number' && (status < 400 || status >= 600)) { | ||
78 | + deprecate('non-error status code; use only 4xx or 5xx status codes') | ||
79 | + } | ||
80 | + | ||
81 | + if (typeof status !== 'number' || | ||
82 | + (!statuses[status] && (status < 400 || status >= 600))) { | ||
83 | + status = 500 | ||
84 | + } | ||
85 | + | ||
86 | + // constructor | ||
87 | + var HttpError = createError[status] || createError[codeClass(status)] | ||
88 | + | ||
89 | + if (!err) { | ||
90 | + // create error | ||
91 | + err = HttpError | ||
92 | + ? new HttpError(msg) | ||
93 | + : new Error(msg || statuses[status]) | ||
94 | + Error.captureStackTrace(err, createError) | ||
95 | + } | ||
96 | + | ||
97 | + if (!HttpError || !(err instanceof HttpError) || err.status !== status) { | ||
98 | + // add properties to generic error | ||
99 | + err.expose = status < 500 | ||
100 | + err.status = err.statusCode = status | ||
101 | + } | ||
102 | + | ||
103 | + for (var key in props) { | ||
104 | + if (key !== 'status' && key !== 'statusCode') { | ||
105 | + err[key] = props[key] | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + return err | ||
110 | +} | ||
111 | + | ||
112 | +/** | ||
113 | + * Create HTTP error abstract base class. | ||
114 | + * @private | ||
115 | + */ | ||
116 | + | ||
117 | +function createHttpErrorConstructor () { | ||
118 | + function HttpError () { | ||
119 | + throw new TypeError('cannot construct abstract class') | ||
120 | + } | ||
121 | + | ||
122 | + inherits(HttpError, Error) | ||
123 | + | ||
124 | + return HttpError | ||
125 | +} | ||
126 | + | ||
127 | +/** | ||
128 | + * Create a constructor for a client error. | ||
129 | + * @private | ||
130 | + */ | ||
131 | + | ||
132 | +function createClientErrorConstructor (HttpError, name, code) { | ||
133 | + var className = name.match(/Error$/) ? name : name + 'Error' | ||
134 | + | ||
135 | + function ClientError (message) { | ||
136 | + // create the error object | ||
137 | + var msg = message != null ? message : statuses[code] | ||
138 | + var err = new Error(msg) | ||
139 | + | ||
140 | + // capture a stack trace to the construction point | ||
141 | + Error.captureStackTrace(err, ClientError) | ||
142 | + | ||
143 | + // adjust the [[Prototype]] | ||
144 | + setPrototypeOf(err, ClientError.prototype) | ||
145 | + | ||
146 | + // redefine the error message | ||
147 | + Object.defineProperty(err, 'message', { | ||
148 | + enumerable: true, | ||
149 | + configurable: true, | ||
150 | + value: msg, | ||
151 | + writable: true | ||
152 | + }) | ||
153 | + | ||
154 | + // redefine the error name | ||
155 | + Object.defineProperty(err, 'name', { | ||
156 | + enumerable: false, | ||
157 | + configurable: true, | ||
158 | + value: className, | ||
159 | + writable: true | ||
160 | + }) | ||
161 | + | ||
162 | + return err | ||
163 | + } | ||
164 | + | ||
165 | + inherits(ClientError, HttpError) | ||
166 | + nameFunc(ClientError, className) | ||
167 | + | ||
168 | + ClientError.prototype.status = code | ||
169 | + ClientError.prototype.statusCode = code | ||
170 | + ClientError.prototype.expose = true | ||
171 | + | ||
172 | + return ClientError | ||
173 | +} | ||
174 | + | ||
175 | +/** | ||
176 | + * Create a constructor for a server error. | ||
177 | + * @private | ||
178 | + */ | ||
179 | + | ||
180 | +function createServerErrorConstructor (HttpError, name, code) { | ||
181 | + var className = name.match(/Error$/) ? name : name + 'Error' | ||
182 | + | ||
183 | + function ServerError (message) { | ||
184 | + // create the error object | ||
185 | + var msg = message != null ? message : statuses[code] | ||
186 | + var err = new Error(msg) | ||
187 | + | ||
188 | + // capture a stack trace to the construction point | ||
189 | + Error.captureStackTrace(err, ServerError) | ||
190 | + | ||
191 | + // adjust the [[Prototype]] | ||
192 | + setPrototypeOf(err, ServerError.prototype) | ||
193 | + | ||
194 | + // redefine the error message | ||
195 | + Object.defineProperty(err, 'message', { | ||
196 | + enumerable: true, | ||
197 | + configurable: true, | ||
198 | + value: msg, | ||
199 | + writable: true | ||
200 | + }) | ||
201 | + | ||
202 | + // redefine the error name | ||
203 | + Object.defineProperty(err, 'name', { | ||
204 | + enumerable: false, | ||
205 | + configurable: true, | ||
206 | + value: className, | ||
207 | + writable: true | ||
208 | + }) | ||
209 | + | ||
210 | + return err | ||
211 | + } | ||
212 | + | ||
213 | + inherits(ServerError, HttpError) | ||
214 | + nameFunc(ServerError, className) | ||
215 | + | ||
216 | + ServerError.prototype.status = code | ||
217 | + ServerError.prototype.statusCode = code | ||
218 | + ServerError.prototype.expose = false | ||
219 | + | ||
220 | + return ServerError | ||
221 | +} | ||
222 | + | ||
223 | +/** | ||
224 | + * Set the name of a function, if possible. | ||
225 | + * @private | ||
226 | + */ | ||
227 | + | ||
228 | +function nameFunc (func, name) { | ||
229 | + var desc = Object.getOwnPropertyDescriptor(func, 'name') | ||
230 | + | ||
231 | + if (desc && desc.configurable) { | ||
232 | + desc.value = name | ||
233 | + Object.defineProperty(func, 'name', desc) | ||
234 | + } | ||
235 | +} | ||
236 | + | ||
237 | +/** | ||
238 | + * Populate the exports object with constructors for every error class. | ||
239 | + * @private | ||
240 | + */ | ||
241 | + | ||
242 | +function populateConstructorExports (exports, codes, HttpError) { | ||
243 | + codes.forEach(function forEachCode (code) { | ||
244 | + var CodeError | ||
245 | + var name = toIdentifier(statuses[code]) | ||
246 | + | ||
247 | + switch (codeClass(code)) { | ||
248 | + case 400: | ||
249 | + CodeError = createClientErrorConstructor(HttpError, name, code) | ||
250 | + break | ||
251 | + case 500: | ||
252 | + CodeError = createServerErrorConstructor(HttpError, name, code) | ||
253 | + break | ||
254 | + } | ||
255 | + | ||
256 | + if (CodeError) { | ||
257 | + // export the constructor | ||
258 | + exports[code] = CodeError | ||
259 | + exports[name] = CodeError | ||
260 | + } | ||
261 | + }) | ||
262 | + | ||
263 | + // backwards-compatibility | ||
264 | + exports["I'mateapot"] = deprecate.function(exports.ImATeapot, | ||
265 | + '"I\'mateapot"; use "ImATeapot" instead') | ||
266 | +} |
1 | +{ | ||
2 | + "_from": "http-errors@1.7.2", | ||
3 | + "_id": "http-errors@1.7.2", | ||
4 | + "_inBundle": false, | ||
5 | + "_integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", | ||
6 | + "_location": "/body-parser/http-errors", | ||
7 | + "_phantomChildren": {}, | ||
8 | + "_requested": { | ||
9 | + "type": "version", | ||
10 | + "registry": true, | ||
11 | + "raw": "http-errors@1.7.2", | ||
12 | + "name": "http-errors", | ||
13 | + "escapedName": "http-errors", | ||
14 | + "rawSpec": "1.7.2", | ||
15 | + "saveSpec": null, | ||
16 | + "fetchSpec": "1.7.2" | ||
17 | + }, | ||
18 | + "_requiredBy": [ | ||
19 | + "/body-parser" | ||
20 | + ], | ||
21 | + "_resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", | ||
22 | + "_shasum": "4f5029cf13239f31036e5b2e55292bcfbcc85c8f", | ||
23 | + "_spec": "http-errors@1.7.2", | ||
24 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\body-parser", | ||
25 | + "author": { | ||
26 | + "name": "Jonathan Ong", | ||
27 | + "email": "me@jongleberry.com", | ||
28 | + "url": "http://jongleberry.com" | ||
29 | + }, | ||
30 | + "bugs": { | ||
31 | + "url": "https://github.com/jshttp/http-errors/issues" | ||
32 | + }, | ||
33 | + "bundleDependencies": false, | ||
34 | + "contributors": [ | ||
35 | + { | ||
36 | + "name": "Alan Plum", | ||
37 | + "email": "me@pluma.io" | ||
38 | + }, | ||
39 | + { | ||
40 | + "name": "Douglas Christopher Wilson", | ||
41 | + "email": "doug@somethingdoug.com" | ||
42 | + } | ||
43 | + ], | ||
44 | + "dependencies": { | ||
45 | + "depd": "~1.1.2", | ||
46 | + "inherits": "2.0.3", | ||
47 | + "setprototypeof": "1.1.1", | ||
48 | + "statuses": ">= 1.5.0 < 2", | ||
49 | + "toidentifier": "1.0.0" | ||
50 | + }, | ||
51 | + "deprecated": false, | ||
52 | + "description": "Create HTTP error objects", | ||
53 | + "devDependencies": { | ||
54 | + "eslint": "5.13.0", | ||
55 | + "eslint-config-standard": "12.0.0", | ||
56 | + "eslint-plugin-import": "2.16.0", | ||
57 | + "eslint-plugin-markdown": "1.0.0", | ||
58 | + "eslint-plugin-node": "7.0.1", | ||
59 | + "eslint-plugin-promise": "4.0.1", | ||
60 | + "eslint-plugin-standard": "4.0.0", | ||
61 | + "istanbul": "0.4.5", | ||
62 | + "mocha": "5.2.0" | ||
63 | + }, | ||
64 | + "engines": { | ||
65 | + "node": ">= 0.6" | ||
66 | + }, | ||
67 | + "files": [ | ||
68 | + "index.js", | ||
69 | + "HISTORY.md", | ||
70 | + "LICENSE", | ||
71 | + "README.md" | ||
72 | + ], | ||
73 | + "homepage": "https://github.com/jshttp/http-errors#readme", | ||
74 | + "keywords": [ | ||
75 | + "http", | ||
76 | + "error" | ||
77 | + ], | ||
78 | + "license": "MIT", | ||
79 | + "name": "http-errors", | ||
80 | + "repository": { | ||
81 | + "type": "git", | ||
82 | + "url": "git+https://github.com/jshttp/http-errors.git" | ||
83 | + }, | ||
84 | + "scripts": { | ||
85 | + "lint": "eslint --plugin markdown --ext js,md . && node ./scripts/lint-readme-list.js", | ||
86 | + "test": "mocha --reporter spec --bail", | ||
87 | + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot", | ||
88 | + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot" | ||
89 | + }, | ||
90 | + "version": "1.7.2" | ||
91 | +} |
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 | + | ||
12 | +[test/*] | ||
13 | +max_line_length = off | ||
14 | + | ||
15 | +[*.md] | ||
16 | +max_line_length = off | ||
17 | + | ||
18 | +[*.json] | ||
19 | +max_line_length = off | ||
20 | + | ||
21 | +[Makefile] | ||
22 | +max_line_length = off | ||
23 | + | ||
24 | +[CHANGELOG.md] | ||
25 | +indent_style = space | ||
26 | +indent_size = 2 | ||
27 | + | ||
28 | +[LICENSE] | ||
29 | +indent_size = 2 | ||
30 | +max_line_length = off |
1 | +dist |
1 | +{ | ||
2 | + "root": true, | ||
3 | + | ||
4 | + "extends": "@ljharb", | ||
5 | + | ||
6 | + "rules": { | ||
7 | + "complexity": 0, | ||
8 | + "consistent-return": 1, | ||
9 | + "func-name-matching": 0, | ||
10 | + "id-length": [2, { "min": 1, "max": 25, "properties": "never" }], | ||
11 | + "indent": [2, 4], | ||
12 | + "max-lines-per-function": [2, { "max": 150 }], | ||
13 | + "max-params": [2, 14], | ||
14 | + "max-statements": [2, 52], | ||
15 | + "multiline-comment-style": 0, | ||
16 | + "no-continue": 1, | ||
17 | + "no-magic-numbers": 0, | ||
18 | + "no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"], | ||
19 | + "operator-linebreak": [2, "before"], | ||
20 | + } | ||
21 | +} |
This diff is collapsed. Click to expand it.
1 | +Copyright (c) 2014 Nathan LaFreniere and other contributors. | ||
2 | +All rights reserved. | ||
3 | + | ||
4 | +Redistribution and use in source and binary forms, with or without | ||
5 | +modification, are permitted provided that the following conditions are met: | ||
6 | + * Redistributions of source code must retain the above copyright | ||
7 | + notice, this list of conditions and the following disclaimer. | ||
8 | + * Redistributions in binary form must reproduce the above copyright | ||
9 | + notice, this list of conditions and the following disclaimer in the | ||
10 | + documentation and/or other materials provided with the distribution. | ||
11 | + * The names of any contributors may not be used to endorse or promote | ||
12 | + products derived from this software without specific prior written | ||
13 | + permission. | ||
14 | + | ||
15 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
16 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
17 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
18 | +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY | ||
19 | +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
20 | +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
21 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
22 | +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
23 | +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
24 | +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
25 | + | ||
26 | + * * * | ||
27 | + | ||
28 | +The complete list of contributors can be found at: https://github.com/hapijs/qs/graphs/contributors |
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 | +module.exports = { | ||
7 | + 'default': 'RFC3986', | ||
8 | + formatters: { | ||
9 | + RFC1738: function (value) { | ||
10 | + return replace.call(value, percentTwenties, '+'); | ||
11 | + }, | ||
12 | + RFC3986: function (value) { | ||
13 | + return value; | ||
14 | + } | ||
15 | + }, | ||
16 | + RFC1738: 'RFC1738', | ||
17 | + RFC3986: 'RFC3986' | ||
18 | +}; |
1 | +'use strict'; | ||
2 | + | ||
3 | +var utils = require('./utils'); | ||
4 | + | ||
5 | +var has = Object.prototype.hasOwnProperty; | ||
6 | + | ||
7 | +var defaults = { | ||
8 | + allowDots: false, | ||
9 | + allowPrototypes: false, | ||
10 | + arrayLimit: 20, | ||
11 | + charset: 'utf-8', | ||
12 | + charsetSentinel: false, | ||
13 | + comma: false, | ||
14 | + decoder: utils.decode, | ||
15 | + delimiter: '&', | ||
16 | + depth: 5, | ||
17 | + ignoreQueryPrefix: false, | ||
18 | + interpretNumericEntities: false, | ||
19 | + parameterLimit: 1000, | ||
20 | + parseArrays: true, | ||
21 | + plainObjects: false, | ||
22 | + strictNullHandling: false | ||
23 | +}; | ||
24 | + | ||
25 | +var interpretNumericEntities = function (str) { | ||
26 | + return str.replace(/&#(\d+);/g, function ($0, numberStr) { | ||
27 | + return String.fromCharCode(parseInt(numberStr, 10)); | ||
28 | + }); | ||
29 | +}; | ||
30 | + | ||
31 | +// This is what browsers will submit when the ✓ character occurs in an | ||
32 | +// application/x-www-form-urlencoded body and the encoding of the page containing | ||
33 | +// the form is iso-8859-1, or when the submitted form has an accept-charset | ||
34 | +// attribute of iso-8859-1. Presumably also with other charsets that do not contain | ||
35 | +// the ✓ character, such as us-ascii. | ||
36 | +var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓') | ||
37 | + | ||
38 | +// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded. | ||
39 | +var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓') | ||
40 | + | ||
41 | +var parseValues = function parseQueryStringValues(str, options) { | ||
42 | + var obj = {}; | ||
43 | + var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str; | ||
44 | + var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit; | ||
45 | + var parts = cleanStr.split(options.delimiter, limit); | ||
46 | + var skipIndex = -1; // Keep track of where the utf8 sentinel was found | ||
47 | + var i; | ||
48 | + | ||
49 | + var charset = options.charset; | ||
50 | + if (options.charsetSentinel) { | ||
51 | + for (i = 0; i < parts.length; ++i) { | ||
52 | + if (parts[i].indexOf('utf8=') === 0) { | ||
53 | + if (parts[i] === charsetSentinel) { | ||
54 | + charset = 'utf-8'; | ||
55 | + } else if (parts[i] === isoSentinel) { | ||
56 | + charset = 'iso-8859-1'; | ||
57 | + } | ||
58 | + skipIndex = i; | ||
59 | + i = parts.length; // The eslint settings do not allow break; | ||
60 | + } | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + for (i = 0; i < parts.length; ++i) { | ||
65 | + if (i === skipIndex) { | ||
66 | + continue; | ||
67 | + } | ||
68 | + var part = parts[i]; | ||
69 | + | ||
70 | + var bracketEqualsPos = part.indexOf(']='); | ||
71 | + var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1; | ||
72 | + | ||
73 | + var key, val; | ||
74 | + if (pos === -1) { | ||
75 | + key = options.decoder(part, defaults.decoder, charset); | ||
76 | + val = options.strictNullHandling ? null : ''; | ||
77 | + } else { | ||
78 | + key = options.decoder(part.slice(0, pos), defaults.decoder, charset); | ||
79 | + val = options.decoder(part.slice(pos + 1), defaults.decoder, charset); | ||
80 | + } | ||
81 | + | ||
82 | + if (val && options.interpretNumericEntities && charset === 'iso-8859-1') { | ||
83 | + val = interpretNumericEntities(val); | ||
84 | + } | ||
85 | + | ||
86 | + if (val && options.comma && val.indexOf(',') > -1) { | ||
87 | + val = val.split(','); | ||
88 | + } | ||
89 | + | ||
90 | + if (has.call(obj, key)) { | ||
91 | + obj[key] = utils.combine(obj[key], val); | ||
92 | + } else { | ||
93 | + obj[key] = val; | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | + return obj; | ||
98 | +}; | ||
99 | + | ||
100 | +var parseObject = function (chain, val, options) { | ||
101 | + var leaf = val; | ||
102 | + | ||
103 | + for (var i = chain.length - 1; i >= 0; --i) { | ||
104 | + var obj; | ||
105 | + var root = chain[i]; | ||
106 | + | ||
107 | + if (root === '[]' && options.parseArrays) { | ||
108 | + obj = [].concat(leaf); | ||
109 | + } else { | ||
110 | + obj = options.plainObjects ? Object.create(null) : {}; | ||
111 | + var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; | ||
112 | + var index = parseInt(cleanRoot, 10); | ||
113 | + if (!options.parseArrays && cleanRoot === '') { | ||
114 | + obj = { 0: leaf }; | ||
115 | + } else if ( | ||
116 | + !isNaN(index) | ||
117 | + && root !== cleanRoot | ||
118 | + && String(index) === cleanRoot | ||
119 | + && index >= 0 | ||
120 | + && (options.parseArrays && index <= options.arrayLimit) | ||
121 | + ) { | ||
122 | + obj = []; | ||
123 | + obj[index] = leaf; | ||
124 | + } else { | ||
125 | + obj[cleanRoot] = leaf; | ||
126 | + } | ||
127 | + } | ||
128 | + | ||
129 | + leaf = obj; | ||
130 | + } | ||
131 | + | ||
132 | + return leaf; | ||
133 | +}; | ||
134 | + | ||
135 | +var parseKeys = function parseQueryStringKeys(givenKey, val, options) { | ||
136 | + if (!givenKey) { | ||
137 | + return; | ||
138 | + } | ||
139 | + | ||
140 | + // Transform dot notation to bracket notation | ||
141 | + var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey; | ||
142 | + | ||
143 | + // The regex chunks | ||
144 | + | ||
145 | + var brackets = /(\[[^[\]]*])/; | ||
146 | + var child = /(\[[^[\]]*])/g; | ||
147 | + | ||
148 | + // Get the parent | ||
149 | + | ||
150 | + var segment = brackets.exec(key); | ||
151 | + var parent = segment ? key.slice(0, segment.index) : key; | ||
152 | + | ||
153 | + // Stash the parent if it exists | ||
154 | + | ||
155 | + var keys = []; | ||
156 | + if (parent) { | ||
157 | + // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties | ||
158 | + if (!options.plainObjects && has.call(Object.prototype, parent)) { | ||
159 | + if (!options.allowPrototypes) { | ||
160 | + return; | ||
161 | + } | ||
162 | + } | ||
163 | + | ||
164 | + keys.push(parent); | ||
165 | + } | ||
166 | + | ||
167 | + // Loop through children appending to the array until we hit depth | ||
168 | + | ||
169 | + var i = 0; | ||
170 | + while ((segment = child.exec(key)) !== null && i < options.depth) { | ||
171 | + i += 1; | ||
172 | + if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) { | ||
173 | + if (!options.allowPrototypes) { | ||
174 | + return; | ||
175 | + } | ||
176 | + } | ||
177 | + keys.push(segment[1]); | ||
178 | + } | ||
179 | + | ||
180 | + // If there's a remainder, just add whatever is left | ||
181 | + | ||
182 | + if (segment) { | ||
183 | + keys.push('[' + key.slice(segment.index) + ']'); | ||
184 | + } | ||
185 | + | ||
186 | + return parseObject(keys, val, options); | ||
187 | +}; | ||
188 | + | ||
189 | +var normalizeParseOptions = function normalizeParseOptions(opts) { | ||
190 | + if (!opts) { | ||
191 | + return defaults; | ||
192 | + } | ||
193 | + | ||
194 | + if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') { | ||
195 | + throw new TypeError('Decoder has to be a function.'); | ||
196 | + } | ||
197 | + | ||
198 | + if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') { | ||
199 | + throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined'); | ||
200 | + } | ||
201 | + var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset; | ||
202 | + | ||
203 | + return { | ||
204 | + allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots, | ||
205 | + allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes, | ||
206 | + arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit, | ||
207 | + charset: charset, | ||
208 | + charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel, | ||
209 | + comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma, | ||
210 | + decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder, | ||
211 | + delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter, | ||
212 | + depth: typeof opts.depth === 'number' ? opts.depth : defaults.depth, | ||
213 | + ignoreQueryPrefix: opts.ignoreQueryPrefix === true, | ||
214 | + interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities, | ||
215 | + parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit, | ||
216 | + parseArrays: opts.parseArrays !== false, | ||
217 | + plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects, | ||
218 | + strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling | ||
219 | + }; | ||
220 | +}; | ||
221 | + | ||
222 | +module.exports = function (str, opts) { | ||
223 | + var options = normalizeParseOptions(opts); | ||
224 | + | ||
225 | + if (str === '' || str === null || typeof str === 'undefined') { | ||
226 | + return options.plainObjects ? Object.create(null) : {}; | ||
227 | + } | ||
228 | + | ||
229 | + var tempObj = typeof str === 'string' ? parseValues(str, options) : str; | ||
230 | + var obj = options.plainObjects ? Object.create(null) : {}; | ||
231 | + | ||
232 | + // Iterate over the keys and setup the new object | ||
233 | + | ||
234 | + var keys = Object.keys(tempObj); | ||
235 | + for (var i = 0; i < keys.length; ++i) { | ||
236 | + var key = keys[i]; | ||
237 | + var newObj = parseKeys(key, tempObj[key], options); | ||
238 | + obj = utils.merge(obj, newObj, options); | ||
239 | + } | ||
240 | + | ||
241 | + return utils.compact(obj); | ||
242 | +}; |
1 | +'use strict'; | ||
2 | + | ||
3 | +var utils = require('./utils'); | ||
4 | +var formats = require('./formats'); | ||
5 | +var has = Object.prototype.hasOwnProperty; | ||
6 | + | ||
7 | +var arrayPrefixGenerators = { | ||
8 | + brackets: function brackets(prefix) { // eslint-disable-line func-name-matching | ||
9 | + return prefix + '[]'; | ||
10 | + }, | ||
11 | + comma: 'comma', | ||
12 | + indices: function indices(prefix, key) { // eslint-disable-line func-name-matching | ||
13 | + return prefix + '[' + key + ']'; | ||
14 | + }, | ||
15 | + repeat: function repeat(prefix) { // eslint-disable-line func-name-matching | ||
16 | + return prefix; | ||
17 | + } | ||
18 | +}; | ||
19 | + | ||
20 | +var isArray = Array.isArray; | ||
21 | +var push = Array.prototype.push; | ||
22 | +var pushToArray = function (arr, valueOrArray) { | ||
23 | + push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]); | ||
24 | +}; | ||
25 | + | ||
26 | +var toISO = Date.prototype.toISOString; | ||
27 | + | ||
28 | +var defaults = { | ||
29 | + addQueryPrefix: false, | ||
30 | + allowDots: false, | ||
31 | + charset: 'utf-8', | ||
32 | + charsetSentinel: false, | ||
33 | + delimiter: '&', | ||
34 | + encode: true, | ||
35 | + encoder: utils.encode, | ||
36 | + encodeValuesOnly: false, | ||
37 | + formatter: formats.formatters[formats['default']], | ||
38 | + // deprecated | ||
39 | + indices: false, | ||
40 | + serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching | ||
41 | + return toISO.call(date); | ||
42 | + }, | ||
43 | + skipNulls: false, | ||
44 | + strictNullHandling: false | ||
45 | +}; | ||
46 | + | ||
47 | +var stringify = function stringify( // eslint-disable-line func-name-matching | ||
48 | + object, | ||
49 | + prefix, | ||
50 | + generateArrayPrefix, | ||
51 | + strictNullHandling, | ||
52 | + skipNulls, | ||
53 | + encoder, | ||
54 | + filter, | ||
55 | + sort, | ||
56 | + allowDots, | ||
57 | + serializeDate, | ||
58 | + formatter, | ||
59 | + encodeValuesOnly, | ||
60 | + charset | ||
61 | +) { | ||
62 | + var obj = object; | ||
63 | + if (typeof filter === 'function') { | ||
64 | + obj = filter(prefix, obj); | ||
65 | + } else if (obj instanceof Date) { | ||
66 | + obj = serializeDate(obj); | ||
67 | + } else if (generateArrayPrefix === 'comma' && isArray(obj)) { | ||
68 | + obj = obj.join(','); | ||
69 | + } | ||
70 | + | ||
71 | + if (obj === null) { | ||
72 | + if (strictNullHandling) { | ||
73 | + return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset) : prefix; | ||
74 | + } | ||
75 | + | ||
76 | + obj = ''; | ||
77 | + } | ||
78 | + | ||
79 | + if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) { | ||
80 | + if (encoder) { | ||
81 | + var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset); | ||
82 | + return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset))]; | ||
83 | + } | ||
84 | + return [formatter(prefix) + '=' + formatter(String(obj))]; | ||
85 | + } | ||
86 | + | ||
87 | + var values = []; | ||
88 | + | ||
89 | + if (typeof obj === 'undefined') { | ||
90 | + return values; | ||
91 | + } | ||
92 | + | ||
93 | + var objKeys; | ||
94 | + if (isArray(filter)) { | ||
95 | + objKeys = filter; | ||
96 | + } else { | ||
97 | + var keys = Object.keys(obj); | ||
98 | + objKeys = sort ? keys.sort(sort) : keys; | ||
99 | + } | ||
100 | + | ||
101 | + for (var i = 0; i < objKeys.length; ++i) { | ||
102 | + var key = objKeys[i]; | ||
103 | + | ||
104 | + if (skipNulls && obj[key] === null) { | ||
105 | + continue; | ||
106 | + } | ||
107 | + | ||
108 | + if (isArray(obj)) { | ||
109 | + pushToArray(values, stringify( | ||
110 | + obj[key], | ||
111 | + typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix, | ||
112 | + generateArrayPrefix, | ||
113 | + strictNullHandling, | ||
114 | + skipNulls, | ||
115 | + encoder, | ||
116 | + filter, | ||
117 | + sort, | ||
118 | + allowDots, | ||
119 | + serializeDate, | ||
120 | + formatter, | ||
121 | + encodeValuesOnly, | ||
122 | + charset | ||
123 | + )); | ||
124 | + } else { | ||
125 | + pushToArray(values, stringify( | ||
126 | + obj[key], | ||
127 | + prefix + (allowDots ? '.' + key : '[' + key + ']'), | ||
128 | + generateArrayPrefix, | ||
129 | + strictNullHandling, | ||
130 | + skipNulls, | ||
131 | + encoder, | ||
132 | + filter, | ||
133 | + sort, | ||
134 | + allowDots, | ||
135 | + serializeDate, | ||
136 | + formatter, | ||
137 | + encodeValuesOnly, | ||
138 | + charset | ||
139 | + )); | ||
140 | + } | ||
141 | + } | ||
142 | + | ||
143 | + return values; | ||
144 | +}; | ||
145 | + | ||
146 | +var normalizeStringifyOptions = function normalizeStringifyOptions(opts) { | ||
147 | + if (!opts) { | ||
148 | + return defaults; | ||
149 | + } | ||
150 | + | ||
151 | + if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') { | ||
152 | + throw new TypeError('Encoder has to be a function.'); | ||
153 | + } | ||
154 | + | ||
155 | + var charset = opts.charset || defaults.charset; | ||
156 | + if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') { | ||
157 | + throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'); | ||
158 | + } | ||
159 | + | ||
160 | + var format = formats['default']; | ||
161 | + if (typeof opts.format !== 'undefined') { | ||
162 | + if (!has.call(formats.formatters, opts.format)) { | ||
163 | + throw new TypeError('Unknown format option provided.'); | ||
164 | + } | ||
165 | + format = opts.format; | ||
166 | + } | ||
167 | + var formatter = formats.formatters[format]; | ||
168 | + | ||
169 | + var filter = defaults.filter; | ||
170 | + if (typeof opts.filter === 'function' || isArray(opts.filter)) { | ||
171 | + filter = opts.filter; | ||
172 | + } | ||
173 | + | ||
174 | + return { | ||
175 | + addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix, | ||
176 | + allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots, | ||
177 | + charset: charset, | ||
178 | + charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel, | ||
179 | + delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter, | ||
180 | + encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode, | ||
181 | + encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder, | ||
182 | + encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly, | ||
183 | + filter: filter, | ||
184 | + formatter: formatter, | ||
185 | + serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate, | ||
186 | + skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls, | ||
187 | + sort: typeof opts.sort === 'function' ? opts.sort : null, | ||
188 | + strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling | ||
189 | + }; | ||
190 | +}; | ||
191 | + | ||
192 | +module.exports = function (object, opts) { | ||
193 | + var obj = object; | ||
194 | + var options = normalizeStringifyOptions(opts); | ||
195 | + | ||
196 | + var objKeys; | ||
197 | + var filter; | ||
198 | + | ||
199 | + if (typeof options.filter === 'function') { | ||
200 | + filter = options.filter; | ||
201 | + obj = filter('', obj); | ||
202 | + } else if (isArray(options.filter)) { | ||
203 | + filter = options.filter; | ||
204 | + objKeys = filter; | ||
205 | + } | ||
206 | + | ||
207 | + var keys = []; | ||
208 | + | ||
209 | + if (typeof obj !== 'object' || obj === null) { | ||
210 | + return ''; | ||
211 | + } | ||
212 | + | ||
213 | + var arrayFormat; | ||
214 | + if (opts && opts.arrayFormat in arrayPrefixGenerators) { | ||
215 | + arrayFormat = opts.arrayFormat; | ||
216 | + } else if (opts && 'indices' in opts) { | ||
217 | + arrayFormat = opts.indices ? 'indices' : 'repeat'; | ||
218 | + } else { | ||
219 | + arrayFormat = 'indices'; | ||
220 | + } | ||
221 | + | ||
222 | + var generateArrayPrefix = arrayPrefixGenerators[arrayFormat]; | ||
223 | + | ||
224 | + if (!objKeys) { | ||
225 | + objKeys = Object.keys(obj); | ||
226 | + } | ||
227 | + | ||
228 | + if (options.sort) { | ||
229 | + objKeys.sort(options.sort); | ||
230 | + } | ||
231 | + | ||
232 | + for (var i = 0; i < objKeys.length; ++i) { | ||
233 | + var key = objKeys[i]; | ||
234 | + | ||
235 | + if (options.skipNulls && obj[key] === null) { | ||
236 | + continue; | ||
237 | + } | ||
238 | + pushToArray(keys, stringify( | ||
239 | + obj[key], | ||
240 | + key, | ||
241 | + generateArrayPrefix, | ||
242 | + options.strictNullHandling, | ||
243 | + options.skipNulls, | ||
244 | + options.encode ? options.encoder : null, | ||
245 | + options.filter, | ||
246 | + options.sort, | ||
247 | + options.allowDots, | ||
248 | + options.serializeDate, | ||
249 | + options.formatter, | ||
250 | + options.encodeValuesOnly, | ||
251 | + options.charset | ||
252 | + )); | ||
253 | + } | ||
254 | + | ||
255 | + var joined = keys.join(options.delimiter); | ||
256 | + var prefix = options.addQueryPrefix === true ? '?' : ''; | ||
257 | + | ||
258 | + if (options.charsetSentinel) { | ||
259 | + if (options.charset === 'iso-8859-1') { | ||
260 | + // encodeURIComponent('✓'), the "numeric entity" representation of a checkmark | ||
261 | + prefix += 'utf8=%26%2310003%3B&'; | ||
262 | + } else { | ||
263 | + // encodeURIComponent('✓') | ||
264 | + prefix += 'utf8=%E2%9C%93&'; | ||
265 | + } | ||
266 | + } | ||
267 | + | ||
268 | + return joined.length > 0 ? prefix + joined : ''; | ||
269 | +}; |
1 | +'use strict'; | ||
2 | + | ||
3 | +var has = Object.prototype.hasOwnProperty; | ||
4 | +var isArray = Array.isArray; | ||
5 | + | ||
6 | +var hexTable = (function () { | ||
7 | + var array = []; | ||
8 | + for (var i = 0; i < 256; ++i) { | ||
9 | + array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase()); | ||
10 | + } | ||
11 | + | ||
12 | + return array; | ||
13 | +}()); | ||
14 | + | ||
15 | +var compactQueue = function compactQueue(queue) { | ||
16 | + while (queue.length > 1) { | ||
17 | + var item = queue.pop(); | ||
18 | + var obj = item.obj[item.prop]; | ||
19 | + | ||
20 | + if (isArray(obj)) { | ||
21 | + var compacted = []; | ||
22 | + | ||
23 | + for (var j = 0; j < obj.length; ++j) { | ||
24 | + if (typeof obj[j] !== 'undefined') { | ||
25 | + compacted.push(obj[j]); | ||
26 | + } | ||
27 | + } | ||
28 | + | ||
29 | + item.obj[item.prop] = compacted; | ||
30 | + } | ||
31 | + } | ||
32 | +}; | ||
33 | + | ||
34 | +var arrayToObject = function arrayToObject(source, options) { | ||
35 | + var obj = options && options.plainObjects ? Object.create(null) : {}; | ||
36 | + for (var i = 0; i < source.length; ++i) { | ||
37 | + if (typeof source[i] !== 'undefined') { | ||
38 | + obj[i] = source[i]; | ||
39 | + } | ||
40 | + } | ||
41 | + | ||
42 | + return obj; | ||
43 | +}; | ||
44 | + | ||
45 | +var merge = function merge(target, source, options) { | ||
46 | + if (!source) { | ||
47 | + return target; | ||
48 | + } | ||
49 | + | ||
50 | + if (typeof source !== 'object') { | ||
51 | + if (isArray(target)) { | ||
52 | + target.push(source); | ||
53 | + } else if (target && typeof target === 'object') { | ||
54 | + if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) { | ||
55 | + target[source] = true; | ||
56 | + } | ||
57 | + } else { | ||
58 | + return [target, source]; | ||
59 | + } | ||
60 | + | ||
61 | + return target; | ||
62 | + } | ||
63 | + | ||
64 | + if (!target || typeof target !== 'object') { | ||
65 | + return [target].concat(source); | ||
66 | + } | ||
67 | + | ||
68 | + var mergeTarget = target; | ||
69 | + if (isArray(target) && !isArray(source)) { | ||
70 | + mergeTarget = arrayToObject(target, options); | ||
71 | + } | ||
72 | + | ||
73 | + if (isArray(target) && isArray(source)) { | ||
74 | + source.forEach(function (item, i) { | ||
75 | + if (has.call(target, i)) { | ||
76 | + var targetItem = target[i]; | ||
77 | + if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') { | ||
78 | + target[i] = merge(targetItem, item, options); | ||
79 | + } else { | ||
80 | + target.push(item); | ||
81 | + } | ||
82 | + } else { | ||
83 | + target[i] = item; | ||
84 | + } | ||
85 | + }); | ||
86 | + return target; | ||
87 | + } | ||
88 | + | ||
89 | + return Object.keys(source).reduce(function (acc, key) { | ||
90 | + var value = source[key]; | ||
91 | + | ||
92 | + if (has.call(acc, key)) { | ||
93 | + acc[key] = merge(acc[key], value, options); | ||
94 | + } else { | ||
95 | + acc[key] = value; | ||
96 | + } | ||
97 | + return acc; | ||
98 | + }, mergeTarget); | ||
99 | +}; | ||
100 | + | ||
101 | +var assign = function assignSingleSource(target, source) { | ||
102 | + return Object.keys(source).reduce(function (acc, key) { | ||
103 | + acc[key] = source[key]; | ||
104 | + return acc; | ||
105 | + }, target); | ||
106 | +}; | ||
107 | + | ||
108 | +var decode = function (str, decoder, charset) { | ||
109 | + var strWithoutPlus = str.replace(/\+/g, ' '); | ||
110 | + if (charset === 'iso-8859-1') { | ||
111 | + // unescape never throws, no try...catch needed: | ||
112 | + return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape); | ||
113 | + } | ||
114 | + // utf-8 | ||
115 | + try { | ||
116 | + return decodeURIComponent(strWithoutPlus); | ||
117 | + } catch (e) { | ||
118 | + return strWithoutPlus; | ||
119 | + } | ||
120 | +}; | ||
121 | + | ||
122 | +var encode = function encode(str, defaultEncoder, charset) { | ||
123 | + // This code was originally written by Brian White (mscdex) for the io.js core querystring library. | ||
124 | + // It has been adapted here for stricter adherence to RFC 3986 | ||
125 | + if (str.length === 0) { | ||
126 | + return str; | ||
127 | + } | ||
128 | + | ||
129 | + var string = typeof str === 'string' ? str : String(str); | ||
130 | + | ||
131 | + if (charset === 'iso-8859-1') { | ||
132 | + return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) { | ||
133 | + return '%26%23' + parseInt($0.slice(2), 16) + '%3B'; | ||
134 | + }); | ||
135 | + } | ||
136 | + | ||
137 | + var out = ''; | ||
138 | + for (var i = 0; i < string.length; ++i) { | ||
139 | + var c = string.charCodeAt(i); | ||
140 | + | ||
141 | + if ( | ||
142 | + c === 0x2D // - | ||
143 | + || c === 0x2E // . | ||
144 | + || c === 0x5F // _ | ||
145 | + || c === 0x7E // ~ | ||
146 | + || (c >= 0x30 && c <= 0x39) // 0-9 | ||
147 | + || (c >= 0x41 && c <= 0x5A) // a-z | ||
148 | + || (c >= 0x61 && c <= 0x7A) // A-Z | ||
149 | + ) { | ||
150 | + out += string.charAt(i); | ||
151 | + continue; | ||
152 | + } | ||
153 | + | ||
154 | + if (c < 0x80) { | ||
155 | + out = out + hexTable[c]; | ||
156 | + continue; | ||
157 | + } | ||
158 | + | ||
159 | + if (c < 0x800) { | ||
160 | + out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]); | ||
161 | + continue; | ||
162 | + } | ||
163 | + | ||
164 | + if (c < 0xD800 || c >= 0xE000) { | ||
165 | + out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]); | ||
166 | + continue; | ||
167 | + } | ||
168 | + | ||
169 | + i += 1; | ||
170 | + c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF)); | ||
171 | + out += hexTable[0xF0 | (c >> 18)] | ||
172 | + + hexTable[0x80 | ((c >> 12) & 0x3F)] | ||
173 | + + hexTable[0x80 | ((c >> 6) & 0x3F)] | ||
174 | + + hexTable[0x80 | (c & 0x3F)]; | ||
175 | + } | ||
176 | + | ||
177 | + return out; | ||
178 | +}; | ||
179 | + | ||
180 | +var compact = function compact(value) { | ||
181 | + var queue = [{ obj: { o: value }, prop: 'o' }]; | ||
182 | + var refs = []; | ||
183 | + | ||
184 | + for (var i = 0; i < queue.length; ++i) { | ||
185 | + var item = queue[i]; | ||
186 | + var obj = item.obj[item.prop]; | ||
187 | + | ||
188 | + var keys = Object.keys(obj); | ||
189 | + for (var j = 0; j < keys.length; ++j) { | ||
190 | + var key = keys[j]; | ||
191 | + var val = obj[key]; | ||
192 | + if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) { | ||
193 | + queue.push({ obj: obj, prop: key }); | ||
194 | + refs.push(val); | ||
195 | + } | ||
196 | + } | ||
197 | + } | ||
198 | + | ||
199 | + compactQueue(queue); | ||
200 | + | ||
201 | + return value; | ||
202 | +}; | ||
203 | + | ||
204 | +var isRegExp = function isRegExp(obj) { | ||
205 | + return Object.prototype.toString.call(obj) === '[object RegExp]'; | ||
206 | +}; | ||
207 | + | ||
208 | +var isBuffer = function isBuffer(obj) { | ||
209 | + if (!obj || typeof obj !== 'object') { | ||
210 | + return false; | ||
211 | + } | ||
212 | + | ||
213 | + return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj)); | ||
214 | +}; | ||
215 | + | ||
216 | +var combine = function combine(a, b) { | ||
217 | + return [].concat(a, b); | ||
218 | +}; | ||
219 | + | ||
220 | +module.exports = { | ||
221 | + arrayToObject: arrayToObject, | ||
222 | + assign: assign, | ||
223 | + combine: combine, | ||
224 | + compact: compact, | ||
225 | + decode: decode, | ||
226 | + encode: encode, | ||
227 | + isBuffer: isBuffer, | ||
228 | + isRegExp: isRegExp, | ||
229 | + merge: merge | ||
230 | +}; |
1 | +{ | ||
2 | + "_from": "qs@6.7.0", | ||
3 | + "_id": "qs@6.7.0", | ||
4 | + "_inBundle": false, | ||
5 | + "_integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", | ||
6 | + "_location": "/body-parser/qs", | ||
7 | + "_phantomChildren": {}, | ||
8 | + "_requested": { | ||
9 | + "type": "version", | ||
10 | + "registry": true, | ||
11 | + "raw": "qs@6.7.0", | ||
12 | + "name": "qs", | ||
13 | + "escapedName": "qs", | ||
14 | + "rawSpec": "6.7.0", | ||
15 | + "saveSpec": null, | ||
16 | + "fetchSpec": "6.7.0" | ||
17 | + }, | ||
18 | + "_requiredBy": [ | ||
19 | + "/body-parser" | ||
20 | + ], | ||
21 | + "_resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", | ||
22 | + "_shasum": "41dc1a015e3d581f1621776be31afb2876a9b1bc", | ||
23 | + "_spec": "qs@6.7.0", | ||
24 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\body-parser", | ||
25 | + "bugs": { | ||
26 | + "url": "https://github.com/ljharb/qs/issues" | ||
27 | + }, | ||
28 | + "bundleDependencies": false, | ||
29 | + "contributors": [ | ||
30 | + { | ||
31 | + "name": "Jordan Harband", | ||
32 | + "email": "ljharb@gmail.com", | ||
33 | + "url": "http://ljharb.codes" | ||
34 | + } | ||
35 | + ], | ||
36 | + "dependencies": {}, | ||
37 | + "deprecated": false, | ||
38 | + "description": "A querystring parser that supports nesting and arrays, with a depth limit", | ||
39 | + "devDependencies": { | ||
40 | + "@ljharb/eslint-config": "^13.1.1", | ||
41 | + "browserify": "^16.2.3", | ||
42 | + "covert": "^1.1.1", | ||
43 | + "editorconfig-tools": "^0.1.1", | ||
44 | + "eslint": "^5.15.3", | ||
45 | + "evalmd": "^0.0.17", | ||
46 | + "for-each": "^0.3.3", | ||
47 | + "iconv-lite": "^0.4.24", | ||
48 | + "mkdirp": "^0.5.1", | ||
49 | + "object-inspect": "^1.6.0", | ||
50 | + "qs-iconv": "^1.0.4", | ||
51 | + "safe-publish-latest": "^1.1.2", | ||
52 | + "safer-buffer": "^2.1.2", | ||
53 | + "tape": "^4.10.1" | ||
54 | + }, | ||
55 | + "engines": { | ||
56 | + "node": ">=0.6" | ||
57 | + }, | ||
58 | + "homepage": "https://github.com/ljharb/qs", | ||
59 | + "keywords": [ | ||
60 | + "querystring", | ||
61 | + "qs", | ||
62 | + "query", | ||
63 | + "url", | ||
64 | + "parse", | ||
65 | + "stringify" | ||
66 | + ], | ||
67 | + "license": "BSD-3-Clause", | ||
68 | + "main": "lib/index.js", | ||
69 | + "name": "qs", | ||
70 | + "repository": { | ||
71 | + "type": "git", | ||
72 | + "url": "git+https://github.com/ljharb/qs.git" | ||
73 | + }, | ||
74 | + "scripts": { | ||
75 | + "coverage": "covert test", | ||
76 | + "dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js", | ||
77 | + "lint": "eslint lib/*.js test/*.js", | ||
78 | + "postlint": "editorconfig-tools check * lib/* test/*", | ||
79 | + "prepublish": "safe-publish-latest && npm run dist", | ||
80 | + "pretest": "npm run --silent readme && npm run --silent lint", | ||
81 | + "readme": "evalmd README.md", | ||
82 | + "test": "npm run --silent coverage", | ||
83 | + "tests-only": "node test" | ||
84 | + }, | ||
85 | + "version": "6.7.0" | ||
86 | +} |
1 | +{ | ||
2 | + "rules": { | ||
3 | + "array-bracket-newline": 0, | ||
4 | + "array-element-newline": 0, | ||
5 | + "consistent-return": 2, | ||
6 | + "function-paren-newline": 0, | ||
7 | + "max-lines": 0, | ||
8 | + "max-lines-per-function": 0, | ||
9 | + "max-nested-callbacks": [2, 3], | ||
10 | + "max-statements": 0, | ||
11 | + "no-buffer-constructor": 0, | ||
12 | + "no-extend-native": 0, | ||
13 | + "no-magic-numbers": 0, | ||
14 | + "object-curly-newline": 0, | ||
15 | + "sort-keys": 0 | ||
16 | + } | ||
17 | +} |
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.from('abc') : new Buffer('abc'); | ||
134 | + t.equal(utils.isBuffer(buffer), true, 'real Buffer instance is a buffer'); | ||
135 | + t.end(); | ||
136 | +}); |
1 | +Copyright (c) 2015, Wes Todd | ||
2 | + | ||
3 | +Permission to use, copy, modify, and/or distribute this software for any | ||
4 | +purpose with or without fee is hereby granted, provided that the above | ||
5 | +copyright notice and this permission notice appear in all copies. | ||
6 | + | ||
7 | +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
8 | +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
9 | +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
10 | +SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
11 | +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
12 | +OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
13 | +CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
1 | +# Polyfill for `Object.setPrototypeOf` | ||
2 | + | ||
3 | +[![NPM Version](https://img.shields.io/npm/v/setprototypeof.svg)](https://npmjs.org/package/setprototypeof) | ||
4 | +[![NPM Downloads](https://img.shields.io/npm/dm/setprototypeof.svg)](https://npmjs.org/package/setprototypeof) | ||
5 | +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/standard/standard) | ||
6 | + | ||
7 | +A simple cross platform implementation to set the prototype of an instianted object. Supports all modern browsers and at least back to IE8. | ||
8 | + | ||
9 | +## Usage: | ||
10 | + | ||
11 | +``` | ||
12 | +$ npm install --save setprototypeof | ||
13 | +``` | ||
14 | + | ||
15 | +```javascript | ||
16 | +var setPrototypeOf = require('setprototypeof') | ||
17 | + | ||
18 | +var obj = {} | ||
19 | +setPrototypeOf(obj, { | ||
20 | + foo: function () { | ||
21 | + return 'bar' | ||
22 | + } | ||
23 | +}) | ||
24 | +obj.foo() // bar | ||
25 | +``` | ||
26 | + | ||
27 | +TypeScript is also supported: | ||
28 | + | ||
29 | +```typescript | ||
30 | +import setPrototypeOf = require('setprototypeof') | ||
31 | +``` |
1 | +'use strict' | ||
2 | +/* eslint no-proto: 0 */ | ||
3 | +module.exports = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array ? setProtoOf : mixinProperties) | ||
4 | + | ||
5 | +function setProtoOf (obj, proto) { | ||
6 | + obj.__proto__ = proto | ||
7 | + return obj | ||
8 | +} | ||
9 | + | ||
10 | +function mixinProperties (obj, proto) { | ||
11 | + for (var prop in proto) { | ||
12 | + if (!obj.hasOwnProperty(prop)) { | ||
13 | + obj[prop] = proto[prop] | ||
14 | + } | ||
15 | + } | ||
16 | + return obj | ||
17 | +} |
1 | +{ | ||
2 | + "_from": "setprototypeof@1.1.1", | ||
3 | + "_id": "setprototypeof@1.1.1", | ||
4 | + "_inBundle": false, | ||
5 | + "_integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==", | ||
6 | + "_location": "/body-parser/setprototypeof", | ||
7 | + "_phantomChildren": {}, | ||
8 | + "_requested": { | ||
9 | + "type": "version", | ||
10 | + "registry": true, | ||
11 | + "raw": "setprototypeof@1.1.1", | ||
12 | + "name": "setprototypeof", | ||
13 | + "escapedName": "setprototypeof", | ||
14 | + "rawSpec": "1.1.1", | ||
15 | + "saveSpec": null, | ||
16 | + "fetchSpec": "1.1.1" | ||
17 | + }, | ||
18 | + "_requiredBy": [ | ||
19 | + "/body-parser/http-errors" | ||
20 | + ], | ||
21 | + "_resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", | ||
22 | + "_shasum": "7e95acb24aa92f5885e0abef5ba131330d4ae683", | ||
23 | + "_spec": "setprototypeof@1.1.1", | ||
24 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\body-parser\\node_modules\\http-errors", | ||
25 | + "author": { | ||
26 | + "name": "Wes Todd" | ||
27 | + }, | ||
28 | + "bugs": { | ||
29 | + "url": "https://github.com/wesleytodd/setprototypeof/issues" | ||
30 | + }, | ||
31 | + "bundleDependencies": false, | ||
32 | + "deprecated": false, | ||
33 | + "description": "A small polyfill for Object.setprototypeof", | ||
34 | + "devDependencies": { | ||
35 | + "mocha": "^5.2.0", | ||
36 | + "standard": "^12.0.1" | ||
37 | + }, | ||
38 | + "homepage": "https://github.com/wesleytodd/setprototypeof", | ||
39 | + "keywords": [ | ||
40 | + "polyfill", | ||
41 | + "object", | ||
42 | + "setprototypeof" | ||
43 | + ], | ||
44 | + "license": "ISC", | ||
45 | + "main": "index.js", | ||
46 | + "name": "setprototypeof", | ||
47 | + "repository": { | ||
48 | + "type": "git", | ||
49 | + "url": "git+https://github.com/wesleytodd/setprototypeof.git" | ||
50 | + }, | ||
51 | + "scripts": { | ||
52 | + "node010": "NODE_VER=0.10 MOCHA_VER=3 npm run testversion", | ||
53 | + "node11": "NODE_VER=11 npm run testversion", | ||
54 | + "node4": "NODE_VER=4 npm run testversion", | ||
55 | + "node6": "NODE_VER=6 npm run testversion", | ||
56 | + "node9": "NODE_VER=9 npm run testversion", | ||
57 | + "test": "standard && mocha", | ||
58 | + "testallversions": "npm run node010 && npm run node4 && npm run node6 && npm run node9 && npm run node11", | ||
59 | + "testversion": "docker run -it --rm -v $(PWD):/usr/src/app -w /usr/src/app node:${NODE_VER} npm install mocha@${MOCHA_VER:-latest} && npm t" | ||
60 | + }, | ||
61 | + "typings": "index.d.ts", | ||
62 | + "version": "1.1.1" | ||
63 | +} |
1 | +'use strict' | ||
2 | +/* eslint-env mocha */ | ||
3 | +/* eslint no-proto: 0 */ | ||
4 | +var assert = require('assert') | ||
5 | +var setPrototypeOf = require('..') | ||
6 | + | ||
7 | +describe('setProtoOf(obj, proto)', function () { | ||
8 | + it('should merge objects', function () { | ||
9 | + var obj = { a: 1, b: 2 } | ||
10 | + var proto = { b: 3, c: 4 } | ||
11 | + var mergeObj = setPrototypeOf(obj, proto) | ||
12 | + | ||
13 | + if (Object.getPrototypeOf) { | ||
14 | + assert.strictEqual(Object.getPrototypeOf(obj), proto) | ||
15 | + } else if ({ __proto__: [] } instanceof Array) { | ||
16 | + assert.strictEqual(obj.__proto__, proto) | ||
17 | + } else { | ||
18 | + assert.strictEqual(obj.a, 1) | ||
19 | + assert.strictEqual(obj.b, 2) | ||
20 | + assert.strictEqual(obj.c, 4) | ||
21 | + } | ||
22 | + assert.strictEqual(mergeObj, obj) | ||
23 | + }) | ||
24 | +}) |
1 | +1.5.0 / 2018-03-27 | ||
2 | +================== | ||
3 | + | ||
4 | + * Add `103 Early Hints` | ||
5 | + | ||
6 | +1.4.0 / 2017-10-20 | ||
7 | +================== | ||
8 | + | ||
9 | + * Add `STATUS_CODES` export | ||
10 | + | ||
11 | +1.3.1 / 2016-11-11 | ||
12 | +================== | ||
13 | + | ||
14 | + * Fix return type in JSDoc | ||
15 | + | ||
16 | +1.3.0 / 2016-05-17 | ||
17 | +================== | ||
18 | + | ||
19 | + * Add `421 Misdirected Request` | ||
20 | + * perf: enable strict mode | ||
21 | + | ||
22 | +1.2.1 / 2015-02-01 | ||
23 | +================== | ||
24 | + | ||
25 | + * Fix message for status 451 | ||
26 | + - `451 Unavailable For Legal Reasons` | ||
27 | + | ||
28 | +1.2.0 / 2014-09-28 | ||
29 | +================== | ||
30 | + | ||
31 | + * Add `208 Already Repored` | ||
32 | + * Add `226 IM Used` | ||
33 | + * Add `306 (Unused)` | ||
34 | + * Add `415 Unable For Legal Reasons` | ||
35 | + * Add `508 Loop Detected` | ||
36 | + | ||
37 | +1.1.1 / 2014-09-24 | ||
38 | +================== | ||
39 | + | ||
40 | + * Add missing 308 to `codes.json` | ||
41 | + | ||
42 | +1.1.0 / 2014-09-21 | ||
43 | +================== | ||
44 | + | ||
45 | + * Add `codes.json` for universal support | ||
46 | + | ||
47 | +1.0.4 / 2014-08-20 | ||
48 | +================== | ||
49 | + | ||
50 | + * Package cleanup | ||
51 | + | ||
52 | +1.0.3 / 2014-06-08 | ||
53 | +================== | ||
54 | + | ||
55 | + * Add 308 to `.redirect` category | ||
56 | + | ||
57 | +1.0.2 / 2014-03-13 | ||
58 | +================== | ||
59 | + | ||
60 | + * Add `.retry` category | ||
61 | + | ||
62 | +1.0.1 / 2014-03-12 | ||
63 | +================== | ||
64 | + | ||
65 | + * Initial release |
1 | + | ||
2 | +The MIT License (MIT) | ||
3 | + | ||
4 | +Copyright (c) 2014 Jonathan Ong <me@jongleberry.com> | ||
5 | +Copyright (c) 2016 Douglas Christopher Wilson <doug@somethingdoug.com> | ||
6 | + | ||
7 | +Permission is hereby granted, free of charge, to any person obtaining a copy | ||
8 | +of this software and associated documentation files (the "Software"), to deal | ||
9 | +in the Software without restriction, including without limitation the rights | ||
10 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
11 | +copies of the Software, and to permit persons to whom the Software is | ||
12 | +furnished to do so, subject to the following conditions: | ||
13 | + | ||
14 | +The above copyright notice and this permission notice shall be included in | ||
15 | +all copies or substantial portions of the Software. | ||
16 | + | ||
17 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
22 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
23 | +THE SOFTWARE. |
1 | +# Statuses | ||
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 | +HTTP status utility for node. | ||
10 | + | ||
11 | +This module provides a list of status codes and messages sourced from | ||
12 | +a few different projects: | ||
13 | + | ||
14 | + * The [IANA Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) | ||
15 | + * The [Node.js project](https://nodejs.org/) | ||
16 | + * The [NGINX project](https://www.nginx.com/) | ||
17 | + * The [Apache HTTP Server project](https://httpd.apache.org/) | ||
18 | + | ||
19 | +## Installation | ||
20 | + | ||
21 | +This is a [Node.js](https://nodejs.org/en/) module available through the | ||
22 | +[npm registry](https://www.npmjs.com/). Installation is done using the | ||
23 | +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): | ||
24 | + | ||
25 | +```sh | ||
26 | +$ npm install statuses | ||
27 | +``` | ||
28 | + | ||
29 | +## API | ||
30 | + | ||
31 | +<!-- eslint-disable no-unused-vars --> | ||
32 | + | ||
33 | +```js | ||
34 | +var status = require('statuses') | ||
35 | +``` | ||
36 | + | ||
37 | +### var code = status(Integer || String) | ||
38 | + | ||
39 | +If `Integer` or `String` is a valid HTTP code or status message, then the | ||
40 | +appropriate `code` will be returned. Otherwise, an error will be thrown. | ||
41 | + | ||
42 | +<!-- eslint-disable no-undef --> | ||
43 | + | ||
44 | +```js | ||
45 | +status(403) // => 403 | ||
46 | +status('403') // => 403 | ||
47 | +status('forbidden') // => 403 | ||
48 | +status('Forbidden') // => 403 | ||
49 | +status(306) // throws, as it's not supported by node.js | ||
50 | +``` | ||
51 | + | ||
52 | +### status.STATUS_CODES | ||
53 | + | ||
54 | +Returns an object which maps status codes to status messages, in | ||
55 | +the same format as the | ||
56 | +[Node.js http module](https://nodejs.org/dist/latest/docs/api/http.html#http_http_status_codes). | ||
57 | + | ||
58 | +### status.codes | ||
59 | + | ||
60 | +Returns an array of all the status codes as `Integer`s. | ||
61 | + | ||
62 | +### var msg = status[code] | ||
63 | + | ||
64 | +Map of `code` to `status message`. `undefined` for invalid `code`s. | ||
65 | + | ||
66 | +<!-- eslint-disable no-undef, no-unused-expressions --> | ||
67 | + | ||
68 | +```js | ||
69 | +status[404] // => 'Not Found' | ||
70 | +``` | ||
71 | + | ||
72 | +### var code = status[msg] | ||
73 | + | ||
74 | +Map of `status message` to `code`. `msg` can either be title-cased or | ||
75 | +lower-cased. `undefined` for invalid `status message`s. | ||
76 | + | ||
77 | +<!-- eslint-disable no-undef, no-unused-expressions --> | ||
78 | + | ||
79 | +```js | ||
80 | +status['not found'] // => 404 | ||
81 | +status['Not Found'] // => 404 | ||
82 | +``` | ||
83 | + | ||
84 | +### status.redirect[code] | ||
85 | + | ||
86 | +Returns `true` if a status code is a valid redirect status. | ||
87 | + | ||
88 | +<!-- eslint-disable no-undef, no-unused-expressions --> | ||
89 | + | ||
90 | +```js | ||
91 | +status.redirect[200] // => undefined | ||
92 | +status.redirect[301] // => true | ||
93 | +``` | ||
94 | + | ||
95 | +### status.empty[code] | ||
96 | + | ||
97 | +Returns `true` if a status code expects an empty body. | ||
98 | + | ||
99 | +<!-- eslint-disable no-undef, no-unused-expressions --> | ||
100 | + | ||
101 | +```js | ||
102 | +status.empty[200] // => undefined | ||
103 | +status.empty[204] // => true | ||
104 | +status.empty[304] // => true | ||
105 | +``` | ||
106 | + | ||
107 | +### status.retry[code] | ||
108 | + | ||
109 | +Returns `true` if you should retry the rest. | ||
110 | + | ||
111 | +<!-- eslint-disable no-undef, no-unused-expressions --> | ||
112 | + | ||
113 | +```js | ||
114 | +status.retry[501] // => undefined | ||
115 | +status.retry[503] // => true | ||
116 | +``` | ||
117 | + | ||
118 | +[npm-image]: https://img.shields.io/npm/v/statuses.svg | ||
119 | +[npm-url]: https://npmjs.org/package/statuses | ||
120 | +[node-version-image]: https://img.shields.io/node/v/statuses.svg | ||
121 | +[node-version-url]: https://nodejs.org/en/download | ||
122 | +[travis-image]: https://img.shields.io/travis/jshttp/statuses.svg | ||
123 | +[travis-url]: https://travis-ci.org/jshttp/statuses | ||
124 | +[coveralls-image]: https://img.shields.io/coveralls/jshttp/statuses.svg | ||
125 | +[coveralls-url]: https://coveralls.io/r/jshttp/statuses?branch=master | ||
126 | +[downloads-image]: https://img.shields.io/npm/dm/statuses.svg | ||
127 | +[downloads-url]: https://npmjs.org/package/statuses |
1 | +{ | ||
2 | + "100": "Continue", | ||
3 | + "101": "Switching Protocols", | ||
4 | + "102": "Processing", | ||
5 | + "103": "Early Hints", | ||
6 | + "200": "OK", | ||
7 | + "201": "Created", | ||
8 | + "202": "Accepted", | ||
9 | + "203": "Non-Authoritative Information", | ||
10 | + "204": "No Content", | ||
11 | + "205": "Reset Content", | ||
12 | + "206": "Partial Content", | ||
13 | + "207": "Multi-Status", | ||
14 | + "208": "Already Reported", | ||
15 | + "226": "IM Used", | ||
16 | + "300": "Multiple Choices", | ||
17 | + "301": "Moved Permanently", | ||
18 | + "302": "Found", | ||
19 | + "303": "See Other", | ||
20 | + "304": "Not Modified", | ||
21 | + "305": "Use Proxy", | ||
22 | + "306": "(Unused)", | ||
23 | + "307": "Temporary Redirect", | ||
24 | + "308": "Permanent Redirect", | ||
25 | + "400": "Bad Request", | ||
26 | + "401": "Unauthorized", | ||
27 | + "402": "Payment Required", | ||
28 | + "403": "Forbidden", | ||
29 | + "404": "Not Found", | ||
30 | + "405": "Method Not Allowed", | ||
31 | + "406": "Not Acceptable", | ||
32 | + "407": "Proxy Authentication Required", | ||
33 | + "408": "Request Timeout", | ||
34 | + "409": "Conflict", | ||
35 | + "410": "Gone", | ||
36 | + "411": "Length Required", | ||
37 | + "412": "Precondition Failed", | ||
38 | + "413": "Payload Too Large", | ||
39 | + "414": "URI Too Long", | ||
40 | + "415": "Unsupported Media Type", | ||
41 | + "416": "Range Not Satisfiable", | ||
42 | + "417": "Expectation Failed", | ||
43 | + "418": "I'm a teapot", | ||
44 | + "421": "Misdirected Request", | ||
45 | + "422": "Unprocessable Entity", | ||
46 | + "423": "Locked", | ||
47 | + "424": "Failed Dependency", | ||
48 | + "425": "Unordered Collection", | ||
49 | + "426": "Upgrade Required", | ||
50 | + "428": "Precondition Required", | ||
51 | + "429": "Too Many Requests", | ||
52 | + "431": "Request Header Fields Too Large", | ||
53 | + "451": "Unavailable For Legal Reasons", | ||
54 | + "500": "Internal Server Error", | ||
55 | + "501": "Not Implemented", | ||
56 | + "502": "Bad Gateway", | ||
57 | + "503": "Service Unavailable", | ||
58 | + "504": "Gateway Timeout", | ||
59 | + "505": "HTTP Version Not Supported", | ||
60 | + "506": "Variant Also Negotiates", | ||
61 | + "507": "Insufficient Storage", | ||
62 | + "508": "Loop Detected", | ||
63 | + "509": "Bandwidth Limit Exceeded", | ||
64 | + "510": "Not Extended", | ||
65 | + "511": "Network Authentication Required" | ||
66 | +} |
1 | +/*! | ||
2 | + * statuses | ||
3 | + * Copyright(c) 2014 Jonathan Ong | ||
4 | + * Copyright(c) 2016 Douglas Christopher Wilson | ||
5 | + * MIT Licensed | ||
6 | + */ | ||
7 | + | ||
8 | +'use strict' | ||
9 | + | ||
10 | +/** | ||
11 | + * Module dependencies. | ||
12 | + * @private | ||
13 | + */ | ||
14 | + | ||
15 | +var codes = require('./codes.json') | ||
16 | + | ||
17 | +/** | ||
18 | + * Module exports. | ||
19 | + * @public | ||
20 | + */ | ||
21 | + | ||
22 | +module.exports = status | ||
23 | + | ||
24 | +// status code to message map | ||
25 | +status.STATUS_CODES = codes | ||
26 | + | ||
27 | +// array of status codes | ||
28 | +status.codes = populateStatusesMap(status, codes) | ||
29 | + | ||
30 | +// status codes for redirects | ||
31 | +status.redirect = { | ||
32 | + 300: true, | ||
33 | + 301: true, | ||
34 | + 302: true, | ||
35 | + 303: true, | ||
36 | + 305: true, | ||
37 | + 307: true, | ||
38 | + 308: true | ||
39 | +} | ||
40 | + | ||
41 | +// status codes for empty bodies | ||
42 | +status.empty = { | ||
43 | + 204: true, | ||
44 | + 205: true, | ||
45 | + 304: true | ||
46 | +} | ||
47 | + | ||
48 | +// status codes for when you should retry the request | ||
49 | +status.retry = { | ||
50 | + 502: true, | ||
51 | + 503: true, | ||
52 | + 504: true | ||
53 | +} | ||
54 | + | ||
55 | +/** | ||
56 | + * Populate the statuses map for given codes. | ||
57 | + * @private | ||
58 | + */ | ||
59 | + | ||
60 | +function populateStatusesMap (statuses, codes) { | ||
61 | + var arr = [] | ||
62 | + | ||
63 | + Object.keys(codes).forEach(function forEachCode (code) { | ||
64 | + var message = codes[code] | ||
65 | + var status = Number(code) | ||
66 | + | ||
67 | + // Populate properties | ||
68 | + statuses[status] = message | ||
69 | + statuses[message] = status | ||
70 | + statuses[message.toLowerCase()] = status | ||
71 | + | ||
72 | + // Add to array | ||
73 | + arr.push(status) | ||
74 | + }) | ||
75 | + | ||
76 | + return arr | ||
77 | +} | ||
78 | + | ||
79 | +/** | ||
80 | + * Get the status code. | ||
81 | + * | ||
82 | + * Given a number, this will throw if it is not a known status | ||
83 | + * code, otherwise the code will be returned. Given a string, | ||
84 | + * the string will be parsed for a number and return the code | ||
85 | + * if valid, otherwise will lookup the code assuming this is | ||
86 | + * the status message. | ||
87 | + * | ||
88 | + * @param {string|number} code | ||
89 | + * @returns {number} | ||
90 | + * @public | ||
91 | + */ | ||
92 | + | ||
93 | +function status (code) { | ||
94 | + if (typeof code === 'number') { | ||
95 | + if (!status[code]) throw new Error('invalid status code: ' + code) | ||
96 | + return code | ||
97 | + } | ||
98 | + | ||
99 | + if (typeof code !== 'string') { | ||
100 | + throw new TypeError('code must be a number or string') | ||
101 | + } | ||
102 | + | ||
103 | + // '403' | ||
104 | + var n = parseInt(code, 10) | ||
105 | + if (!isNaN(n)) { | ||
106 | + if (!status[n]) throw new Error('invalid status code: ' + n) | ||
107 | + return n | ||
108 | + } | ||
109 | + | ||
110 | + n = status[code.toLowerCase()] | ||
111 | + if (!n) throw new Error('invalid status message: "' + code + '"') | ||
112 | + return n | ||
113 | +} |
1 | +{ | ||
2 | + "_from": "statuses@>= 1.5.0 < 2", | ||
3 | + "_id": "statuses@1.5.0", | ||
4 | + "_inBundle": false, | ||
5 | + "_integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", | ||
6 | + "_location": "/body-parser/statuses", | ||
7 | + "_phantomChildren": {}, | ||
8 | + "_requested": { | ||
9 | + "type": "range", | ||
10 | + "registry": true, | ||
11 | + "raw": "statuses@>= 1.5.0 < 2", | ||
12 | + "name": "statuses", | ||
13 | + "escapedName": "statuses", | ||
14 | + "rawSpec": ">= 1.5.0 < 2", | ||
15 | + "saveSpec": null, | ||
16 | + "fetchSpec": ">= 1.5.0 < 2" | ||
17 | + }, | ||
18 | + "_requiredBy": [ | ||
19 | + "/body-parser/http-errors" | ||
20 | + ], | ||
21 | + "_resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", | ||
22 | + "_shasum": "161c7dac177659fd9811f43771fa99381478628c", | ||
23 | + "_spec": "statuses@>= 1.5.0 < 2", | ||
24 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\body-parser\\node_modules\\http-errors", | ||
25 | + "bugs": { | ||
26 | + "url": "https://github.com/jshttp/statuses/issues" | ||
27 | + }, | ||
28 | + "bundleDependencies": false, | ||
29 | + "contributors": [ | ||
30 | + { | ||
31 | + "name": "Douglas Christopher Wilson", | ||
32 | + "email": "doug@somethingdoug.com" | ||
33 | + }, | ||
34 | + { | ||
35 | + "name": "Jonathan Ong", | ||
36 | + "email": "me@jongleberry.com", | ||
37 | + "url": "http://jongleberry.com" | ||
38 | + } | ||
39 | + ], | ||
40 | + "deprecated": false, | ||
41 | + "description": "HTTP status utility", | ||
42 | + "devDependencies": { | ||
43 | + "csv-parse": "1.2.4", | ||
44 | + "eslint": "4.19.1", | ||
45 | + "eslint-config-standard": "11.0.0", | ||
46 | + "eslint-plugin-import": "2.9.0", | ||
47 | + "eslint-plugin-markdown": "1.0.0-beta.6", | ||
48 | + "eslint-plugin-node": "6.0.1", | ||
49 | + "eslint-plugin-promise": "3.7.0", | ||
50 | + "eslint-plugin-standard": "3.0.1", | ||
51 | + "istanbul": "0.4.5", | ||
52 | + "mocha": "1.21.5", | ||
53 | + "raw-body": "2.3.2", | ||
54 | + "stream-to-array": "2.3.0" | ||
55 | + }, | ||
56 | + "engines": { | ||
57 | + "node": ">= 0.6" | ||
58 | + }, | ||
59 | + "files": [ | ||
60 | + "HISTORY.md", | ||
61 | + "index.js", | ||
62 | + "codes.json", | ||
63 | + "LICENSE" | ||
64 | + ], | ||
65 | + "homepage": "https://github.com/jshttp/statuses#readme", | ||
66 | + "keywords": [ | ||
67 | + "http", | ||
68 | + "status", | ||
69 | + "code" | ||
70 | + ], | ||
71 | + "license": "MIT", | ||
72 | + "name": "statuses", | ||
73 | + "repository": { | ||
74 | + "type": "git", | ||
75 | + "url": "git+https://github.com/jshttp/statuses.git" | ||
76 | + }, | ||
77 | + "scripts": { | ||
78 | + "build": "node scripts/build.js", | ||
79 | + "fetch": "node scripts/fetch-apache.js && node scripts/fetch-iana.js && node scripts/fetch-nginx.js && node scripts/fetch-node.js", | ||
80 | + "lint": "eslint --plugin markdown --ext js,md .", | ||
81 | + "test": "mocha --reporter spec --check-leaks --bail test/", | ||
82 | + "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", | ||
83 | + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", | ||
84 | + "update": "npm run fetch && npm run build" | ||
85 | + }, | ||
86 | + "version": "1.5.0" | ||
87 | +} |
1 | { | 1 | { |
2 | - "_from": "body-parser@1.18.3", | 2 | + "_from": "body-parser", |
3 | - "_id": "body-parser@1.18.3", | 3 | + "_id": "body-parser@1.19.0", |
4 | "_inBundle": false, | 4 | "_inBundle": false, |
5 | - "_integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", | 5 | + "_integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", |
6 | "_location": "/body-parser", | 6 | "_location": "/body-parser", |
7 | - "_phantomChildren": {}, | 7 | + "_phantomChildren": { |
8 | + "depd": "1.1.2", | ||
9 | + "inherits": "2.0.3", | ||
10 | + "toidentifier": "1.0.0" | ||
11 | + }, | ||
8 | "_requested": { | 12 | "_requested": { |
9 | - "type": "version", | 13 | + "type": "tag", |
10 | "registry": true, | 14 | "registry": true, |
11 | - "raw": "body-parser@1.18.3", | 15 | + "raw": "body-parser", |
12 | "name": "body-parser", | 16 | "name": "body-parser", |
13 | "escapedName": "body-parser", | 17 | "escapedName": "body-parser", |
14 | - "rawSpec": "1.18.3", | 18 | + "rawSpec": "", |
15 | "saveSpec": null, | 19 | "saveSpec": null, |
16 | - "fetchSpec": "1.18.3" | 20 | + "fetchSpec": "latest" |
17 | }, | 21 | }, |
18 | "_requiredBy": [ | 22 | "_requiredBy": [ |
19 | - "/express" | 23 | + "#USER", |
24 | + "/" | ||
20 | ], | 25 | ], |
21 | - "_resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", | 26 | + "_resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", |
22 | - "_shasum": "5b292198ffdd553b3a0f20ded0592b956955c8b4", | 27 | + "_shasum": "96b2709e57c9c4e09a6fd66a8fd979844f69f08a", |
23 | - "_spec": "body-parser@1.18.3", | 28 | + "_spec": "body-parser", |
24 | - "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\express", | 29 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk", |
25 | "bugs": { | 30 | "bugs": { |
26 | "url": "https://github.com/expressjs/body-parser/issues" | 31 | "url": "https://github.com/expressjs/body-parser/issues" |
27 | }, | 32 | }, |
... | @@ -38,32 +43,32 @@ | ... | @@ -38,32 +43,32 @@ |
38 | } | 43 | } |
39 | ], | 44 | ], |
40 | "dependencies": { | 45 | "dependencies": { |
41 | - "bytes": "3.0.0", | 46 | + "bytes": "3.1.0", |
42 | "content-type": "~1.0.4", | 47 | "content-type": "~1.0.4", |
43 | "debug": "2.6.9", | 48 | "debug": "2.6.9", |
44 | "depd": "~1.1.2", | 49 | "depd": "~1.1.2", |
45 | - "http-errors": "~1.6.3", | 50 | + "http-errors": "1.7.2", |
46 | - "iconv-lite": "0.4.23", | 51 | + "iconv-lite": "0.4.24", |
47 | "on-finished": "~2.3.0", | 52 | "on-finished": "~2.3.0", |
48 | - "qs": "6.5.2", | 53 | + "qs": "6.7.0", |
49 | - "raw-body": "2.3.3", | 54 | + "raw-body": "2.4.0", |
50 | - "type-is": "~1.6.16" | 55 | + "type-is": "~1.6.17" |
51 | }, | 56 | }, |
52 | "deprecated": false, | 57 | "deprecated": false, |
53 | "description": "Node.js body parsing middleware", | 58 | "description": "Node.js body parsing middleware", |
54 | "devDependencies": { | 59 | "devDependencies": { |
55 | - "eslint": "4.19.1", | 60 | + "eslint": "5.16.0", |
56 | - "eslint-config-standard": "11.0.0", | 61 | + "eslint-config-standard": "12.0.0", |
57 | - "eslint-plugin-import": "2.11.0", | 62 | + "eslint-plugin-import": "2.17.2", |
58 | - "eslint-plugin-markdown": "1.0.0-beta.6", | 63 | + "eslint-plugin-markdown": "1.0.0", |
59 | - "eslint-plugin-node": "6.0.1", | 64 | + "eslint-plugin-node": "8.0.1", |
60 | - "eslint-plugin-promise": "3.7.0", | 65 | + "eslint-plugin-promise": "4.1.1", |
61 | - "eslint-plugin-standard": "3.1.0", | 66 | + "eslint-plugin-standard": "4.0.0", |
62 | "istanbul": "0.4.5", | 67 | "istanbul": "0.4.5", |
63 | "methods": "1.1.2", | 68 | "methods": "1.1.2", |
64 | - "mocha": "2.5.3", | 69 | + "mocha": "6.1.4", |
65 | "safe-buffer": "5.1.2", | 70 | "safe-buffer": "5.1.2", |
66 | - "supertest": "1.1.0" | 71 | + "supertest": "4.0.2" |
67 | }, | 72 | }, |
68 | "engines": { | 73 | "engines": { |
69 | "node": ">= 0.8" | 74 | "node": ">= 0.8" |
... | @@ -87,5 +92,5 @@ | ... | @@ -87,5 +92,5 @@ |
87 | "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/", | 92 | "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/", |
88 | "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/" | 93 | "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/" |
89 | }, | 94 | }, |
90 | - "version": "1.18.3" | 95 | + "version": "1.19.0" |
91 | } | 96 | } | ... | ... |
... | @@ -83,6 +83,7 @@ Supported units and abbreviations are as follows and are case-insensitive: | ... | @@ -83,6 +83,7 @@ Supported units and abbreviations are as follows and are case-insensitive: |
83 | * `mb` for megabytes | 83 | * `mb` for megabytes |
84 | * `gb` for gigabytes | 84 | * `gb` for gigabytes |
85 | * `tb` for terabytes | 85 | * `tb` for terabytes |
86 | + * `pb` for petabytes | ||
86 | 87 | ||
87 | The units are in powers of two, not ten. This means 1kb = 1024b according to this parser. | 88 | The units are in powers of two, not ten. This means 1kb = 1024b according to this parser. |
88 | 89 | ||
... | @@ -108,18 +109,18 @@ bytes('1024'); | ... | @@ -108,18 +109,18 @@ bytes('1024'); |
108 | // output: 1024 | 109 | // output: 1024 |
109 | 110 | ||
110 | bytes(1024); | 111 | bytes(1024); |
111 | -// output: 1024 | 112 | +// output: 1KB |
112 | ``` | 113 | ``` |
113 | 114 | ||
114 | ## License | 115 | ## License |
115 | 116 | ||
116 | [MIT](LICENSE) | 117 | [MIT](LICENSE) |
117 | 118 | ||
118 | -[downloads-image]: https://img.shields.io/npm/dm/bytes.svg | 119 | +[coveralls-image]: https://badgen.net/coveralls/c/github/visionmedia/bytes.js/master |
120 | +[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master | ||
121 | +[downloads-image]: https://badgen.net/npm/dm/bytes | ||
119 | [downloads-url]: https://npmjs.org/package/bytes | 122 | [downloads-url]: https://npmjs.org/package/bytes |
120 | -[npm-image]: https://img.shields.io/npm/v/bytes.svg | 123 | +[npm-image]: https://badgen.net/npm/node/bytes |
121 | [npm-url]: https://npmjs.org/package/bytes | 124 | [npm-url]: https://npmjs.org/package/bytes |
122 | -[travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg | 125 | +[travis-image]: https://badgen.net/travis/visionmedia/bytes.js/master |
123 | [travis-url]: https://travis-ci.org/visionmedia/bytes.js | 126 | [travis-url]: https://travis-ci.org/visionmedia/bytes.js |
124 | -[coveralls-image]: https://img.shields.io/coveralls/visionmedia/bytes.js/master.svg | ||
125 | -[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master | ... | ... |
... | @@ -30,10 +30,11 @@ var map = { | ... | @@ -30,10 +30,11 @@ var map = { |
30 | kb: 1 << 10, | 30 | kb: 1 << 10, |
31 | mb: 1 << 20, | 31 | mb: 1 << 20, |
32 | gb: 1 << 30, | 32 | gb: 1 << 30, |
33 | - tb: ((1 << 30) * 1024) | 33 | + tb: Math.pow(1024, 4), |
34 | + pb: Math.pow(1024, 5), | ||
34 | }; | 35 | }; |
35 | 36 | ||
36 | -var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb)$/i; | 37 | +var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i; |
37 | 38 | ||
38 | /** | 39 | /** |
39 | * Convert the given value in bytes into a string or parse to string to an integer in bytes. | 40 | * Convert the given value in bytes into a string or parse to string to an integer in bytes. |
... | @@ -93,7 +94,9 @@ function format(value, options) { | ... | @@ -93,7 +94,9 @@ function format(value, options) { |
93 | var unit = (options && options.unit) || ''; | 94 | var unit = (options && options.unit) || ''; |
94 | 95 | ||
95 | if (!unit || !map[unit.toLowerCase()]) { | 96 | if (!unit || !map[unit.toLowerCase()]) { |
96 | - if (mag >= map.tb) { | 97 | + if (mag >= map.pb) { |
98 | + unit = 'PB'; | ||
99 | + } else if (mag >= map.tb) { | ||
97 | unit = 'TB'; | 100 | unit = 'TB'; |
98 | } else if (mag >= map.gb) { | 101 | } else if (mag >= map.gb) { |
99 | unit = 'GB'; | 102 | unit = 'GB'; | ... | ... |
1 | { | 1 | { |
2 | - "_from": "bytes@3.0.0", | 2 | + "_from": "bytes@3.1.0", |
3 | - "_id": "bytes@3.0.0", | 3 | + "_id": "bytes@3.1.0", |
4 | "_inBundle": false, | 4 | "_inBundle": false, |
5 | - "_integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=", | 5 | + "_integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==", |
6 | "_location": "/bytes", | 6 | "_location": "/bytes", |
7 | "_phantomChildren": {}, | 7 | "_phantomChildren": {}, |
8 | "_requested": { | 8 | "_requested": { |
9 | "type": "version", | 9 | "type": "version", |
10 | "registry": true, | 10 | "registry": true, |
11 | - "raw": "bytes@3.0.0", | 11 | + "raw": "bytes@3.1.0", |
12 | "name": "bytes", | 12 | "name": "bytes", |
13 | "escapedName": "bytes", | 13 | "escapedName": "bytes", |
14 | - "rawSpec": "3.0.0", | 14 | + "rawSpec": "3.1.0", |
15 | "saveSpec": null, | 15 | "saveSpec": null, |
16 | - "fetchSpec": "3.0.0" | 16 | + "fetchSpec": "3.1.0" |
17 | }, | 17 | }, |
18 | "_requiredBy": [ | 18 | "_requiredBy": [ |
19 | "/body-parser", | 19 | "/body-parser", |
20 | "/raw-body" | 20 | "/raw-body" |
21 | ], | 21 | ], |
22 | - "_resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", | 22 | + "_resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", |
23 | - "_shasum": "d32815404d689699f85a4ea4fa8755dd13a96048", | 23 | + "_shasum": "f6cf7933a360e0588fa9fde85651cdc7f805d1f6", |
24 | - "_spec": "bytes@3.0.0", | 24 | + "_spec": "bytes@3.1.0", |
25 | "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\body-parser", | 25 | "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\body-parser", |
26 | "author": { | 26 | "author": { |
27 | "name": "TJ Holowaychuk", | 27 | "name": "TJ Holowaychuk", |
... | @@ -45,8 +45,9 @@ | ... | @@ -45,8 +45,9 @@ |
45 | "deprecated": false, | 45 | "deprecated": false, |
46 | "description": "Utility to parse a string bytes to bytes and vice-versa", | 46 | "description": "Utility to parse a string bytes to bytes and vice-versa", |
47 | "devDependencies": { | 47 | "devDependencies": { |
48 | - "mocha": "2.5.3", | 48 | + "eslint": "5.12.1", |
49 | - "nyc": "10.3.2" | 49 | + "mocha": "5.2.0", |
50 | + "nyc": "13.1.0" | ||
50 | }, | 51 | }, |
51 | "engines": { | 52 | "engines": { |
52 | "node": ">= 0.8" | 53 | "node": ">= 0.8" |
... | @@ -74,9 +75,10 @@ | ... | @@ -74,9 +75,10 @@ |
74 | "url": "git+https://github.com/visionmedia/bytes.js.git" | 75 | "url": "git+https://github.com/visionmedia/bytes.js.git" |
75 | }, | 76 | }, |
76 | "scripts": { | 77 | "scripts": { |
78 | + "lint": "eslint .", | ||
77 | "test": "mocha --check-leaks --reporter spec", | 79 | "test": "mocha --check-leaks --reporter spec", |
78 | "test-ci": "nyc --reporter=text npm test", | 80 | "test-ci": "nyc --reporter=text npm test", |
79 | "test-cov": "nyc --reporter=html --reporter=text npm test" | 81 | "test-cov": "nyc --reporter=html --reporter=text npm test" |
80 | }, | 82 | }, |
81 | - "version": "3.0.0" | 83 | + "version": "3.1.0" |
82 | } | 84 | } | ... | ... |
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 | +/*! | ||
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 | + var opts = {} | ||
95 | + | ||
96 | + // exclude type option | ||
97 | + if (options) { | ||
98 | + for (var prop in options) { | ||
99 | + if (prop !== 'type') { | ||
100 | + opts[prop] = options[prop] | ||
101 | + } | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + var _urlencoded = exports.urlencoded(opts) | ||
106 | + var _json = exports.json(opts) | ||
107 | + | ||
108 | + return function bodyParser (req, res, next) { | ||
109 | + _json(req, res, function (err) { | ||
110 | + if (err) return next(err) | ||
111 | + _urlencoded(req, res, next) | ||
112 | + }) | ||
113 | + } | ||
114 | +} | ||
115 | + | ||
116 | +/** | ||
117 | + * Create a getter for loading a parser. | ||
118 | + * @private | ||
119 | + */ | ||
120 | + | ||
121 | +function createParserGetter (name) { | ||
122 | + return function get () { | ||
123 | + return loadParser(name) | ||
124 | + } | ||
125 | +} | ||
126 | + | ||
127 | +/** | ||
128 | + * Load a parser module. | ||
129 | + * @private | ||
130 | + */ | ||
131 | + | ||
132 | +function loadParser (parserName) { | ||
133 | + var parser = parsers[parserName] | ||
134 | + | ||
135 | + if (parser !== undefined) { | ||
136 | + return parser | ||
137 | + } | ||
138 | + | ||
139 | + // this uses a switch for static require analysis | ||
140 | + switch (parserName) { | ||
141 | + case 'json': | ||
142 | + parser = require('./lib/types/json') | ||
143 | + break | ||
144 | + case 'raw': | ||
145 | + parser = require('./lib/types/raw') | ||
146 | + break | ||
147 | + case 'text': | ||
148 | + parser = require('./lib/types/text') | ||
149 | + break | ||
150 | + case 'urlencoded': | ||
151 | + parser = require('./lib/types/urlencoded') | ||
152 | + break | ||
153 | + } | ||
154 | + | ||
155 | + // store to prevent invoking require() | ||
156 | + return (parsers[parserName] = parser) | ||
157 | +} |
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 getBody = require('raw-body') | ||
16 | +var iconv = require('iconv-lite') | ||
17 | +var onFinished = require('on-finished') | ||
18 | +var zlib = require('zlib') | ||
19 | + | ||
20 | +/** | ||
21 | + * Module exports. | ||
22 | + */ | ||
23 | + | ||
24 | +module.exports = read | ||
25 | + | ||
26 | +/** | ||
27 | + * Read a request into a buffer and parse. | ||
28 | + * | ||
29 | + * @param {object} req | ||
30 | + * @param {object} res | ||
31 | + * @param {function} next | ||
32 | + * @param {function} parse | ||
33 | + * @param {function} debug | ||
34 | + * @param {object} options | ||
35 | + * @private | ||
36 | + */ | ||
37 | + | ||
38 | +function read (req, res, next, parse, debug, options) { | ||
39 | + var length | ||
40 | + var opts = options | ||
41 | + var stream | ||
42 | + | ||
43 | + // flag as parsed | ||
44 | + req._body = true | ||
45 | + | ||
46 | + // read options | ||
47 | + var encoding = opts.encoding !== null | ||
48 | + ? opts.encoding | ||
49 | + : null | ||
50 | + var verify = opts.verify | ||
51 | + | ||
52 | + try { | ||
53 | + // get the content stream | ||
54 | + stream = contentstream(req, debug, opts.inflate) | ||
55 | + length = stream.length | ||
56 | + stream.length = undefined | ||
57 | + } catch (err) { | ||
58 | + return next(err) | ||
59 | + } | ||
60 | + | ||
61 | + // set raw-body options | ||
62 | + opts.length = length | ||
63 | + opts.encoding = verify | ||
64 | + ? null | ||
65 | + : encoding | ||
66 | + | ||
67 | + // assert charset is supported | ||
68 | + if (opts.encoding === null && encoding !== null && !iconv.encodingExists(encoding)) { | ||
69 | + return next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', { | ||
70 | + charset: encoding.toLowerCase(), | ||
71 | + type: 'charset.unsupported' | ||
72 | + })) | ||
73 | + } | ||
74 | + | ||
75 | + // read body | ||
76 | + debug('read body') | ||
77 | + getBody(stream, opts, function (error, body) { | ||
78 | + if (error) { | ||
79 | + var _error | ||
80 | + | ||
81 | + if (error.type === 'encoding.unsupported') { | ||
82 | + // echo back charset | ||
83 | + _error = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', { | ||
84 | + charset: encoding.toLowerCase(), | ||
85 | + type: 'charset.unsupported' | ||
86 | + }) | ||
87 | + } else { | ||
88 | + // set status code on error | ||
89 | + _error = createError(400, error) | ||
90 | + } | ||
91 | + | ||
92 | + // read off entire request | ||
93 | + stream.resume() | ||
94 | + onFinished(req, function onfinished () { | ||
95 | + next(createError(400, _error)) | ||
96 | + }) | ||
97 | + return | ||
98 | + } | ||
99 | + | ||
100 | + // verify | ||
101 | + if (verify) { | ||
102 | + try { | ||
103 | + debug('verify body') | ||
104 | + verify(req, res, body, encoding) | ||
105 | + } catch (err) { | ||
106 | + next(createError(403, err, { | ||
107 | + body: body, | ||
108 | + type: err.type || 'entity.verify.failed' | ||
109 | + })) | ||
110 | + return | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | + // parse | ||
115 | + var str = body | ||
116 | + try { | ||
117 | + debug('parse body') | ||
118 | + str = typeof body !== 'string' && encoding !== null | ||
119 | + ? iconv.decode(body, encoding) | ||
120 | + : body | ||
121 | + req.body = parse(str) | ||
122 | + } catch (err) { | ||
123 | + next(createError(400, err, { | ||
124 | + body: str, | ||
125 | + type: err.type || 'entity.parse.failed' | ||
126 | + })) | ||
127 | + return | ||
128 | + } | ||
129 | + | ||
130 | + next() | ||
131 | + }) | ||
132 | +} | ||
133 | + | ||
134 | +/** | ||
135 | + * Get the content stream of the request. | ||
136 | + * | ||
137 | + * @param {object} req | ||
138 | + * @param {function} debug | ||
139 | + * @param {boolean} [inflate=true] | ||
140 | + * @return {object} | ||
141 | + * @api private | ||
142 | + */ | ||
143 | + | ||
144 | +function contentstream (req, debug, inflate) { | ||
145 | + var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase() | ||
146 | + var length = req.headers['content-length'] | ||
147 | + var stream | ||
148 | + | ||
149 | + debug('content-encoding "%s"', encoding) | ||
150 | + | ||
151 | + if (inflate === false && encoding !== 'identity') { | ||
152 | + throw createError(415, 'content encoding unsupported', { | ||
153 | + encoding: encoding, | ||
154 | + type: 'encoding.unsupported' | ||
155 | + }) | ||
156 | + } | ||
157 | + | ||
158 | + switch (encoding) { | ||
159 | + case 'deflate': | ||
160 | + stream = zlib.createInflate() | ||
161 | + debug('inflate body') | ||
162 | + req.pipe(stream) | ||
163 | + break | ||
164 | + case 'gzip': | ||
165 | + stream = zlib.createGunzip() | ||
166 | + debug('gunzip body') | ||
167 | + req.pipe(stream) | ||
168 | + break | ||
169 | + case 'identity': | ||
170 | + stream = req | ||
171 | + stream.length = length | ||
172 | + break | ||
173 | + default: | ||
174 | + throw createError(415, 'unsupported content encoding "' + encoding + '"', { | ||
175 | + encoding: encoding, | ||
176 | + type: 'encoding.unsupported' | ||
177 | + }) | ||
178 | + } | ||
179 | + | ||
180 | + return stream | ||
181 | +} |
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]*(.)/ // 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.substr(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 = str.substring(0, index) + '#' | ||
156 | + | ||
157 | + try { | ||
158 | + JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation') | ||
159 | + } catch (e) { | ||
160 | + return normalizeJsonSyntaxError(e, { | ||
161 | + message: e.message.replace('#', char), | ||
162 | + stack: e.stack | ||
163 | + }) | ||
164 | + } | ||
165 | +} | ||
166 | + | ||
167 | +/** | ||
168 | + * Get the first non-whitespace character in a string. | ||
169 | + * | ||
170 | + * @param {string} str | ||
171 | + * @return {function} | ||
172 | + * @private | ||
173 | + */ | ||
174 | + | ||
175 | +function firstchar (str) { | ||
176 | + return FIRST_CHAR_REGEXP.exec(str)[1] | ||
177 | +} | ||
178 | + | ||
179 | +/** | ||
180 | + * Get the charset of a request. | ||
181 | + * | ||
182 | + * @param {object} req | ||
183 | + * @api private | ||
184 | + */ | ||
185 | + | ||
186 | +function getCharset (req) { | ||
187 | + try { | ||
188 | + return (contentType.parse(req).parameters.charset || '').toLowerCase() | ||
189 | + } catch (e) { | ||
190 | + return undefined | ||
191 | + } | ||
192 | +} | ||
193 | + | ||
194 | +/** | ||
195 | + * Normalize a SyntaxError for JSON.parse. | ||
196 | + * | ||
197 | + * @param {SyntaxError} error | ||
198 | + * @param {object} obj | ||
199 | + * @return {SyntaxError} | ||
200 | + */ | ||
201 | + | ||
202 | +function normalizeJsonSyntaxError (error, obj) { | ||
203 | + var keys = Object.getOwnPropertyNames(error) | ||
204 | + | ||
205 | + for (var i = 0; i < keys.length; i++) { | ||
206 | + var key = keys[i] | ||
207 | + if (key !== 'stack' && key !== 'message') { | ||
208 | + delete error[key] | ||
209 | + } | ||
210 | + } | ||
211 | + | ||
212 | + // replace stack before message for Node.js 0.10 and below | ||
213 | + error.stack = obj.stack.replace(error.message, obj.message) | ||
214 | + error.message = obj.message | ||
215 | + | ||
216 | + return error | ||
217 | +} | ||
218 | + | ||
219 | +/** | ||
220 | + * Get the simple type checker. | ||
221 | + * | ||
222 | + * @param {string} type | ||
223 | + * @return {function} | ||
224 | + */ | ||
225 | + | ||
226 | +function typeChecker (type) { | ||
227 | + return function checkType (req) { | ||
228 | + return Boolean(typeis(req, type)) | ||
229 | + } | ||
230 | +} |
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 | +{ | ||
2 | + "_from": "body-parser@1.18.3", | ||
3 | + "_id": "body-parser@1.18.3", | ||
4 | + "_inBundle": false, | ||
5 | + "_integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", | ||
6 | + "_location": "/express/body-parser", | ||
7 | + "_phantomChildren": {}, | ||
8 | + "_requested": { | ||
9 | + "type": "version", | ||
10 | + "registry": true, | ||
11 | + "raw": "body-parser@1.18.3", | ||
12 | + "name": "body-parser", | ||
13 | + "escapedName": "body-parser", | ||
14 | + "rawSpec": "1.18.3", | ||
15 | + "saveSpec": null, | ||
16 | + "fetchSpec": "1.18.3" | ||
17 | + }, | ||
18 | + "_requiredBy": [ | ||
19 | + "/express" | ||
20 | + ], | ||
21 | + "_resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", | ||
22 | + "_shasum": "5b292198ffdd553b3a0f20ded0592b956955c8b4", | ||
23 | + "_spec": "body-parser@1.18.3", | ||
24 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\express", | ||
25 | + "bugs": { | ||
26 | + "url": "https://github.com/expressjs/body-parser/issues" | ||
27 | + }, | ||
28 | + "bundleDependencies": false, | ||
29 | + "contributors": [ | ||
30 | + { | ||
31 | + "name": "Douglas Christopher Wilson", | ||
32 | + "email": "doug@somethingdoug.com" | ||
33 | + }, | ||
34 | + { | ||
35 | + "name": "Jonathan Ong", | ||
36 | + "email": "me@jongleberry.com", | ||
37 | + "url": "http://jongleberry.com" | ||
38 | + } | ||
39 | + ], | ||
40 | + "dependencies": { | ||
41 | + "bytes": "3.0.0", | ||
42 | + "content-type": "~1.0.4", | ||
43 | + "debug": "2.6.9", | ||
44 | + "depd": "~1.1.2", | ||
45 | + "http-errors": "~1.6.3", | ||
46 | + "iconv-lite": "0.4.23", | ||
47 | + "on-finished": "~2.3.0", | ||
48 | + "qs": "6.5.2", | ||
49 | + "raw-body": "2.3.3", | ||
50 | + "type-is": "~1.6.16" | ||
51 | + }, | ||
52 | + "deprecated": false, | ||
53 | + "description": "Node.js body parsing middleware", | ||
54 | + "devDependencies": { | ||
55 | + "eslint": "4.19.1", | ||
56 | + "eslint-config-standard": "11.0.0", | ||
57 | + "eslint-plugin-import": "2.11.0", | ||
58 | + "eslint-plugin-markdown": "1.0.0-beta.6", | ||
59 | + "eslint-plugin-node": "6.0.1", | ||
60 | + "eslint-plugin-promise": "3.7.0", | ||
61 | + "eslint-plugin-standard": "3.1.0", | ||
62 | + "istanbul": "0.4.5", | ||
63 | + "methods": "1.1.2", | ||
64 | + "mocha": "2.5.3", | ||
65 | + "safe-buffer": "5.1.2", | ||
66 | + "supertest": "1.1.0" | ||
67 | + }, | ||
68 | + "engines": { | ||
69 | + "node": ">= 0.8" | ||
70 | + }, | ||
71 | + "files": [ | ||
72 | + "lib/", | ||
73 | + "LICENSE", | ||
74 | + "HISTORY.md", | ||
75 | + "index.js" | ||
76 | + ], | ||
77 | + "homepage": "https://github.com/expressjs/body-parser#readme", | ||
78 | + "license": "MIT", | ||
79 | + "name": "body-parser", | ||
80 | + "repository": { | ||
81 | + "type": "git", | ||
82 | + "url": "git+https://github.com/expressjs/body-parser.git" | ||
83 | + }, | ||
84 | + "scripts": { | ||
85 | + "lint": "eslint --plugin markdown --ext js,md .", | ||
86 | + "test": "mocha --require test/support/env --reporter spec --check-leaks --bail test/", | ||
87 | + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/", | ||
88 | + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/" | ||
89 | + }, | ||
90 | + "version": "1.18.3" | ||
91 | +} |
1 | +3.0.0 / 2017-08-31 | ||
2 | +================== | ||
3 | + | ||
4 | + * Change "kB" to "KB" in format output | ||
5 | + * Remove support for Node.js 0.6 | ||
6 | + * Remove support for ComponentJS | ||
7 | + | ||
8 | +2.5.0 / 2017-03-24 | ||
9 | +================== | ||
10 | + | ||
11 | + * Add option "unit" | ||
12 | + | ||
13 | +2.4.0 / 2016-06-01 | ||
14 | +================== | ||
15 | + | ||
16 | + * Add option "unitSeparator" | ||
17 | + | ||
18 | +2.3.0 / 2016-02-15 | ||
19 | +================== | ||
20 | + | ||
21 | + * Drop partial bytes on all parsed units | ||
22 | + * Fix non-finite numbers to `.format` to return `null` | ||
23 | + * Fix parsing byte string that looks like hex | ||
24 | + * perf: hoist regular expressions | ||
25 | + | ||
26 | +2.2.0 / 2015-11-13 | ||
27 | +================== | ||
28 | + | ||
29 | + * add option "decimalPlaces" | ||
30 | + * add option "fixedDecimals" | ||
31 | + | ||
32 | +2.1.0 / 2015-05-21 | ||
33 | +================== | ||
34 | + | ||
35 | + * add `.format` export | ||
36 | + * add `.parse` export | ||
37 | + | ||
38 | +2.0.2 / 2015-05-20 | ||
39 | +================== | ||
40 | + | ||
41 | + * remove map recreation | ||
42 | + * remove unnecessary object construction | ||
43 | + | ||
44 | +2.0.1 / 2015-05-07 | ||
45 | +================== | ||
46 | + | ||
47 | + * fix browserify require | ||
48 | + * remove node.extend dependency | ||
49 | + | ||
50 | +2.0.0 / 2015-04-12 | ||
51 | +================== | ||
52 | + | ||
53 | + * add option "case" | ||
54 | + * add option "thousandsSeparator" | ||
55 | + * return "null" on invalid parse input | ||
56 | + * support proper round-trip: bytes(bytes(num)) === num | ||
57 | + * units no longer case sensitive when parsing | ||
58 | + | ||
59 | +1.0.0 / 2014-05-05 | ||
60 | +================== | ||
61 | + | ||
62 | + * add negative support. fixes #6 | ||
63 | + | ||
64 | +0.3.0 / 2014-03-19 | ||
65 | +================== | ||
66 | + | ||
67 | + * added terabyte support | ||
68 | + | ||
69 | +0.2.1 / 2013-04-01 | ||
70 | +================== | ||
71 | + | ||
72 | + * add .component | ||
73 | + | ||
74 | +0.2.0 / 2012-10-28 | ||
75 | +================== | ||
76 | + | ||
77 | + * bytes(200).should.eql('200b') | ||
78 | + | ||
79 | +0.1.0 / 2012-07-04 | ||
80 | +================== | ||
81 | + | ||
82 | + * 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][travis-image]][travis-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.format(number value, [options]): string|null | ||
27 | + | ||
28 | +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 | ||
29 | + rounded. | ||
30 | + | ||
31 | +**Arguments** | ||
32 | + | ||
33 | +| Name | Type | Description | | ||
34 | +|---------|----------|--------------------| | ||
35 | +| value | `number` | Value in bytes | | ||
36 | +| options | `Object` | Conversion options | | ||
37 | + | ||
38 | +**Options** | ||
39 | + | ||
40 | +| Property | Type | Description | | ||
41 | +|-------------------|--------|-----------------------------------------------------------------------------------------| | ||
42 | +| decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. | | ||
43 | +| fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` | | ||
44 | +| thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `.`... Default value to `''`. | | ||
45 | +| unit | `string`|`null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). | | ||
46 | +| unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. | | ||
47 | + | ||
48 | +**Returns** | ||
49 | + | ||
50 | +| Name | Type | Description | | ||
51 | +|---------|------------------|-------------------------------------------------| | ||
52 | +| results | `string`|`null` | Return null upon error. String value otherwise. | | ||
53 | + | ||
54 | +**Example** | ||
55 | + | ||
56 | +```js | ||
57 | +bytes(1024); | ||
58 | +// output: '1KB' | ||
59 | + | ||
60 | +bytes(1000); | ||
61 | +// output: '1000B' | ||
62 | + | ||
63 | +bytes(1000, {thousandsSeparator: ' '}); | ||
64 | +// output: '1 000B' | ||
65 | + | ||
66 | +bytes(1024 * 1.7, {decimalPlaces: 0}); | ||
67 | +// output: '2KB' | ||
68 | + | ||
69 | +bytes(1024, {unitSeparator: ' '}); | ||
70 | +// output: '1 KB' | ||
71 | + | ||
72 | +``` | ||
73 | + | ||
74 | +#### bytes.parse(string|number value): number|null | ||
75 | + | ||
76 | +Parse the string value into an integer in bytes. If no unit is given, or `value` | ||
77 | +is a number, it is assumed the value is in bytes. | ||
78 | + | ||
79 | +Supported units and abbreviations are as follows and are case-insensitive: | ||
80 | + | ||
81 | + * `b` for bytes | ||
82 | + * `kb` for kilobytes | ||
83 | + * `mb` for megabytes | ||
84 | + * `gb` for gigabytes | ||
85 | + * `tb` for terabytes | ||
86 | + | ||
87 | +The units are in powers of two, not ten. This means 1kb = 1024b according to this parser. | ||
88 | + | ||
89 | +**Arguments** | ||
90 | + | ||
91 | +| Name | Type | Description | | ||
92 | +|---------------|--------|--------------------| | ||
93 | +| value | `string`|`number` | String to parse, or number in bytes. | | ||
94 | + | ||
95 | +**Returns** | ||
96 | + | ||
97 | +| Name | Type | Description | | ||
98 | +|---------|-------------|-------------------------| | ||
99 | +| results | `number`|`null` | Return null upon error. Value in bytes otherwise. | | ||
100 | + | ||
101 | +**Example** | ||
102 | + | ||
103 | +```js | ||
104 | +bytes('1KB'); | ||
105 | +// output: 1024 | ||
106 | + | ||
107 | +bytes('1024'); | ||
108 | +// output: 1024 | ||
109 | + | ||
110 | +bytes(1024); | ||
111 | +// output: 1024 | ||
112 | +``` | ||
113 | + | ||
114 | +## License | ||
115 | + | ||
116 | +[MIT](LICENSE) | ||
117 | + | ||
118 | +[downloads-image]: https://img.shields.io/npm/dm/bytes.svg | ||
119 | +[downloads-url]: https://npmjs.org/package/bytes | ||
120 | +[npm-image]: https://img.shields.io/npm/v/bytes.svg | ||
121 | +[npm-url]: https://npmjs.org/package/bytes | ||
122 | +[travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg | ||
123 | +[travis-url]: https://travis-ci.org/visionmedia/bytes.js | ||
124 | +[coveralls-image]: https://img.shields.io/coveralls/visionmedia/bytes.js/master.svg | ||
125 | +[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master |
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: ((1 << 30) * 1024) | ||
34 | +}; | ||
35 | + | ||
36 | +var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb)$/i; | ||
37 | + | ||
38 | +/** | ||
39 | + * Convert the given value in bytes into a string or parse to string to an integer in bytes. | ||
40 | + * | ||
41 | + * @param {string|number} value | ||
42 | + * @param {{ | ||
43 | + * case: [string], | ||
44 | + * decimalPlaces: [number] | ||
45 | + * fixedDecimals: [boolean] | ||
46 | + * thousandsSeparator: [string] | ||
47 | + * unitSeparator: [string] | ||
48 | + * }} [options] bytes options. | ||
49 | + * | ||
50 | + * @returns {string|number|null} | ||
51 | + */ | ||
52 | + | ||
53 | +function bytes(value, options) { | ||
54 | + if (typeof value === 'string') { | ||
55 | + return parse(value); | ||
56 | + } | ||
57 | + | ||
58 | + if (typeof value === 'number') { | ||
59 | + return format(value, options); | ||
60 | + } | ||
61 | + | ||
62 | + return null; | ||
63 | +} | ||
64 | + | ||
65 | +/** | ||
66 | + * Format the given value in bytes into a string. | ||
67 | + * | ||
68 | + * If the value is negative, it is kept as such. If it is a float, | ||
69 | + * it is rounded. | ||
70 | + * | ||
71 | + * @param {number} value | ||
72 | + * @param {object} [options] | ||
73 | + * @param {number} [options.decimalPlaces=2] | ||
74 | + * @param {number} [options.fixedDecimals=false] | ||
75 | + * @param {string} [options.thousandsSeparator=] | ||
76 | + * @param {string} [options.unit=] | ||
77 | + * @param {string} [options.unitSeparator=] | ||
78 | + * | ||
79 | + * @returns {string|null} | ||
80 | + * @public | ||
81 | + */ | ||
82 | + | ||
83 | +function format(value, options) { | ||
84 | + if (!Number.isFinite(value)) { | ||
85 | + return null; | ||
86 | + } | ||
87 | + | ||
88 | + var mag = Math.abs(value); | ||
89 | + var thousandsSeparator = (options && options.thousandsSeparator) || ''; | ||
90 | + var unitSeparator = (options && options.unitSeparator) || ''; | ||
91 | + var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2; | ||
92 | + var fixedDecimals = Boolean(options && options.fixedDecimals); | ||
93 | + var unit = (options && options.unit) || ''; | ||
94 | + | ||
95 | + if (!unit || !map[unit.toLowerCase()]) { | ||
96 | + if (mag >= map.tb) { | ||
97 | + unit = 'TB'; | ||
98 | + } else if (mag >= map.gb) { | ||
99 | + unit = 'GB'; | ||
100 | + } else if (mag >= map.mb) { | ||
101 | + unit = 'MB'; | ||
102 | + } else if (mag >= map.kb) { | ||
103 | + unit = 'KB'; | ||
104 | + } else { | ||
105 | + unit = 'B'; | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + var val = value / map[unit.toLowerCase()]; | ||
110 | + var str = val.toFixed(decimalPlaces); | ||
111 | + | ||
112 | + if (!fixedDecimals) { | ||
113 | + str = str.replace(formatDecimalsRegExp, '$1'); | ||
114 | + } | ||
115 | + | ||
116 | + if (thousandsSeparator) { | ||
117 | + str = str.replace(formatThousandsRegExp, thousandsSeparator); | ||
118 | + } | ||
119 | + | ||
120 | + return str + unitSeparator + unit; | ||
121 | +} | ||
122 | + | ||
123 | +/** | ||
124 | + * Parse the string value into an integer in bytes. | ||
125 | + * | ||
126 | + * If no unit is given, it is assumed the value is in bytes. | ||
127 | + * | ||
128 | + * @param {number|string} val | ||
129 | + * | ||
130 | + * @returns {number|null} | ||
131 | + * @public | ||
132 | + */ | ||
133 | + | ||
134 | +function parse(val) { | ||
135 | + if (typeof val === 'number' && !isNaN(val)) { | ||
136 | + return val; | ||
137 | + } | ||
138 | + | ||
139 | + if (typeof val !== 'string') { | ||
140 | + return null; | ||
141 | + } | ||
142 | + | ||
143 | + // Test if the string passed is valid | ||
144 | + var results = parseRegExp.exec(val); | ||
145 | + var floatValue; | ||
146 | + var unit = 'b'; | ||
147 | + | ||
148 | + if (!results) { | ||
149 | + // Nothing could be extracted from the given string | ||
150 | + floatValue = parseInt(val, 10); | ||
151 | + unit = 'b' | ||
152 | + } else { | ||
153 | + // Retrieve the value and the unit | ||
154 | + floatValue = parseFloat(results[1]); | ||
155 | + unit = results[4].toLowerCase(); | ||
156 | + } | ||
157 | + | ||
158 | + return Math.floor(map[unit] * floatValue); | ||
159 | +} |
1 | +{ | ||
2 | + "_from": "bytes@3.0.0", | ||
3 | + "_id": "bytes@3.0.0", | ||
4 | + "_inBundle": false, | ||
5 | + "_integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=", | ||
6 | + "_location": "/express/bytes", | ||
7 | + "_phantomChildren": {}, | ||
8 | + "_requested": { | ||
9 | + "type": "version", | ||
10 | + "registry": true, | ||
11 | + "raw": "bytes@3.0.0", | ||
12 | + "name": "bytes", | ||
13 | + "escapedName": "bytes", | ||
14 | + "rawSpec": "3.0.0", | ||
15 | + "saveSpec": null, | ||
16 | + "fetchSpec": "3.0.0" | ||
17 | + }, | ||
18 | + "_requiredBy": [ | ||
19 | + "/express/body-parser", | ||
20 | + "/express/raw-body" | ||
21 | + ], | ||
22 | + "_resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", | ||
23 | + "_shasum": "d32815404d689699f85a4ea4fa8755dd13a96048", | ||
24 | + "_spec": "bytes@3.0.0", | ||
25 | + "_where": "C:\\Users\\LG\\Desktop\\4-1\\Reminder-Talk\\node_modules\\express\\node_modules\\body-parser", | ||
26 | + "author": { | ||
27 | + "name": "TJ Holowaychuk", | ||
28 | + "email": "tj@vision-media.ca", | ||
29 | + "url": "http://tjholowaychuk.com" | ||
30 | + }, | ||
31 | + "bugs": { | ||
32 | + "url": "https://github.com/visionmedia/bytes.js/issues" | ||
33 | + }, | ||
34 | + "bundleDependencies": false, | ||
35 | + "contributors": [ | ||
36 | + { | ||
37 | + "name": "Jed Watson", | ||
38 | + "email": "jed.watson@me.com" | ||
39 | + }, | ||
40 | + { | ||
41 | + "name": "Théo FIDRY", | ||
42 | + "email": "theo.fidry@gmail.com" | ||
43 | + } | ||
44 | + ], | ||
45 | + "deprecated": false, | ||
46 | + "description": "Utility to parse a string bytes to bytes and vice-versa", | ||
47 | + "devDependencies": { | ||
48 | + "mocha": "2.5.3", | ||
49 | + "nyc": "10.3.2" | ||
50 | + }, | ||
51 | + "engines": { | ||
52 | + "node": ">= 0.8" | ||
53 | + }, | ||
54 | + "files": [ | ||
55 | + "History.md", | ||
56 | + "LICENSE", | ||
57 | + "Readme.md", | ||
58 | + "index.js" | ||
59 | + ], | ||
60 | + "homepage": "https://github.com/visionmedia/bytes.js#readme", | ||
61 | + "keywords": [ | ||
62 | + "byte", | ||
63 | + "bytes", | ||
64 | + "utility", | ||
65 | + "parse", | ||
66 | + "parser", | ||
67 | + "convert", | ||
68 | + "converter" | ||
69 | + ], | ||
70 | + "license": "MIT", | ||
71 | + "name": "bytes", | ||
72 | + "repository": { | ||
73 | + "type": "git", | ||
74 | + "url": "git+https://github.com/visionmedia/bytes.js.git" | ||
75 | + }, | ||
76 | + "scripts": { | ||
77 | + "test": "mocha --check-leaks --reporter spec", | ||
78 | + "test-ci": "nyc --reporter=text npm test", | ||
79 | + "test-cov": "nyc --reporter=html --reporter=text npm test" | ||
80 | + }, | ||
81 | + "version": "3.0.0" | ||
82 | +} |
File moved
1 | + | ||
2 | +# 0.4.23 / 2018-05-07 | ||
3 | + | ||
4 | + * Fix deprecation warning in Node v10 due to the last usage of `new Buffer` (#185, by @felixbuenemann) | ||
5 | + * Switched from NodeBuffer to Buffer in typings (#155 by @felixfbecker, #186 by @larssn) | ||
6 | + | ||
7 | + | ||
8 | +# 0.4.22 / 2018-05-05 | ||
9 | + | ||
10 | + * Use older semver style for dependencies to be compatible with Node version 0.10 (#182, by @dougwilson) | ||
11 | + * Fix tests to accomodate fixes in Node v10 (#182, by @dougwilson) | ||
12 | + | ||
13 | + | ||
14 | +# 0.4.21 / 2018-04-06 | ||
15 | + | ||
16 | + * Fix encoding canonicalization (#156) | ||
17 | + * Fix the paths in the "browser" field in package.json (#174 by @LMLB) | ||
18 | + * Removed "contributors" section in package.json - see Git history instead. | ||
19 | + | ||
20 | + | ||
21 | +# 0.4.20 / 2018-04-06 | ||
22 | + | ||
23 | + * Updated `new Buffer()` usages with recommended replacements as it's being deprecated in Node v10 (#176, #178 by @ChALkeR) | ||
24 | + | ||
25 | + | ||
26 | +# 0.4.19 / 2017-09-09 | ||
27 | + | ||
28 | + * Fixed iso8859-1 codec regression in handling untranslatable characters (#162, caused by #147) | ||
29 | + * Re-generated windows1255 codec, because it was updated in iconv project | ||
30 | + * Fixed grammar in error message when iconv-lite is loaded with encoding other than utf8 | ||
31 | + | ||
32 | + | ||
33 | +# 0.4.18 / 2017-06-13 | ||
34 | + | ||
35 | + * Fixed CESU-8 regression in Node v8. | ||
36 | + | ||
37 | + | ||
38 | +# 0.4.17 / 2017-04-22 | ||
39 | + | ||
40 | + * Updated typescript definition file to support Angular 2 AoT mode (#153 by @larssn) | ||
41 | + | ||
42 | + | ||
43 | +# 0.4.16 / 2017-04-22 | ||
44 | + | ||
45 | + * Added support for React Native (#150) | ||
46 | + * Changed iso8859-1 encoding to usine internal 'binary' encoding, as it's the same thing (#147 by @mscdex) | ||
47 | + * Fixed typo in Readme (#138 by @jiangzhuo) | ||
48 | + * Fixed build for Node v6.10+ by making correct version comparison | ||
49 | + * Added a warning if iconv-lite is loaded not as utf-8 (see #142) | ||
50 | + | ||
51 | + | ||
52 | +# 0.4.15 / 2016-11-21 | ||
53 | + | ||
54 | + * Fixed typescript type definition (#137) | ||
55 | + | ||
56 | + | ||
57 | +# 0.4.14 / 2016-11-20 | ||
58 | + | ||
59 | + * Preparation for v1.0 | ||
60 | + * Added Node v6 and latest Node versions to Travis CI test rig | ||
61 | + * Deprecated Node v0.8 support | ||
62 | + * Typescript typings (@larssn) | ||
63 | + * Fix encoding of Euro character in GB 18030 (inspired by @lygstate) | ||
64 | + * Add ms prefix to dbcs windows encodings (@rokoroku) | ||
65 | + | ||
66 | + | ||
67 | +# 0.4.13 / 2015-10-01 | ||
68 | + | ||
69 | + * Fix silly mistake in deprecation notice. | ||
70 | + | ||
71 | + | ||
72 | +# 0.4.12 / 2015-09-26 | ||
73 | + | ||
74 | + * Node v4 support: | ||
75 | + * Added CESU-8 decoding (#106) | ||
76 | + * Added deprecation notice for `extendNodeEncodings` | ||
77 | + * Added Travis tests for Node v4 and io.js latest (#105 by @Mithgol) | ||
78 | + | ||
79 | + | ||
80 | +# 0.4.11 / 2015-07-03 | ||
81 | + | ||
82 | + * Added CESU-8 encoding. | ||
83 | + | ||
84 | + | ||
85 | +# 0.4.10 / 2015-05-26 | ||
86 | + | ||
87 | + * Changed UTF-16 endianness heuristic to take into account any ASCII chars, not | ||
88 | + just spaces. This should minimize the importance of "default" endianness. | ||
89 | + | ||
90 | + | ||
91 | +# 0.4.9 / 2015-05-24 | ||
92 | + | ||
93 | + * Streamlined BOM handling: strip BOM by default, add BOM when encoding if | ||
94 | + addBOM: true. Added docs to Readme. | ||
95 | + * UTF16 now uses UTF16-LE by default. | ||
96 | + * Fixed minor issue with big5 encoding. | ||
97 | + * Added io.js testing on Travis; updated node-iconv version to test against. | ||
98 | + Now we just skip testing SBCS encodings that node-iconv doesn't support. | ||
99 | + * (internal refactoring) Updated codec interface to use classes. | ||
100 | + * Use strict mode in all files. | ||
101 | + | ||
102 | + | ||
103 | +# 0.4.8 / 2015-04-14 | ||
104 | + | ||
105 | + * added alias UNICODE-1-1-UTF-7 for UTF-7 encoding (#94) | ||
106 | + | ||
107 | + | ||
108 | +# 0.4.7 / 2015-02-05 | ||
109 | + | ||
110 | + * stop official support of Node.js v0.8. Should still work, but no guarantees. | ||
111 | + reason: Packages needed for testing are hard to get on Travis CI. | ||
112 | + * work in environment where Object.prototype is monkey patched with enumerable | ||
113 | + props (#89). | ||
114 | + | ||
115 | + | ||
116 | +# 0.4.6 / 2015-01-12 | ||
117 | + | ||
118 | + * fix rare aliases of single-byte encodings (thanks @mscdex) | ||
119 | + * double the timeout for dbcs tests to make them less flaky on travis | ||
120 | + | ||
121 | + | ||
122 | +# 0.4.5 / 2014-11-20 | ||
123 | + | ||
124 | + * fix windows-31j and x-sjis encoding support (@nleush) | ||
125 | + * minor fix: undefined variable reference when internal error happens | ||
126 | + | ||
127 | + | ||
128 | +# 0.4.4 / 2014-07-16 | ||
129 | + | ||
130 | + * added encodings UTF-7 (RFC2152) and UTF-7-IMAP (RFC3501 Section 5.1.3) | ||
131 | + * fixed streaming base64 encoding | ||
132 | + | ||
133 | + | ||
134 | +# 0.4.3 / 2014-06-14 | ||
135 | + | ||
136 | + * added encodings UTF-16BE and UTF-16 with BOM | ||
137 | + | ||
138 | + | ||
139 | +# 0.4.2 / 2014-06-12 | ||
140 | + | ||
141 | + * don't throw exception if `extendNodeEncodings()` is called more than once | ||
142 | + | ||
143 | + | ||
144 | +# 0.4.1 / 2014-06-11 | ||
145 | + | ||
146 | + * codepage 808 added | ||
147 | + | ||
148 | + | ||
149 | +# 0.4.0 / 2014-06-10 | ||
150 | + | ||
151 | + * code is rewritten from scratch | ||
152 | + * all widespread encodings are supported | ||
153 | + * streaming interface added | ||
154 | + * browserify compatibility added | ||
155 | + * (optional) extend core primitive encodings to make usage even simpler | ||
156 | + * moved from vows to mocha as the testing framework | ||
157 | + | ||
158 | + |
1 | +Copyright (c) 2011 Alexander Shtuchkin | ||
2 | + | ||
3 | +Permission is hereby granted, free of charge, to any person obtaining | ||
4 | +a copy of this software and associated documentation files (the | ||
5 | +"Software"), to deal in the Software without restriction, including | ||
6 | +without limitation the rights to use, copy, modify, merge, publish, | ||
7 | +distribute, sublicense, and/or sell copies of the Software, and to | ||
8 | +permit persons to whom the Software is furnished to do so, subject to | ||
9 | +the following conditions: | ||
10 | + | ||
11 | +The above copyright notice and this permission notice shall be | ||
12 | +included in all copies or substantial portions of the Software. | ||
13 | + | ||
14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
15 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
16 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
17 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
18 | +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
19 | +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
20 | +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
21 | + |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/oauth/.npmignore
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/Makefile
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/Readme.md
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/oauth/index.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/lib/_utils.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/lib/oauth.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/lib/oauth2.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/lib/sha1.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/package.json
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/tests/oauth2tests.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/tests/oauthtests.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/tests/sha1tests.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/oauth/tests/shared.js
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport-google-oauth20/LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport-oauth2/.npmignore
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-oauth2/LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-oauth2/README.md
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport-oauth2/lib/index.js
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport-oauth2/lib/strategy.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-oauth2/lib/utils.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-oauth2/package.json
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-strategy/.jshintrc
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-strategy/.travis.yml
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-strategy/LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-strategy/README.md
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport-strategy/lib/index.js
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport-strategy/package.json
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport/.npmignore
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport/LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport/README.md
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport/lib/authenticator.js
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport/lib/http/request.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/passport/lib/index.js
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport/lib/sessionmanager.js
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/passport/package.json
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/pause/.npmignore
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/pause/History.md
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/pause/Makefile
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/pause/Readme.md
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/pause/index.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/pause/package.json
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
node_modules/toidentifier/LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/toidentifier/README.md
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/toidentifier/index.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/toidentifier/package.json
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/uid2/LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/uid2/index.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/uid2/package.json
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
routes/calendar.js
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
views/calendar.ejs
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment