Ga Min Cha
1 +const soccerAPI = '526fc70a2e8b315e9a960ac4b4764191';
2 +const hostUrl = 'v3.football.api-sports.io';
3 +
4 +var request = require('request');
5 +
6 +var leagueNum = '39';
7 +var seasonNum = '2021';
8 +
9 +const sampleJsonBody = {"get":"teams","parameters":{"league":"39","season":"2021"},"errors":[],"results":20,"paging":{"current":1,"total":1},"response":[{"team":{"id":33,"name":"Manchester United","code":"MUN","country":"England","founded":1878,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/33.png"},"venue":{"id":556,"name":"Old Trafford","address":"Sir Matt Busby Way","city":"Manchester","capacity":76212,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/556.png"}},{"team":{"id":34,"name":"Newcastle","code":"NEW","country":"England","founded":1892,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/34.png"},"venue":{"id":562,"name":"St. James' Park","address":"St. James' Street","city":"Newcastle upon Tyne","capacity":52389,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/562.png"}},{"team":{"id":38,"name":"Watford","code":"WAT","country":"England","founded":1881,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/38.png"},"venue":{"id":596,"name":"Vicarage Road","address":"Vicarage Road","city":"Watford","capacity":22200,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/596.png"}},{"team":{"id":39,"name":"Wolves","code":"WOL","country":"England","founded":1877,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/39.png"},"venue":{"id":600,"name":"Molineux Stadium","address":"Waterloo Road","city":"Wolverhampton, West Midlands","capacity":32050,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/600.png"}},{"team":{"id":40,"name":"Liverpool","code":"LIV","country":"England","founded":1892,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/40.png"},"venue":{"id":550,"name":"Anfield","address":"Anfield Road","city":"Liverpool","capacity":55212,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/550.png"}},{"team":{"id":41,"name":"Southampton","code":"SOU","country":"England","founded":1885,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/41.png"},"venue":{"id":585,"name":"St. Mary's Stadium","address":"Britannia Road","city":"Southampton, Hampshire","capacity":32689,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/585.png"}},{"team":{"id":42,"name":"Arsenal","code":"ARS","country":"England","founded":1886,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/42.png"},"venue":{"id":494,"name":"Emirates Stadium","address":"Queensland Road","city":"London","capacity":60383,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/494.png"}},{"team":{"id":44,"name":"Burnley","code":"BUR","country":"England","founded":1882,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/44.png"},"venue":{"id":512,"name":"Turf Moor","address":"Harry Potts Way","city":"Burnley","capacity":22546,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/512.png"}},{"team":{"id":45,"name":"Everton","code":"EVE","country":"England","founded":1878,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/45.png"},"venue":{"id":8560,"name":"Goodison Park","address":"Goodison Road","city":"Liverpool","capacity":40569,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/8560.png"}},{"team":{"id":46,"name":"Leicester","code":"LEI","country":"England","founded":1884,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/46.png"},"venue":{"id":547,"name":"King Power Stadium","address":"Filbert Way","city":"Leicester, Leicestershire","capacity":34310,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/547.png"}},{"team":{"id":47,"name":"Tottenham","code":"TOT","country":"England","founded":1882,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/47.png"},"venue":{"id":593,"name":"Tottenham Hotspur Stadium","address":"Bill Nicholson Way, 748 High Road","city":"London","capacity":62062,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/593.png"}},{"team":{"id":48,"name":"West Ham","code":"WES","country":"England","founded":1895,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/48.png"},"venue":{"id":598,"name":"London Stadium","address":"Marshgate Lane, Stratford","city":"London","capacity":60000,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/598.png"}},{"team":{"id":49,"name":"Chelsea","code":"CHE","country":"England","founded":1905,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/49.png"},"venue":{"id":519,"name":"Stamford Bridge","address":"Fulham Road","city":"London","capacity":41841,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/519.png"}},{"team":{"id":50,"name":"Manchester City","code":"MAC","country":"England","founded":1880,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/50.png"},"venue":{"id":555,"name":"Etihad Stadium","address":"Rowsley Street","city":"Manchester","capacity":55097,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/555.png"}},{"team":{"id":51,"name":"Brighton","code":"BRI","country":"England","founded":1901,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/51.png"},"venue":{"id":508,"name":"The American Express Community Stadium","address":"Village Way","city":"Falmer, East Sussex","capacity":31800,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/508.png"}},{"team":{"id":52,"name":"Crystal Palace","code":"CRY","country":"England","founded":1905,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/52.png"},"venue":{"id":525,"name":"Selhurst Park","address":"Holmesdale Road","city":"London","capacity":26309,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/525.png"}},{"team":{"id":55,"name":"Brentford","code":"BRE","country":"England","founded":1889,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/55.png"},"venue":{"id":10503,"name":"Brentford Community Stadium","address":"166 Lionel Rd N, Brentford","city":"Brentford, Middlesex","capacity":17250,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/10503.png"}},{"team":{"id":63,"name":"Leeds","code":"LEE","country":"England","founded":1919,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/63.png"},"venue":{"id":546,"name":"Elland Road","address":"Elland Road","city":"Leeds, West Yorkshire","capacity":40204,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/546.png"}},{"team":{"id":66,"name":"Aston Villa","code":"AST","country":"England","founded":1874,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/66.png"},"venue":{"id":495,"name":"Villa Park","address":"Trinity Road","city":"Birmingham","capacity":42788,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/495.png"}},{"team":{"id":71,"name":"Norwich","code":"NOR","country":"England","founded":1902,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/71.png"},"venue":{"id":565,"name":"Carrow Road","address":"Carrow Road","city":"Norwich, Norfolk","capacity":27606,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/565.png"}}]};
10 +var IDNameDict = {};
11 +var responseArr = [];
12 +
13 +// function GetTeamIDsByLeagueID(leagueNum, seasonNum){
14 +// var options = {
15 +// method : 'GET',
16 +// url : 'https://v3.football.api-sports.io/teams?league='+leagueNum+'&season='+seasonNum,
17 +
18 +// headers:{
19 +// 'x-rapidapi-host':hostUrl,
20 +// 'x-rapidapi-key':soccerAPI
21 +// }
22 +// };
23 +
24 +// request(options, function (error, response, body) {
25 +// if (error) throw new Error(error);
26 +// console.log(body);
27 +// });
28 +// }
29 +
30 +responseArr = sampleJsonBody.response;
31 +
32 +function SetTeamIDNameDict(){
33 + responseArr.forEach(teamInfo => IDNameDict[teamInfo.team.name] = teamInfo.team.id);
34 + console.log(Object.keys(IDNameDict));
35 +}
36 +
37 +SetTeamIDNameDict();
38 +
39 +function GetTeamIDByName(teamName){
40 + if(teamName in IDNameDict){
41 + console.log(teamName + " : " + IDNameDict[teamName]);
42 + return IDNameDict[teamName];
43 + }
44 + else{
45 + console.log("There is no team name in this league");
46 + return 0;
47 + }
48 +}
49 +
50 +console.log(GetTeamIDByName('Newcastle'));
51 +GetTeamIDByName('ABC');
...\ No newline at end of file ...\ No newline at end of file
...@@ -508,6 +508,14 @@ ...@@ -508,6 +508,14 @@
508 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 508 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
509 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==" 509 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
510 }, 510 },
511 + "node_modules/JSON": {
512 + "version": "1.0.0",
513 + "resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
514 + "integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA==",
515 + "engines": {
516 + "node": ">= 0.2.0"
517 + }
518 + },
511 "node_modules/json-schema": { 519 "node_modules/json-schema": {
512 "version": "0.4.0", 520 "version": "0.4.0",
513 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", 521 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
......
1 +/*
2 + http://www.JSON.org/json2.js
3 + 2011-02-23
4 +
5 + Public Domain.
6 +
7 + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8 +
9 + See http://www.JSON.org/js.html
10 +
11 +
12 + This code should be minified before deployment.
13 + See http://javascript.crockford.com/jsmin.html
14 +
15 + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
16 + NOT CONTROL.
17 +
18 +
19 + This file creates a global JSON object containing two methods: stringify
20 + and parse.
21 +
22 + JSON.stringify(value, replacer, space)
23 + value any JavaScript value, usually an object or array.
24 +
25 + replacer an optional parameter that determines how object
26 + values are stringified for objects. It can be a
27 + function or an array of strings.
28 +
29 + space an optional parameter that specifies the indentation
30 + of nested structures. If it is omitted, the text will
31 + be packed without extra whitespace. If it is a number,
32 + it will specify the number of spaces to indent at each
33 + level. If it is a string (such as '\t' or ' '),
34 + it contains the characters used to indent at each level.
35 +
36 + This method produces a JSON text from a JavaScript value.
37 +
38 + When an object value is found, if the object contains a toJSON
39 + method, its toJSON method will be called and the result will be
40 + stringified. A toJSON method does not serialize: it returns the
41 + value represented by the name/value pair that should be serialized,
42 + or undefined if nothing should be serialized. The toJSON method
43 + will be passed the key associated with the value, and this will be
44 + bound to the value
45 +
46 + For example, this would serialize Dates as ISO strings.
47 +
48 + Date.prototype.toJSON = function (key) {
49 + function f(n) {
50 + // Format integers to have at least two digits.
51 + return n < 10 ? '0' + n : n;
52 + }
53 +
54 + return this.getUTCFullYear() + '-' +
55 + f(this.getUTCMonth() + 1) + '-' +
56 + f(this.getUTCDate()) + 'T' +
57 + f(this.getUTCHours()) + ':' +
58 + f(this.getUTCMinutes()) + ':' +
59 + f(this.getUTCSeconds()) + 'Z';
60 + };
61 +
62 + You can provide an optional replacer method. It will be passed the
63 + key and value of each member, with this bound to the containing
64 + object. The value that is returned from your method will be
65 + serialized. If your method returns undefined, then the member will
66 + be excluded from the serialization.
67 +
68 + If the replacer parameter is an array of strings, then it will be
69 + used to select the members to be serialized. It filters the results
70 + such that only members with keys listed in the replacer array are
71 + stringified.
72 +
73 + Values that do not have JSON representations, such as undefined or
74 + functions, will not be serialized. Such values in objects will be
75 + dropped; in arrays they will be replaced with null. You can use
76 + a replacer function to replace those with JSON values.
77 + JSON.stringify(undefined) returns undefined.
78 +
79 + The optional space parameter produces a stringification of the
80 + value that is filled with line breaks and indentation to make it
81 + easier to read.
82 +
83 + If the space parameter is a non-empty string, then that string will
84 + be used for indentation. If the space parameter is a number, then
85 + the indentation will be that many spaces.
86 +
87 + Example:
88 +
89 + text = JSON.stringify(['e', {pluribus: 'unum'}]);
90 + // text is '["e",{"pluribus":"unum"}]'
91 +
92 +
93 + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
94 + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
95 +
96 + text = JSON.stringify([new Date()], function (key, value) {
97 + return this[key] instanceof Date ?
98 + 'Date(' + this[key] + ')' : value;
99 + });
100 + // text is '["Date(---current time---)"]'
101 +
102 +
103 + JSON.parse(text, reviver)
104 + This method parses a JSON text to produce an object or array.
105 + It can throw a SyntaxError exception.
106 +
107 + The optional reviver parameter is a function that can filter and
108 + transform the results. It receives each of the keys and values,
109 + and its return value is used instead of the original value.
110 + If it returns what it received, then the structure is not modified.
111 + If it returns undefined then the member is deleted.
112 +
113 + Example:
114 +
115 + // Parse the text. Values that look like ISO date strings will
116 + // be converted to Date objects.
117 +
118 + myData = JSON.parse(text, function (key, value) {
119 + var a;
120 + if (typeof value === 'string') {
121 + a =
122 +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
123 + if (a) {
124 + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
125 + +a[5], +a[6]));
126 + }
127 + }
128 + return value;
129 + });
130 +
131 + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
132 + var d;
133 + if (typeof value === 'string' &&
134 + value.slice(0, 5) === 'Date(' &&
135 + value.slice(-1) === ')') {
136 + d = new Date(value.slice(5, -1));
137 + if (d) {
138 + return d;
139 + }
140 + }
141 + return value;
142 + });
143 +
144 +
145 + This is a reference implementation. You are free to copy, modify, or
146 + redistribute.
147 +*/
148 +
149 +/*jslint evil: true, strict: false, regexp: false */
150 +
151 +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
152 + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
153 + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
154 + lastIndex, length, parse, prototype, push, replace, slice, stringify,
155 + test, toJSON, toString, valueOf
156 +*/
157 +
158 +
159 +// Create a JSON object only if one does not already exist. We create the
160 +// methods in a closure to avoid creating global variables.
161 +
162 +var JSON;
163 +if (!JSON) {
164 + JSON = {};
165 +}
166 +
167 +(function () {
168 + "use strict";
169 +
170 + var global = Function('return this')()
171 + , JSON = global.JSON
172 + ;
173 +
174 + if (!JSON) {
175 + JSON = {};
176 + }
177 +
178 + function f(n) {
179 + // Format integers to have at least two digits.
180 + return n < 10 ? '0' + n : n;
181 + }
182 +
183 + if (typeof Date.prototype.toJSON !== 'function') {
184 +
185 + Date.prototype.toJSON = function (key) {
186 +
187 + return isFinite(this.valueOf()) ?
188 + this.getUTCFullYear() + '-' +
189 + f(this.getUTCMonth() + 1) + '-' +
190 + f(this.getUTCDate()) + 'T' +
191 + f(this.getUTCHours()) + ':' +
192 + f(this.getUTCMinutes()) + ':' +
193 + f(this.getUTCSeconds()) + 'Z' : null;
194 + };
195 +
196 + String.prototype.toJSON =
197 + Number.prototype.toJSON =
198 + Boolean.prototype.toJSON = function (key) {
199 + return this.valueOf();
200 + };
201 + }
202 +
203 + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
204 + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
205 + gap,
206 + indent,
207 + meta = { // table of character substitutions
208 + '\b': '\\b',
209 + '\t': '\\t',
210 + '\n': '\\n',
211 + '\f': '\\f',
212 + '\r': '\\r',
213 + '"' : '\\"',
214 + '\\': '\\\\'
215 + },
216 + rep;
217 +
218 +
219 + function quote(string) {
220 +
221 +// If the string contains no control characters, no quote characters, and no
222 +// backslash characters, then we can safely slap some quotes around it.
223 +// Otherwise we must also replace the offending characters with safe escape
224 +// sequences.
225 +
226 + escapable.lastIndex = 0;
227 + return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
228 + var c = meta[a];
229 + return typeof c === 'string' ? c :
230 + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
231 + }) + '"' : '"' + string + '"';
232 + }
233 +
234 +
235 + function str(key, holder) {
236 +
237 +// Produce a string from holder[key].
238 +
239 + var i, // The loop counter.
240 + k, // The member key.
241 + v, // The member value.
242 + length,
243 + mind = gap,
244 + partial,
245 + value = holder[key];
246 +
247 +// If the value has a toJSON method, call it to obtain a replacement value.
248 +
249 + if (value && typeof value === 'object' &&
250 + typeof value.toJSON === 'function') {
251 + value = value.toJSON(key);
252 + }
253 +
254 +// If we were called with a replacer function, then call the replacer to
255 +// obtain a replacement value.
256 +
257 + if (typeof rep === 'function') {
258 + value = rep.call(holder, key, value);
259 + }
260 +
261 +// What happens next depends on the value's type.
262 +
263 + switch (typeof value) {
264 + case 'string':
265 + return quote(value);
266 +
267 + case 'number':
268 +
269 +// JSON numbers must be finite. Encode non-finite numbers as null.
270 +
271 + return isFinite(value) ? String(value) : 'null';
272 +
273 + case 'boolean':
274 + case 'null':
275 +
276 +// If the value is a boolean or null, convert it to a string. Note:
277 +// typeof null does not produce 'null'. The case is included here in
278 +// the remote chance that this gets fixed someday.
279 +
280 + return String(value);
281 +
282 +// If the type is 'object', we might be dealing with an object or an array or
283 +// null.
284 +
285 + case 'object':
286 +
287 +// Due to a specification blunder in ECMAScript, typeof null is 'object',
288 +// so watch out for that case.
289 +
290 + if (!value) {
291 + return 'null';
292 + }
293 +
294 +// Make an array to hold the partial results of stringifying this object value.
295 +
296 + gap += indent;
297 + partial = [];
298 +
299 +// Is the value an array?
300 +
301 + if (Object.prototype.toString.apply(value) === '[object Array]') {
302 +
303 +// The value is an array. Stringify every element. Use null as a placeholder
304 +// for non-JSON values.
305 +
306 + length = value.length;
307 + for (i = 0; i < length; i += 1) {
308 + partial[i] = str(i, value) || 'null';
309 + }
310 +
311 +// Join all of the elements together, separated with commas, and wrap them in
312 +// brackets.
313 +
314 + v = partial.length === 0 ? '[]' : gap ?
315 + '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
316 + '[' + partial.join(',') + ']';
317 + gap = mind;
318 + return v;
319 + }
320 +
321 +// If the replacer is an array, use it to select the members to be stringified.
322 +
323 + if (rep && typeof rep === 'object') {
324 + length = rep.length;
325 + for (i = 0; i < length; i += 1) {
326 + if (typeof rep[i] === 'string') {
327 + k = rep[i];
328 + v = str(k, value);
329 + if (v) {
330 + partial.push(quote(k) + (gap ? ': ' : ':') + v);
331 + }
332 + }
333 + }
334 + } else {
335 +
336 +// Otherwise, iterate through all of the keys in the object.
337 +
338 + for (k in value) {
339 + if (Object.prototype.hasOwnProperty.call(value, k)) {
340 + v = str(k, value);
341 + if (v) {
342 + partial.push(quote(k) + (gap ? ': ' : ':') + v);
343 + }
344 + }
345 + }
346 + }
347 +
348 +// Join all of the member texts together, separated with commas,
349 +// and wrap them in braces.
350 +
351 + v = partial.length === 0 ? '{}' : gap ?
352 + '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
353 + '{' + partial.join(',') + '}';
354 + gap = mind;
355 + return v;
356 + }
357 + }
358 +
359 +// If the JSON object does not yet have a stringify method, give it one.
360 +
361 + if (typeof JSON.stringify !== 'function') {
362 + JSON.stringify = function (value, replacer, space) {
363 +
364 +// The stringify method takes a value and an optional replacer, and an optional
365 +// space parameter, and returns a JSON text. The replacer can be a function
366 +// that can replace values, or an array of strings that will select the keys.
367 +// A default replacer method can be provided. Use of the space parameter can
368 +// produce text that is more easily readable.
369 +
370 + var i;
371 + gap = '';
372 + indent = '';
373 +
374 +// If the space parameter is a number, make an indent string containing that
375 +// many spaces.
376 +
377 + if (typeof space === 'number') {
378 + for (i = 0; i < space; i += 1) {
379 + indent += ' ';
380 + }
381 +
382 +// If the space parameter is a string, it will be used as the indent string.
383 +
384 + } else if (typeof space === 'string') {
385 + indent = space;
386 + }
387 +
388 +// If there is a replacer, it must be a function or an array.
389 +// Otherwise, throw an error.
390 +
391 + rep = replacer;
392 + if (replacer && typeof replacer !== 'function' &&
393 + (typeof replacer !== 'object' ||
394 + typeof replacer.length !== 'number')) {
395 + throw new Error('JSON.stringify');
396 + }
397 +
398 +// Make a fake root object containing our value under the key of ''.
399 +// Return the result of stringifying the value.
400 +
401 + return str('', {'': value});
402 + };
403 + }
404 +
405 +
406 +// If the JSON object does not yet have a parse method, give it one.
407 +
408 + if (typeof JSON.parse !== 'function') {
409 + JSON.parse = function (text, reviver) {
410 +
411 +// The parse method takes a text and an optional reviver function, and returns
412 +// a JavaScript value if the text is a valid JSON text.
413 +
414 + var j;
415 +
416 + function walk(holder, key) {
417 +
418 +// The walk method is used to recursively walk the resulting structure so
419 +// that modifications can be made.
420 +
421 + var k, v, value = holder[key];
422 + if (value && typeof value === 'object') {
423 + for (k in value) {
424 + if (Object.prototype.hasOwnProperty.call(value, k)) {
425 + v = walk(value, k);
426 + if (v !== undefined) {
427 + value[k] = v;
428 + } else {
429 + delete value[k];
430 + }
431 + }
432 + }
433 + }
434 + return reviver.call(holder, key, value);
435 + }
436 +
437 +
438 +// Parsing happens in four stages. In the first stage, we replace certain
439 +// Unicode characters with escape sequences. JavaScript handles many characters
440 +// incorrectly, either silently deleting them, or treating them as line endings.
441 +
442 + text = String(text);
443 + cx.lastIndex = 0;
444 + if (cx.test(text)) {
445 + text = text.replace(cx, function (a) {
446 + return '\\u' +
447 + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
448 + });
449 + }
450 +
451 +// In the second stage, we run the text against regular expressions that look
452 +// for non-JSON patterns. We are especially concerned with '()' and 'new'
453 +// because they can cause invocation, and '=' because it can cause mutation.
454 +// But just to be safe, we want to reject all unexpected forms.
455 +
456 +// We split the second stage into 4 regexp operations in order to work around
457 +// crippling inefficiencies in IE's and Safari's regexp engines. First we
458 +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
459 +// replace all simple value tokens with ']' characters. Third, we delete all
460 +// open brackets that follow a colon or comma or that begin the text. Finally,
461 +// we look to see that the remaining characters are only whitespace or ']' or
462 +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
463 +
464 + if (/^[\],:{}\s]*$/
465 + .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
466 + .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
467 + .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
468 +
469 +// In the third stage we use the eval function to compile the text into a
470 +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
471 +// in JavaScript: it can begin a block or an object literal. We wrap the text
472 +// in parens to eliminate the ambiguity.
473 +
474 + j = eval('(' + text + ')');
475 +
476 +// In the optional fourth stage, we recursively walk the new structure, passing
477 +// each name/value pair to a reviver function for possible transformation.
478 +
479 + return typeof reviver === 'function' ?
480 + walk({'': j}, '') : j;
481 + }
482 +
483 +// If the text is not JSON parseable, then a SyntaxError is thrown.
484 +
485 + throw new SyntaxError('JSON.parse');
486 + };
487 + }
488 +
489 + global.JSON = JSON;
490 + module.exports = JSON;
491 +}());
1 +{
2 + "author": "Douglas Crockford <douglas@crockford.com> (http://crockford.com)",
3 + "contributors" : ["AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)"],
4 + "name": "JSON",
5 + "description": "Douglas Crockford's json2.js",
6 + "keywords": ["ender"],
7 + "version": "1.0.0",
8 + "homepage": "http://json.org",
9 + "repository": {
10 + "url": "git://github.com/douglascrockford/JSON-js.git"
11 + },
12 + "main": "json2.js",
13 + "engines": {
14 + "node": ">= 0.2.0"
15 + },
16 + "dependencies": {},
17 + "devDependencies": {}
18 +}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
10 "license": "ISC", 10 "license": "ISC",
11 "dependencies": { 11 "dependencies": {
12 "express": "^4.18.1", 12 "express": "^4.18.1",
13 + "JSON": "^1.0.0",
13 "request": "^2.88.2" 14 "request": "^2.88.2"
14 } 15 }
15 }, 16 },
...@@ -517,6 +518,14 @@ ...@@ -517,6 +518,14 @@
517 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 518 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
518 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==" 519 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
519 }, 520 },
521 + "node_modules/JSON": {
522 + "version": "1.0.0",
523 + "resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
524 + "integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA==",
525 + "engines": {
526 + "node": ">= 0.2.0"
527 + }
528 + },
520 "node_modules/json-schema": { 529 "node_modules/json-schema": {
521 "version": "0.4.0", 530 "version": "0.4.0",
522 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", 531 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
...@@ -1372,6 +1381,11 @@ ...@@ -1372,6 +1381,11 @@
1372 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 1381 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
1373 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==" 1382 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
1374 }, 1383 },
1384 + "JSON": {
1385 + "version": "1.0.0",
1386 + "resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
1387 + "integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA=="
1388 + },
1375 "json-schema": { 1389 "json-schema": {
1376 "version": "0.4.0", 1390 "version": "0.4.0",
1377 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", 1391 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
14 "license": "ISC", 14 "license": "ISC",
15 "dependencies": { 15 "dependencies": {
16 "express": "^4.18.1", 16 "express": "^4.18.1",
17 + "JSON": "^1.0.0",
17 "request": "^2.88.2" 18 "request": "^2.88.2"
18 } 19 }
19 } 20 }
......