오수빈

Merge branch 'subin'

...@@ -6,6 +6,7 @@ var logger = require('morgan'); ...@@ -6,6 +6,7 @@ var logger = require('morgan');
6 6
7 var indexRouter = require('./routes/index'); 7 var indexRouter = require('./routes/index');
8 var usersRouter = require('./routes/users'); 8 var usersRouter = require('./routes/users');
9 +//var categoryRouter = require('./routes/category');
9 var categoryRouter = require('./routes/category'); 10 var categoryRouter = require('./routes/category');
10 11
11 var app = express(); 12 var app = express();
......
1 +# Changelog
2 +
3 +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 +
5 +### [0.2.1](https://github.com/Gozala/querystring/compare/v0.2.0...v0.2.1) (2021-02-15)
6 +
7 +_Maintanance update_
8 +
9 +## [0.2.0] - 2013-02-21
10 +
11 +### Changed
12 +
13 +- Refactor into function per-module idiomatic style.
14 +- Improved test coverage.
15 +
16 +## [0.1.0] - 2011-12-13
17 +
18 +### Changed
19 +
20 +- Minor project reorganization
21 +
22 +## [0.0.3] - 2011-04-16
23 +
24 +### Added
25 +
26 +- Support for AMD module loaders
27 +
28 +## [0.0.2] - 2011-04-16
29 +
30 +### Changed
31 +
32 +- Ported unit tests
33 +
34 +### Removed
35 +
36 +- Removed functionality that depended on Buffers
37 +
38 +## [0.0.1] - 2011-04-15
39 +
40 +### Added
41 +
42 +- Initial release
1 +Copyright 2012 Irakli Gozalishvili
2 +
3 +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 +
5 +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 +
7 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# querystring
2 +
3 +[![NPM](https://img.shields.io/npm/v/querystring.svg)](https://npm.im/querystring)
4 +[![gzip](https://badgen.net/bundlephobia/minzip/querystring@latest)](https://bundlephobia.com/result?p=querystring@latest)
5 +
6 +Node's querystring module for all engines.
7 +
8 +_If you want to help with evolution of this package, please see https://github.com/Gozala/querystring/issues/20 PR's welcome!_
9 +
10 +## 🔧 Install
11 +
12 +```sh
13 +npm i querystring
14 +```
15 +
16 +## 📖 Documentation
17 +
18 +Refer to [Node's documentation for `querystring`](https://nodejs.org/api/querystring.html).
19 +
20 +## 📜 License
21 +
22 +MIT © [Gozala](https://github.com/Gozala)
1 +/**
2 + * parses a URL query string into a collection of key and value pairs
3 + *
4 + * @param qs The URL query string to parse
5 + * @param sep The substring used to delimit key and value pairs in the query string
6 + * @param eq The substring used to delimit keys and values in the query string
7 + * @param options.decodeURIComponent The function to use when decoding percent-encoded characters in the query string
8 + * @param options.maxKeys Specifies the maximum number of keys to parse. Specify 0 to remove key counting limitations default 1000
9 + */
10 +export type decodeFuncType = (
11 + qs?: string,
12 + sep?: string,
13 + eq?: string,
14 + options?: {
15 + decodeURIComponent?: Function;
16 + maxKeys?: number;
17 + }
18 +) => Record<any, unknown>;
19 +
20 +export default decodeFuncType;
1 +// Copyright Joyent, Inc. and other Node contributors.
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 permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// 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 NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +'use strict';
23 +
24 +// If obj.hasOwnProperty has been overridden, then calling
25 +// obj.hasOwnProperty(prop) will break.
26 +// See: https://github.com/joyent/node/issues/1707
27 +function hasOwnProperty(obj, prop) {
28 + return Object.prototype.hasOwnProperty.call(obj, prop);
29 +}
30 +
31 +module.exports = function(qs, sep, eq, options) {
32 + sep = sep || '&';
33 + eq = eq || '=';
34 + var obj = {};
35 +
36 + if (typeof qs !== 'string' || qs.length === 0) {
37 + return obj;
38 + }
39 +
40 + var regexp = /\+/g;
41 + qs = qs.split(sep);
42 +
43 + var maxKeys = 1000;
44 + if (options && typeof options.maxKeys === 'number') {
45 + maxKeys = options.maxKeys;
46 + }
47 +
48 + var len = qs.length;
49 + // maxKeys <= 0 means that we should not limit keys count
50 + if (maxKeys > 0 && len > maxKeys) {
51 + len = maxKeys;
52 + }
53 +
54 + for (var i = 0; i < len; ++i) {
55 + var x = qs[i].replace(regexp, '%20'),
56 + idx = x.indexOf(eq),
57 + kstr, vstr, k, v;
58 +
59 + if (idx >= 0) {
60 + kstr = x.substr(0, idx);
61 + vstr = x.substr(idx + 1);
62 + } else {
63 + kstr = x;
64 + vstr = '';
65 + }
66 +
67 + k = decodeURIComponent(kstr);
68 + v = decodeURIComponent(vstr);
69 +
70 + if (!hasOwnProperty(obj, k)) {
71 + obj[k] = v;
72 + } else if (Array.isArray(obj[k])) {
73 + obj[k].push(v);
74 + } else {
75 + obj[k] = [obj[k], v];
76 + }
77 + }
78 +
79 + return obj;
80 +};
1 +/**
2 + * It serializes passed object into string
3 + * The numeric values must be finite.
4 + * Any other input values will be coerced to empty strings.
5 + *
6 + * @param obj The object to serialize into a URL query string
7 + * @param sep The substring used to delimit key and value pairs in the query string
8 + * @param eq The substring used to delimit keys and values in the query string
9 + * @param name
10 + */
11 +export type encodeFuncType = (
12 + obj?: Record<any, unknown>,
13 + sep?: string,
14 + eq?: string,
15 + name?: any
16 +) => string;
17 +
18 +export default encodeFuncType;
1 +// Copyright Joyent, Inc. and other Node contributors.
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 permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// 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 NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +'use strict';
23 +
24 +var stringifyPrimitive = function(v) {
25 + switch (typeof v) {
26 + case 'string':
27 + return v;
28 +
29 + case 'boolean':
30 + return v ? 'true' : 'false';
31 +
32 + case 'number':
33 + return isFinite(v) ? v : '';
34 +
35 + default:
36 + return '';
37 + }
38 +};
39 +
40 +module.exports = function(obj, sep, eq, name) {
41 + sep = sep || '&';
42 + eq = eq || '=';
43 + if (obj === null) {
44 + obj = undefined;
45 + }
46 +
47 + if (typeof obj === 'object') {
48 + return Object.keys(obj).map(function(k) {
49 + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
50 + if (Array.isArray(obj[k])) {
51 + return obj[k].map(function(v) {
52 + return ks + encodeURIComponent(stringifyPrimitive(v));
53 + }).join(sep);
54 + } else {
55 + return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
56 + }
57 + }).filter(Boolean).join(sep);
58 +
59 + }
60 +
61 + if (!name) return '';
62 + return encodeURIComponent(stringifyPrimitive(name)) + eq +
63 + encodeURIComponent(stringifyPrimitive(obj));
64 +};
1 +import decodeFuncType from "./decode";
2 +import encodeFuncType from "./encode";
3 +
4 +export const decode: decodeFuncType;
5 +export const parse: decodeFuncType;
6 +
7 +export const encode: encodeFuncType;
8 +export const stringify: encodeFuncType;
1 +'use strict';
2 +
3 +exports.decode = exports.parse = require('./decode');
4 +exports.encode = exports.stringify = require('./encode');
1 +{
2 + "_from": "querystring",
3 + "_id": "querystring@0.2.1",
4 + "_inBundle": false,
5 + "_integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==",
6 + "_location": "/querystring",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "tag",
10 + "registry": true,
11 + "raw": "querystring",
12 + "name": "querystring",
13 + "escapedName": "querystring",
14 + "rawSpec": "",
15 + "saveSpec": null,
16 + "fetchSpec": "latest"
17 + },
18 + "_requiredBy": [
19 + "#USER",
20 + "/"
21 + ],
22 + "_resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz",
23 + "_shasum": "40d77615bb09d16902a85c3e38aa8b5ed761c2dd",
24 + "_spec": "querystring",
25 + "_where": "C:\\Users\\se051\\OneDrive\\바탕 화면\\나의 대학라이프\\오픈소스SW개발\\텀프\\animal-Info",
26 + "author": {
27 + "name": "Irakli Gozalishvili",
28 + "email": "rfobic@gmail.com"
29 + },
30 + "bugs": {
31 + "url": "http://github.com/Gozala/querystring/issues/"
32 + },
33 + "bundleDependencies": false,
34 + "deprecated": false,
35 + "description": "Node's querystring module for all engines.",
36 + "devDependencies": {
37 + "retape": "~0.x.0",
38 + "tape": "~0.1.5",
39 + "test": "~0.x.0"
40 + },
41 + "engines": {
42 + "node": ">=0.4.x"
43 + },
44 + "homepage": "https://github.com/Gozala/querystring#readme",
45 + "id": "querystring",
46 + "keywords": [
47 + "commonjs",
48 + "query",
49 + "querystring"
50 + ],
51 + "license": "MIT",
52 + "main": "index.js",
53 + "name": "querystring",
54 + "repository": {
55 + "type": "git",
56 + "url": "git://github.com/Gozala/querystring.git",
57 + "web": "https://github.com/Gozala/querystring"
58 + },
59 + "scripts": {
60 + "test": "npm run test-node && npm run test-tap",
61 + "test-node": "node ./test/common-index.js",
62 + "test-tap": "node ./test/tap-index.js"
63 + },
64 + "version": "0.2.1"
65 +}
1 +
2 +1.1.0 / 2015-08-14
3 +==================
4 +
5 + * fix typo
6 + * feat: Support IE8
7 +
8 +1.0.1 / 2015-07-06
9 +==================
10 +
11 + * refactor: add \n to benchmark
12 + * fix '\n' encoding
13 +
14 +1.0.0 / 2015-04-04
15 +==================
16 +
17 + * deps: upgrade iconv-lite to 0.4.7
18 +
19 +0.2.0 / 2014-04-25
20 +==================
21 +
22 + * urlencode.stringify done (@alsotang)
23 +
24 +0.1.2 / 2014-04-09
25 +==================
26 +
27 + * remove unused variable QueryString (@azbykov)
28 +
29 +0.1.1 / 2014-02-25
30 +==================
31 +
32 + * improve parse() performance 10x
33 +
34 +0.1.0 / 2014-02-24
35 +==================
36 +
37 + * decode with charset
38 + * add npm image
39 + * remove 0.6 for travis
40 + * update to support coveralls
41 + * use jscover instead of jscoverage
42 + * update gitignore
43 + * Merge pull request #1 from aleafs/master
44 + * Add http entries test case
45 +
46 +0.0.1 / 2012-10-31
47 +==================
48 +
49 + * encode() done. add benchmark and tests
50 + * Initial commit
1 +This software is licensed under the MIT License.
2 +
3 +Copyright (C) 2012 - 2014 fengmk2 <fengmk2@gmail.com>
4 +Copyright (C) 2015 node-modules
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining a copy
7 +of this software and associated documentation files (the "Software"), to deal
8 +in the Software without restriction, including without limitation the rights
9 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 +copies of the Software, and to permit persons to whom the Software is
11 +furnished to do so, subject to the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be included in
14 +all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 +THE SOFTWARE.
1 +urlencode [![Build Status](https://secure.travis-ci.org/node-modules/urlencode.png)](http://travis-ci.org/node-modules/urlencode) [![Coverage Status](https://coveralls.io/repos/node-modules/urlencode/badge.png)](https://coveralls.io/r/node-modules/urlencode)
2 +=======
3 +
4 +[![NPM](https://nodei.co/npm/urlencode.png?downloads=true&stars=true)](https://nodei.co/npm/urlencode/)
5 +
6 +encodeURIComponent with charset, e.g.: `gbk`
7 +
8 +## Install
9 +
10 +```bash
11 +$ npm install urlencode
12 +```
13 +
14 +## Usage
15 +
16 +```js
17 +var urlencode = require('urlencode');
18 +
19 +console.log(urlencode('苏千')); // default is utf8
20 +console.log(urlencode('苏千', 'gbk')); // '%CB%D5%C7%A7'
21 +
22 +// decode gbk
23 +urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千'
24 +
25 +// parse gbk querystring
26 +urlencode.parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'}
27 +
28 +// stringify obj with gbk encoding
29 +var str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk'); // x[y][0][v][w]=%CE%ED%BF%D5
30 +var obj = {'x' : {'y' : [{'v' : {'w' : '雾空'}}]}};
31 +urlencode.stringify(obj, {charset: 'gbk'}).should.equal(str);
32 +
33 +```
34 +
35 +## Benchmark
36 +
37 +### urlencode(str, encoding)
38 +
39 +```bash
40 +$ node benchmark/urlencode.js
41 +
42 +node version: v0.10.26
43 +urlencode(str) x 11,980 ops/sec ±1.13% (100 runs sampled)
44 +urlencode(str, "gbk") x 8,575 ops/sec ±1.58% (94 runs sampled)
45 +encodeURIComponent(str) x 11,677 ops/sec ±2.32% (93 runs sampled)
46 +Fastest is urlencode(str)
47 +```
48 +
49 +### urlencode.decode(str, encoding)
50 +
51 +```bash
52 +$ node benchmark/urlencode.decode.js
53 +
54 +node version: v0.10.26
55 +urlencode.decode(str) x 26,027 ops/sec ±7.51% (73 runs sampled)
56 +urlencode.decode(str, "gbk") x 14,409 ops/sec ±1.72% (98 runs sampled)
57 +decodeURIComponent(str) x 36,052 ops/sec ±0.90% (96 runs sampled)
58 +urlencode.parse(qs, {charset: "gbk"}) x 16,401 ops/sec ±1.09% (98 runs sampled)
59 +urlencode.parse(qs, {charset: "utf8"}) x 23,381 ops/sec ±2.22% (93 runs sampled)
60 +Fastest is decodeURIComponent(str)
61 +```
62 +
63 +## TODO
64 +
65 +* [x] stringify()
66 +
67 +## License
68 +
69 +[MIT](LICENSE.txt)
1 +/**!
2 + * urlencode - lib/urlencode.js
3 + *
4 + * MIT Licensed
5 + *
6 + * Authors:
7 + * fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
8 + */
9 +
10 +"use strict";
11 +
12 +/**
13 + * Module dependencies.
14 + */
15 +
16 +var iconv = require('iconv-lite');
17 +
18 +function isUTF8(charset) {
19 + if (!charset) {
20 + return true;
21 + }
22 + charset = charset.toLowerCase();
23 + return charset === 'utf8' || charset === 'utf-8';
24 +}
25 +
26 +function encode(str, charset) {
27 + if (isUTF8(charset)) {
28 + return encodeURIComponent(str);
29 + }
30 +
31 + var buf = iconv.encode(str, charset);
32 + var encodeStr = '';
33 + var ch = '';
34 + for (var i = 0; i < buf.length; i++) {
35 + ch = buf[i].toString('16');
36 + if (ch.length === 1) {
37 + ch = '0' + ch;
38 + }
39 + encodeStr += '%' + ch;
40 + }
41 + encodeStr = encodeStr.toUpperCase();
42 + return encodeStr;
43 +}
44 +
45 +function decode(str, charset) {
46 + if (isUTF8(charset)) {
47 + return decodeURIComponent(str);
48 + }
49 +
50 + var bytes = [];
51 + for (var i = 0; i < str.length; ) {
52 + if (str[i] === '%') {
53 + i++;
54 + bytes.push(parseInt(str.substring(i, i + 2), 16));
55 + i += 2;
56 + } else {
57 + bytes.push(str.charCodeAt(i));
58 + i++;
59 + }
60 + }
61 + var buf = new Buffer(bytes);
62 + return iconv.decode(buf, charset);
63 +}
64 +
65 +function parse(qs, sep, eq, options) {
66 + if (typeof sep === 'object') {
67 + // parse(qs, options)
68 + options = sep;
69 + sep = null;
70 + }
71 +
72 + sep = sep || '&';
73 + eq = eq || '=';
74 + var obj = {};
75 +
76 + if (typeof qs !== 'string' || qs.length === 0) {
77 + return obj;
78 + }
79 +
80 + var regexp = /\+/g;
81 + qs = qs.split(sep);
82 +
83 + var maxKeys = 1000;
84 + var charset = null;
85 + if (options) {
86 + if (typeof options.maxKeys === 'number') {
87 + maxKeys = options.maxKeys;
88 + }
89 + if (typeof options.charset === 'string') {
90 + charset = options.charset;
91 + }
92 + }
93 +
94 + var len = qs.length;
95 + // maxKeys <= 0 means that we should not limit keys count
96 + if (maxKeys > 0 && len > maxKeys) {
97 + len = maxKeys;
98 + }
99 +
100 + for (var i = 0; i < len; ++i) {
101 + var x = qs[i].replace(regexp, '%20');
102 + var idx = x.indexOf(eq);
103 + var kstr, vstr, k, v;
104 +
105 + if (idx >= 0) {
106 + kstr = x.substr(0, idx);
107 + vstr = x.substr(idx + 1);
108 + } else {
109 + kstr = x;
110 + vstr = '';
111 + }
112 +
113 + if (kstr && kstr.indexOf('%') >= 0) {
114 + try {
115 + k = decode(kstr, charset);
116 + } catch (e) {
117 + k = kstr;
118 + }
119 + } else {
120 + k = kstr;
121 + }
122 +
123 + if (vstr && vstr.indexOf('%') >= 0) {
124 + try {
125 + v = decode(vstr, charset);
126 + } catch (e) {
127 + v = vstr;
128 + }
129 + } else {
130 + v = vstr;
131 + }
132 +
133 + if (!has(obj, k)) {
134 + obj[k] = v;
135 + } else if (Array.isArray(obj[k])) {
136 + obj[k].push(v);
137 + } else {
138 + obj[k] = [obj[k], v];
139 + }
140 + }
141 +
142 + return obj;
143 +}
144 +
145 +function has(obj, prop) {
146 + return Object.prototype.hasOwnProperty.call(obj, prop);
147 +}
148 +
149 +function isASCII(str) {
150 + return (/^[\x00-\x7F]*$/).test(str);
151 +}
152 +
153 +function encodeComponent(item, charset) {
154 + item = String(item);
155 + if (isASCII(item)) {
156 + item = encodeURIComponent(item);
157 + } else {
158 + item = encode(item, charset);
159 + }
160 + return item;
161 +}
162 +
163 +var stringify = function(obj, prefix, options) {
164 + if (typeof prefix !== 'string') {
165 + options = prefix || {};
166 + prefix = null;
167 + }
168 + var charset = options.charset || 'utf-8';
169 + if (Array.isArray(obj)) {
170 + return stringifyArray(obj, prefix, options);
171 + } else if ('[object Object]' === {}.toString.call(obj)) {
172 + return stringifyObject(obj, prefix, options);
173 + } else if ('string' === typeof obj) {
174 + return stringifyString(obj, prefix, options);
175 + } else {
176 + return prefix + '=' + encodeComponent(String(obj), charset);
177 + }
178 +};
179 +
180 +function stringifyString(str, prefix, options) {
181 + if (!prefix) {
182 + throw new TypeError('stringify expects an object');
183 + }
184 + var charset = options.charset;
185 + return prefix + '=' + encodeComponent(str, charset);
186 +}
187 +
188 +function stringifyArray(arr, prefix, options) {
189 + var ret = [];
190 + if (!prefix) {
191 + throw new TypeError('stringify expects an object');
192 + }
193 + for (var i = 0; i < arr.length; i++) {
194 + ret.push(stringify(arr[i], prefix + '[' + i + ']', options));
195 + }
196 + return ret.join('&');
197 +}
198 +
199 +function stringifyObject(obj, prefix, options) {
200 + var ret = [];
201 + var keys = Object.keys(obj);
202 + var key;
203 +
204 + var charset = options.charset;
205 + for (var i = 0, len = keys.length; i < len; ++i) {
206 + key = keys[i];
207 + if ('' === key) {
208 + continue;
209 + }
210 + if (null === obj[key]) {
211 + ret.push(encode(key, charset) + '=');
212 + } else {
213 + ret.push(stringify(
214 + obj[key],
215 + prefix ? prefix + '[' + encodeComponent(key, charset) + ']': encodeComponent(key, charset),
216 + options));
217 + }
218 + }
219 +
220 + return ret.join('&');
221 +}
222 +
223 +module.exports = encode;
224 +module.exports.encode = encode;
225 +module.exports.decode = decode;
226 +module.exports.parse = parse;
227 +module.exports.stringify = stringify;
1 +{
2 + "_from": "urlencode@^1.1.0",
3 + "_id": "urlencode@1.1.0",
4 + "_inBundle": false,
5 + "_integrity": "sha1-HyuibwE8hfATP3o61v8nMK33y7c=",
6 + "_location": "/urlencode",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "range",
10 + "registry": true,
11 + "raw": "urlencode@^1.1.0",
12 + "name": "urlencode",
13 + "escapedName": "urlencode",
14 + "rawSpec": "^1.1.0",
15 + "saveSpec": null,
16 + "fetchSpec": "^1.1.0"
17 + },
18 + "_requiredBy": [
19 + "#USER",
20 + "/"
21 + ],
22 + "_resolved": "https://registry.npmjs.org/urlencode/-/urlencode-1.1.0.tgz",
23 + "_shasum": "1f2ba26f013c85f0133f7a3ad6ff2730adf7cbb7",
24 + "_spec": "urlencode@^1.1.0",
25 + "_where": "C:\\Users\\se051\\OneDrive\\바탕 화면\\나의 대학라이프\\오픈소스SW개발\\텀프\\animal-Info",
26 + "author": {
27 + "name": "fengmk2",
28 + "email": "fengmk2@gmail.com"
29 + },
30 + "bugs": {
31 + "url": "https://github.com/node-modules/urlencode/issues"
32 + },
33 + "bundleDependencies": false,
34 + "dependencies": {
35 + "iconv-lite": "~0.4.11"
36 + },
37 + "deprecated": false,
38 + "description": "encodeURIComponent with charset",
39 + "devDependencies": {
40 + "autod": "*",
41 + "beautify-benchmark": "*",
42 + "benchmark": "*",
43 + "blanket": "*",
44 + "contributors": "*",
45 + "istanbul": "~0.3.17",
46 + "jshint": "*",
47 + "mocha": "*",
48 + "should": "7"
49 + },
50 + "files": [
51 + "lib"
52 + ],
53 + "homepage": "https://github.com/node-modules/urlencode",
54 + "keywords": [
55 + "urlencode",
56 + "urldecode",
57 + "encodeURIComponent",
58 + "decodeURIComponent",
59 + "querystring",
60 + "parse"
61 + ],
62 + "license": "MIT",
63 + "main": "lib/urlencode.js",
64 + "name": "urlencode",
65 + "repository": {
66 + "type": "git",
67 + "url": "git://github.com/node-modules/urlencode.git"
68 + },
69 + "scripts": {
70 + "autod": "autod -w --prefix '~' -t test -e examples",
71 + "benchmark": "node benchmark/urlencode.js && node benchmark/urlencode.decode.js",
72 + "cnpm": "npm install --registry=https://registry.npm.taobao.org",
73 + "jshint": "jshint .",
74 + "test": "mocha -R spec -t 20000 -r should test/*.test.js",
75 + "test-cov": "istanbul cover node_modules/.bin/_mocha -- -t 20000 -r should test/*.test.js",
76 + "test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- -t 20000 -r should test/*.test.js"
77 + },
78 + "version": "1.1.0"
79 +}
...@@ -534,6 +534,11 @@ ...@@ -534,6 +534,11 @@
534 "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", 534 "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
535 "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" 535 "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
536 }, 536 },
537 + "querystring": {
538 + "version": "0.2.1",
539 + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz",
540 + "integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg=="
541 + },
537 "range-parser": { 542 "range-parser": {
538 "version": "1.2.1", 543 "version": "1.2.1",
539 "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", 544 "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
...@@ -693,6 +698,14 @@ ...@@ -693,6 +698,14 @@
693 "punycode": "^2.1.0" 698 "punycode": "^2.1.0"
694 } 699 }
695 }, 700 },
701 + "urlencode": {
702 + "version": "1.1.0",
703 + "resolved": "https://registry.npmjs.org/urlencode/-/urlencode-1.1.0.tgz",
704 + "integrity": "sha1-HyuibwE8hfATP3o61v8nMK33y7c=",
705 + "requires": {
706 + "iconv-lite": "~0.4.11"
707 + }
708 + },
696 "utils-merge": { 709 "utils-merge": {
697 "version": "1.0.1", 710 "version": "1.0.1",
698 "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 711 "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
14 "express": "~4.16.1", 14 "express": "~4.16.1",
15 "http-errors": "~1.6.3", 15 "http-errors": "~1.6.3",
16 "morgan": "~1.9.1", 16 "morgan": "~1.9.1",
17 + "querystring": "^0.2.1",
17 "request": "^2.88.2", 18 "request": "^2.88.2",
19 + "urlencode": "^1.1.0",
18 "xml-js": "^1.6.11", 20 "xml-js": "^1.6.11",
19 "xml2js": "^0.4.23" 21 "xml2js": "^0.4.23"
20 } 22 }
......
...@@ -3,6 +3,7 @@ var router = express.Router(); ...@@ -3,6 +3,7 @@ var router = express.Router();
3 var request = require('request'); 3 var request = require('request');
4 const convert = require('xml-js'); 4 const convert = require('xml-js');
5 require('dotenv').config(); 5 require('dotenv').config();
6 +var urlencode = require('urlencode');
6 7
7 /* GET home page. */ 8 /* GET home page. */
8 let GU_CODE; 9 let GU_CODE;
...@@ -10,38 +11,48 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY; ...@@ -10,38 +11,48 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY;
10 let user_gu; 11 let user_gu;
11 let user_latitude; 12 let user_latitude;
12 let user_longitude; 13 let user_longitude;
13 -let hospital_list = [];
14 14
15 -router.get('/hospital', function (req, res) { 15 +router.post('/hospital', function(req, res){
16 - //api 16 + //gu 받아오기
17 - let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=%EB%8F%99%EB%AC%BC%EB%B3%91%EC%9B%90&where=%EA%B0%95%EB%B6%81%EA%B5%AC`; 17 + var body = req.body;
18 - request(pet_url, function(err, response, body){ 18 + var gu_select = body.user_gu;
19 - if(err) { 19 + var menu = '동물병원';
20 - console.log(`err => ${err}`) 20 +
21 + // encoding for url
22 + var menu_encode = urlencode(menu);
23 + var gu_select_encode = urlencode(gu_select);
24 +
25 + //api
26 + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`;
27 + request(pet_url, function(err, response, body){
28 + if(err) {
29 + console.log(`err => ${err}`)
30 + }
31 + else {
32 + if(res.statusCode == 200) {
33 + var hospital_list = []; //얘를 전역으로 선언해서 중복이 발생했던 거였어요 ㅠ
34 + var titles = '';
35 +
36 + var result = convert.xml2json(body, {compact: true, spaces: 4});
37 + var petJson = JSON.parse(result)
38 + var itemList = petJson.response.body.items;
39 + var numRows = itemList.item.length; //개수
40 + for (i=0; i<numRows; i++){
41 + // state 정상인 것만 추리기
42 + if (itemList.item[i].state._text == '정상'){
43 + hospital_list.push(itemList.item[i]);
44 + }
21 } 45 }
22 - else { 46 +
23 - if(res.statusCode == 200) { 47 + //테스트용 console.log
24 - var result = convert.xml2json(body, {compact: true, spaces: 4}); 48 + for(i=0; i<hospital_list.length; i++){
25 - var petJson = JSON.parse(result) 49 + titles = titles+hospital_list[i].title._text+'\n';
26 - var itemList = petJson.response.body.items; 50 + }
27 - var numRows = itemList.item.length; //개수 51 + console.log(titles);
28 - for (i=0; i<numRows; i++){ 52 + }
29 - // state 정상인 것만 추리기
30 - if (itemList.item[i].state._text == '정상'){
31 - hospital_list.push(itemList.item[i]);
32 - }
33 - }
34 -
35 - //테스트용 console.log
36 - var titles = '';
37 - for(i=0; i<hospital_list.length; i++){
38 - titles = titles+hospital_list[i].title._text+'\n';
39 - }
40 - console.log(titles);
41 - }
42 } 53 }
43 - res.send("finish"); 54 + res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list });
44 }) 55 })
45 }); 56 });
46 - 57 +
47 module.exports = router; 58 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -65,6 +65,14 @@ ...@@ -65,6 +65,14 @@
65 font-size: xx-large; 65 font-size: xx-large;
66 } 66 }
67 </style> 67 </style>
68 +
69 + <script>
70 + function sm() {
71 + document.getElementById("location").submit();
72 + }
73 + </script>
74 +
75 +
68 </head> 76 </head>
69 77
70 <body> 78 <body>
...@@ -83,9 +91,13 @@ ...@@ -83,9 +91,13 @@
83 <p> 91 <p>
84 지역 선택 92 지역 선택
85 </p> 93 </p>
86 - <select> 94 + <form action="/category/hospital" method="post" name="location" id="location">
87 - <option value='금천구'>금천구</option> 95 + <select onchange="sm()" name="user_gu" id="user_gu_select">
88 - </select> 96 + <option value='' selected="true" disabled="true">--Please choose an option--</option>
97 + <option value='금천구'>금천구</option>
98 + <option value='강남구'>강남구</option>
99 + </select>
100 + </form>
89 </div> 101 </div>
90 </div> 102 </div>
91 103
......
1 +<body>
2 + <%- include(`results/${category}`) -%>
3 +</body>
...\ No newline at end of file ...\ No newline at end of file
1 +it's hospital page
...\ No newline at end of file ...\ No newline at end of file