강희주

Merge branch 'feature/WeatherAPI'

Showing 300 changed files with 4599 additions and 62 deletions
...@@ -15,29 +15,99 @@ const url_newage = "https://www.melon.com/genre/song_list.htm?gnrCode=GN1800#par ...@@ -15,29 +15,99 @@ const url_newage = "https://www.melon.com/genre/song_list.htm?gnrCode=GN1800#par
15 const url_classic = "" 15 const url_classic = ""
16 const url_jazz = "https://www.melon.com/genre/jazz_list.htm?gnrCode=GN1700#params%5BgnrCode%5D=GN1700&params%5BdtlGnrCode%5D=GN1701&params%5BorderBy%5D=POP&params%5BsteadyYn%5D=&po=pageObj&startIndex=1" 16 const url_jazz = "https://www.melon.com/genre/jazz_list.htm?gnrCode=GN1700#params%5BgnrCode%5D=GN1700&params%5BdtlGnrCode%5D=GN1701&params%5BorderBy%5D=POP&params%5BsteadyYn%5D=&po=pageObj&startIndex=1"
17 17
18 +<<<<<<< HEAD:Crawling/MelonChart_Crawling/MelonChart.js
18 19
19 const getHTML = async() => { 20 const getHTML = async() => {
20 try{ 21 try{
21 return await axios.get(url_hiphop_kr) 22 return await axios.get(url_hiphop_kr)
23 +=======
24 +const getHTML = async(genre) => {
25 + try{
26 + return await axios.get(genre)
27 +>>>>>>> feature/WeatherAPI:MelonChart_Crawling/MelonChart.js
22 }catch(err) { 28 }catch(err) {
23 console.log(err); 29 console.log(err);
24 } 30 }
25 } 31 }
32 +// parsing() 함수는 한가지 파라미터를 가집니다. 파라미터에 각 장르이름 변수를 넣으면 각 장르별 5곡이 리턴됩니다.
33 +// 장르별 변수명은 다음과 같습니다.
34 +// url_ballad
35 +// url_hiphop_kr
36 +// url_hiphop_us
37 +// url_dance
38 +// url_rock_kr
39 +// url_rock_us
40 +// url_pop
41 +// url_RNB_kr
42 +// url_RNB_us
43 +// url_indie
44 +// url_newage
45 +// url_jazz
46 +// parsing_exception()은 한가지 파라미터를 가집니다. 그 인자는 'snow' 또는 'classic'으로 해야 합니다.
47 +// 'classic' 이나 'snow'를 인자로 주면 각각 배열에 저장되어있는 노래 중 랜덤으로 5개가 출력됩니다.
48 +// classic
49 +// snow
26 50
27 -const parsing = async() => { 51 +const parsing = async(genre) => {
28 - const html = await getHTML(); 52 + const html = await getHTML(genre);
29 const $ = cheerio.load(html.data); 53 const $ = cheerio.load(html.data);
30 const $TitleList = $("div.ellipsis.rank01"); 54 const $TitleList = $("div.ellipsis.rank01");
31 55
56 +
32 let Titles = []; 57 let Titles = [];
33 - $TitleList.each((inx, node) => { 58 + $TitleList.each((index, node) => {
34 const title = $(node).find("a").text(); 59 const title = $(node).find("a").text();
35 - console.log(title); 60 + Titles[Titles.length] = title;
36 }); 61 });
37 62
63 + let Titles5 = [];
64 + for(i = 0; i <= 4; i++){
65 + Titles5.push(Titles[i])
66 + };
67 +
68 + console.log(Titles5);
69 + return(Titles5);
38 } 70 }
39 71
40 -parsing(); 72 +const parsing_exception = (genre) => { // 'snow' 또는 'classic' 에만 작동합니다.
73 + snow = ['눈사람', '십이월 이십오일의 고백', '첫 눈', '첫눈처럼 너에게 가겠다', '겨울사랑', '눈꽃', '사월의 눈', '코끝에 겨울', '눈이 내린다', '새겨울', '공드리',
74 +'눈이 오네', '이번 겨울', 'I Miss You', '나의 옛날 이야기', '너의 모든 순간', '내 생에 아름다운', '너를', '눈의꽃', '야생화'];
75 +
76 + classic = ['G선상의 아리아', '트로이메라이', '무언가', '백조', '세레나데', '울게하소서', '카발레리아 루스티카나', '사랑의 인사', '보칼리제', '뱃노래',
77 +'안단테 칸타빌레', '월광의 소나타', '미뉴엣 G장조', '엘리제를 위하여', '로망스'];
78 +
79 + function shuffleArray(array) { // array의 요소들을 임의로 섞어주는 함수
80 + array.sort(() => Math.random() - 0.5);
81 + }
82 + shuffleArray(snow); //실행할 때마다 snow와 classic에 들어있는 요소들을 랜덤으로 배치
83 + shuffleArray(classic);
84 +
85 + let snow5 = [];// 그 중 앞에서 5개를 뽑아 제공
86 + let classic5 = [];
87 + for(i = 0; i <= 4; i++){
88 + snow5.push(snow[i])
89 + };
90 +
91 + for(i = 0; i <= 4; i++){
92 + classic5.push(classic[i])
93 + };
94 +
95 + if(genre == 'snow'){
96 + console.log(snow5); // console.log() 는 값 시험용으로 우선 넣어두었습니다.
97 + return(snow5);
98 + }else if(genre == 'classic'){
99 + console.log(snow5); //
100 + return(classic5);
101 + }else{
102 + console.log("input value error(The input value is snow or classic)");
103 + }
104 +}
105 +
106 +parsing(url_ballad);
107 +parsing_exception('snow');
108 +
109 +
110 +
41 111
42 112
43 113
......
...@@ -1193,6 +1193,7 @@ ...@@ -1193,6 +1193,7 @@
1193 "node": ">= 0.12" 1193 "node": ">= 0.12"
1194 } 1194 }
1195 }, 1195 },
1196 +<<<<<<< HEAD
1196 "node_modules/fs.realpath": { 1197 "node_modules/fs.realpath": {
1197 "version": "1.0.0", 1198 "version": "1.0.0",
1198 "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 1199 "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
...@@ -1260,6 +1261,12 @@ ...@@ -1260,6 +1261,12 @@
1260 "funding": { 1261 "funding": {
1261 "url": "https://github.com/sponsors/ljharb" 1262 "url": "https://github.com/sponsors/ljharb"
1262 } 1263 }
1264 +=======
1265 + "node_modules/fs": {
1266 + "version": "0.0.1-security",
1267 + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
1268 + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
1269 +>>>>>>> feature/WeatherAPI
1263 }, 1270 },
1264 "node_modules/getpass": { 1271 "node_modules/getpass": {
1265 "version": "0.1.7", 1272 "version": "0.1.7",
......
1 +# Security holding package
2 +
3 +This package name is not currently in use, but was formerly occupied
4 +by another package. To avoid malicious use, npm is hanging on to the
5 +package name, but loosely, and we'll probably give it to you if you
6 +want it.
7 +
8 +You may adopt this package by contacting support@npmjs.com and
9 +requesting the name.
1 +{
2 + "name": "fs",
3 + "version": "0.0.1-security",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "repository": {
10 + "type": "git",
11 + "url": "git+https://github.com/npm/security-holder.git"
12 + },
13 + "keywords": [],
14 + "author": "",
15 + "license": "ISC",
16 + "bugs": {
17 + "url": "https://github.com/npm/security-holder/issues"
18 + },
19 + "homepage": "https://github.com/npm/security-holder#readme"
20 +}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
9 "browserify": "^17.0.0", 9 "browserify": "^17.0.0",
10 "cheerio": "^1.0.0-rc.11", 10 "cheerio": "^1.0.0-rc.11",
11 "crawler": "^1.3.0", 11 "crawler": "^1.3.0",
12 +<<<<<<< HEAD
12 "uniq": "^1.0.1", 13 "uniq": "^1.0.1",
13 "youtube-node": "^1.3.3" 14 "youtube-node": "^1.3.3"
14 } 15 }
...@@ -48,6 +49,9 @@ ...@@ -48,6 +49,9 @@
48 "integrity": "sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==", 49 "integrity": "sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==",
49 "engines": { 50 "engines": {
50 "node": ">=0.4.0" 51 "node": ">=0.4.0"
52 +=======
53 + "fs": "^0.0.1-security"
54 +>>>>>>> feature/WeatherAPI
51 } 55 }
52 }, 56 },
53 "node_modules/ajv": { 57 "node_modules/ajv": {
...@@ -1203,6 +1207,7 @@ ...@@ -1203,6 +1207,7 @@
1203 "node": ">= 0.12" 1207 "node": ">= 0.12"
1204 } 1208 }
1205 }, 1209 },
1210 +<<<<<<< HEAD
1206 "node_modules/fs.realpath": { 1211 "node_modules/fs.realpath": {
1207 "version": "1.0.0", 1212 "version": "1.0.0",
1208 "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 1213 "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
...@@ -1270,6 +1275,12 @@ ...@@ -1270,6 +1275,12 @@
1270 "funding": { 1275 "funding": {
1271 "url": "https://github.com/sponsors/ljharb" 1276 "url": "https://github.com/sponsors/ljharb"
1272 } 1277 }
1278 +=======
1279 + "node_modules/fs": {
1280 + "version": "0.0.1-security",
1281 + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
1282 + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
1283 +>>>>>>> feature/WeatherAPI
1273 }, 1284 },
1274 "node_modules/getpass": { 1285 "node_modules/getpass": {
1275 "version": "0.1.7", 1286 "version": "0.1.7",
...@@ -4059,6 +4070,7 @@ ...@@ -4059,6 +4070,7 @@
4059 "mime-types": "^2.1.12" 4070 "mime-types": "^2.1.12"
4060 } 4071 }
4061 }, 4072 },
4073 +<<<<<<< HEAD
4062 "fs.realpath": { 4074 "fs.realpath": {
4063 "version": "1.0.0", 4075 "version": "1.0.0",
4064 "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 4076 "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
...@@ -4108,6 +4120,12 @@ ...@@ -4108,6 +4120,12 @@
4108 "call-bind": "^1.0.2", 4120 "call-bind": "^1.0.2",
4109 "get-intrinsic": "^1.1.1" 4121 "get-intrinsic": "^1.1.1"
4110 } 4122 }
4123 +=======
4124 + "fs": {
4125 + "version": "0.0.1-security",
4126 + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
4127 + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
4128 +>>>>>>> feature/WeatherAPI
4111 }, 4129 },
4112 "getpass": { 4130 "getpass": {
4113 "version": "0.1.7", 4131 "version": "0.1.7",
......
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
4 "browserify": "^17.0.0", 4 "browserify": "^17.0.0",
5 "cheerio": "^1.0.0-rc.11", 5 "cheerio": "^1.0.0-rc.11",
6 "crawler": "^1.3.0", 6 "crawler": "^1.3.0",
7 +<<<<<<< HEAD
7 "uniq": "^1.0.1", 8 "uniq": "^1.0.1",
8 "youtube-node": "^1.3.3" 9 "youtube-node": "^1.3.3"
10 +=======
11 + "fs": "^0.0.1-security"
12 +>>>>>>> feature/WeatherAPI
9 } 13 }
10 } 14 }
......
1 +<!DOCTYPE html>
2 +<html lang="ko">
3 + <head>
4 + <meta charset="UTF-8">
5 + <title>최초 창</title>
6 + <style>
7 + #container {
8 + width:600px;
9 + margin:10px auto;
10 + }
11 + </style>
12 + <link rel="stylesheet" href="first.css">
13 + </head>
14 + <body>
15 + <div id="container">
16 + <h1>'프로그램명'을 방문해주셔서 감사합니다.</h1>
17 +
18 + <input type="button" value="login" onclick="movepage()"/><script type="text/javascript">
19 + function movepage() {
20 + location.href = "/login";
21 + }
22 + </script>
23 +
24 + <input type="button" value="register" onclick="movepage1()"/>
25 + <script type="text/javascript">
26 + function movepage1() {
27 + location.href = "/join";
28 + }
29 + </script>
30 +
31 + <footer>
32 + <div>
33 + <p><b>developed by 강희주, 진재영, 김재욱</b></p>
34 + <address>Contact for more information. 010-2400-6771</address>
35 + <img style="width: 30%; height: 30%; float: right;" src="https://blog.kakaocdn.net/dn/bjsDsi/btqxXJM3JKe/WAK7xHbOm7kxyVqRIvoOaK/img.jpg" alt="경희대 마크">
36 + </div>
37 + </footer>
38 +
39 + </div>
40 +
41 + </body>
42 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +<!DOCTYPE html>
2 +<html lang="ko">
3 + <head>
4 + <meta charset="UTF-8">
5 + <title>로그인</title>
6 + <style>
7 + #container {
8 + width:600px;
9 + margin:10px auto;
10 + }
11 + </style>
12 + <link rel="stylesheet" href="http://localhost:3000/register.css">
13 + </head>
14 + <body>
15 + <div id="container">
16 + <h1>'프로그램명'을 방문해주셔서 감사합니다.</h1>
17 + <form action="/login" method="post">
18 + <fieldset>
19 + <legend>로그인</legend>
20 + <ul>
21 + <li>
22 + <label for="umail">아이디(이메일)</label>
23 + <input type="email" id="umail" required>
24 + </li>
25 + <li>
26 + <label for="pwd">비밀번호</label>
27 + <input type="password" id="pwd" placeholder="문자와 숫자, 특수 기호 포함" required>
28 + </li>
29 + </ul>
30 + </fieldset>
31 +
32 + <div id="buttons">
33 + <input type="submit" value="로그인">
34 + <input type="reset" value="취소" onclick="movepage3()"/>
35 + <script type="text/javascript">
36 + function movepage3() {
37 + location.href = "/"
38 + }
39 + </script>
40 + </div>
41 + </form>
42 + <br>
43 + <br>
44 + <br>
45 + <!-- 공간확보 -->
46 +
47 + <footer>
48 + <div>
49 + <p><b>developed by 강희주, 진재영, 김재욱</b></p>
50 + <address>Contact for more information. 010-2400-6771</address>
51 + <img style="width: 30%; height: 30%; float: right;" src="https://blog.kakaocdn.net/dn/bjsDsi/btqxXJM3JKe/WAK7xHbOm7kxyVqRIvoOaK/img.jpg" alt="경희대 마크">
52 + </div>
53 + </footer>
54 +
55 + </div>
56 + </body>
57 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +<!DOCTYPE html>
2 +<html lang="ko">
3 + <head>
4 + <script src="main.js"> </script>
5 + <meta charset="UTF-8">
6 + <title>날씨에 따른 음악 추천 사이트</title>
7 + <style>
8 + #container {
9 + width:600px;
10 + margin:10px auto;
11 + }
12 + </style>
13 + <link rel="stylesheet" href="http://localhost:3000/register1.css">
14 + </head>
15 + <body>
16 + <div id="container">
17 + <h1>'프로그램명'을 방문해주셔서 감사합니다.</h1>
18 +
19 + <fieldset>
20 + <legend>현재 시각 정보</legend>
21 + <div><input type="button" value="현재 시간 새로고침"></div><br>
22 + </fieldset>
23 +
24 + <fieldset>
25 + <legend>현재 내 위치 정보</legend>
26 + <div><input type="button" value="현재 내 위치 검색"></div><br><!-- 검색 버튼 누르면 팝업으로 위치 서비스 동의 버튼 뜨게 하기 -->
27 + </fieldset>
28 +
29 + <fieldset>
30 + <legend>추천 음악 정보</legend>
31 + <div><input type="button" value="음악 추천 받기"></div><br>
32 +
33 + <h4>첫 번째 음악 재생</h4>
34 + <div>playlist</div>
35 + <iframe width="942" height="530" src="https://www.youtube.com/embed/vnS_jn2uibs" title="YouTube video player" frameborder="0"
36 + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
37 + <!-- 위에는 예시 영상임(데이식스-한 페이지가 될 수 있게). 나중에 자동으로 영상 키를 받아올 수 있도록 구현해야 할 듯.
38 + 참고로 영상 키는 위 링크 중 embed 다음에 오는 "vnS_jn2uibs"에 해당. -->
39 + </fieldset>
40 +
41 +
42 + <br>
43 + <br>
44 + <br>
45 + <br>
46 + <br>
47 + <br>
48 + <br>
49 + <br>
50 + <br>
51 + <!-- 공간확보 -->
52 +
53 + <footer>
54 + <div>
55 + <p><b>developed by 강희주, 진재영, 김재욱</b></p>
56 + <address>Contact for more information. 010-2400-6771</address>
57 + <img style="width: 30%; height: 30%; float: right;" src="https://blog.kakaocdn.net/dn/bjsDsi/btqxXJM3JKe/WAK7xHbOm7kxyVqRIvoOaK/img.jpg" alt="경희대 마크">
58 + </div>
59 + </footer>
60 +
61 + </div>
62 + </body>
63 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 // 사용 전 npm 설치 1 // 사용 전 npm 설치
2 -// npm install express express-session session-file-store passport passport-local 2 +// npm install express express-session session-file-store passport passport-local//
3 +// npm install body-parser --save
3 4
4 -const express = require('express'); 5 +var express = require('express');
6 +var app = express();
7 +var fs = require('fs');
5 const session = require('express-session'); 8 const session = require('express-session');
9 +const exp = require('constants');
6 const passport = require('passport'), LocalStrategy = require('passport-local').Strategy; 10 const passport = require('passport'), LocalStrategy = require('passport-local').Strategy;
7 -
8 const fileStore = require('session-file-store')(session); 11 const fileStore = require('session-file-store')(session);
9 -const app = express(); 12 +var bodyParser = require('body-parser');
13 +
10 14
11 //미들웨어 리스트 15 //미들웨어 리스트
12 app.use(express.urlencoded({extended:false})); 16 app.use(express.urlencoded({extended:false}));
...@@ -18,6 +22,8 @@ app.use(session({ ...@@ -18,6 +22,8 @@ app.use(session({
18 })); 22 }));
19 app.use(passport.initialize()); 23 app.use(passport.initialize());
20 app.use(passport.session()); 24 app.use(passport.session());
25 +app.use(express.static('public'));
26 +app.use(bodyParser.urlencoded({extended:false}));
21 27
22 //사용자 정보 session 읽기, 쓰기 28 //사용자 정보 session 읽기, 쓰기
23 passport.serializeUser(function(user, done) { //쓰기 29 passport.serializeUser(function(user, done) { //쓰기
...@@ -29,26 +35,23 @@ passport.deserializeUser(function(id, done) { //읽기 ...@@ -29,26 +35,23 @@ passport.deserializeUser(function(id, done) { //읽기
29 }); 35 });
30 36
31 //메인 페이지 37 //메인 페이지
32 -app.get('/',(req,res)=>{ 38 +app.get('/', function (req, res) {
33 - let page = getPage('Passport','example page(수정하시기 바랍니다)',authInfo(req)); 39 + fs.readFile('first.html', function(error, data) {
34 - res.send(page); 40 + res.writeHead(200, { 'Content-Type': 'text/html' });
41 + res.end(data);
42 + });
35 }); 43 });
36 44
37 //로그인 페이지 45 //로그인 페이지
38 -app.get('/login',(req,res)=>{ 46 +app.get('/login',function(req, res) {
39 - let page = getPage('로그인',` 47 + fs.readFile('login.html', function(error, data) {
40 - <form action="/login" method="post"> 48 + res.writeHead(200, { 'Content-Type': 'text/html'});
41 - <input type="text" name="email" placeholder="email"><br> 49 + res.end(data);
42 - <input type="password" name="password" placeholder="****"><br> 50 + })
43 - <div style="display : flex;justify-content:space-between;width: 153px;">
44 - <input type="submit" value="로그인" style="display:inline-block;">
45 - <a href="/join" style="background : #E5E5E5;padding : 2px; border: 0.5px solid black;cursor:pointer;border-radius:3px;font-size:13px;color:black;text-decoration:none;">회원가입</a>
46 - </div>
47 - </form>
48 - `,`<a href="/">뒤로가기</a>`);
49 - res.send(page);
50 }); 51 });
51 52
53 +
54 +
52 //로그인 인증 (Passport) 55 //로그인 인증 (Passport)
53 passport.use(new LocalStrategy({ 56 passport.use(new LocalStrategy({
54 //로그인 페이지 input 태그 내 name 57 //로그인 페이지 input 태그 내 name
...@@ -63,10 +66,10 @@ passport.use(new LocalStrategy({ ...@@ -63,10 +66,10 @@ passport.use(new LocalStrategy({
63 66
64 //아이디가 다를때 67 //아이디가 다를때
65 if (id !== user.email) 68 if (id !== user.email)
66 - return done(null, false, { message: '아이디가 다다' }); 69 + return done(null, false, { message: '아이디가 다릅니다' });
67 //비밀번호가 다를때 70 //비밀번호가 다를때
68 else if (password !== user.password) 71 else if (password !== user.password)
69 - return done(null, false, { message: '비번이 다다' }); 72 + return done(null, false, { message: '비번이 다릅니다' });
70 //아이디, 비밀번호 모두 맞을 경우 73 //아이디, 비밀번호 모두 맞을 경우
71 return done(null, user); 74 return done(null, user);
72 } 75 }
...@@ -75,32 +78,35 @@ passport.use(new LocalStrategy({ ...@@ -75,32 +78,35 @@ passport.use(new LocalStrategy({
75 //로그인 처리 (Passport) 78 //로그인 처리 (Passport)
76 app.post('/login', 79 app.post('/login',
77 passport.authenticate('local', { 80 passport.authenticate('local', {
78 - //성공시, 메인페이지 이동 81 +
79 - //실패시 로그인 페이지 이동 82 + successRedirect: '/main',
80 - successRedirect: '/',
81 failureRedirect: '/login' 83 failureRedirect: '/login'
82 })); 84 }));
83 85
84 86
85 //회원가입 페이지 Get 87 //회원가입 페이지 Get
86 -app.get('/join',(req,res)=>{ 88 +app.get('/join',function(req, res) {
87 - let page = getPage('회원가입',` 89 + fs.readFile('register.html', function(error, data) {
88 - <form action="/join" method="post"> 90 + res.writeHead(200, { 'Contect-Type': 'text/html'});
89 - <input type="email" name="email" placeholder="email"><br> 91 + res.end(data);
90 - <input type="password" name="password" placeholder="****"><br> 92 + })
91 - <input type="name" name="name" placeholder="이름"><br>
92 - <input type="submit" value="회원가입"><br>
93 - </form>
94 - `,'<a href="/login">뒤로가기</a>');
95 - res.send(page);
96 }); 93 });
97 94
98 -//회원가입 처리 Post : 예제를 위해 간단 저장 방식으로 구현 95 +app.get('/main',function(req, res) {
96 + fs.readFile('main.html', function(error, data) {
97 + res.writeHead(200, { 'Contect-Type': 'text/html'});
98 + res.end(data);
99 + })
100 +});
101 +
102 +//회원가입
99 var user = {}; 103 var user = {};
100 -app.post('/join',(req,res)=>{ 104 +app.post('/join',(req,res) =>{
105 +
101 user.email = req.body.email; 106 user.email = req.body.email;
102 user.password = req.body.password; 107 user.password = req.body.password;
103 - user.name=req.body.name; 108 + user.name = req.body.name;
109 +
104 //로그인 페이지로 이동 110 //로그인 페이지로 이동
105 res.redirect('/login'); 111 res.redirect('/login');
106 }); 112 });
...@@ -119,7 +125,9 @@ app.get('/logout',(req,res)=>{ ...@@ -119,7 +125,9 @@ app.get('/logout',(req,res)=>{
119 125
120 126
121 //포트 연결 127 //포트 연결
122 -app.listen(3000,()=>console.log(`http://localhost:3000`)); 128 +app.listen(3000, function() {
129 + console.log('http://localhost:3000');
130 +});
123 131
124 132
125 //로그인 로그아웃 여부 133 //로그인 로그아웃 여부
...@@ -128,22 +136,3 @@ const authInfo = (req)=>{ ...@@ -128,22 +136,3 @@ const authInfo = (req)=>{
128 return `<a href="/login">login</a>`; 136 return `<a href="/login">login</a>`;
129 } 137 }
130 138
131 -//페이지 템플릿
132 -const getPage = (title, content, auth) =>{
133 - return `
134 - <!DOCTYPE html>
135 - <html lang="en">
136 - <head>
137 - <meta charset="UTF-8">
138 - <meta http-equiv="X-UA-Compatible" content="IE=edge">
139 - <meta name="viewport" content="width=device-width, initial-scale=1.0">
140 - <title>Passport Example</title>
141 - </head>
142 - <body>
143 - ${auth}
144 - <h1>${title}</h1>
145 - <p>${content}</p>
146 - </body>
147 - </html>
148 - `;
149 -}
...\ No newline at end of file ...\ No newline at end of file
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +(The MIT License)
2 +
3 +Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
4 +Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining
7 +a copy of this software and associated documentation files (the
8 +'Software'), to deal in the Software without restriction, including
9 +without limitation the rights to use, copy, modify, merge, publish,
10 +distribute, sublicense, and/or sell copies of the Software, and to
11 +permit persons to whom the Software is furnished to do so, subject to
12 +the following conditions:
13 +
14 +The above copyright notice and this permission notice shall be
15 +included in all copies or substantial portions of the Software.
16 +
17 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This diff is collapsed. Click to expand it.
1 +# Security Policies and Procedures
2 +
3 +## Reporting a Bug
4 +
5 +The Express team and community take all security bugs seriously. Thank you
6 +for improving the security of Express. We appreciate your efforts and
7 +responsible disclosure and will make every effort to acknowledge your
8 +contributions.
9 +
10 +Report security bugs by emailing the current owner(s) of `body-parser`. This
11 +information can be found in the npm registry using the command
12 +`npm owner ls body-parser`.
13 +If unsure or unable to get the information from the above, open an issue
14 +in the [project issue tracker](https://github.com/expressjs/body-parser/issues)
15 +asking for the current contact information.
16 +
17 +To ensure the timely response to your report, please ensure that the entirety
18 +of the report is contained within the email body and not solely behind a web
19 +link or an attachment.
20 +
21 +At least one owner will acknowledge your email within 48 hours, and will send a
22 +more detailed response within 48 hours indicating the next steps in handling
23 +your report. After the initial reply to your report, the owners will
24 +endeavor to keep you informed of the progress towards a fix and full
25 +announcement, and may ask for additional information or guidance.
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module dependencies.
11 + * @private
12 + */
13 +
14 +var deprecate = require('depd')('body-parser')
15 +
16 +/**
17 + * Cache of loaded parsers.
18 + * @private
19 + */
20 +
21 +var parsers = Object.create(null)
22 +
23 +/**
24 + * @typedef Parsers
25 + * @type {function}
26 + * @property {function} json
27 + * @property {function} raw
28 + * @property {function} text
29 + * @property {function} urlencoded
30 + */
31 +
32 +/**
33 + * Module exports.
34 + * @type {Parsers}
35 + */
36 +
37 +exports = module.exports = deprecate.function(bodyParser,
38 + 'bodyParser: use individual json/urlencoded middlewares')
39 +
40 +/**
41 + * JSON parser.
42 + * @public
43 + */
44 +
45 +Object.defineProperty(exports, 'json', {
46 + configurable: true,
47 + enumerable: true,
48 + get: createParserGetter('json')
49 +})
50 +
51 +/**
52 + * Raw parser.
53 + * @public
54 + */
55 +
56 +Object.defineProperty(exports, 'raw', {
57 + configurable: true,
58 + enumerable: true,
59 + get: createParserGetter('raw')
60 +})
61 +
62 +/**
63 + * Text parser.
64 + * @public
65 + */
66 +
67 +Object.defineProperty(exports, 'text', {
68 + configurable: true,
69 + enumerable: true,
70 + get: createParserGetter('text')
71 +})
72 +
73 +/**
74 + * URL-encoded parser.
75 + * @public
76 + */
77 +
78 +Object.defineProperty(exports, 'urlencoded', {
79 + configurable: true,
80 + enumerable: true,
81 + get: createParserGetter('urlencoded')
82 +})
83 +
84 +/**
85 + * Create a middleware to parse json and urlencoded bodies.
86 + *
87 + * @param {object} [options]
88 + * @return {function}
89 + * @deprecated
90 + * @public
91 + */
92 +
93 +function bodyParser (options) {
94 + 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 destroy = require('destroy')
16 +var getBody = require('raw-body')
17 +var iconv = require('iconv-lite')
18 +var onFinished = require('on-finished')
19 +var unpipe = require('unpipe')
20 +var zlib = require('zlib')
21 +
22 +/**
23 + * Module exports.
24 + */
25 +
26 +module.exports = read
27 +
28 +/**
29 + * Read a request into a buffer and parse.
30 + *
31 + * @param {object} req
32 + * @param {object} res
33 + * @param {function} next
34 + * @param {function} parse
35 + * @param {function} debug
36 + * @param {object} options
37 + * @private
38 + */
39 +
40 +function read (req, res, next, parse, debug, options) {
41 + var length
42 + var opts = options
43 + var stream
44 +
45 + // flag as parsed
46 + req._body = true
47 +
48 + // read options
49 + var encoding = opts.encoding !== null
50 + ? opts.encoding
51 + : null
52 + var verify = opts.verify
53 +
54 + try {
55 + // get the content stream
56 + stream = contentstream(req, debug, opts.inflate)
57 + length = stream.length
58 + stream.length = undefined
59 + } catch (err) {
60 + return next(err)
61 + }
62 +
63 + // set raw-body options
64 + opts.length = length
65 + opts.encoding = verify
66 + ? null
67 + : encoding
68 +
69 + // assert charset is supported
70 + if (opts.encoding === null && encoding !== null && !iconv.encodingExists(encoding)) {
71 + return next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
72 + charset: encoding.toLowerCase(),
73 + type: 'charset.unsupported'
74 + }))
75 + }
76 +
77 + // read body
78 + debug('read body')
79 + getBody(stream, opts, function (error, body) {
80 + if (error) {
81 + var _error
82 +
83 + if (error.type === 'encoding.unsupported') {
84 + // echo back charset
85 + _error = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
86 + charset: encoding.toLowerCase(),
87 + type: 'charset.unsupported'
88 + })
89 + } else {
90 + // set status code on error
91 + _error = createError(400, error)
92 + }
93 +
94 + // unpipe from stream and destroy
95 + if (stream !== req) {
96 + unpipe(req)
97 + destroy(stream, true)
98 + }
99 +
100 + // read off entire request
101 + dump(req, function onfinished () {
102 + next(createError(400, _error))
103 + })
104 + return
105 + }
106 +
107 + // verify
108 + if (verify) {
109 + try {
110 + debug('verify body')
111 + verify(req, res, body, encoding)
112 + } catch (err) {
113 + next(createError(403, err, {
114 + body: body,
115 + type: err.type || 'entity.verify.failed'
116 + }))
117 + return
118 + }
119 + }
120 +
121 + // parse
122 + var str = body
123 + try {
124 + debug('parse body')
125 + str = typeof body !== 'string' && encoding !== null
126 + ? iconv.decode(body, encoding)
127 + : body
128 + req.body = parse(str)
129 + } catch (err) {
130 + next(createError(400, err, {
131 + body: str,
132 + type: err.type || 'entity.parse.failed'
133 + }))
134 + return
135 + }
136 +
137 + next()
138 + })
139 +}
140 +
141 +/**
142 + * Get the content stream of the request.
143 + *
144 + * @param {object} req
145 + * @param {function} debug
146 + * @param {boolean} [inflate=true]
147 + * @return {object}
148 + * @api private
149 + */
150 +
151 +function contentstream (req, debug, inflate) {
152 + var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase()
153 + var length = req.headers['content-length']
154 + var stream
155 +
156 + debug('content-encoding "%s"', encoding)
157 +
158 + if (inflate === false && encoding !== 'identity') {
159 + throw createError(415, 'content encoding unsupported', {
160 + encoding: encoding,
161 + type: 'encoding.unsupported'
162 + })
163 + }
164 +
165 + switch (encoding) {
166 + case 'deflate':
167 + stream = zlib.createInflate()
168 + debug('inflate body')
169 + req.pipe(stream)
170 + break
171 + case 'gzip':
172 + stream = zlib.createGunzip()
173 + debug('gunzip body')
174 + req.pipe(stream)
175 + break
176 + case 'identity':
177 + stream = req
178 + stream.length = length
179 + break
180 + default:
181 + throw createError(415, 'unsupported content encoding "' + encoding + '"', {
182 + encoding: encoding,
183 + type: 'encoding.unsupported'
184 + })
185 + }
186 +
187 + return stream
188 +}
189 +
190 +/**
191 + * Dump the contents of a request.
192 + *
193 + * @param {object} req
194 + * @param {function} callback
195 + * @api private
196 + */
197 +
198 +function dump (req, callback) {
199 + if (onFinished.isFinished(req)) {
200 + callback(null)
201 + } else {
202 + onFinished(req, callback)
203 + req.resume()
204 + }
205 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014 Jonathan Ong
4 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict'
9 +
10 +/**
11 + * Module dependencies.
12 + * @private
13 + */
14 +
15 +var bytes = require('bytes')
16 +var contentType = require('content-type')
17 +var createError = require('http-errors')
18 +var debug = require('debug')('body-parser:json')
19 +var read = require('../read')
20 +var typeis = require('type-is')
21 +
22 +/**
23 + * Module exports.
24 + */
25 +
26 +module.exports = json
27 +
28 +/**
29 + * RegExp to match the first non-space in a string.
30 + *
31 + * Allowed whitespace is defined in RFC 7159:
32 + *
33 + * ws = *(
34 + * %x20 / ; Space
35 + * %x09 / ; Horizontal tab
36 + * %x0A / ; Line feed or New line
37 + * %x0D ) ; Carriage return
38 + */
39 +
40 +var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/ // eslint-disable-line no-control-regex
41 +
42 +/**
43 + * Create a middleware to parse JSON bodies.
44 + *
45 + * @param {object} [options]
46 + * @return {function}
47 + * @public
48 + */
49 +
50 +function json (options) {
51 + var opts = options || {}
52 +
53 + var limit = typeof opts.limit !== 'number'
54 + ? bytes.parse(opts.limit || '100kb')
55 + : opts.limit
56 + var inflate = opts.inflate !== false
57 + var reviver = opts.reviver
58 + var strict = opts.strict !== false
59 + var type = opts.type || 'application/json'
60 + var verify = opts.verify || false
61 +
62 + if (verify !== false && typeof verify !== 'function') {
63 + throw new TypeError('option verify must be function')
64 + }
65 +
66 + // create the appropriate type checking function
67 + var shouldParse = typeof type !== 'function'
68 + ? typeChecker(type)
69 + : type
70 +
71 + function parse (body) {
72 + if (body.length === 0) {
73 + // special-case empty json body, as it's a common client-side mistake
74 + // TODO: maybe make this configurable or part of "strict" option
75 + return {}
76 + }
77 +
78 + if (strict) {
79 + var first = firstchar(body)
80 +
81 + if (first !== '{' && first !== '[') {
82 + debug('strict violation')
83 + throw createStrictSyntaxError(body, first)
84 + }
85 + }
86 +
87 + try {
88 + debug('parse json')
89 + return JSON.parse(body, reviver)
90 + } catch (e) {
91 + throw normalizeJsonSyntaxError(e, {
92 + message: e.message,
93 + stack: e.stack
94 + })
95 + }
96 + }
97 +
98 + return function jsonParser (req, res, next) {
99 + if (req._body) {
100 + debug('body already parsed')
101 + next()
102 + return
103 + }
104 +
105 + req.body = req.body || {}
106 +
107 + // skip requests without bodies
108 + if (!typeis.hasBody(req)) {
109 + debug('skip empty body')
110 + next()
111 + return
112 + }
113 +
114 + debug('content-type %j', req.headers['content-type'])
115 +
116 + // determine if request should be parsed
117 + if (!shouldParse(req)) {
118 + debug('skip parsing')
119 + next()
120 + return
121 + }
122 +
123 + // assert charset per RFC 7159 sec 8.1
124 + var charset = getCharset(req) || 'utf-8'
125 + if (charset.slice(0, 4) !== 'utf-') {
126 + debug('invalid charset')
127 + next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
128 + charset: charset,
129 + type: 'charset.unsupported'
130 + }))
131 + return
132 + }
133 +
134 + // read
135 + read(req, res, next, parse, debug, {
136 + encoding: charset,
137 + inflate: inflate,
138 + limit: limit,
139 + verify: verify
140 + })
141 + }
142 +}
143 +
144 +/**
145 + * Create strict violation syntax error matching native error.
146 + *
147 + * @param {string} str
148 + * @param {string} char
149 + * @return {Error}
150 + * @private
151 + */
152 +
153 +function createStrictSyntaxError (str, char) {
154 + var index = str.indexOf(char)
155 + var partial = index !== -1
156 + ? str.substring(0, index) + '#'
157 + : ''
158 +
159 + try {
160 + JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
161 + } catch (e) {
162 + return normalizeJsonSyntaxError(e, {
163 + message: e.message.replace('#', char),
164 + stack: e.stack
165 + })
166 + }
167 +}
168 +
169 +/**
170 + * Get the first non-whitespace character in a string.
171 + *
172 + * @param {string} str
173 + * @return {function}
174 + * @private
175 + */
176 +
177 +function firstchar (str) {
178 + var match = FIRST_CHAR_REGEXP.exec(str)
179 +
180 + return match
181 + ? match[1]
182 + : undefined
183 +}
184 +
185 +/**
186 + * Get the charset of a request.
187 + *
188 + * @param {object} req
189 + * @api private
190 + */
191 +
192 +function getCharset (req) {
193 + try {
194 + return (contentType.parse(req).parameters.charset || '').toLowerCase()
195 + } catch (e) {
196 + return undefined
197 + }
198 +}
199 +
200 +/**
201 + * Normalize a SyntaxError for JSON.parse.
202 + *
203 + * @param {SyntaxError} error
204 + * @param {object} obj
205 + * @return {SyntaxError}
206 + */
207 +
208 +function normalizeJsonSyntaxError (error, obj) {
209 + var keys = Object.getOwnPropertyNames(error)
210 +
211 + for (var i = 0; i < keys.length; i++) {
212 + var key = keys[i]
213 + if (key !== 'stack' && key !== 'message') {
214 + delete error[key]
215 + }
216 + }
217 +
218 + // replace stack before message for Node.js 0.10 and below
219 + error.stack = obj.stack.replace(error.message, obj.message)
220 + error.message = obj.message
221 +
222 + return error
223 +}
224 +
225 +/**
226 + * Get the simple type checker.
227 + *
228 + * @param {string} type
229 + * @return {function}
230 + */
231 +
232 +function typeChecker (type) {
233 + return function checkType (req) {
234 + return Boolean(typeis(req, type))
235 + }
236 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module dependencies.
11 + */
12 +
13 +var bytes = require('bytes')
14 +var debug = require('debug')('body-parser:raw')
15 +var read = require('../read')
16 +var typeis = require('type-is')
17 +
18 +/**
19 + * Module exports.
20 + */
21 +
22 +module.exports = raw
23 +
24 +/**
25 + * Create a middleware to parse raw bodies.
26 + *
27 + * @param {object} [options]
28 + * @return {function}
29 + * @api public
30 + */
31 +
32 +function raw (options) {
33 + var opts = options || {}
34 +
35 + var inflate = opts.inflate !== false
36 + var limit = typeof opts.limit !== 'number'
37 + ? bytes.parse(opts.limit || '100kb')
38 + : opts.limit
39 + var type = opts.type || 'application/octet-stream'
40 + var verify = opts.verify || false
41 +
42 + if (verify !== false && typeof verify !== 'function') {
43 + throw new TypeError('option verify must be function')
44 + }
45 +
46 + // create the appropriate type checking function
47 + var shouldParse = typeof type !== 'function'
48 + ? typeChecker(type)
49 + : type
50 +
51 + function parse (buf) {
52 + return buf
53 + }
54 +
55 + return function rawParser (req, res, next) {
56 + if (req._body) {
57 + debug('body already parsed')
58 + next()
59 + return
60 + }
61 +
62 + req.body = req.body || {}
63 +
64 + // skip requests without bodies
65 + if (!typeis.hasBody(req)) {
66 + debug('skip empty body')
67 + next()
68 + return
69 + }
70 +
71 + debug('content-type %j', req.headers['content-type'])
72 +
73 + // determine if request should be parsed
74 + if (!shouldParse(req)) {
75 + debug('skip parsing')
76 + next()
77 + return
78 + }
79 +
80 + // read
81 + read(req, res, next, parse, debug, {
82 + encoding: null,
83 + inflate: inflate,
84 + limit: limit,
85 + verify: verify
86 + })
87 + }
88 +}
89 +
90 +/**
91 + * Get the simple type checker.
92 + *
93 + * @param {string} type
94 + * @return {function}
95 + */
96 +
97 +function typeChecker (type) {
98 + return function checkType (req) {
99 + return Boolean(typeis(req, type))
100 + }
101 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module dependencies.
11 + */
12 +
13 +var bytes = require('bytes')
14 +var contentType = require('content-type')
15 +var debug = require('debug')('body-parser:text')
16 +var read = require('../read')
17 +var typeis = require('type-is')
18 +
19 +/**
20 + * Module exports.
21 + */
22 +
23 +module.exports = text
24 +
25 +/**
26 + * Create a middleware to parse text bodies.
27 + *
28 + * @param {object} [options]
29 + * @return {function}
30 + * @api public
31 + */
32 +
33 +function text (options) {
34 + var opts = options || {}
35 +
36 + var defaultCharset = opts.defaultCharset || 'utf-8'
37 + var inflate = opts.inflate !== false
38 + var limit = typeof opts.limit !== 'number'
39 + ? bytes.parse(opts.limit || '100kb')
40 + : opts.limit
41 + var type = opts.type || 'text/plain'
42 + var verify = opts.verify || false
43 +
44 + if (verify !== false && typeof verify !== 'function') {
45 + throw new TypeError('option verify must be function')
46 + }
47 +
48 + // create the appropriate type checking function
49 + var shouldParse = typeof type !== 'function'
50 + ? typeChecker(type)
51 + : type
52 +
53 + function parse (buf) {
54 + return buf
55 + }
56 +
57 + return function textParser (req, res, next) {
58 + if (req._body) {
59 + debug('body already parsed')
60 + next()
61 + return
62 + }
63 +
64 + req.body = req.body || {}
65 +
66 + // skip requests without bodies
67 + if (!typeis.hasBody(req)) {
68 + debug('skip empty body')
69 + next()
70 + return
71 + }
72 +
73 + debug('content-type %j', req.headers['content-type'])
74 +
75 + // determine if request should be parsed
76 + if (!shouldParse(req)) {
77 + debug('skip parsing')
78 + next()
79 + return
80 + }
81 +
82 + // get charset
83 + var charset = getCharset(req) || defaultCharset
84 +
85 + // read
86 + read(req, res, next, parse, debug, {
87 + encoding: charset,
88 + inflate: inflate,
89 + limit: limit,
90 + verify: verify
91 + })
92 + }
93 +}
94 +
95 +/**
96 + * Get the charset of a request.
97 + *
98 + * @param {object} req
99 + * @api private
100 + */
101 +
102 +function getCharset (req) {
103 + try {
104 + return (contentType.parse(req).parameters.charset || '').toLowerCase()
105 + } catch (e) {
106 + return undefined
107 + }
108 +}
109 +
110 +/**
111 + * Get the simple type checker.
112 + *
113 + * @param {string} type
114 + * @return {function}
115 + */
116 +
117 +function typeChecker (type) {
118 + return function checkType (req) {
119 + return Boolean(typeis(req, type))
120 + }
121 +}
1 +/*!
2 + * body-parser
3 + * Copyright(c) 2014 Jonathan Ong
4 + * Copyright(c) 2014-2015 Douglas Christopher Wilson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict'
9 +
10 +/**
11 + * Module dependencies.
12 + * @private
13 + */
14 +
15 +var bytes = require('bytes')
16 +var contentType = require('content-type')
17 +var createError = require('http-errors')
18 +var debug = require('debug')('body-parser:urlencoded')
19 +var deprecate = require('depd')('body-parser')
20 +var read = require('../read')
21 +var typeis = require('type-is')
22 +
23 +/**
24 + * Module exports.
25 + */
26 +
27 +module.exports = urlencoded
28 +
29 +/**
30 + * Cache of parser modules.
31 + */
32 +
33 +var parsers = Object.create(null)
34 +
35 +/**
36 + * Create a middleware to parse urlencoded bodies.
37 + *
38 + * @param {object} [options]
39 + * @return {function}
40 + * @public
41 + */
42 +
43 +function urlencoded (options) {
44 + var opts = options || {}
45 +
46 + // notice because option default will flip in next major
47 + if (opts.extended === undefined) {
48 + deprecate('undefined extended: provide extended option')
49 + }
50 +
51 + var extended = opts.extended !== false
52 + var inflate = opts.inflate !== false
53 + var limit = typeof opts.limit !== 'number'
54 + ? bytes.parse(opts.limit || '100kb')
55 + : opts.limit
56 + var type = opts.type || 'application/x-www-form-urlencoded'
57 + var verify = opts.verify || false
58 +
59 + if (verify !== false && typeof verify !== 'function') {
60 + throw new TypeError('option verify must be function')
61 + }
62 +
63 + // create the appropriate query parser
64 + var queryparse = extended
65 + ? extendedparser(opts)
66 + : simpleparser(opts)
67 +
68 + // create the appropriate type checking function
69 + var shouldParse = typeof type !== 'function'
70 + ? typeChecker(type)
71 + : type
72 +
73 + function parse (body) {
74 + return body.length
75 + ? queryparse(body)
76 + : {}
77 + }
78 +
79 + return function urlencodedParser (req, res, next) {
80 + if (req._body) {
81 + debug('body already parsed')
82 + next()
83 + return
84 + }
85 +
86 + req.body = req.body || {}
87 +
88 + // skip requests without bodies
89 + if (!typeis.hasBody(req)) {
90 + debug('skip empty body')
91 + next()
92 + return
93 + }
94 +
95 + debug('content-type %j', req.headers['content-type'])
96 +
97 + // determine if request should be parsed
98 + if (!shouldParse(req)) {
99 + debug('skip parsing')
100 + next()
101 + return
102 + }
103 +
104 + // assert charset
105 + var charset = getCharset(req) || 'utf-8'
106 + if (charset !== 'utf-8') {
107 + debug('invalid charset')
108 + next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
109 + charset: charset,
110 + type: 'charset.unsupported'
111 + }))
112 + return
113 + }
114 +
115 + // read
116 + read(req, res, next, parse, debug, {
117 + debug: debug,
118 + encoding: charset,
119 + inflate: inflate,
120 + limit: limit,
121 + verify: verify
122 + })
123 + }
124 +}
125 +
126 +/**
127 + * Get the extended query parser.
128 + *
129 + * @param {object} options
130 + */
131 +
132 +function extendedparser (options) {
133 + var parameterLimit = options.parameterLimit !== undefined
134 + ? options.parameterLimit
135 + : 1000
136 + var parse = parser('qs')
137 +
138 + if (isNaN(parameterLimit) || parameterLimit < 1) {
139 + throw new TypeError('option parameterLimit must be a positive number')
140 + }
141 +
142 + if (isFinite(parameterLimit)) {
143 + parameterLimit = parameterLimit | 0
144 + }
145 +
146 + return function queryparse (body) {
147 + var paramCount = parameterCount(body, parameterLimit)
148 +
149 + if (paramCount === undefined) {
150 + debug('too many parameters')
151 + throw createError(413, 'too many parameters', {
152 + type: 'parameters.too.many'
153 + })
154 + }
155 +
156 + var arrayLimit = Math.max(100, paramCount)
157 +
158 + debug('parse extended urlencoding')
159 + return parse(body, {
160 + allowPrototypes: true,
161 + arrayLimit: arrayLimit,
162 + depth: Infinity,
163 + parameterLimit: parameterLimit
164 + })
165 + }
166 +}
167 +
168 +/**
169 + * Get the charset of a request.
170 + *
171 + * @param {object} req
172 + * @api private
173 + */
174 +
175 +function getCharset (req) {
176 + try {
177 + return (contentType.parse(req).parameters.charset || '').toLowerCase()
178 + } catch (e) {
179 + return undefined
180 + }
181 +}
182 +
183 +/**
184 + * Count the number of parameters, stopping once limit reached
185 + *
186 + * @param {string} body
187 + * @param {number} limit
188 + * @api private
189 + */
190 +
191 +function parameterCount (body, limit) {
192 + var count = 0
193 + var index = 0
194 +
195 + while ((index = body.indexOf('&', index)) !== -1) {
196 + count++
197 + index++
198 +
199 + if (count === limit) {
200 + return undefined
201 + }
202 + }
203 +
204 + return count
205 +}
206 +
207 +/**
208 + * Get parser for module name dynamically.
209 + *
210 + * @param {string} name
211 + * @return {function}
212 + * @api private
213 + */
214 +
215 +function parser (name) {
216 + var mod = parsers[name]
217 +
218 + if (mod !== undefined) {
219 + return mod.parse
220 + }
221 +
222 + // this uses a switch for static require analysis
223 + switch (name) {
224 + case 'qs':
225 + mod = require('qs')
226 + break
227 + case 'querystring':
228 + mod = require('querystring')
229 + break
230 + }
231 +
232 + // store to prevent invoking require()
233 + parsers[name] = mod
234 +
235 + return mod.parse
236 +}
237 +
238 +/**
239 + * Get the simple query parser.
240 + *
241 + * @param {object} options
242 + */
243 +
244 +function simpleparser (options) {
245 + var parameterLimit = options.parameterLimit !== undefined
246 + ? options.parameterLimit
247 + : 1000
248 + var parse = parser('querystring')
249 +
250 + if (isNaN(parameterLimit) || parameterLimit < 1) {
251 + throw new TypeError('option parameterLimit must be a positive number')
252 + }
253 +
254 + if (isFinite(parameterLimit)) {
255 + parameterLimit = parameterLimit | 0
256 + }
257 +
258 + return function queryparse (body) {
259 + var paramCount = parameterCount(body, parameterLimit)
260 +
261 + if (paramCount === undefined) {
262 + debug('too many parameters')
263 + throw createError(413, 'too many parameters', {
264 + type: 'parameters.too.many'
265 + })
266 + }
267 +
268 + debug('parse urlencoding')
269 + return parse(body, undefined, undefined, { maxKeys: parameterLimit })
270 + }
271 +}
272 +
273 +/**
274 + * Get the simple type checker.
275 + *
276 + * @param {string} type
277 + * @return {function}
278 + */
279 +
280 +function typeChecker (type) {
281 + return function checkType (req) {
282 + return Boolean(typeis(req, type))
283 + }
284 +}
1 +{
2 + "name": "body-parser",
3 + "description": "Node.js body parsing middleware",
4 + "version": "1.20.0",
5 + "contributors": [
6 + "Douglas Christopher Wilson <doug@somethingdoug.com>",
7 + "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
8 + ],
9 + "license": "MIT",
10 + "repository": "expressjs/body-parser",
11 + "dependencies": {
12 + "bytes": "3.1.2",
13 + "content-type": "~1.0.4",
14 + "debug": "2.6.9",
15 + "depd": "2.0.0",
16 + "destroy": "1.2.0",
17 + "http-errors": "2.0.0",
18 + "iconv-lite": "0.4.24",
19 + "on-finished": "2.4.1",
20 + "qs": "6.10.3",
21 + "raw-body": "2.5.1",
22 + "type-is": "~1.6.18",
23 + "unpipe": "1.0.0"
24 + },
25 + "devDependencies": {
26 + "eslint": "7.32.0",
27 + "eslint-config-standard": "14.1.1",
28 + "eslint-plugin-import": "2.25.4",
29 + "eslint-plugin-markdown": "2.2.1",
30 + "eslint-plugin-node": "11.1.0",
31 + "eslint-plugin-promise": "5.2.0",
32 + "eslint-plugin-standard": "4.1.0",
33 + "methods": "1.1.2",
34 + "mocha": "9.2.2",
35 + "nyc": "15.1.0",
36 + "safe-buffer": "5.2.1",
37 + "supertest": "6.2.2"
38 + },
39 + "files": [
40 + "lib/",
41 + "LICENSE",
42 + "HISTORY.md",
43 + "SECURITY.md",
44 + "index.js"
45 + ],
46 + "engines": {
47 + "node": ">= 0.8",
48 + "npm": "1.2.8000 || >= 1.4.16"
49 + },
50 + "scripts": {
51 + "lint": "eslint .",
52 + "test": "mocha --require test/support/env --reporter spec --check-leaks --bail test/",
53 + "test-ci": "nyc --reporter=lcov --reporter=text npm test",
54 + "test-cov": "nyc --reporter=html --reporter=text npm test"
55 + }
56 +}
1 +3.1.2 / 2022-01-27
2 +==================
3 +
4 + * Fix return value for un-parsable strings
5 +
6 +3.1.1 / 2021-11-15
7 +==================
8 +
9 + * Fix "thousandsSeparator" incorrecting formatting fractional part
10 +
11 +3.1.0 / 2019-01-22
12 +==================
13 +
14 + * Add petabyte (`pb`) support
15 +
16 +3.0.0 / 2017-08-31
17 +==================
18 +
19 + * Change "kB" to "KB" in format output
20 + * Remove support for Node.js 0.6
21 + * Remove support for ComponentJS
22 +
23 +2.5.0 / 2017-03-24
24 +==================
25 +
26 + * Add option "unit"
27 +
28 +2.4.0 / 2016-06-01
29 +==================
30 +
31 + * Add option "unitSeparator"
32 +
33 +2.3.0 / 2016-02-15
34 +==================
35 +
36 + * Drop partial bytes on all parsed units
37 + * Fix non-finite numbers to `.format` to return `null`
38 + * Fix parsing byte string that looks like hex
39 + * perf: hoist regular expressions
40 +
41 +2.2.0 / 2015-11-13
42 +==================
43 +
44 + * add option "decimalPlaces"
45 + * add option "fixedDecimals"
46 +
47 +2.1.0 / 2015-05-21
48 +==================
49 +
50 + * add `.format` export
51 + * add `.parse` export
52 +
53 +2.0.2 / 2015-05-20
54 +==================
55 +
56 + * remove map recreation
57 + * remove unnecessary object construction
58 +
59 +2.0.1 / 2015-05-07
60 +==================
61 +
62 + * fix browserify require
63 + * remove node.extend dependency
64 +
65 +2.0.0 / 2015-04-12
66 +==================
67 +
68 + * add option "case"
69 + * add option "thousandsSeparator"
70 + * return "null" on invalid parse input
71 + * support proper round-trip: bytes(bytes(num)) === num
72 + * units no longer case sensitive when parsing
73 +
74 +1.0.0 / 2014-05-05
75 +==================
76 +
77 + * add negative support. fixes #6
78 +
79 +0.3.0 / 2014-03-19
80 +==================
81 +
82 + * added terabyte support
83 +
84 +0.2.1 / 2013-04-01
85 +==================
86 +
87 + * add .component
88 +
89 +0.2.0 / 2012-10-28
90 +==================
91 +
92 + * bytes(200).should.eql('200b')
93 +
94 +0.1.0 / 2012-07-04
95 +==================
96 +
97 + * add bytes to string conversion [yields]
1 +(The MIT License)
2 +
3 +Copyright (c) 2012-2014 TJ Holowaychuk <tj@vision-media.ca>
4 +Copyright (c) 2015 Jed Watson <jed.watson@me.com>
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining
7 +a copy of this software and associated documentation files (the
8 +'Software'), to deal in the Software without restriction, including
9 +without limitation the rights to use, copy, modify, merge, publish,
10 +distribute, sublicense, and/or sell copies of the Software, and to
11 +permit persons to whom the Software is furnished to do so, subject to
12 +the following conditions:
13 +
14 +The above copyright notice and this permission notice shall be
15 +included in all copies or substantial portions of the Software.
16 +
17 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# Bytes utility
2 +
3 +[![NPM Version][npm-image]][npm-url]
4 +[![NPM Downloads][downloads-image]][downloads-url]
5 +[![Build Status][ci-image]][ci-url]
6 +[![Test Coverage][coveralls-image]][coveralls-url]
7 +
8 +Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
9 +
10 +## Installation
11 +
12 +This is a [Node.js](https://nodejs.org/en/) module available through the
13 +[npm registry](https://www.npmjs.com/). Installation is done using the
14 +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
15 +
16 +```bash
17 +$ npm install bytes
18 +```
19 +
20 +## Usage
21 +
22 +```js
23 +var bytes = require('bytes');
24 +```
25 +
26 +#### bytes(number|string value, [options]): number|string|null
27 +
28 +Default export function. Delegates to either `bytes.format` or `bytes.parse` based on the type of `value`.
29 +
30 +**Arguments**
31 +
32 +| Name | Type | Description |
33 +|---------|----------|--------------------|
34 +| value | `number``string` | Number value to format or string value to parse |
35 +| options | `Object` | Conversion options for `format` |
36 +
37 +**Returns**
38 +
39 +| Name | Type | Description |
40 +|---------|------------------|-------------------------------------------------|
41 +| results | `string``number``null` | Return null upon error. Numeric value in bytes, or string value otherwise. |
42 +
43 +**Example**
44 +
45 +```js
46 +bytes(1024);
47 +// output: '1KB'
48 +
49 +bytes('1KB');
50 +// output: 1024
51 +```
52 +
53 +#### bytes.format(number value, [options]): string|null
54 +
55 +Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is
56 + rounded.
57 +
58 +**Arguments**
59 +
60 +| Name | Type | Description |
61 +|---------|----------|--------------------|
62 +| value | `number` | Value in bytes |
63 +| options | `Object` | Conversion options |
64 +
65 +**Options**
66 +
67 +| Property | Type | Description |
68 +|-------------------|--------|-----------------------------------------------------------------------------------------|
69 +| decimalPlaces | `number``null` | Maximum number of decimal places to include in output. Default value to `2`. |
70 +| fixedDecimals | `boolean``null` | Whether to always display the maximum number of decimal places. Default value to `false` |
71 +| thousandsSeparator | `string``null` | Example of values: `' '`, `','` and `'.'`... Default value to `''`. |
72 +| unit | `string``null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |
73 +| unitSeparator | `string``null` | Separator to use between number and unit. Default value to `''`. |
74 +
75 +**Returns**
76 +
77 +| Name | Type | Description |
78 +|---------|------------------|-------------------------------------------------|
79 +| results | `string``null` | Return null upon error. String value otherwise. |
80 +
81 +**Example**
82 +
83 +```js
84 +bytes.format(1024);
85 +// output: '1KB'
86 +
87 +bytes.format(1000);
88 +// output: '1000B'
89 +
90 +bytes.format(1000, {thousandsSeparator: ' '});
91 +// output: '1 000B'
92 +
93 +bytes.format(1024 * 1.7, {decimalPlaces: 0});
94 +// output: '2KB'
95 +
96 +bytes.format(1024, {unitSeparator: ' '});
97 +// output: '1 KB'
98 +```
99 +
100 +#### bytes.parse(string|number value): number|null
101 +
102 +Parse the string value into an integer in bytes. If no unit is given, or `value`
103 +is a number, it is assumed the value is in bytes.
104 +
105 +Supported units and abbreviations are as follows and are case-insensitive:
106 +
107 + * `b` for bytes
108 + * `kb` for kilobytes
109 + * `mb` for megabytes
110 + * `gb` for gigabytes
111 + * `tb` for terabytes
112 + * `pb` for petabytes
113 +
114 +The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
115 +
116 +**Arguments**
117 +
118 +| Name | Type | Description |
119 +|---------------|--------|--------------------|
120 +| value | `string``number` | String to parse, or number in bytes. |
121 +
122 +**Returns**
123 +
124 +| Name | Type | Description |
125 +|---------|-------------|-------------------------|
126 +| results | `number``null` | Return null upon error. Value in bytes otherwise. |
127 +
128 +**Example**
129 +
130 +```js
131 +bytes.parse('1KB');
132 +// output: 1024
133 +
134 +bytes.parse('1024');
135 +// output: 1024
136 +
137 +bytes.parse(1024);
138 +// output: 1024
139 +```
140 +
141 +## License
142 +
143 +[MIT](LICENSE)
144 +
145 +[ci-image]: https://badgen.net/github/checks/visionmedia/bytes.js/master?label=ci
146 +[ci-url]: https://github.com/visionmedia/bytes.js/actions?query=workflow%3Aci
147 +[coveralls-image]: https://badgen.net/coveralls/c/github/visionmedia/bytes.js/master
148 +[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master
149 +[downloads-image]: https://badgen.net/npm/dm/bytes
150 +[downloads-url]: https://npmjs.org/package/bytes
151 +[npm-image]: https://badgen.net/npm/v/bytes
152 +[npm-url]: https://npmjs.org/package/bytes
1 +/*!
2 + * bytes
3 + * Copyright(c) 2012-2014 TJ Holowaychuk
4 + * Copyright(c) 2015 Jed Watson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict';
9 +
10 +/**
11 + * Module exports.
12 + * @public
13 + */
14 +
15 +module.exports = bytes;
16 +module.exports.format = format;
17 +module.exports.parse = parse;
18 +
19 +/**
20 + * Module variables.
21 + * @private
22 + */
23 +
24 +var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g;
25 +
26 +var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/;
27 +
28 +var map = {
29 + b: 1,
30 + kb: 1 << 10,
31 + mb: 1 << 20,
32 + gb: 1 << 30,
33 + tb: Math.pow(1024, 4),
34 + pb: Math.pow(1024, 5),
35 +};
36 +
37 +var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i;
38 +
39 +/**
40 + * Convert the given value in bytes into a string or parse to string to an integer in bytes.
41 + *
42 + * @param {string|number} value
43 + * @param {{
44 + * case: [string],
45 + * decimalPlaces: [number]
46 + * fixedDecimals: [boolean]
47 + * thousandsSeparator: [string]
48 + * unitSeparator: [string]
49 + * }} [options] bytes options.
50 + *
51 + * @returns {string|number|null}
52 + */
53 +
54 +function bytes(value, options) {
55 + if (typeof value === 'string') {
56 + return parse(value);
57 + }
58 +
59 + if (typeof value === 'number') {
60 + return format(value, options);
61 + }
62 +
63 + return null;
64 +}
65 +
66 +/**
67 + * Format the given value in bytes into a string.
68 + *
69 + * If the value is negative, it is kept as such. If it is a float,
70 + * it is rounded.
71 + *
72 + * @param {number} value
73 + * @param {object} [options]
74 + * @param {number} [options.decimalPlaces=2]
75 + * @param {number} [options.fixedDecimals=false]
76 + * @param {string} [options.thousandsSeparator=]
77 + * @param {string} [options.unit=]
78 + * @param {string} [options.unitSeparator=]
79 + *
80 + * @returns {string|null}
81 + * @public
82 + */
83 +
84 +function format(value, options) {
85 + if (!Number.isFinite(value)) {
86 + return null;
87 + }
88 +
89 + var mag = Math.abs(value);
90 + var thousandsSeparator = (options && options.thousandsSeparator) || '';
91 + var unitSeparator = (options && options.unitSeparator) || '';
92 + var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;
93 + var fixedDecimals = Boolean(options && options.fixedDecimals);
94 + var unit = (options && options.unit) || '';
95 +
96 + if (!unit || !map[unit.toLowerCase()]) {
97 + if (mag >= map.pb) {
98 + unit = 'PB';
99 + } else if (mag >= map.tb) {
100 + unit = 'TB';
101 + } else if (mag >= map.gb) {
102 + unit = 'GB';
103 + } else if (mag >= map.mb) {
104 + unit = 'MB';
105 + } else if (mag >= map.kb) {
106 + unit = 'KB';
107 + } else {
108 + unit = 'B';
109 + }
110 + }
111 +
112 + var val = value / map[unit.toLowerCase()];
113 + var str = val.toFixed(decimalPlaces);
114 +
115 + if (!fixedDecimals) {
116 + str = str.replace(formatDecimalsRegExp, '$1');
117 + }
118 +
119 + if (thousandsSeparator) {
120 + str = str.split('.').map(function (s, i) {
121 + return i === 0
122 + ? s.replace(formatThousandsRegExp, thousandsSeparator)
123 + : s
124 + }).join('.');
125 + }
126 +
127 + return str + unitSeparator + unit;
128 +}
129 +
130 +/**
131 + * Parse the string value into an integer in bytes.
132 + *
133 + * If no unit is given, it is assumed the value is in bytes.
134 + *
135 + * @param {number|string} val
136 + *
137 + * @returns {number|null}
138 + * @public
139 + */
140 +
141 +function parse(val) {
142 + if (typeof val === 'number' && !isNaN(val)) {
143 + return val;
144 + }
145 +
146 + if (typeof val !== 'string') {
147 + return null;
148 + }
149 +
150 + // Test if the string passed is valid
151 + var results = parseRegExp.exec(val);
152 + var floatValue;
153 + var unit = 'b';
154 +
155 + if (!results) {
156 + // Nothing could be extracted from the given string
157 + floatValue = parseInt(val, 10);
158 + unit = 'b'
159 + } else {
160 + // Retrieve the value and the unit
161 + floatValue = parseFloat(results[1]);
162 + unit = results[4].toLowerCase();
163 + }
164 +
165 + if (isNaN(floatValue)) {
166 + return null;
167 + }
168 +
169 + return Math.floor(map[unit] * floatValue);
170 +}
1 +{
2 + "name": "bytes",
3 + "description": "Utility to parse a string bytes to bytes and vice-versa",
4 + "version": "3.1.2",
5 + "author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
6 + "contributors": [
7 + "Jed Watson <jed.watson@me.com>",
8 + "Théo FIDRY <theo.fidry@gmail.com>"
9 + ],
10 + "license": "MIT",
11 + "keywords": [
12 + "byte",
13 + "bytes",
14 + "utility",
15 + "parse",
16 + "parser",
17 + "convert",
18 + "converter"
19 + ],
20 + "repository": "visionmedia/bytes.js",
21 + "devDependencies": {
22 + "eslint": "7.32.0",
23 + "eslint-plugin-markdown": "2.2.1",
24 + "mocha": "9.2.0",
25 + "nyc": "15.1.0"
26 + },
27 + "files": [
28 + "History.md",
29 + "LICENSE",
30 + "Readme.md",
31 + "index.js"
32 + ],
33 + "engines": {
34 + "node": ">= 0.8"
35 + },
36 + "scripts": {
37 + "lint": "eslint .",
38 + "test": "mocha --check-leaks --reporter spec",
39 + "test-ci": "nyc --reporter=lcov --reporter=text npm test",
40 + "test-cov": "nyc --reporter=html --reporter=text npm test"
41 + }
42 +}
1 +{
2 + "root": true,
3 +
4 + "extends": "@ljharb",
5 +
6 + "rules": {
7 + "func-name-matching": 0,
8 + "id-length": 0,
9 + "new-cap": [2, {
10 + "capIsNewExceptions": [
11 + "GetIntrinsic",
12 + ],
13 + }],
14 + "no-magic-numbers": 0,
15 + "operator-linebreak": [2, "before"],
16 + },
17 +}
1 +# These are supported funding model platforms
2 +
3 +github: [ljharb]
4 +patreon: # Replace with a single Patreon username
5 +open_collective: # Replace with a single Open Collective username
6 +ko_fi: # Replace with a single Ko-fi username
7 +tidelift: npm/call-bind
8 +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 +liberapay: # Replace with a single Liberapay username
10 +issuehunt: # Replace with a single IssueHunt username
11 +otechie: # Replace with a single Otechie username
12 +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1 +{
2 + "all": true,
3 + "check-coverage": false,
4 + "reporter": ["text-summary", "text", "html", "json"],
5 + "lines": 86,
6 + "statements": 85.93,
7 + "functions": 82.43,
8 + "branches": 76.06,
9 + "exclude": [
10 + "coverage",
11 + "test"
12 + ]
13 +}
1 +# Changelog
2 +
3 +All notable changes to this project will be documented in this file.
4 +
5 +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6 +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 +
8 +## [v1.0.2](https://github.com/ljharb/call-bind/compare/v1.0.1...v1.0.2) - 2021-01-11
9 +
10 +### Commits
11 +
12 +- [Fix] properly include the receiver in the bound length [`dbae7bc`](https://github.com/ljharb/call-bind/commit/dbae7bc676c079a0d33c0a43e9ef92cb7b01345d)
13 +
14 +## [v1.0.1](https://github.com/ljharb/call-bind/compare/v1.0.0...v1.0.1) - 2021-01-08
15 +
16 +### Commits
17 +
18 +- [Tests] migrate tests to Github Actions [`b6db284`](https://github.com/ljharb/call-bind/commit/b6db284c36f8ccd195b88a6764fe84b7223a0da1)
19 +- [meta] do not publish github action workflow files [`ec7fe46`](https://github.com/ljharb/call-bind/commit/ec7fe46e60cfa4764ee943d2755f5e5a366e578e)
20 +- [Fix] preserve original function’s length when possible [`adbceaa`](https://github.com/ljharb/call-bind/commit/adbceaa3cac4b41ea78bb19d7ccdbaaf7e0bdadb)
21 +- [Tests] gather coverage data on every job [`d69e23c`](https://github.com/ljharb/call-bind/commit/d69e23cc65f101ba1d4c19bb07fa8eb0ec624be8)
22 +- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`2fd3586`](https://github.com/ljharb/call-bind/commit/2fd3586c5d47b335364c14293114c6b625ae1f71)
23 +- [Deps] update `get-intrinsic` [`f23e931`](https://github.com/ljharb/call-bind/commit/f23e9318cc271c2add8bb38cfded85ee7baf8eee)
24 +- [Deps] update `get-intrinsic` [`72d9f44`](https://github.com/ljharb/call-bind/commit/72d9f44e184465ba8dd3fb48260bbcff234985f2)
25 +- [meta] fix FUNDING.yml [`e723573`](https://github.com/ljharb/call-bind/commit/e723573438c5a68dcec31fb5d96ea6b7e4a93be8)
26 +- [eslint] ignore coverage output [`15e76d2`](https://github.com/ljharb/call-bind/commit/15e76d28a5f43e504696401e5b31ebb78ee1b532)
27 +- [meta] add Automatic Rebase and Require Allow Edits workflows [`8fa4dab`](https://github.com/ljharb/call-bind/commit/8fa4dabb23ba3dd7bb92c9571c1241c08b56e4b6)
28 +
29 +## v1.0.0 - 2020-10-30
30 +
31 +### Commits
32 +
33 +- Initial commit [`306cf98`](https://github.com/ljharb/call-bind/commit/306cf98c7ec9e7ef66b653ec152277ac1381eb50)
34 +- Tests [`e10d0bb`](https://github.com/ljharb/call-bind/commit/e10d0bbdadc7a10ecedc9a1c035112d3e368b8df)
35 +- Implementation [`43852ed`](https://github.com/ljharb/call-bind/commit/43852eda0f187327b7fad2423ca972149a52bd65)
36 +- npm init [`408f860`](https://github.com/ljharb/call-bind/commit/408f860b773a2f610805fd3613d0d71bac1b6249)
37 +- [meta] add Automatic Rebase and Require Allow Edits workflows [`fb349b2`](https://github.com/ljharb/call-bind/commit/fb349b2e48defbec8b5ec8a8395cc8f69f220b13)
38 +- [meta] add `auto-changelog` [`c4001fc`](https://github.com/ljharb/call-bind/commit/c4001fc43031799ef908211c98d3b0fb2b60fde4)
39 +- [meta] add "funding"; create `FUNDING.yml` [`d4d6d29`](https://github.com/ljharb/call-bind/commit/d4d6d2974a14bc2e98830468eda7fe6d6a776717)
40 +- [Tests] add `npm run lint` [`dedfb98`](https://github.com/ljharb/call-bind/commit/dedfb98bd0ecefb08ddb9a94061bd10cde4332af)
41 +- Only apps should have lockfiles [`54ac776`](https://github.com/ljharb/call-bind/commit/54ac77653db45a7361dc153d2f478e743f110650)
42 +- [meta] add `safe-publish-latest` [`9ea8e43`](https://github.com/ljharb/call-bind/commit/9ea8e435b950ce9b705559cd651039f9bf40140f)
1 +MIT License
2 +
3 +Copyright (c) 2020 Jordan Harband
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in all
13 +copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 +SOFTWARE.
1 +# call-bind
2 +Robustly `.call.bind()` a function.
1 +'use strict';
2 +
3 +var GetIntrinsic = require('get-intrinsic');
4 +
5 +var callBind = require('./');
6 +
7 +var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));
8 +
9 +module.exports = function callBoundIntrinsic(name, allowMissing) {
10 + var intrinsic = GetIntrinsic(name, !!allowMissing);
11 + if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) {
12 + return callBind(intrinsic);
13 + }
14 + return intrinsic;
15 +};
1 +'use strict';
2 +
3 +var bind = require('function-bind');
4 +var GetIntrinsic = require('get-intrinsic');
5 +
6 +var $apply = GetIntrinsic('%Function.prototype.apply%');
7 +var $call = GetIntrinsic('%Function.prototype.call%');
8 +var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
9 +
10 +var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
11 +var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
12 +var $max = GetIntrinsic('%Math.max%');
13 +
14 +if ($defineProperty) {
15 + try {
16 + $defineProperty({}, 'a', { value: 1 });
17 + } catch (e) {
18 + // IE 8 has a broken defineProperty
19 + $defineProperty = null;
20 + }
21 +}
22 +
23 +module.exports = function callBind(originalFunction) {
24 + var func = $reflectApply(bind, $call, arguments);
25 + if ($gOPD && $defineProperty) {
26 + var desc = $gOPD(func, 'length');
27 + if (desc.configurable) {
28 + // original length, plus the receiver, minus any additional arguments (after the receiver)
29 + $defineProperty(
30 + func,
31 + 'length',
32 + { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) }
33 + );
34 + }
35 + }
36 + return func;
37 +};
38 +
39 +var applyBind = function applyBind() {
40 + return $reflectApply(bind, $apply, arguments);
41 +};
42 +
43 +if ($defineProperty) {
44 + $defineProperty(module.exports, 'apply', { value: applyBind });
45 +} else {
46 + module.exports.apply = applyBind;
47 +}
1 +{
2 + "name": "call-bind",
3 + "version": "1.0.2",
4 + "description": "Robustly `.call.bind()` a function",
5 + "main": "index.js",
6 + "exports": {
7 + ".": [
8 + {
9 + "default": "./index.js"
10 + },
11 + "./index.js"
12 + ],
13 + "./callBound": [
14 + {
15 + "default": "./callBound.js"
16 + },
17 + "./callBound.js"
18 + ],
19 + "./package.json": "./package.json"
20 + },
21 + "scripts": {
22 + "prepublish": "safe-publish-latest",
23 + "lint": "eslint --ext=.js,.mjs .",
24 + "pretest": "npm run lint",
25 + "tests-only": "nyc tape 'test/*'",
26 + "test": "npm run tests-only",
27 + "posttest": "aud --production",
28 + "version": "auto-changelog && git add CHANGELOG.md",
29 + "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
30 + },
31 + "repository": {
32 + "type": "git",
33 + "url": "git+https://github.com/ljharb/call-bind.git"
34 + },
35 + "keywords": [
36 + "javascript",
37 + "ecmascript",
38 + "es",
39 + "js",
40 + "callbind",
41 + "callbound",
42 + "call",
43 + "bind",
44 + "bound",
45 + "call-bind",
46 + "call-bound",
47 + "function",
48 + "es-abstract"
49 + ],
50 + "author": "Jordan Harband <ljharb@gmail.com>",
51 + "funding": {
52 + "url": "https://github.com/sponsors/ljharb"
53 + },
54 + "license": "MIT",
55 + "bugs": {
56 + "url": "https://github.com/ljharb/call-bind/issues"
57 + },
58 + "homepage": "https://github.com/ljharb/call-bind#readme",
59 + "devDependencies": {
60 + "@ljharb/eslint-config": "^17.3.0",
61 + "aud": "^1.1.3",
62 + "auto-changelog": "^2.2.1",
63 + "eslint": "^7.17.0",
64 + "nyc": "^10.3.2",
65 + "safe-publish-latest": "^1.1.4",
66 + "tape": "^5.1.1"
67 + },
68 + "dependencies": {
69 + "function-bind": "^1.1.1",
70 + "get-intrinsic": "^1.0.2"
71 + },
72 + "auto-changelog": {
73 + "output": "CHANGELOG.md",
74 + "template": "keepachangelog",
75 + "unreleased": false,
76 + "commitLimit": false,
77 + "backfillLimit": false,
78 + "hideCredit": true
79 + }
80 +}
1 +'use strict';
2 +
3 +var test = require('tape');
4 +
5 +var callBound = require('../callBound');
6 +
7 +test('callBound', function (t) {
8 + // static primitive
9 + t.equal(callBound('Array.length'), Array.length, 'Array.length yields itself');
10 + t.equal(callBound('%Array.length%'), Array.length, '%Array.length% yields itself');
11 +
12 + // static non-function object
13 + t.equal(callBound('Array.prototype'), Array.prototype, 'Array.prototype yields itself');
14 + t.equal(callBound('%Array.prototype%'), Array.prototype, '%Array.prototype% yields itself');
15 + t.equal(callBound('Array.constructor'), Array.constructor, 'Array.constructor yields itself');
16 + t.equal(callBound('%Array.constructor%'), Array.constructor, '%Array.constructor% yields itself');
17 +
18 + // static function
19 + t.equal(callBound('Date.parse'), Date.parse, 'Date.parse yields itself');
20 + t.equal(callBound('%Date.parse%'), Date.parse, '%Date.parse% yields itself');
21 +
22 + // prototype primitive
23 + t.equal(callBound('Error.prototype.message'), Error.prototype.message, 'Error.prototype.message yields itself');
24 + t.equal(callBound('%Error.prototype.message%'), Error.prototype.message, '%Error.prototype.message% yields itself');
25 +
26 + // prototype function
27 + t.notEqual(callBound('Object.prototype.toString'), Object.prototype.toString, 'Object.prototype.toString does not yield itself');
28 + t.notEqual(callBound('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% does not yield itself');
29 + t.equal(callBound('Object.prototype.toString')(true), Object.prototype.toString.call(true), 'call-bound Object.prototype.toString calls into the original');
30 + t.equal(callBound('%Object.prototype.toString%')(true), Object.prototype.toString.call(true), 'call-bound %Object.prototype.toString% calls into the original');
31 +
32 + t['throws'](
33 + function () { callBound('does not exist'); },
34 + SyntaxError,
35 + 'nonexistent intrinsic throws'
36 + );
37 + t['throws'](
38 + function () { callBound('does not exist', true); },
39 + SyntaxError,
40 + 'allowMissing arg still throws for unknown intrinsic'
41 + );
42 +
43 + /* globals WeakRef: false */
44 + t.test('real but absent intrinsic', { skip: typeof WeakRef !== 'undefined' }, function (st) {
45 + st['throws'](
46 + function () { callBound('WeakRef'); },
47 + TypeError,
48 + 'real but absent intrinsic throws'
49 + );
50 + st.equal(callBound('WeakRef', true), undefined, 'allowMissing arg avoids exception');
51 + st.end();
52 + });
53 +
54 + t.end();
55 +});
1 +'use strict';
2 +
3 +var callBind = require('../');
4 +var bind = require('function-bind');
5 +
6 +var test = require('tape');
7 +
8 +/*
9 + * older engines have length nonconfigurable
10 + * in io.js v3, it is configurable except on bound functions, hence the .bind()
11 + */
12 +var functionsHaveConfigurableLengths = !!(
13 + Object.getOwnPropertyDescriptor
14 + && Object.getOwnPropertyDescriptor(bind.call(function () {}), 'length').configurable
15 +);
16 +
17 +test('callBind', function (t) {
18 + var sentinel = { sentinel: true };
19 + var func = function (a, b) {
20 + // eslint-disable-next-line no-invalid-this
21 + return [this, a, b];
22 + };
23 + t.equal(func.length, 2, 'original function length is 2');
24 + t.deepEqual(func(), [undefined, undefined, undefined], 'unbound func with too few args');
25 + t.deepEqual(func(1, 2), [undefined, 1, 2], 'unbound func with right args');
26 + t.deepEqual(func(1, 2, 3), [undefined, 1, 2], 'unbound func with too many args');
27 +
28 + var bound = callBind(func);
29 + t.equal(bound.length, func.length + 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
30 + t.deepEqual(bound(), [undefined, undefined, undefined], 'bound func with too few args');
31 + t.deepEqual(bound(1, 2), [1, 2, undefined], 'bound func with right args');
32 + t.deepEqual(bound(1, 2, 3), [1, 2, 3], 'bound func with too many args');
33 +
34 + var boundR = callBind(func, sentinel);
35 + t.equal(boundR.length, func.length, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
36 + t.deepEqual(boundR(), [sentinel, undefined, undefined], 'bound func with receiver, with too few args');
37 + t.deepEqual(boundR(1, 2), [sentinel, 1, 2], 'bound func with receiver, with right args');
38 + t.deepEqual(boundR(1, 2, 3), [sentinel, 1, 2], 'bound func with receiver, with too many args');
39 +
40 + var boundArg = callBind(func, sentinel, 1);
41 + t.equal(boundArg.length, func.length - 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
42 + t.deepEqual(boundArg(), [sentinel, 1, undefined], 'bound func with receiver and arg, with too few args');
43 + t.deepEqual(boundArg(2), [sentinel, 1, 2], 'bound func with receiver and arg, with right arg');
44 + t.deepEqual(boundArg(2, 3), [sentinel, 1, 2], 'bound func with receiver and arg, with too many args');
45 +
46 + t.test('callBind.apply', function (st) {
47 + var aBound = callBind.apply(func);
48 + st.deepEqual(aBound(sentinel), [sentinel, undefined, undefined], 'apply-bound func with no args');
49 + st.deepEqual(aBound(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
50 + st.deepEqual(aBound(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
51 +
52 + var aBoundArg = callBind.apply(func);
53 + st.deepEqual(aBoundArg(sentinel, [1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with too many args');
54 + st.deepEqual(aBoundArg(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
55 + st.deepEqual(aBoundArg(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
56 +
57 + var aBoundR = callBind.apply(func, sentinel);
58 + st.deepEqual(aBoundR([1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with receiver and too many args');
59 + st.deepEqual(aBoundR([1, 2], 4), [sentinel, 1, 2], 'apply-bound func with receiver and right args');
60 + st.deepEqual(aBoundR([1], 4), [sentinel, 1, undefined], 'apply-bound func with receiver and too few args');
61 +
62 + st.end();
63 + });
64 +
65 + t.end();
66 +});
1 +1.0.4 / 2017-09-11
2 +==================
3 +
4 + * perf: skip parameter parsing when no parameters
5 +
6 +1.0.3 / 2017-09-10
7 +==================
8 +
9 + * perf: remove argument reassignment
10 +
11 +1.0.2 / 2016-05-09
12 +==================
13 +
14 + * perf: enable strict mode
15 +
16 +1.0.1 / 2015-02-13
17 +==================
18 +
19 + * Improve missing `Content-Type` header error message
20 +
21 +1.0.0 / 2015-02-01
22 +==================
23 +
24 + * Initial implementation, derived from `media-typer@0.3.0`
1 +(The MIT License)
2 +
3 +Copyright (c) 2015 Douglas Christopher Wilson
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining
6 +a copy of this software and associated documentation files (the
7 +'Software'), to deal in the Software without restriction, including
8 +without limitation the rights to use, copy, modify, merge, publish,
9 +distribute, sublicense, and/or sell copies of the Software, and to
10 +permit persons to whom the Software is furnished to do so, subject to
11 +the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be
14 +included in all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# content-type
2 +
3 +[![NPM Version][npm-image]][npm-url]
4 +[![NPM Downloads][downloads-image]][downloads-url]
5 +[![Node.js Version][node-version-image]][node-version-url]
6 +[![Build Status][travis-image]][travis-url]
7 +[![Test Coverage][coveralls-image]][coveralls-url]
8 +
9 +Create and parse HTTP Content-Type header according to RFC 7231
10 +
11 +## Installation
12 +
13 +```sh
14 +$ npm install content-type
15 +```
16 +
17 +## API
18 +
19 +```js
20 +var contentType = require('content-type')
21 +```
22 +
23 +### contentType.parse(string)
24 +
25 +```js
26 +var obj = contentType.parse('image/svg+xml; charset=utf-8')
27 +```
28 +
29 +Parse a content type string. This will return an object with the following
30 +properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
31 +
32 + - `type`: The media type (the type and subtype, always lower case).
33 + Example: `'image/svg+xml'`
34 +
35 + - `parameters`: An object of the parameters in the media type (name of parameter
36 + always lower case). Example: `{charset: 'utf-8'}`
37 +
38 +Throws a `TypeError` if the string is missing or invalid.
39 +
40 +### contentType.parse(req)
41 +
42 +```js
43 +var obj = contentType.parse(req)
44 +```
45 +
46 +Parse the `content-type` header from the given `req`. Short-cut for
47 +`contentType.parse(req.headers['content-type'])`.
48 +
49 +Throws a `TypeError` if the `Content-Type` header is missing or invalid.
50 +
51 +### contentType.parse(res)
52 +
53 +```js
54 +var obj = contentType.parse(res)
55 +```
56 +
57 +Parse the `content-type` header set on the given `res`. Short-cut for
58 +`contentType.parse(res.getHeader('content-type'))`.
59 +
60 +Throws a `TypeError` if the `Content-Type` header is missing or invalid.
61 +
62 +### contentType.format(obj)
63 +
64 +```js
65 +var str = contentType.format({type: 'image/svg+xml'})
66 +```
67 +
68 +Format an object into a content type string. This will return a string of the
69 +content type for the given object with the following properties (examples are
70 +shown that produce the string `'image/svg+xml; charset=utf-8'`):
71 +
72 + - `type`: The media type (will be lower-cased). Example: `'image/svg+xml'`
73 +
74 + - `parameters`: An object of the parameters in the media type (name of the
75 + parameter will be lower-cased). Example: `{charset: 'utf-8'}`
76 +
77 +Throws a `TypeError` if the object contains an invalid type or parameter names.
78 +
79 +## License
80 +
81 +[MIT](LICENSE)
82 +
83 +[npm-image]: https://img.shields.io/npm/v/content-type.svg
84 +[npm-url]: https://npmjs.org/package/content-type
85 +[node-version-image]: https://img.shields.io/node/v/content-type.svg
86 +[node-version-url]: http://nodejs.org/download/
87 +[travis-image]: https://img.shields.io/travis/jshttp/content-type/master.svg
88 +[travis-url]: https://travis-ci.org/jshttp/content-type
89 +[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-type/master.svg
90 +[coveralls-url]: https://coveralls.io/r/jshttp/content-type
91 +[downloads-image]: https://img.shields.io/npm/dm/content-type.svg
92 +[downloads-url]: https://npmjs.org/package/content-type
1 +/*!
2 + * content-type
3 + * Copyright(c) 2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1
11 + *
12 + * parameter = token "=" ( token / quoted-string )
13 + * token = 1*tchar
14 + * tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
15 + * / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
16 + * / DIGIT / ALPHA
17 + * ; any VCHAR, except delimiters
18 + * quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
19 + * qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
20 + * obs-text = %x80-FF
21 + * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
22 + */
23 +var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g
24 +var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/
25 +var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
26 +
27 +/**
28 + * RegExp to match quoted-pair in RFC 7230 sec 3.2.6
29 + *
30 + * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
31 + * obs-text = %x80-FF
32 + */
33 +var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g
34 +
35 +/**
36 + * RegExp to match chars that must be quoted-pair in RFC 7230 sec 3.2.6
37 + */
38 +var QUOTE_REGEXP = /([\\"])/g
39 +
40 +/**
41 + * RegExp to match type in RFC 7231 sec 3.1.1.1
42 + *
43 + * media-type = type "/" subtype
44 + * type = token
45 + * subtype = token
46 + */
47 +var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
48 +
49 +/**
50 + * Module exports.
51 + * @public
52 + */
53 +
54 +exports.format = format
55 +exports.parse = parse
56 +
57 +/**
58 + * Format object to media type.
59 + *
60 + * @param {object} obj
61 + * @return {string}
62 + * @public
63 + */
64 +
65 +function format (obj) {
66 + if (!obj || typeof obj !== 'object') {
67 + throw new TypeError('argument obj is required')
68 + }
69 +
70 + var parameters = obj.parameters
71 + var type = obj.type
72 +
73 + if (!type || !TYPE_REGEXP.test(type)) {
74 + throw new TypeError('invalid type')
75 + }
76 +
77 + var string = type
78 +
79 + // append parameters
80 + if (parameters && typeof parameters === 'object') {
81 + var param
82 + var params = Object.keys(parameters).sort()
83 +
84 + for (var i = 0; i < params.length; i++) {
85 + param = params[i]
86 +
87 + if (!TOKEN_REGEXP.test(param)) {
88 + throw new TypeError('invalid parameter name')
89 + }
90 +
91 + string += '; ' + param + '=' + qstring(parameters[param])
92 + }
93 + }
94 +
95 + return string
96 +}
97 +
98 +/**
99 + * Parse media type to object.
100 + *
101 + * @param {string|object} string
102 + * @return {Object}
103 + * @public
104 + */
105 +
106 +function parse (string) {
107 + if (!string) {
108 + throw new TypeError('argument string is required')
109 + }
110 +
111 + // support req/res-like objects as argument
112 + var header = typeof string === 'object'
113 + ? getcontenttype(string)
114 + : string
115 +
116 + if (typeof header !== 'string') {
117 + throw new TypeError('argument string is required to be a string')
118 + }
119 +
120 + var index = header.indexOf(';')
121 + var type = index !== -1
122 + ? header.substr(0, index).trim()
123 + : header.trim()
124 +
125 + if (!TYPE_REGEXP.test(type)) {
126 + throw new TypeError('invalid media type')
127 + }
128 +
129 + var obj = new ContentType(type.toLowerCase())
130 +
131 + // parse parameters
132 + if (index !== -1) {
133 + var key
134 + var match
135 + var value
136 +
137 + PARAM_REGEXP.lastIndex = index
138 +
139 + while ((match = PARAM_REGEXP.exec(header))) {
140 + if (match.index !== index) {
141 + throw new TypeError('invalid parameter format')
142 + }
143 +
144 + index += match[0].length
145 + key = match[1].toLowerCase()
146 + value = match[2]
147 +
148 + if (value[0] === '"') {
149 + // remove quotes and escapes
150 + value = value
151 + .substr(1, value.length - 2)
152 + .replace(QESC_REGEXP, '$1')
153 + }
154 +
155 + obj.parameters[key] = value
156 + }
157 +
158 + if (index !== header.length) {
159 + throw new TypeError('invalid parameter format')
160 + }
161 + }
162 +
163 + return obj
164 +}
165 +
166 +/**
167 + * Get content-type from req/res objects.
168 + *
169 + * @param {object}
170 + * @return {Object}
171 + * @private
172 + */
173 +
174 +function getcontenttype (obj) {
175 + var header
176 +
177 + if (typeof obj.getHeader === 'function') {
178 + // res-like
179 + header = obj.getHeader('content-type')
180 + } else if (typeof obj.headers === 'object') {
181 + // req-like
182 + header = obj.headers && obj.headers['content-type']
183 + }
184 +
185 + if (typeof header !== 'string') {
186 + throw new TypeError('content-type header is missing from object')
187 + }
188 +
189 + return header
190 +}
191 +
192 +/**
193 + * Quote a string if necessary.
194 + *
195 + * @param {string} val
196 + * @return {string}
197 + * @private
198 + */
199 +
200 +function qstring (val) {
201 + var str = String(val)
202 +
203 + // no need to quote tokens
204 + if (TOKEN_REGEXP.test(str)) {
205 + return str
206 + }
207 +
208 + if (str.length > 0 && !TEXT_REGEXP.test(str)) {
209 + throw new TypeError('invalid parameter value')
210 + }
211 +
212 + return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"'
213 +}
214 +
215 +/**
216 + * Class to represent a content type.
217 + * @private
218 + */
219 +function ContentType (type) {
220 + this.parameters = Object.create(null)
221 + this.type = type
222 +}
1 +{
2 + "name": "content-type",
3 + "description": "Create and parse HTTP Content-Type header",
4 + "version": "1.0.4",
5 + "author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
6 + "license": "MIT",
7 + "keywords": [
8 + "content-type",
9 + "http",
10 + "req",
11 + "res",
12 + "rfc7231"
13 + ],
14 + "repository": "jshttp/content-type",
15 + "devDependencies": {
16 + "eslint": "3.19.0",
17 + "eslint-config-standard": "10.2.1",
18 + "eslint-plugin-import": "2.7.0",
19 + "eslint-plugin-node": "5.1.1",
20 + "eslint-plugin-promise": "3.5.0",
21 + "eslint-plugin-standard": "3.0.1",
22 + "istanbul": "0.4.5",
23 + "mocha": "~1.21.5"
24 + },
25 + "files": [
26 + "LICENSE",
27 + "HISTORY.md",
28 + "README.md",
29 + "index.js"
30 + ],
31 + "engines": {
32 + "node": ">= 0.6"
33 + },
34 + "scripts": {
35 + "lint": "eslint .",
36 + "test": "mocha --reporter spec --check-leaks --bail test/",
37 + "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
38 + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
39 + }
40 +}
1 +repo_token: SIAeZjKYlHK74rbcFvNHMUzjRiMpflxve
1 +{
2 + "env": {
3 + "browser": true,
4 + "node": true
5 + },
6 + "rules": {
7 + "no-console": 0,
8 + "no-empty": [1, { "allowEmptyCatch": true }]
9 + },
10 + "extends": "eslint:recommended"
11 +}
1 +support
2 +test
3 +examples
4 +example
5 +*.sock
6 +dist
7 +yarn.lock
8 +coverage
9 +bower.json
1 +
2 +language: node_js
3 +node_js:
4 + - "6"
5 + - "5"
6 + - "4"
7 +
8 +install:
9 + - make node_modules
10 +
11 +script:
12 + - make lint
13 + - make test
14 + - make coveralls
This diff is collapsed. Click to expand it.
1 +(The MIT License)
2 +
3 +Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6 +and associated documentation files (the 'Software'), to deal in the Software without restriction,
7 +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 +subject to the following conditions:
10 +
11 +The above copyright notice and this permission notice shall be included in all copies or substantial
12 +portions of the Software.
13 +
14 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 +
1 +# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
2 +THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
3 +THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
4 +
5 +# BIN directory
6 +BIN := $(THIS_DIR)/node_modules/.bin
7 +
8 +# Path
9 +PATH := node_modules/.bin:$(PATH)
10 +SHELL := /bin/bash
11 +
12 +# applications
13 +NODE ?= $(shell which node)
14 +YARN ?= $(shell which yarn)
15 +PKG ?= $(if $(YARN),$(YARN),$(NODE) $(shell which npm))
16 +BROWSERIFY ?= $(NODE) $(BIN)/browserify
17 +
18 +.FORCE:
19 +
20 +install: node_modules
21 +
22 +node_modules: package.json
23 + @NODE_ENV= $(PKG) install
24 + @touch node_modules
25 +
26 +lint: .FORCE
27 + eslint browser.js debug.js index.js node.js
28 +
29 +test-node: .FORCE
30 + istanbul cover node_modules/mocha/bin/_mocha -- test/**.js
31 +
32 +test-browser: .FORCE
33 + mkdir -p dist
34 +
35 + @$(BROWSERIFY) \
36 + --standalone debug \
37 + . > dist/debug.js
38 +
39 + karma start --single-run
40 + rimraf dist
41 +
42 +test: .FORCE
43 + concurrently \
44 + "make test-node" \
45 + "make test-browser"
46 +
47 +coveralls:
48 + cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
49 +
50 +.PHONY: all install clean distclean
This diff is collapsed. Click to expand it.
1 +{
2 + "name": "debug",
3 + "repo": "visionmedia/debug",
4 + "description": "small debugging utility",
5 + "version": "2.6.9",
6 + "keywords": [
7 + "debug",
8 + "log",
9 + "debugger"
10 + ],
11 + "main": "src/browser.js",
12 + "scripts": [
13 + "src/browser.js",
14 + "src/debug.js"
15 + ],
16 + "dependencies": {
17 + "rauchg/ms.js": "0.7.1"
18 + }
19 +}
1 +// Karma configuration
2 +// Generated on Fri Dec 16 2016 13:09:51 GMT+0000 (UTC)
3 +
4 +module.exports = function(config) {
5 + config.set({
6 +
7 + // base path that will be used to resolve all patterns (eg. files, exclude)
8 + basePath: '',
9 +
10 +
11 + // frameworks to use
12 + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13 + frameworks: ['mocha', 'chai', 'sinon'],
14 +
15 +
16 + // list of files / patterns to load in the browser
17 + files: [
18 + 'dist/debug.js',
19 + 'test/*spec.js'
20 + ],
21 +
22 +
23 + // list of files to exclude
24 + exclude: [
25 + 'src/node.js'
26 + ],
27 +
28 +
29 + // preprocess matching files before serving them to the browser
30 + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
31 + preprocessors: {
32 + },
33 +
34 + // test results reporter to use
35 + // possible values: 'dots', 'progress'
36 + // available reporters: https://npmjs.org/browse/keyword/karma-reporter
37 + reporters: ['progress'],
38 +
39 +
40 + // web server port
41 + port: 9876,
42 +
43 +
44 + // enable / disable colors in the output (reporters and logs)
45 + colors: true,
46 +
47 +
48 + // level of logging
49 + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
50 + logLevel: config.LOG_INFO,
51 +
52 +
53 + // enable / disable watching file and executing tests whenever any file changes
54 + autoWatch: true,
55 +
56 +
57 + // start these browsers
58 + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
59 + browsers: ['PhantomJS'],
60 +
61 +
62 + // Continuous Integration mode
63 + // if true, Karma captures browsers, runs the tests and exits
64 + singleRun: false,
65 +
66 + // Concurrency level
67 + // how many browser should be started simultaneous
68 + concurrency: Infinity
69 + })
70 +}
1 +module.exports = require('./src/node');
1 +{
2 + "name": "debug",
3 + "version": "2.6.9",
4 + "repository": {
5 + "type": "git",
6 + "url": "git://github.com/visionmedia/debug.git"
7 + },
8 + "description": "small debugging utility",
9 + "keywords": [
10 + "debug",
11 + "log",
12 + "debugger"
13 + ],
14 + "author": "TJ Holowaychuk <tj@vision-media.ca>",
15 + "contributors": [
16 + "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io)",
17 + "Andrew Rhyne <rhyneandrew@gmail.com>"
18 + ],
19 + "license": "MIT",
20 + "dependencies": {
21 + "ms": "2.0.0"
22 + },
23 + "devDependencies": {
24 + "browserify": "9.0.3",
25 + "chai": "^3.5.0",
26 + "concurrently": "^3.1.0",
27 + "coveralls": "^2.11.15",
28 + "eslint": "^3.12.1",
29 + "istanbul": "^0.4.5",
30 + "karma": "^1.3.0",
31 + "karma-chai": "^0.1.0",
32 + "karma-mocha": "^1.3.0",
33 + "karma-phantomjs-launcher": "^1.0.2",
34 + "karma-sinon": "^1.0.5",
35 + "mocha": "^3.2.0",
36 + "mocha-lcov-reporter": "^1.2.0",
37 + "rimraf": "^2.5.4",
38 + "sinon": "^1.17.6",
39 + "sinon-chai": "^2.8.0"
40 + },
41 + "main": "./src/index.js",
42 + "browser": "./src/browser.js",
43 + "component": {
44 + "scripts": {
45 + "debug/index.js": "browser.js",
46 + "debug/debug.js": "debug.js"
47 + }
48 + }
49 +}
1 +/**
2 + * This is the web browser implementation of `debug()`.
3 + *
4 + * Expose `debug()` as the module.
5 + */
6 +
7 +exports = module.exports = require('./debug');
8 +exports.log = log;
9 +exports.formatArgs = formatArgs;
10 +exports.save = save;
11 +exports.load = load;
12 +exports.useColors = useColors;
13 +exports.storage = 'undefined' != typeof chrome
14 + && 'undefined' != typeof chrome.storage
15 + ? chrome.storage.local
16 + : localstorage();
17 +
18 +/**
19 + * Colors.
20 + */
21 +
22 +exports.colors = [
23 + 'lightseagreen',
24 + 'forestgreen',
25 + 'goldenrod',
26 + 'dodgerblue',
27 + 'darkorchid',
28 + 'crimson'
29 +];
30 +
31 +/**
32 + * Currently only WebKit-based Web Inspectors, Firefox >= v31,
33 + * and the Firebug extension (any Firefox version) are known
34 + * to support "%c" CSS customizations.
35 + *
36 + * TODO: add a `localStorage` variable to explicitly enable/disable colors
37 + */
38 +
39 +function useColors() {
40 + // NB: In an Electron preload script, document will be defined but not fully
41 + // initialized. Since we know we're in Chrome, we'll just detect this case
42 + // explicitly
43 + if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
44 + return true;
45 + }
46 +
47 + // is webkit? http://stackoverflow.com/a/16459606/376773
48 + // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
49 + return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
50 + // is firebug? http://stackoverflow.com/a/398120/376773
51 + (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
52 + // is firefox >= v31?
53 + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
54 + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
55 + // double check webkit in userAgent just in case we are in a worker
56 + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
57 +}
58 +
59 +/**
60 + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
61 + */
62 +
63 +exports.formatters.j = function(v) {
64 + try {
65 + return JSON.stringify(v);
66 + } catch (err) {
67 + return '[UnexpectedJSONParseError]: ' + err.message;
68 + }
69 +};
70 +
71 +
72 +/**
73 + * Colorize log arguments if enabled.
74 + *
75 + * @api public
76 + */
77 +
78 +function formatArgs(args) {
79 + var useColors = this.useColors;
80 +
81 + args[0] = (useColors ? '%c' : '')
82 + + this.namespace
83 + + (useColors ? ' %c' : ' ')
84 + + args[0]
85 + + (useColors ? '%c ' : ' ')
86 + + '+' + exports.humanize(this.diff);
87 +
88 + if (!useColors) return;
89 +
90 + var c = 'color: ' + this.color;
91 + args.splice(1, 0, c, 'color: inherit')
92 +
93 + // the final "%c" is somewhat tricky, because there could be other
94 + // arguments passed either before or after the %c, so we need to
95 + // figure out the correct index to insert the CSS into
96 + var index = 0;
97 + var lastC = 0;
98 + args[0].replace(/%[a-zA-Z%]/g, function(match) {
99 + if ('%%' === match) return;
100 + index++;
101 + if ('%c' === match) {
102 + // we only are interested in the *last* %c
103 + // (the user may have provided their own)
104 + lastC = index;
105 + }
106 + });
107 +
108 + args.splice(lastC, 0, c);
109 +}
110 +
111 +/**
112 + * Invokes `console.log()` when available.
113 + * No-op when `console.log` is not a "function".
114 + *
115 + * @api public
116 + */
117 +
118 +function log() {
119 + // this hackery is required for IE8/9, where
120 + // the `console.log` function doesn't have 'apply'
121 + return 'object' === typeof console
122 + && console.log
123 + && Function.prototype.apply.call(console.log, console, arguments);
124 +}
125 +
126 +/**
127 + * Save `namespaces`.
128 + *
129 + * @param {String} namespaces
130 + * @api private
131 + */
132 +
133 +function save(namespaces) {
134 + try {
135 + if (null == namespaces) {
136 + exports.storage.removeItem('debug');
137 + } else {
138 + exports.storage.debug = namespaces;
139 + }
140 + } catch(e) {}
141 +}
142 +
143 +/**
144 + * Load `namespaces`.
145 + *
146 + * @return {String} returns the previously persisted debug modes
147 + * @api private
148 + */
149 +
150 +function load() {
151 + var r;
152 + try {
153 + r = exports.storage.debug;
154 + } catch(e) {}
155 +
156 + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
157 + if (!r && typeof process !== 'undefined' && 'env' in process) {
158 + r = process.env.DEBUG;
159 + }
160 +
161 + return r;
162 +}
163 +
164 +/**
165 + * Enable namespaces listed in `localStorage.debug` initially.
166 + */
167 +
168 +exports.enable(load());
169 +
170 +/**
171 + * Localstorage attempts to return the localstorage.
172 + *
173 + * This is necessary because safari throws
174 + * when a user disables cookies/localstorage
175 + * and you attempt to access it.
176 + *
177 + * @return {LocalStorage}
178 + * @api private
179 + */
180 +
181 +function localstorage() {
182 + try {
183 + return window.localStorage;
184 + } catch (e) {}
185 +}
1 +
2 +/**
3 + * This is the common logic for both the Node.js and web browser
4 + * implementations of `debug()`.
5 + *
6 + * Expose `debug()` as the module.
7 + */
8 +
9 +exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
10 +exports.coerce = coerce;
11 +exports.disable = disable;
12 +exports.enable = enable;
13 +exports.enabled = enabled;
14 +exports.humanize = require('ms');
15 +
16 +/**
17 + * The currently active debug mode names, and names to skip.
18 + */
19 +
20 +exports.names = [];
21 +exports.skips = [];
22 +
23 +/**
24 + * Map of special "%n" handling functions, for the debug "format" argument.
25 + *
26 + * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
27 + */
28 +
29 +exports.formatters = {};
30 +
31 +/**
32 + * Previous log timestamp.
33 + */
34 +
35 +var prevTime;
36 +
37 +/**
38 + * Select a color.
39 + * @param {String} namespace
40 + * @return {Number}
41 + * @api private
42 + */
43 +
44 +function selectColor(namespace) {
45 + var hash = 0, i;
46 +
47 + for (i in namespace) {
48 + hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
49 + hash |= 0; // Convert to 32bit integer
50 + }
51 +
52 + return exports.colors[Math.abs(hash) % exports.colors.length];
53 +}
54 +
55 +/**
56 + * Create a debugger with the given `namespace`.
57 + *
58 + * @param {String} namespace
59 + * @return {Function}
60 + * @api public
61 + */
62 +
63 +function createDebug(namespace) {
64 +
65 + function debug() {
66 + // disabled?
67 + if (!debug.enabled) return;
68 +
69 + var self = debug;
70 +
71 + // set `diff` timestamp
72 + var curr = +new Date();
73 + var ms = curr - (prevTime || curr);
74 + self.diff = ms;
75 + self.prev = prevTime;
76 + self.curr = curr;
77 + prevTime = curr;
78 +
79 + // turn the `arguments` into a proper Array
80 + var args = new Array(arguments.length);
81 + for (var i = 0; i < args.length; i++) {
82 + args[i] = arguments[i];
83 + }
84 +
85 + args[0] = exports.coerce(args[0]);
86 +
87 + if ('string' !== typeof args[0]) {
88 + // anything else let's inspect with %O
89 + args.unshift('%O');
90 + }
91 +
92 + // apply any `formatters` transformations
93 + var index = 0;
94 + args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
95 + // if we encounter an escaped % then don't increase the array index
96 + if (match === '%%') return match;
97 + index++;
98 + var formatter = exports.formatters[format];
99 + if ('function' === typeof formatter) {
100 + var val = args[index];
101 + match = formatter.call(self, val);
102 +
103 + // now we need to remove `args[index]` since it's inlined in the `format`
104 + args.splice(index, 1);
105 + index--;
106 + }
107 + return match;
108 + });
109 +
110 + // apply env-specific formatting (colors, etc.)
111 + exports.formatArgs.call(self, args);
112 +
113 + var logFn = debug.log || exports.log || console.log.bind(console);
114 + logFn.apply(self, args);
115 + }
116 +
117 + debug.namespace = namespace;
118 + debug.enabled = exports.enabled(namespace);
119 + debug.useColors = exports.useColors();
120 + debug.color = selectColor(namespace);
121 +
122 + // env-specific initialization logic for debug instances
123 + if ('function' === typeof exports.init) {
124 + exports.init(debug);
125 + }
126 +
127 + return debug;
128 +}
129 +
130 +/**
131 + * Enables a debug mode by namespaces. This can include modes
132 + * separated by a colon and wildcards.
133 + *
134 + * @param {String} namespaces
135 + * @api public
136 + */
137 +
138 +function enable(namespaces) {
139 + exports.save(namespaces);
140 +
141 + exports.names = [];
142 + exports.skips = [];
143 +
144 + var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
145 + var len = split.length;
146 +
147 + for (var i = 0; i < len; i++) {
148 + if (!split[i]) continue; // ignore empty strings
149 + namespaces = split[i].replace(/\*/g, '.*?');
150 + if (namespaces[0] === '-') {
151 + exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
152 + } else {
153 + exports.names.push(new RegExp('^' + namespaces + '$'));
154 + }
155 + }
156 +}
157 +
158 +/**
159 + * Disable debug output.
160 + *
161 + * @api public
162 + */
163 +
164 +function disable() {
165 + exports.enable('');
166 +}
167 +
168 +/**
169 + * Returns true if the given mode name is enabled, false otherwise.
170 + *
171 + * @param {String} name
172 + * @return {Boolean}
173 + * @api public
174 + */
175 +
176 +function enabled(name) {
177 + var i, len;
178 + for (i = 0, len = exports.skips.length; i < len; i++) {
179 + if (exports.skips[i].test(name)) {
180 + return false;
181 + }
182 + }
183 + for (i = 0, len = exports.names.length; i < len; i++) {
184 + if (exports.names[i].test(name)) {
185 + return true;
186 + }
187 + }
188 + return false;
189 +}
190 +
191 +/**
192 + * Coerce `val`.
193 + *
194 + * @param {Mixed} val
195 + * @return {Mixed}
196 + * @api private
197 + */
198 +
199 +function coerce(val) {
200 + if (val instanceof Error) return val.stack || val.message;
201 + return val;
202 +}
1 +/**
2 + * Detect Electron renderer process, which is node, but we should
3 + * treat as a browser.
4 + */
5 +
6 +if (typeof process !== 'undefined' && process.type === 'renderer') {
7 + module.exports = require('./browser.js');
8 +} else {
9 + module.exports = require('./node.js');
10 +}
1 +module.exports = inspectorLog;
2 +
3 +// black hole
4 +const nullStream = new (require('stream').Writable)();
5 +nullStream._write = () => {};
6 +
7 +/**
8 + * Outputs a `console.log()` to the Node.js Inspector console *only*.
9 + */
10 +function inspectorLog() {
11 + const stdout = console._stdout;
12 + console._stdout = nullStream;
13 + console.log.apply(console, arguments);
14 + console._stdout = stdout;
15 +}
1 +/**
2 + * Module dependencies.
3 + */
4 +
5 +var tty = require('tty');
6 +var util = require('util');
7 +
8 +/**
9 + * This is the Node.js implementation of `debug()`.
10 + *
11 + * Expose `debug()` as the module.
12 + */
13 +
14 +exports = module.exports = require('./debug');
15 +exports.init = init;
16 +exports.log = log;
17 +exports.formatArgs = formatArgs;
18 +exports.save = save;
19 +exports.load = load;
20 +exports.useColors = useColors;
21 +
22 +/**
23 + * Colors.
24 + */
25 +
26 +exports.colors = [6, 2, 3, 4, 5, 1];
27 +
28 +/**
29 + * Build up the default `inspectOpts` object from the environment variables.
30 + *
31 + * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
32 + */
33 +
34 +exports.inspectOpts = Object.keys(process.env).filter(function (key) {
35 + return /^debug_/i.test(key);
36 +}).reduce(function (obj, key) {
37 + // camel-case
38 + var prop = key
39 + .substring(6)
40 + .toLowerCase()
41 + .replace(/_([a-z])/g, function (_, k) { return k.toUpperCase() });
42 +
43 + // coerce string value into JS value
44 + var val = process.env[key];
45 + if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
46 + else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
47 + else if (val === 'null') val = null;
48 + else val = Number(val);
49 +
50 + obj[prop] = val;
51 + return obj;
52 +}, {});
53 +
54 +/**
55 + * The file descriptor to write the `debug()` calls to.
56 + * Set the `DEBUG_FD` env variable to override with another value. i.e.:
57 + *
58 + * $ DEBUG_FD=3 node script.js 3>debug.log
59 + */
60 +
61 +var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
62 +
63 +if (1 !== fd && 2 !== fd) {
64 + util.deprecate(function(){}, 'except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)')()
65 +}
66 +
67 +var stream = 1 === fd ? process.stdout :
68 + 2 === fd ? process.stderr :
69 + createWritableStdioStream(fd);
70 +
71 +/**
72 + * Is stdout a TTY? Colored output is enabled when `true`.
73 + */
74 +
75 +function useColors() {
76 + return 'colors' in exports.inspectOpts
77 + ? Boolean(exports.inspectOpts.colors)
78 + : tty.isatty(fd);
79 +}
80 +
81 +/**
82 + * Map %o to `util.inspect()`, all on a single line.
83 + */
84 +
85 +exports.formatters.o = function(v) {
86 + this.inspectOpts.colors = this.useColors;
87 + return util.inspect(v, this.inspectOpts)
88 + .split('\n').map(function(str) {
89 + return str.trim()
90 + }).join(' ');
91 +};
92 +
93 +/**
94 + * Map %o to `util.inspect()`, allowing multiple lines if needed.
95 + */
96 +
97 +exports.formatters.O = function(v) {
98 + this.inspectOpts.colors = this.useColors;
99 + return util.inspect(v, this.inspectOpts);
100 +};
101 +
102 +/**
103 + * Adds ANSI color escape codes if enabled.
104 + *
105 + * @api public
106 + */
107 +
108 +function formatArgs(args) {
109 + var name = this.namespace;
110 + var useColors = this.useColors;
111 +
112 + if (useColors) {
113 + var c = this.color;
114 + var prefix = ' \u001b[3' + c + ';1m' + name + ' ' + '\u001b[0m';
115 +
116 + args[0] = prefix + args[0].split('\n').join('\n' + prefix);
117 + args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
118 + } else {
119 + args[0] = new Date().toUTCString()
120 + + ' ' + name + ' ' + args[0];
121 + }
122 +}
123 +
124 +/**
125 + * Invokes `util.format()` with the specified arguments and writes to `stream`.
126 + */
127 +
128 +function log() {
129 + return stream.write(util.format.apply(util, arguments) + '\n');
130 +}
131 +
132 +/**
133 + * Save `namespaces`.
134 + *
135 + * @param {String} namespaces
136 + * @api private
137 + */
138 +
139 +function save(namespaces) {
140 + if (null == namespaces) {
141 + // If you set a process.env field to null or undefined, it gets cast to the
142 + // string 'null' or 'undefined'. Just delete instead.
143 + delete process.env.DEBUG;
144 + } else {
145 + process.env.DEBUG = namespaces;
146 + }
147 +}
148 +
149 +/**
150 + * Load `namespaces`.
151 + *
152 + * @return {String} returns the previously persisted debug modes
153 + * @api private
154 + */
155 +
156 +function load() {
157 + return process.env.DEBUG;
158 +}
159 +
160 +/**
161 + * Copied from `node/src/node.js`.
162 + *
163 + * XXX: It's lame that node doesn't expose this API out-of-the-box. It also
164 + * relies on the undocumented `tty_wrap.guessHandleType()` which is also lame.
165 + */
166 +
167 +function createWritableStdioStream (fd) {
168 + var stream;
169 + var tty_wrap = process.binding('tty_wrap');
170 +
171 + // Note stream._type is used for test-module-load-list.js
172 +
173 + switch (tty_wrap.guessHandleType(fd)) {
174 + case 'TTY':
175 + stream = new tty.WriteStream(fd);
176 + stream._type = 'tty';
177 +
178 + // Hack to have stream not keep the event loop alive.
179 + // See https://github.com/joyent/node/issues/1726
180 + if (stream._handle && stream._handle.unref) {
181 + stream._handle.unref();
182 + }
183 + break;
184 +
185 + case 'FILE':
186 + var fs = require('fs');
187 + stream = new fs.SyncWriteStream(fd, { autoClose: false });
188 + stream._type = 'fs';
189 + break;
190 +
191 + case 'PIPE':
192 + case 'TCP':
193 + var net = require('net');
194 + stream = new net.Socket({
195 + fd: fd,
196 + readable: false,
197 + writable: true
198 + });
199 +
200 + // FIXME Should probably have an option in net.Socket to create a
201 + // stream from an existing fd which is writable only. But for now
202 + // we'll just add this hack and set the `readable` member to false.
203 + // Test: ./node test/fixtures/echo.js < /etc/passwd
204 + stream.readable = false;
205 + stream.read = null;
206 + stream._type = 'pipe';
207 +
208 + // FIXME Hack to have stream not keep the event loop alive.
209 + // See https://github.com/joyent/node/issues/1726
210 + if (stream._handle && stream._handle.unref) {
211 + stream._handle.unref();
212 + }
213 + break;
214 +
215 + default:
216 + // Probably an error on in uv_guess_handle()
217 + throw new Error('Implement me. Unknown stream file type!');
218 + }
219 +
220 + // For supporting legacy API we put the FD here.
221 + stream.fd = fd;
222 +
223 + stream._isStdio = true;
224 +
225 + return stream;
226 +}
227 +
228 +/**
229 + * Init logic for `debug` instances.
230 + *
231 + * Create a new `inspectOpts` object in case `useColors` is set
232 + * differently for a particular `debug` instance.
233 + */
234 +
235 +function init (debug) {
236 + debug.inspectOpts = {};
237 +
238 + var keys = Object.keys(exports.inspectOpts);
239 + for (var i = 0; i < keys.length; i++) {
240 + debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
241 + }
242 +}
243 +
244 +/**
245 + * Enable namespaces listed in `process.env.DEBUG` initially.
246 + */
247 +
248 +exports.enable(load());
1 +2.0.0 / 2018-10-26
2 +==================
3 +
4 + * Drop support for Node.js 0.6
5 + * Replace internal `eval` usage with `Function` constructor
6 + * Use instance methods on `process` to check for listeners
7 +
8 +1.1.2 / 2018-01-11
9 +==================
10 +
11 + * perf: remove argument reassignment
12 + * Support Node.js 0.6 to 9.x
13 +
14 +1.1.1 / 2017-07-27
15 +==================
16 +
17 + * Remove unnecessary `Buffer` loading
18 + * Support Node.js 0.6 to 8.x
19 +
20 +1.1.0 / 2015-09-14
21 +==================
22 +
23 + * Enable strict mode in more places
24 + * Support io.js 3.x
25 + * Support io.js 2.x
26 + * Support web browser loading
27 + - Requires bundler like Browserify or webpack
28 +
29 +1.0.1 / 2015-04-07
30 +==================
31 +
32 + * Fix `TypeError`s when under `'use strict'` code
33 + * Fix useless type name on auto-generated messages
34 + * Support io.js 1.x
35 + * Support Node.js 0.12
36 +
37 +1.0.0 / 2014-09-17
38 +==================
39 +
40 + * No changes
41 +
42 +0.4.5 / 2014-09-09
43 +==================
44 +
45 + * Improve call speed to functions using the function wrapper
46 + * Support Node.js 0.6
47 +
48 +0.4.4 / 2014-07-27
49 +==================
50 +
51 + * Work-around v8 generating empty stack traces
52 +
53 +0.4.3 / 2014-07-26
54 +==================
55 +
56 + * Fix exception when global `Error.stackTraceLimit` is too low
57 +
58 +0.4.2 / 2014-07-19
59 +==================
60 +
61 + * Correct call site for wrapped functions and properties
62 +
63 +0.4.1 / 2014-07-19
64 +==================
65 +
66 + * Improve automatic message generation for function properties
67 +
68 +0.4.0 / 2014-07-19
69 +==================
70 +
71 + * Add `TRACE_DEPRECATION` environment variable
72 + * Remove non-standard grey color from color output
73 + * Support `--no-deprecation` argument
74 + * Support `--trace-deprecation` argument
75 + * Support `deprecate.property(fn, prop, message)`
76 +
77 +0.3.0 / 2014-06-16
78 +==================
79 +
80 + * Add `NO_DEPRECATION` environment variable
81 +
82 +0.2.0 / 2014-06-15
83 +==================
84 +
85 + * Add `deprecate.property(obj, prop, message)`
86 + * Remove `supports-color` dependency for node.js 0.8
87 +
88 +0.1.0 / 2014-06-15
89 +==================
90 +
91 + * Add `deprecate.function(fn, message)`
92 + * Add `process.on('deprecation', fn)` emitter
93 + * Automatically generate message when omitted from `deprecate()`
94 +
95 +0.0.1 / 2014-06-15
96 +==================
97 +
98 + * Fix warning for dynamic calls at singe call site
99 +
100 +0.0.0 / 2014-06-15
101 +==================
102 +
103 + * Initial implementation
1 +(The MIT License)
2 +
3 +Copyright (c) 2014-2018 Douglas Christopher Wilson
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining
6 +a copy of this software and associated documentation files (the
7 +'Software'), to deal in the Software without restriction, including
8 +without limitation the rights to use, copy, modify, merge, publish,
9 +distribute, sublicense, and/or sell copies of the Software, and to
10 +permit persons to whom the Software is furnished to do so, subject to
11 +the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be
14 +included in all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# depd
2 +
3 +[![NPM Version][npm-version-image]][npm-url]
4 +[![NPM Downloads][npm-downloads-image]][npm-url]
5 +[![Node.js Version][node-image]][node-url]
6 +[![Linux Build][travis-image]][travis-url]
7 +[![Windows Build][appveyor-image]][appveyor-url]
8 +[![Coverage Status][coveralls-image]][coveralls-url]
9 +
10 +Deprecate all the things
11 +
12 +> With great modules comes great responsibility; mark things deprecated!
13 +
14 +## Install
15 +
16 +This module is installed directly using `npm`:
17 +
18 +```sh
19 +$ npm install depd
20 +```
21 +
22 +This module can also be bundled with systems like
23 +[Browserify](http://browserify.org/) or [webpack](https://webpack.github.io/),
24 +though by default this module will alter it's API to no longer display or
25 +track deprecations.
26 +
27 +## API
28 +
29 +<!-- eslint-disable no-unused-vars -->
30 +
31 +```js
32 +var deprecate = require('depd')('my-module')
33 +```
34 +
35 +This library allows you to display deprecation messages to your users.
36 +This library goes above and beyond with deprecation warnings by
37 +introspection of the call stack (but only the bits that it is interested
38 +in).
39 +
40 +Instead of just warning on the first invocation of a deprecated
41 +function and never again, this module will warn on the first invocation
42 +of a deprecated function per unique call site, making it ideal to alert
43 +users of all deprecated uses across the code base, rather than just
44 +whatever happens to execute first.
45 +
46 +The deprecation warnings from this module also include the file and line
47 +information for the call into the module that the deprecated function was
48 +in.
49 +
50 +**NOTE** this library has a similar interface to the `debug` module, and
51 +this module uses the calling file to get the boundary for the call stacks,
52 +so you should always create a new `deprecate` object in each file and not
53 +within some central file.
54 +
55 +### depd(namespace)
56 +
57 +Create a new deprecate function that uses the given namespace name in the
58 +messages and will display the call site prior to the stack entering the
59 +file this function was called from. It is highly suggested you use the
60 +name of your module as the namespace.
61 +
62 +### deprecate(message)
63 +
64 +Call this function from deprecated code to display a deprecation message.
65 +This message will appear once per unique caller site. Caller site is the
66 +first call site in the stack in a different file from the caller of this
67 +function.
68 +
69 +If the message is omitted, a message is generated for you based on the site
70 +of the `deprecate()` call and will display the name of the function called,
71 +similar to the name displayed in a stack trace.
72 +
73 +### deprecate.function(fn, message)
74 +
75 +Call this function to wrap a given function in a deprecation message on any
76 +call to the function. An optional message can be supplied to provide a custom
77 +message.
78 +
79 +### deprecate.property(obj, prop, message)
80 +
81 +Call this function to wrap a given property on object in a deprecation message
82 +on any accessing or setting of the property. An optional message can be supplied
83 +to provide a custom message.
84 +
85 +The method must be called on the object where the property belongs (not
86 +inherited from the prototype).
87 +
88 +If the property is a data descriptor, it will be converted to an accessor
89 +descriptor in order to display the deprecation message.
90 +
91 +### process.on('deprecation', fn)
92 +
93 +This module will allow easy capturing of deprecation errors by emitting the
94 +errors as the type "deprecation" on the global `process`. If there are no
95 +listeners for this type, the errors are written to STDERR as normal, but if
96 +there are any listeners, nothing will be written to STDERR and instead only
97 +emitted. From there, you can write the errors in a different format or to a
98 +logging source.
99 +
100 +The error represents the deprecation and is emitted only once with the same
101 +rules as writing to STDERR. The error has the following properties:
102 +
103 + - `message` - This is the message given by the library
104 + - `name` - This is always `'DeprecationError'`
105 + - `namespace` - This is the namespace the deprecation came from
106 + - `stack` - This is the stack of the call to the deprecated thing
107 +
108 +Example `error.stack` output:
109 +
110 +```
111 +DeprecationError: my-cool-module deprecated oldfunction
112 + at Object.<anonymous> ([eval]-wrapper:6:22)
113 + at Module._compile (module.js:456:26)
114 + at evalScript (node.js:532:25)
115 + at startup (node.js:80:7)
116 + at node.js:902:3
117 +```
118 +
119 +### process.env.NO_DEPRECATION
120 +
121 +As a user of modules that are deprecated, the environment variable `NO_DEPRECATION`
122 +is provided as a quick solution to silencing deprecation warnings from being
123 +output. The format of this is similar to that of `DEBUG`:
124 +
125 +```sh
126 +$ NO_DEPRECATION=my-module,othermod node app.js
127 +```
128 +
129 +This will suppress deprecations from being output for "my-module" and "othermod".
130 +The value is a list of comma-separated namespaces. To suppress every warning
131 +across all namespaces, use the value `*` for a namespace.
132 +
133 +Providing the argument `--no-deprecation` to the `node` executable will suppress
134 +all deprecations (only available in Node.js 0.8 or higher).
135 +
136 +**NOTE** This will not suppress the deperecations given to any "deprecation"
137 +event listeners, just the output to STDERR.
138 +
139 +### process.env.TRACE_DEPRECATION
140 +
141 +As a user of modules that are deprecated, the environment variable `TRACE_DEPRECATION`
142 +is provided as a solution to getting more detailed location information in deprecation
143 +warnings by including the entire stack trace. The format of this is the same as
144 +`NO_DEPRECATION`:
145 +
146 +```sh
147 +$ TRACE_DEPRECATION=my-module,othermod node app.js
148 +```
149 +
150 +This will include stack traces for deprecations being output for "my-module" and
151 +"othermod". The value is a list of comma-separated namespaces. To trace every
152 +warning across all namespaces, use the value `*` for a namespace.
153 +
154 +Providing the argument `--trace-deprecation` to the `node` executable will trace
155 +all deprecations (only available in Node.js 0.8 or higher).
156 +
157 +**NOTE** This will not trace the deperecations silenced by `NO_DEPRECATION`.
158 +
159 +## Display
160 +
161 +![message](files/message.png)
162 +
163 +When a user calls a function in your library that you mark deprecated, they
164 +will see the following written to STDERR (in the given colors, similar colors
165 +and layout to the `debug` module):
166 +
167 +```
168 +bright cyan bright yellow
169 +| | reset cyan
170 +| | | |
171 +▼ ▼ ▼ ▼
172 +my-cool-module deprecated oldfunction [eval]-wrapper:6:22
173 +▲ ▲ ▲ ▲
174 +| | | |
175 +namespace | | location of mycoolmod.oldfunction() call
176 + | deprecation message
177 + the word "deprecated"
178 +```
179 +
180 +If the user redirects their STDERR to a file or somewhere that does not support
181 +colors, they see (similar layout to the `debug` module):
182 +
183 +```
184 +Sun, 15 Jun 2014 05:21:37 GMT my-cool-module deprecated oldfunction at [eval]-wrapper:6:22
185 +▲ ▲ ▲ ▲ ▲
186 +| | | | |
187 +timestamp of message namespace | | location of mycoolmod.oldfunction() call
188 + | deprecation message
189 + the word "deprecated"
190 +```
191 +
192 +## Examples
193 +
194 +### Deprecating all calls to a function
195 +
196 +This will display a deprecated message about "oldfunction" being deprecated
197 +from "my-module" on STDERR.
198 +
199 +```js
200 +var deprecate = require('depd')('my-cool-module')
201 +
202 +// message automatically derived from function name
203 +// Object.oldfunction
204 +exports.oldfunction = deprecate.function(function oldfunction () {
205 + // all calls to function are deprecated
206 +})
207 +
208 +// specific message
209 +exports.oldfunction = deprecate.function(function () {
210 + // all calls to function are deprecated
211 +}, 'oldfunction')
212 +```
213 +
214 +### Conditionally deprecating a function call
215 +
216 +This will display a deprecated message about "weirdfunction" being deprecated
217 +from "my-module" on STDERR when called with less than 2 arguments.
218 +
219 +```js
220 +var deprecate = require('depd')('my-cool-module')
221 +
222 +exports.weirdfunction = function () {
223 + if (arguments.length < 2) {
224 + // calls with 0 or 1 args are deprecated
225 + deprecate('weirdfunction args < 2')
226 + }
227 +}
228 +```
229 +
230 +When calling `deprecate` as a function, the warning is counted per call site
231 +within your own module, so you can display different deprecations depending
232 +on different situations and the users will still get all the warnings:
233 +
234 +```js
235 +var deprecate = require('depd')('my-cool-module')
236 +
237 +exports.weirdfunction = function () {
238 + if (arguments.length < 2) {
239 + // calls with 0 or 1 args are deprecated
240 + deprecate('weirdfunction args < 2')
241 + } else if (typeof arguments[0] !== 'string') {
242 + // calls with non-string first argument are deprecated
243 + deprecate('weirdfunction non-string first arg')
244 + }
245 +}
246 +```
247 +
248 +### Deprecating property access
249 +
250 +This will display a deprecated message about "oldprop" being deprecated
251 +from "my-module" on STDERR when accessed. A deprecation will be displayed
252 +when setting the value and when getting the value.
253 +
254 +```js
255 +var deprecate = require('depd')('my-cool-module')
256 +
257 +exports.oldprop = 'something'
258 +
259 +// message automatically derives from property name
260 +deprecate.property(exports, 'oldprop')
261 +
262 +// explicit message
263 +deprecate.property(exports, 'oldprop', 'oldprop >= 0.10')
264 +```
265 +
266 +## License
267 +
268 +[MIT](LICENSE)
269 +
270 +[appveyor-image]: https://badgen.net/appveyor/ci/dougwilson/nodejs-depd/master?label=windows
271 +[appveyor-url]: https://ci.appveyor.com/project/dougwilson/nodejs-depd
272 +[coveralls-image]: https://badgen.net/coveralls/c/github/dougwilson/nodejs-depd/master
273 +[coveralls-url]: https://coveralls.io/r/dougwilson/nodejs-depd?branch=master
274 +[node-image]: https://badgen.net/npm/node/depd
275 +[node-url]: https://nodejs.org/en/download/
276 +[npm-downloads-image]: https://badgen.net/npm/dm/depd
277 +[npm-url]: https://npmjs.org/package/depd
278 +[npm-version-image]: https://badgen.net/npm/v/depd
279 +[travis-image]: https://badgen.net/travis/dougwilson/nodejs-depd/master?label=linux
280 +[travis-url]: https://travis-ci.org/dougwilson/nodejs-depd
This diff is collapsed. Click to expand it.
1 +/*!
2 + * depd
3 + * Copyright(c) 2015 Douglas Christopher Wilson
4 + * MIT Licensed
5 + */
6 +
7 +'use strict'
8 +
9 +/**
10 + * Module exports.
11 + * @public
12 + */
13 +
14 +module.exports = depd
15 +
16 +/**
17 + * Create deprecate for namespace in caller.
18 + */
19 +
20 +function depd (namespace) {
21 + if (!namespace) {
22 + throw new TypeError('argument namespace is required')
23 + }
24 +
25 + function deprecate (message) {
26 + // no-op in browser
27 + }
28 +
29 + deprecate._file = undefined
30 + deprecate._ignored = true
31 + deprecate._namespace = namespace
32 + deprecate._traced = false
33 + deprecate._warned = Object.create(null)
34 +
35 + deprecate.function = wrapfunction
36 + deprecate.property = wrapproperty
37 +
38 + return deprecate
39 +}
40 +
41 +/**
42 + * Return a wrapped function in a deprecation message.
43 + *
44 + * This is a no-op version of the wrapper, which does nothing but call
45 + * validation.
46 + */
47 +
48 +function wrapfunction (fn, message) {
49 + if (typeof fn !== 'function') {
50 + throw new TypeError('argument fn must be a function')
51 + }
52 +
53 + return fn
54 +}
55 +
56 +/**
57 + * Wrap property in a deprecation message.
58 + *
59 + * This is a no-op version of the wrapper, which does nothing but call
60 + * validation.
61 + */
62 +
63 +function wrapproperty (obj, prop, message) {
64 + if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
65 + throw new TypeError('argument obj must be object')
66 + }
67 +
68 + var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
69 +
70 + if (!descriptor) {
71 + throw new TypeError('must call property on owner object')
72 + }
73 +
74 + if (!descriptor.configurable) {
75 + throw new TypeError('property must be configurable')
76 + }
77 +}
1 +{
2 + "name": "depd",
3 + "description": "Deprecate all the things",
4 + "version": "2.0.0",
5 + "author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
6 + "license": "MIT",
7 + "keywords": [
8 + "deprecate",
9 + "deprecated"
10 + ],
11 + "repository": "dougwilson/nodejs-depd",
12 + "browser": "lib/browser/index.js",
13 + "devDependencies": {
14 + "benchmark": "2.1.4",
15 + "beautify-benchmark": "0.2.4",
16 + "eslint": "5.7.0",
17 + "eslint-config-standard": "12.0.0",
18 + "eslint-plugin-import": "2.14.0",
19 + "eslint-plugin-markdown": "1.0.0-beta.7",
20 + "eslint-plugin-node": "7.0.1",
21 + "eslint-plugin-promise": "4.0.1",
22 + "eslint-plugin-standard": "4.0.0",
23 + "istanbul": "0.4.5",
24 + "mocha": "5.2.0",
25 + "safe-buffer": "5.1.2",
26 + "uid-safe": "2.1.5"
27 + },
28 + "files": [
29 + "lib/",
30 + "History.md",
31 + "LICENSE",
32 + "index.js",
33 + "Readme.md"
34 + ],
35 + "engines": {
36 + "node": ">= 0.8"
37 + },
38 + "scripts": {
39 + "bench": "node benchmark/index.js",
40 + "lint": "eslint --plugin markdown --ext js,md .",
41 + "test": "mocha --reporter spec --bail test/",
42 + "test-ci": "istanbul cover --print=none node_modules/mocha/bin/_mocha -- --reporter spec test/ && istanbul report lcovonly text-summary",
43 + "test-cov": "istanbul cover --print=none node_modules/mocha/bin/_mocha -- --reporter dot test/ && istanbul report lcov text-summary"
44 + }
45 +}
1 +
2 +The MIT License (MIT)
3 +
4 +Copyright (c) 2014 Jonathan Ong me@jongleberry.com
5 +Copyright (c) 2015-2022 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 +# destroy
2 +
3 +[![NPM version][npm-image]][npm-url]
4 +[![Build Status][github-actions-ci-image]][github-actions-ci-url]
5 +[![Test coverage][coveralls-image]][coveralls-url]
6 +[![License][license-image]][license-url]
7 +[![Downloads][downloads-image]][downloads-url]
8 +
9 +Destroy a stream.
10 +
11 +This module is meant to ensure a stream gets destroyed, handling different APIs
12 +and Node.js bugs.
13 +
14 +## API
15 +
16 +```js
17 +var destroy = require('destroy')
18 +```
19 +
20 +### destroy(stream [, suppress])
21 +
22 +Destroy the given stream, and optionally suppress any future `error` events.
23 +
24 +In most cases, this is identical to a simple `stream.destroy()` call. The rules
25 +are as follows for a given stream:
26 +
27 + 1. If the `stream` is an instance of `ReadStream`, then call `stream.destroy()`
28 + and add a listener to the `open` event to call `stream.close()` if it is
29 + fired. This is for a Node.js bug that will leak a file descriptor if
30 + `.destroy()` is called before `open`.
31 + 2. If the `stream` is an instance of a zlib stream, then call `stream.destroy()`
32 + and close the underlying zlib handle if open, otherwise call `stream.close()`.
33 + This is for consistency across Node.js versions and a Node.js bug that will
34 + leak a native zlib handle.
35 + 3. If the `stream` is not an instance of `Stream`, then nothing happens.
36 + 4. If the `stream` has a `.destroy()` method, then call it.
37 +
38 +The function returns the `stream` passed in as the argument.
39 +
40 +## Example
41 +
42 +```js
43 +var destroy = require('destroy')
44 +
45 +var fs = require('fs')
46 +var stream = fs.createReadStream('package.json')
47 +
48 +// ... and later
49 +destroy(stream)
50 +```
51 +
52 +[npm-image]: https://img.shields.io/npm/v/destroy.svg?style=flat-square
53 +[npm-url]: https://npmjs.org/package/destroy
54 +[github-tag]: http://img.shields.io/github/tag/stream-utils/destroy.svg?style=flat-square
55 +[github-url]: https://github.com/stream-utils/destroy/tags
56 +[coveralls-image]: https://img.shields.io/coveralls/stream-utils/destroy.svg?style=flat-square
57 +[coveralls-url]: https://coveralls.io/r/stream-utils/destroy?branch=master
58 +[license-image]: http://img.shields.io/npm/l/destroy.svg?style=flat-square
59 +[license-url]: LICENSE.md
60 +[downloads-image]: http://img.shields.io/npm/dm/destroy.svg?style=flat-square
61 +[downloads-url]: https://npmjs.org/package/destroy
62 +[github-actions-ci-image]: https://img.shields.io/github/workflow/status/stream-utils/destroy/ci/master?label=ci&style=flat-square
63 +[github-actions-ci-url]: https://github.com/stream-utils/destroy/actions/workflows/ci.yml
1 +/*!
2 + * destroy
3 + * Copyright(c) 2014 Jonathan Ong
4 + * Copyright(c) 2015-2022 Douglas Christopher Wilson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict'
9 +
10 +/**
11 + * Module dependencies.
12 + * @private
13 + */
14 +
15 +var EventEmitter = require('events').EventEmitter
16 +var ReadStream = require('fs').ReadStream
17 +var Stream = require('stream')
18 +var Zlib = require('zlib')
19 +
20 +/**
21 + * Module exports.
22 + * @public
23 + */
24 +
25 +module.exports = destroy
26 +
27 +/**
28 + * Destroy the given stream, and optionally suppress any future `error` events.
29 + *
30 + * @param {object} stream
31 + * @param {boolean} suppress
32 + * @public
33 + */
34 +
35 +function destroy (stream, suppress) {
36 + if (isFsReadStream(stream)) {
37 + destroyReadStream(stream)
38 + } else if (isZlibStream(stream)) {
39 + destroyZlibStream(stream)
40 + } else if (hasDestroy(stream)) {
41 + stream.destroy()
42 + }
43 +
44 + if (isEventEmitter(stream) && suppress) {
45 + stream.removeAllListeners('error')
46 + stream.addListener('error', noop)
47 + }
48 +
49 + return stream
50 +}
51 +
52 +/**
53 + * Destroy a ReadStream.
54 + *
55 + * @param {object} stream
56 + * @private
57 + */
58 +
59 +function destroyReadStream (stream) {
60 + stream.destroy()
61 +
62 + if (typeof stream.close === 'function') {
63 + // node.js core bug work-around
64 + stream.on('open', onOpenClose)
65 + }
66 +}
67 +
68 +/**
69 + * Close a Zlib stream.
70 + *
71 + * Zlib streams below Node.js 4.5.5 have a buggy implementation
72 + * of .close() when zlib encountered an error.
73 + *
74 + * @param {object} stream
75 + * @private
76 + */
77 +
78 +function closeZlibStream (stream) {
79 + if (stream._hadError === true) {
80 + var prop = stream._binding === null
81 + ? '_binding'
82 + : '_handle'
83 +
84 + stream[prop] = {
85 + close: function () { this[prop] = null }
86 + }
87 + }
88 +
89 + stream.close()
90 +}
91 +
92 +/**
93 + * Destroy a Zlib stream.
94 + *
95 + * Zlib streams don't have a destroy function in Node.js 6. On top of that
96 + * simply calling destroy on a zlib stream in Node.js 8+ will result in a
97 + * memory leak. So until that is fixed, we need to call both close AND destroy.
98 + *
99 + * PR to fix memory leak: https://github.com/nodejs/node/pull/23734
100 + *
101 + * In Node.js 6+8, it's important that destroy is called before close as the
102 + * stream would otherwise emit the error 'zlib binding closed'.
103 + *
104 + * @param {object} stream
105 + * @private
106 + */
107 +
108 +function destroyZlibStream (stream) {
109 + if (typeof stream.destroy === 'function') {
110 + // node.js core bug work-around
111 + // istanbul ignore if: node.js 0.8
112 + if (stream._binding) {
113 + // node.js < 0.10.0
114 + stream.destroy()
115 + if (stream._processing) {
116 + stream._needDrain = true
117 + stream.once('drain', onDrainClearBinding)
118 + } else {
119 + stream._binding.clear()
120 + }
121 + } else if (stream._destroy && stream._destroy !== Stream.Transform.prototype._destroy) {
122 + // node.js >= 12, ^11.1.0, ^10.15.1
123 + stream.destroy()
124 + } else if (stream._destroy && typeof stream.close === 'function') {
125 + // node.js 7, 8
126 + stream.destroyed = true
127 + stream.close()
128 + } else {
129 + // fallback
130 + // istanbul ignore next
131 + stream.destroy()
132 + }
133 + } else if (typeof stream.close === 'function') {
134 + // node.js < 8 fallback
135 + closeZlibStream(stream)
136 + }
137 +}
138 +
139 +/**
140 + * Determine if stream has destroy.
141 + * @private
142 + */
143 +
144 +function hasDestroy (stream) {
145 + return stream instanceof Stream &&
146 + typeof stream.destroy === 'function'
147 +}
148 +
149 +/**
150 + * Determine if val is EventEmitter.
151 + * @private
152 + */
153 +
154 +function isEventEmitter (val) {
155 + return val instanceof EventEmitter
156 +}
157 +
158 +/**
159 + * Determine if stream is fs.ReadStream stream.
160 + * @private
161 + */
162 +
163 +function isFsReadStream (stream) {
164 + return stream instanceof ReadStream
165 +}
166 +
167 +/**
168 + * Determine if stream is Zlib stream.
169 + * @private
170 + */
171 +
172 +function isZlibStream (stream) {
173 + return stream instanceof Zlib.Gzip ||
174 + stream instanceof Zlib.Gunzip ||
175 + stream instanceof Zlib.Deflate ||
176 + stream instanceof Zlib.DeflateRaw ||
177 + stream instanceof Zlib.Inflate ||
178 + stream instanceof Zlib.InflateRaw ||
179 + stream instanceof Zlib.Unzip
180 +}
181 +
182 +/**
183 + * No-op function.
184 + * @private
185 + */
186 +
187 +function noop () {}
188 +
189 +/**
190 + * On drain handler to clear binding.
191 + * @private
192 + */
193 +
194 +// istanbul ignore next: node.js 0.8
195 +function onDrainClearBinding () {
196 + this._binding.clear()
197 +}
198 +
199 +/**
200 + * On open handler to close stream.
201 + * @private
202 + */
203 +
204 +function onOpenClose () {
205 + if (typeof this.fd === 'number') {
206 + // actually close down the fd
207 + this.close()
208 + }
209 +}
1 +{
2 + "name": "destroy",
3 + "description": "destroy a stream if possible",
4 + "version": "1.2.0",
5 + "author": {
6 + "name": "Jonathan Ong",
7 + "email": "me@jongleberry.com",
8 + "url": "http://jongleberry.com",
9 + "twitter": "https://twitter.com/jongleberry"
10 + },
11 + "contributors": [
12 + "Douglas Christopher Wilson <doug@somethingdoug.com>"
13 + ],
14 + "license": "MIT",
15 + "repository": "stream-utils/destroy",
16 + "devDependencies": {
17 + "eslint": "7.32.0",
18 + "eslint-config-standard": "14.1.1",
19 + "eslint-plugin-import": "2.25.4",
20 + "eslint-plugin-node": "11.1.0",
21 + "eslint-plugin-promise": "5.2.0",
22 + "eslint-plugin-standard": "4.1.0",
23 + "mocha": "9.2.2",
24 + "nyc": "15.1.0"
25 + },
26 + "engines": {
27 + "node": ">= 0.8",
28 + "npm": "1.2.8000 || >= 1.4.16"
29 + },
30 + "scripts": {
31 + "lint": "eslint .",
32 + "test": "mocha --reporter spec",
33 + "test-ci": "nyc --reporter=lcovonly --reporter=text npm test",
34 + "test-cov": "nyc --reporter=html --reporter=text npm test"
35 + },
36 + "files": [
37 + "index.js",
38 + "LICENSE"
39 + ],
40 + "keywords": [
41 + "stream",
42 + "streams",
43 + "destroy",
44 + "cleanup",
45 + "leak",
46 + "fd"
47 + ]
48 +}
1 +
2 +The MIT License (MIT)
3 +
4 +Copyright (c) 2014 Jonathan Ong me@jongleberry.com
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.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.