강희주

add files

Showing 1000 changed files with 4784 additions and 0 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

1 +#container {
2 + width:600px;
3 + margin:10px auto;
4 + }
5 + fieldset {
6 + margin-bottom: 20px;
7 + }
8 + ul {
9 + list-style: none;
10 + padding-left: 0;
11 + }
12 + ul li {
13 + margin:10px;
14 + }
15 +
16 + /* label 텍스트 스타일 */
17 + li label {
18 + width:120px;
19 + line-height: 36px;
20 + float:left;
21 + font-weight:bold;
22 + }
23 +
24 + /* 텍스트 필드 스타일 */
25 + input[type="text"], input[type="password"], input[type="email"] {
26 + width:300px;
27 + height:30px;
28 + }
29 +
30 + /* 버튼 스타일 */
31 + #buttons {
32 + width:400px;
33 + margin:20px auto;
34 + text-align: center;
35 + }
36 + #buttons input {
37 + width:150px;
38 + height:50px;
39 + font-size:20px;
40 + }
41 + #buttons input:hover {
42 + background-color:rgb(27, 134, 221);
43 + color:#fff;
44 + border-color:#fff;
45 + }
46 +
47 + /* 드롭다운 메뉴 스타일 */
48 + select {
49 + width:100px;
50 + height:30px;
51 + }
...\ 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 + <script src="http://code.jquery.com/jquery-1.11.0.js"></script>
8 + <script>
9 + // 콜백 함수를 이용할 시 반드시 이 스크립트가 밑의 스크립트보다 먼저 실행돼야 함
10 + function useGps() {
11 + var userLat = document.getElementById('latitude').innerText.trim(); // trim으로 공백을 제거하고 실제 값만 불러오기
12 + console.log(userLat);
13 + var userLng = document.getElementById('longitude').innerText.trim(); // trim으로 공백을 제거하고 실제 값만 불러오기
14 + console.log(userLng);
15 +
16 + const APIKEY = "ea903679a6e5a44da75a971c0231f4f4";
17 + fetch("https://api.openweathermap.org/data/2.5/weather?lat=" + userLat + "&lon=" + userLng + "&appid=" + APIKEY + "&units=metric")
18 + .then(res => res.json())
19 + .then(function(jsonObject) {
20 + //if(!error&&response.statusCode==200)
21 + //request는 string으로 받아오기 때문에 JSON형태로 바꿔준다.
22 + //var jsonObject = JSON.parse();
23 + var LocationName = jsonObject.name; //지역 이름
24 + document.getElementById("LocationName").innerHTML= LocationName;
25 + var WeatherCondition = jsonObject.weather[0].main; //현재 날씨
26 + document.getElementById("WeatherCondition").innerHTML= WeatherCondition;
27 + var Temp = jsonObject.main.temp; //현재 기온
28 + document.getElementById("Temp").innerHTML= Temp;
29 + //console.log(body);
30 + console.log(LocationName);
31 + console.log(WeatherCondition);
32 + console.log(Temp);
33 + })
34 + } </script>
35 + <script>
36 + $(function() {
37 + if (navigator.geolocation) {
38 + navigator.geolocation.getCurrentPosition(function(pos) {
39 + $('#latitude').html(pos.coords.latitude);
40 + $('#longitude').html(pos.coords.longitude);
41 + // useGps(); // GPS 정보를 모두받아온 뒤에 코드를 실행함
42 + useGps();
43 + });
44 + }
45 + else {
46 + alert('이 브라우저에서는 안됩니다');
47 + }
48 + });
49 + </script>
50 + <style>
51 + #container {
52 + width:600px;
53 + margin:10px auto;
54 + }
55 + body {
56 + background: url('https://png.pngtree.com/thumb_back/fh260/back_our/20200630/ourmid/pngtree-purple-background-picture-image_340659.jpg') left top no-repeat fixed;
57 + background-size: cover;
58 + }
59 + </style>
60 + <link rel="stylesheet" href="http://localhost:3000/main.css">
61 + </head>
62 + <body>
63 + <div id="container">
64 + <h1>날씨 좋은 날, 뭐 들을래?</h1>
65 +
66 + <fieldset>
67 + <legend>현재 시각 정보</legend>
68 + <div style="text-align: center;">
69 + <span id="clock" style="color:greenyellow; font-size: 100px;">clock</span>
70 + <span id="apm" style="color:greenyellow; font-size: 50px;" >ampm</span>
71 + </div>
72 + <script>
73 + var Target = document.getElementById("clock");
74 + var Target_apm = document.getElementById("apm");
75 + function clock() {
76 + var time = new Date();
77 + var hours = time.getHours();
78 + var minutes = time.getMinutes();
79 + var seconds = time.getSeconds();
80 + var AmPm ="AM";
81 + if(hours > 12){
82 + var AmPm ="PM";
83 + hours %= 12;
84 + }
85 + Target.innerText =
86 + `${hours < 10 ? `0${hours}` : hours}:${minutes < 10 ? `0${minutes}` : minutes}:${seconds < 10 ? `0${seconds}` : seconds}`;
87 + Target_apm.innerText = `${AmPm}`;
88 + }
89 + clock();
90 + setInterval(clock, 1000); // 1초마다 실행
91 + </script>
92 +
93 + </fieldset>
94 +
95 + <fieldset>
96 + <legend>현재 내 위치 정보</legend>
97 + <!-- <div><input type="button" value="현재 내 위치 검색"></div><br> -->
98 + <li>위도:<span id="latitude"></span></li>
99 + <li>경도:<span id="longitude"></span></li>
100 + <li>위치:<span id="LocationName"></span></li>
101 + <li>날씨:<span id="WeatherCondition"></span></li>
102 + <li>기온:<span id="Temp"></span></li>
103 + <!-- 검색 버튼 누르면 팝업으로 위치 서비스 동의 버튼 뜨게 하기 -->
104 + </fieldset>
105 +
106 + <fieldset>
107 + <legend>추천 음악 정보</legend>
108 + <div><input type="button" value="음악 추천 받기"></div><br>
109 +
110 + <h4>추천 음악 1</h4>
111 + <div id="div1"></div>
112 + <iframe width="942" height="530" src="https://www.youtube.com/embed/vnS_jn2uibs" title="YouTube video player" frameborder="0"
113 + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><br>
114 + <h4>추천 음악 2</h4>
115 + <iframe width="942" height="530" src="https://www.youtube.com/embed/P6gV_t70KAk" title="YouTube video player" frameborder="0"
116 + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><br>
117 + </fieldset>
118 +
119 +
120 +
121 + <br>
122 + <br>
123 + <br>
124 + <br>
125 + <br>
126 + <br>
127 + <br>
128 + <br>
129 + <br>
130 + <!-- 공간확보 -->
131 +
132 + <footer>
133 + <div>
134 + <p><b>developed by 강희주, 진재영, 김재욱</b></p>
135 + <address>Contact for more information. 010-2400-6771</address>
136 + <img style="width: 30%; height: 30%; float: right;" src="https://blog.kakaocdn.net/dn/bjsDsi/btqxXJM3JKe/WAK7xHbOm7kxyVqRIvoOaK/img.jpg" alt="경희대 마크">
137 + </div>
138 + </footer>
139 +
140 + </div>
141 + </body>
142 +</html>
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../mime/cli.js" "$@"
10 +else
11 + exec node "$basedir/../mime/cli.js" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mime\cli.js" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../mime/cli.js" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../mime/cli.js" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../mime/cli.js" $args
23 + } else {
24 + & "node$exe" "$basedir/../mime/cli.js" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../sshpk/bin/sshpk-conv" "$@"
10 +else
11 + exec node "$basedir/../sshpk/bin/sshpk-conv" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\sshpk\bin\sshpk-conv" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../sshpk/bin/sshpk-conv" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../sshpk/bin/sshpk-conv" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../sshpk/bin/sshpk-conv" $args
23 + } else {
24 + & "node$exe" "$basedir/../sshpk/bin/sshpk-conv" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../sshpk/bin/sshpk-sign" "$@"
10 +else
11 + exec node "$basedir/../sshpk/bin/sshpk-sign" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\sshpk\bin\sshpk-sign" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../sshpk/bin/sshpk-sign" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../sshpk/bin/sshpk-sign" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../sshpk/bin/sshpk-sign" $args
23 + } else {
24 + & "node$exe" "$basedir/../sshpk/bin/sshpk-sign" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../sshpk/bin/sshpk-verify" "$@"
10 +else
11 + exec node "$basedir/../sshpk/bin/sshpk-verify" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\sshpk\bin\sshpk-verify" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../sshpk/bin/sshpk-verify" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../sshpk/bin/sshpk-verify" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../sshpk/bin/sshpk-verify" $args
23 + } else {
24 + & "node$exe" "$basedir/../sshpk/bin/sshpk-verify" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../uuid/bin/uuid" "$@"
10 +else
11 + exec node "$basedir/../uuid/bin/uuid" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\uuid\bin\uuid" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../uuid/bin/uuid" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../uuid/bin/uuid" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../uuid/bin/uuid" $args
23 + } else {
24 + & "node$exe" "$basedir/../uuid/bin/uuid" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
1 +#!/bin/sh
2 +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 +
4 +case `uname` in
5 + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 +esac
7 +
8 +if [ -x "$basedir/node" ]; then
9 + exec "$basedir/node" "$basedir/../youtube-node/bin/youtube" "$@"
10 +else
11 + exec node "$basedir/../youtube-node/bin/youtube" "$@"
12 +fi
1 +@ECHO off
2 +GOTO start
3 +:find_dp0
4 +SET dp0=%~dp0
5 +EXIT /b
6 +:start
7 +SETLOCAL
8 +CALL :find_dp0
9 +
10 +IF EXIST "%dp0%\node.exe" (
11 + SET "_prog=%dp0%\node.exe"
12 +) ELSE (
13 + SET "_prog=node"
14 + SET PATHEXT=%PATHEXT:;.JS;=;%
15 +)
16 +
17 +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\youtube-node\bin\youtube" %*
1 +#!/usr/bin/env pwsh
2 +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3 +
4 +$exe=""
5 +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6 + # Fix case when both the Windows and Linux builds of Node
7 + # are installed in the same directory
8 + $exe=".exe"
9 +}
10 +$ret=0
11 +if (Test-Path "$basedir/node$exe") {
12 + # Support pipeline input
13 + if ($MyInvocation.ExpectingInput) {
14 + $input | & "$basedir/node$exe" "$basedir/../youtube-node/bin/youtube" $args
15 + } else {
16 + & "$basedir/node$exe" "$basedir/../youtube-node/bin/youtube" $args
17 + }
18 + $ret=$LASTEXITCODE
19 +} else {
20 + # Support pipeline input
21 + if ($MyInvocation.ExpectingInput) {
22 + $input | & "node$exe" "$basedir/../youtube-node/bin/youtube" $args
23 + } else {
24 + & "node$exe" "$basedir/../youtube-node/bin/youtube" $args
25 + }
26 + $ret=$LASTEXITCODE
27 +}
28 +exit $ret
This diff is collapsed. Click to expand it.
1 +MIT License
2 +
3 +Original Library
4 + - Copyright (c) Marak Squires
5 +
6 +Additional Functionality
7 + - Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
8 + - Copyright (c) DABH (https://github.com/DABH)
9 +
10 +Permission is hereby granted, free of charge, to any person obtaining a copy
11 +of this software and associated documentation files (the "Software"), to deal
12 +in the Software without restriction, including without limitation the rights
13 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 +copies of the Software, and to permit persons to whom the Software is
15 +furnished to do so, subject to the following conditions:
16 +
17 +The above copyright notice and this permission notice shall be included in
18 +all copies or substantial portions of the Software.
19 +
20 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 +THE SOFTWARE.
1 +# @colors/colors ("colors.js")
2 +[![Build Status](https://github.com/DABH/colors.js/actions/workflows/ci.yml/badge.svg)](https://github.com/DABH/colors.js/actions/workflows/ci.yml)
3 +[![version](https://img.shields.io/npm/v/@colors/colors.svg)](https://www.npmjs.org/package/@colors/colors)
4 +
5 +Please check out the [roadmap](ROADMAP.md) for upcoming features and releases. Please open Issues to provide feedback.
6 +
7 +## get color and style in your node.js console
8 +
9 +![Demo](https://raw.githubusercontent.com/DABH/colors.js/master/screenshots/colors.png)
10 +
11 +## Installation
12 +
13 + npm install @colors/colors
14 +
15 +## colors and styles!
16 +
17 +### text colors
18 +
19 + - black
20 + - red
21 + - green
22 + - yellow
23 + - blue
24 + - magenta
25 + - cyan
26 + - white
27 + - gray
28 + - grey
29 +
30 +### bright text colors
31 +
32 + - brightRed
33 + - brightGreen
34 + - brightYellow
35 + - brightBlue
36 + - brightMagenta
37 + - brightCyan
38 + - brightWhite
39 +
40 +### background colors
41 +
42 + - bgBlack
43 + - bgRed
44 + - bgGreen
45 + - bgYellow
46 + - bgBlue
47 + - bgMagenta
48 + - bgCyan
49 + - bgWhite
50 + - bgGray
51 + - bgGrey
52 +
53 +### bright background colors
54 +
55 + - bgBrightRed
56 + - bgBrightGreen
57 + - bgBrightYellow
58 + - bgBrightBlue
59 + - bgBrightMagenta
60 + - bgBrightCyan
61 + - bgBrightWhite
62 +
63 +### styles
64 +
65 + - reset
66 + - bold
67 + - dim
68 + - italic
69 + - underline
70 + - inverse
71 + - hidden
72 + - strikethrough
73 +
74 +### extras
75 +
76 + - rainbow
77 + - zebra
78 + - america
79 + - trap
80 + - random
81 +
82 +
83 +## Usage
84 +
85 +By popular demand, `@colors/colors` now ships with two types of usages!
86 +
87 +The super nifty way
88 +
89 +```js
90 +var colors = require('@colors/colors');
91 +
92 +console.log('hello'.green); // outputs green text
93 +console.log('i like cake and pies'.underline.red); // outputs red underlined text
94 +console.log('inverse the color'.inverse); // inverses the color
95 +console.log('OMG Rainbows!'.rainbow); // rainbow
96 +console.log('Run the trap'.trap); // Drops the bass
97 +
98 +```
99 +
100 +or a slightly less nifty way which doesn't extend `String.prototype`
101 +
102 +```js
103 +var colors = require('@colors/colors/safe');
104 +
105 +console.log(colors.green('hello')); // outputs green text
106 +console.log(colors.red.underline('i like cake and pies')); // outputs red underlined text
107 +console.log(colors.inverse('inverse the color')); // inverses the color
108 +console.log(colors.rainbow('OMG Rainbows!')); // rainbow
109 +console.log(colors.trap('Run the trap')); // Drops the bass
110 +
111 +```
112 +
113 +I prefer the first way. Some people seem to be afraid of extending `String.prototype` and prefer the second way.
114 +
115 +If you are writing good code you will never have an issue with the first approach. If you really don't want to touch `String.prototype`, the second usage will not touch `String` native object.
116 +
117 +## Enabling/Disabling Colors
118 +
119 +The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:
120 +
121 +```bash
122 +node myapp.js --no-color
123 +node myapp.js --color=false
124 +
125 +node myapp.js --color
126 +node myapp.js --color=true
127 +node myapp.js --color=always
128 +
129 +FORCE_COLOR=1 node myapp.js
130 +```
131 +
132 +Or in code:
133 +
134 +```javascript
135 +var colors = require('@colors/colors');
136 +colors.enable();
137 +colors.disable();
138 +```
139 +
140 +## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data)
141 +
142 +```js
143 +var name = 'Beowulf';
144 +console.log(colors.green('Hello %s'), name);
145 +// outputs -> 'Hello Beowulf'
146 +```
147 +
148 +## Custom themes
149 +
150 +### Using standard API
151 +
152 +```js
153 +
154 +var colors = require('@colors/colors');
155 +
156 +colors.setTheme({
157 + silly: 'rainbow',
158 + input: 'grey',
159 + verbose: 'cyan',
160 + prompt: 'grey',
161 + info: 'green',
162 + data: 'grey',
163 + help: 'cyan',
164 + warn: 'yellow',
165 + debug: 'blue',
166 + error: 'red'
167 +});
168 +
169 +// outputs red text
170 +console.log("this is an error".error);
171 +
172 +// outputs yellow text
173 +console.log("this is a warning".warn);
174 +```
175 +
176 +### Using string safe API
177 +
178 +```js
179 +var colors = require('@colors/colors/safe');
180 +
181 +// set single property
182 +var error = colors.red;
183 +error('this is red');
184 +
185 +// set theme
186 +colors.setTheme({
187 + silly: 'rainbow',
188 + input: 'grey',
189 + verbose: 'cyan',
190 + prompt: 'grey',
191 + info: 'green',
192 + data: 'grey',
193 + help: 'cyan',
194 + warn: 'yellow',
195 + debug: 'blue',
196 + error: 'red'
197 +});
198 +
199 +// outputs red text
200 +console.log(colors.error("this is an error"));
201 +
202 +// outputs yellow text
203 +console.log(colors.warn("this is a warning"));
204 +
205 +```
206 +
207 +### Combining Colors
208 +
209 +```javascript
210 +var colors = require('@colors/colors');
211 +
212 +colors.setTheme({
213 + custom: ['red', 'underline']
214 +});
215 +
216 +console.log('test'.custom);
217 +```
218 +
219 +*Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.*
1 +var colors = require('../lib/index');
2 +
3 +console.log('First some yellow text'.yellow);
4 +
5 +console.log('Underline that text'.yellow.underline);
6 +
7 +console.log('Make it bold and red'.red.bold);
8 +
9 +console.log(('Double Raindows All Day Long').rainbow);
10 +
11 +console.log('Drop the bass'.trap);
12 +
13 +console.log('DROP THE RAINBOW BASS'.trap.rainbow);
14 +
15 +// styles not widely supported
16 +console.log('Chains are also cool.'.bold.italic.underline.red);
17 +
18 +// styles not widely supported
19 +console.log('So '.green + 'are'.underline + ' ' + 'inverse'.inverse
20 + + ' styles! '.yellow.bold);
21 +console.log('Zebras are so fun!'.zebra);
22 +
23 +//
24 +// Remark: .strikethrough may not work with Mac OS Terminal App
25 +//
26 +console.log('This is ' + 'not'.strikethrough + ' fun.');
27 +
28 +console.log('Background color attack!'.black.bgWhite);
29 +console.log('Use random styles on everything!'.random);
30 +console.log('America, Heck Yeah!'.america);
31 +
32 +// eslint-disable-next-line max-len
33 +console.log('Blindingly '.brightCyan + 'bright? '.brightRed + 'Why '.brightYellow + 'not?!'.brightGreen);
34 +
35 +console.log('Setting themes is useful');
36 +
37 +//
38 +// Custom themes
39 +//
40 +console.log('Generic logging theme as JSON'.green.bold.underline);
41 +// Load theme with JSON literal
42 +colors.setTheme({
43 + silly: 'rainbow',
44 + input: 'grey',
45 + verbose: 'cyan',
46 + prompt: 'grey',
47 + info: 'green',
48 + data: 'grey',
49 + help: 'cyan',
50 + warn: 'yellow',
51 + debug: 'blue',
52 + error: 'red',
53 +});
54 +
55 +// outputs red text
56 +console.log('this is an error'.error);
57 +
58 +// outputs yellow text
59 +console.log('this is a warning'.warn);
60 +
61 +// outputs grey text
62 +console.log('this is an input'.input);
63 +
64 +console.log('Generic logging theme as file'.green.bold.underline);
65 +
66 +// Load a theme from file
67 +try {
68 + colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
69 +} catch (err) {
70 + console.log(err);
71 +}
72 +
73 +// outputs red text
74 +console.log('this is an error'.error);
75 +
76 +// outputs yellow text
77 +console.log('this is a warning'.warn);
78 +
79 +// outputs grey text
80 +console.log('this is an input'.input);
81 +
82 +// console.log("Don't summon".zalgo)
83 +
1 +var colors = require('../safe');
2 +
3 +console.log(colors.yellow('First some yellow text'));
4 +
5 +console.log(colors.yellow.underline('Underline that text'));
6 +
7 +console.log(colors.red.bold('Make it bold and red'));
8 +
9 +console.log(colors.rainbow('Double Raindows All Day Long'));
10 +
11 +console.log(colors.trap('Drop the bass'));
12 +
13 +console.log(colors.rainbow(colors.trap('DROP THE RAINBOW BASS')));
14 +
15 +// styles not widely supported
16 +console.log(colors.bold.italic.underline.red('Chains are also cool.'));
17 +
18 +// styles not widely supported
19 +console.log(colors.green('So ') + colors.underline('are') + ' '
20 + + colors.inverse('inverse') + colors.yellow.bold(' styles! '));
21 +
22 +console.log(colors.zebra('Zebras are so fun!'));
23 +
24 +console.log('This is ' + colors.strikethrough('not') + ' fun.');
25 +
26 +
27 +console.log(colors.black.bgWhite('Background color attack!'));
28 +console.log(colors.random('Use random styles on everything!'));
29 +console.log(colors.america('America, Heck Yeah!'));
30 +
31 +// eslint-disable-next-line max-len
32 +console.log(colors.brightCyan('Blindingly ') + colors.brightRed('bright? ') + colors.brightYellow('Why ') + colors.brightGreen('not?!'));
33 +
34 +console.log('Setting themes is useful');
35 +
36 +//
37 +// Custom themes
38 +//
39 +// console.log('Generic logging theme as JSON'.green.bold.underline);
40 +// Load theme with JSON literal
41 +colors.setTheme({
42 + silly: 'rainbow',
43 + input: 'blue',
44 + verbose: 'cyan',
45 + prompt: 'grey',
46 + info: 'green',
47 + data: 'grey',
48 + help: 'cyan',
49 + warn: 'yellow',
50 + debug: 'blue',
51 + error: 'red',
52 +});
53 +
54 +// outputs red text
55 +console.log(colors.error('this is an error'));
56 +
57 +// outputs yellow text
58 +console.log(colors.warn('this is a warning'));
59 +
60 +// outputs blue text
61 +console.log(colors.input('this is an input'));
62 +
63 +
64 +// console.log('Generic logging theme as file'.green.bold.underline);
65 +
66 +// Load a theme from file
67 +colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
68 +
69 +// outputs red text
70 +console.log(colors.error('this is an error'));
71 +
72 +// outputs yellow text
73 +console.log(colors.warn('this is a warning'));
74 +
75 +// outputs grey text
76 +console.log(colors.input('this is an input'));
77 +
78 +// console.log(colors.zalgo("Don't summon him"))
79 +
80 +
1 +// Type definitions for @colors/colors 1.4+
2 +// Project: https://github.com/Marak/colors.js
3 +// Definitions by: Bart van der Schoor <https://github.com/Bartvds>, Staffan Eketorp <https://github.com/staeke>
4 +// Definitions: https://github.com/DABH/colors.js
5 +
6 +export interface Color {
7 + (text: string): string;
8 +
9 + strip: Color;
10 + stripColors: Color;
11 +
12 + black: Color;
13 + red: Color;
14 + green: Color;
15 + yellow: Color;
16 + blue: Color;
17 + magenta: Color;
18 + cyan: Color;
19 + white: Color;
20 + gray: Color;
21 + grey: Color;
22 +
23 + bgBlack: Color;
24 + bgRed: Color;
25 + bgGreen: Color;
26 + bgYellow: Color;
27 + bgBlue: Color;
28 + bgMagenta: Color;
29 + bgCyan: Color;
30 + bgWhite: Color;
31 +
32 + reset: Color;
33 + bold: Color;
34 + dim: Color;
35 + italic: Color;
36 + underline: Color;
37 + inverse: Color;
38 + hidden: Color;
39 + strikethrough: Color;
40 +
41 + rainbow: Color;
42 + zebra: Color;
43 + america: Color;
44 + trap: Color;
45 + random: Color;
46 + zalgo: Color;
47 +}
48 +
49 +export function enable(): void;
50 +export function disable(): void;
51 +export function setTheme(theme: any): void;
52 +
53 +export let enabled: boolean;
54 +
55 +export const strip: Color;
56 +export const stripColors: Color;
57 +
58 +export const black: Color;
59 +export const red: Color;
60 +export const green: Color;
61 +export const yellow: Color;
62 +export const blue: Color;
63 +export const magenta: Color;
64 +export const cyan: Color;
65 +export const white: Color;
66 +export const gray: Color;
67 +export const grey: Color;
68 +
69 +export const bgBlack: Color;
70 +export const bgRed: Color;
71 +export const bgGreen: Color;
72 +export const bgYellow: Color;
73 +export const bgBlue: Color;
74 +export const bgMagenta: Color;
75 +export const bgCyan: Color;
76 +export const bgWhite: Color;
77 +
78 +export const reset: Color;
79 +export const bold: Color;
80 +export const dim: Color;
81 +export const italic: Color;
82 +export const underline: Color;
83 +export const inverse: Color;
84 +export const hidden: Color;
85 +export const strikethrough: Color;
86 +
87 +export const rainbow: Color;
88 +export const zebra: Color;
89 +export const america: Color;
90 +export const trap: Color;
91 +export const random: Color;
92 +export const zalgo: Color;
93 +
94 +declare global {
95 + interface String {
96 + strip: string;
97 + stripColors: string;
98 +
99 + black: string;
100 + red: string;
101 + green: string;
102 + yellow: string;
103 + blue: string;
104 + magenta: string;
105 + cyan: string;
106 + white: string;
107 + gray: string;
108 + grey: string;
109 +
110 + bgBlack: string;
111 + bgRed: string;
112 + bgGreen: string;
113 + bgYellow: string;
114 + bgBlue: string;
115 + bgMagenta: string;
116 + bgCyan: string;
117 + bgWhite: string;
118 +
119 + reset: string;
120 + // @ts-ignore
121 + bold: string;
122 + dim: string;
123 + italic: string;
124 + underline: string;
125 + inverse: string;
126 + hidden: string;
127 + strikethrough: string;
128 +
129 + rainbow: string;
130 + zebra: string;
131 + america: string;
132 + trap: string;
133 + random: string;
134 + zalgo: string;
135 + }
136 +}
1 +/*
2 +
3 +The MIT License (MIT)
4 +
5 +Original Library
6 + - Copyright (c) Marak Squires
7 +
8 +Additional functionality
9 + - Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
10 +
11 +Permission is hereby granted, free of charge, to any person obtaining a copy
12 +of this software and associated documentation files (the "Software"), to deal
13 +in the Software without restriction, including without limitation the rights
14 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 +copies of the Software, and to permit persons to whom the Software is
16 +furnished to do so, subject to the following conditions:
17 +
18 +The above copyright notice and this permission notice shall be included in
19 +all copies or substantial portions of the Software.
20 +
21 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 +THE SOFTWARE.
28 +
29 +*/
30 +
31 +var colors = {};
32 +module['exports'] = colors;
33 +
34 +colors.themes = {};
35 +
36 +var util = require('util');
37 +var ansiStyles = colors.styles = require('./styles');
38 +var defineProps = Object.defineProperties;
39 +var newLineRegex = new RegExp(/[\r\n]+/g);
40 +
41 +colors.supportsColor = require('./system/supports-colors').supportsColor;
42 +
43 +if (typeof colors.enabled === 'undefined') {
44 + colors.enabled = colors.supportsColor() !== false;
45 +}
46 +
47 +colors.enable = function() {
48 + colors.enabled = true;
49 +};
50 +
51 +colors.disable = function() {
52 + colors.enabled = false;
53 +};
54 +
55 +colors.stripColors = colors.strip = function(str) {
56 + return ('' + str).replace(/\x1B\[\d+m/g, '');
57 +};
58 +
59 +// eslint-disable-next-line no-unused-vars
60 +var stylize = colors.stylize = function stylize(str, style) {
61 + if (!colors.enabled) {
62 + return str+'';
63 + }
64 +
65 + var styleMap = ansiStyles[style];
66 +
67 + // Stylize should work for non-ANSI styles, too
68 + if (!styleMap && style in colors) {
69 + // Style maps like trap operate as functions on strings;
70 + // they don't have properties like open or close.
71 + return colors[style](str);
72 + }
73 +
74 + return styleMap.open + str + styleMap.close;
75 +};
76 +
77 +var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
78 +var escapeStringRegexp = function(str) {
79 + if (typeof str !== 'string') {
80 + throw new TypeError('Expected a string');
81 + }
82 + return str.replace(matchOperatorsRe, '\\$&');
83 +};
84 +
85 +function build(_styles) {
86 + var builder = function builder() {
87 + return applyStyle.apply(builder, arguments);
88 + };
89 + builder._styles = _styles;
90 + // __proto__ is used because we must return a function, but there is
91 + // no way to create a function with a different prototype.
92 + builder.__proto__ = proto;
93 + return builder;
94 +}
95 +
96 +var styles = (function() {
97 + var ret = {};
98 + ansiStyles.grey = ansiStyles.gray;
99 + Object.keys(ansiStyles).forEach(function(key) {
100 + ansiStyles[key].closeRe =
101 + new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
102 + ret[key] = {
103 + get: function() {
104 + return build(this._styles.concat(key));
105 + },
106 + };
107 + });
108 + return ret;
109 +})();
110 +
111 +var proto = defineProps(function colors() {}, styles);
112 +
113 +function applyStyle() {
114 + var args = Array.prototype.slice.call(arguments);
115 +
116 + var str = args.map(function(arg) {
117 + // Use weak equality check so we can colorize null/undefined in safe mode
118 + if (arg != null && arg.constructor === String) {
119 + return arg;
120 + } else {
121 + return util.inspect(arg);
122 + }
123 + }).join(' ');
124 +
125 + if (!colors.enabled || !str) {
126 + return str;
127 + }
128 +
129 + var newLinesPresent = str.indexOf('\n') != -1;
130 +
131 + var nestedStyles = this._styles;
132 +
133 + var i = nestedStyles.length;
134 + while (i--) {
135 + var code = ansiStyles[nestedStyles[i]];
136 + str = code.open + str.replace(code.closeRe, code.open) + code.close;
137 + if (newLinesPresent) {
138 + str = str.replace(newLineRegex, function(match) {
139 + return code.close + match + code.open;
140 + });
141 + }
142 + }
143 +
144 + return str;
145 +}
146 +
147 +colors.setTheme = function(theme) {
148 + if (typeof theme === 'string') {
149 + console.log('colors.setTheme now only accepts an object, not a string. ' +
150 + 'If you are trying to set a theme from a file, it is now your (the ' +
151 + 'caller\'s) responsibility to require the file. The old syntax ' +
152 + 'looked like colors.setTheme(__dirname + ' +
153 + '\'/../themes/generic-logging.js\'); The new syntax looks like '+
154 + 'colors.setTheme(require(__dirname + ' +
155 + '\'/../themes/generic-logging.js\'));');
156 + return;
157 + }
158 + for (var style in theme) {
159 + (function(style) {
160 + colors[style] = function(str) {
161 + if (typeof theme[style] === 'object') {
162 + var out = str;
163 + for (var i in theme[style]) {
164 + out = colors[theme[style][i]](out);
165 + }
166 + return out;
167 + }
168 + return colors[theme[style]](str);
169 + };
170 + })(style);
171 + }
172 +};
173 +
174 +function init() {
175 + var ret = {};
176 + Object.keys(styles).forEach(function(name) {
177 + ret[name] = {
178 + get: function() {
179 + return build([name]);
180 + },
181 + };
182 + });
183 + return ret;
184 +}
185 +
186 +var sequencer = function sequencer(map, str) {
187 + var exploded = str.split('');
188 + exploded = exploded.map(map);
189 + return exploded.join('');
190 +};
191 +
192 +// custom formatter methods
193 +colors.trap = require('./custom/trap');
194 +colors.zalgo = require('./custom/zalgo');
195 +
196 +// maps
197 +colors.maps = {};
198 +colors.maps.america = require('./maps/america')(colors);
199 +colors.maps.zebra = require('./maps/zebra')(colors);
200 +colors.maps.rainbow = require('./maps/rainbow')(colors);
201 +colors.maps.random = require('./maps/random')(colors);
202 +
203 +for (var map in colors.maps) {
204 + (function(map) {
205 + colors[map] = function(str) {
206 + return sequencer(colors.maps[map], str);
207 + };
208 + })(map);
209 +}
210 +
211 +defineProps(colors, init());
1 +module['exports'] = function runTheTrap(text, options) {
2 + var result = '';
3 + text = text || 'Run the trap, drop the bass';
4 + text = text.split('');
5 + var trap = {
6 + a: ['\u0040', '\u0104', '\u023a', '\u0245', '\u0394', '\u039b', '\u0414'],
7 + b: ['\u00df', '\u0181', '\u0243', '\u026e', '\u03b2', '\u0e3f'],
8 + c: ['\u00a9', '\u023b', '\u03fe'],
9 + d: ['\u00d0', '\u018a', '\u0500', '\u0501', '\u0502', '\u0503'],
10 + e: ['\u00cb', '\u0115', '\u018e', '\u0258', '\u03a3', '\u03be', '\u04bc',
11 + '\u0a6c'],
12 + f: ['\u04fa'],
13 + g: ['\u0262'],
14 + h: ['\u0126', '\u0195', '\u04a2', '\u04ba', '\u04c7', '\u050a'],
15 + i: ['\u0f0f'],
16 + j: ['\u0134'],
17 + k: ['\u0138', '\u04a0', '\u04c3', '\u051e'],
18 + l: ['\u0139'],
19 + m: ['\u028d', '\u04cd', '\u04ce', '\u0520', '\u0521', '\u0d69'],
20 + n: ['\u00d1', '\u014b', '\u019d', '\u0376', '\u03a0', '\u048a'],
21 + o: ['\u00d8', '\u00f5', '\u00f8', '\u01fe', '\u0298', '\u047a', '\u05dd',
22 + '\u06dd', '\u0e4f'],
23 + p: ['\u01f7', '\u048e'],
24 + q: ['\u09cd'],
25 + r: ['\u00ae', '\u01a6', '\u0210', '\u024c', '\u0280', '\u042f'],
26 + s: ['\u00a7', '\u03de', '\u03df', '\u03e8'],
27 + t: ['\u0141', '\u0166', '\u0373'],
28 + u: ['\u01b1', '\u054d'],
29 + v: ['\u05d8'],
30 + w: ['\u0428', '\u0460', '\u047c', '\u0d70'],
31 + x: ['\u04b2', '\u04fe', '\u04fc', '\u04fd'],
32 + y: ['\u00a5', '\u04b0', '\u04cb'],
33 + z: ['\u01b5', '\u0240'],
34 + };
35 + text.forEach(function(c) {
36 + c = c.toLowerCase();
37 + var chars = trap[c] || [' '];
38 + var rand = Math.floor(Math.random() * chars.length);
39 + if (typeof trap[c] !== 'undefined') {
40 + result += trap[c][rand];
41 + } else {
42 + result += c;
43 + }
44 + });
45 + return result;
46 +};
1 +// please no
2 +module['exports'] = function zalgo(text, options) {
3 + text = text || ' he is here ';
4 + var soul = {
5 + 'up': [
6 + '̍', '̎', '̄', '̅',
7 + '̿', '̑', '̆', '̐',
8 + '͒', '͗', '͑', '̇',
9 + '̈', '̊', '͂', '̓',
10 + '̈', '͊', '͋', '͌',
11 + '̃', '̂', '̌', '͐',
12 + '̀', '́', '̋', '̏',
13 + '̒', '̓', '̔', '̽',
14 + '̉', 'ͣ', 'ͤ', 'ͥ',
15 + 'ͦ', 'ͧ', 'ͨ', 'ͩ',
16 + 'ͪ', 'ͫ', 'ͬ', 'ͭ',
17 + 'ͮ', 'ͯ', '̾', '͛',
18 + '͆', '̚',
19 + ],
20 + 'down': [
21 + '̖', '̗', '̘', '̙',
22 + '̜', '̝', '̞', '̟',
23 + '̠', '̤', '̥', '̦',
24 + '̩', '̪', '̫', '̬',
25 + '̭', '̮', '̯', '̰',
26 + '̱', '̲', '̳', '̹',
27 + '̺', '̻', '̼', 'ͅ',
28 + '͇', '͈', '͉', '͍',
29 + '͎', '͓', '͔', '͕',
30 + '͖', '͙', '͚', '̣',
31 + ],
32 + 'mid': [
33 + '̕', '̛', '̀', '́',
34 + '͘', '̡', '̢', '̧',
35 + '̨', '̴', '̵', '̶',
36 + '͜', '͝', '͞',
37 + '͟', '͠', '͢', '̸',
38 + '̷', '͡', ' ҉',
39 + ],
40 + };
41 + var all = [].concat(soul.up, soul.down, soul.mid);
42 +
43 + function randomNumber(range) {
44 + var r = Math.floor(Math.random() * range);
45 + return r;
46 + }
47 +
48 + function isChar(character) {
49 + var bool = false;
50 + all.filter(function(i) {
51 + bool = (i === character);
52 + });
53 + return bool;
54 + }
55 +
56 +
57 + function heComes(text, options) {
58 + var result = '';
59 + var counts;
60 + var l;
61 + options = options || {};
62 + options['up'] =
63 + typeof options['up'] !== 'undefined' ? options['up'] : true;
64 + options['mid'] =
65 + typeof options['mid'] !== 'undefined' ? options['mid'] : true;
66 + options['down'] =
67 + typeof options['down'] !== 'undefined' ? options['down'] : true;
68 + options['size'] =
69 + typeof options['size'] !== 'undefined' ? options['size'] : 'maxi';
70 + text = text.split('');
71 + for (l in text) {
72 + if (isChar(l)) {
73 + continue;
74 + }
75 + result = result + text[l];
76 + counts = {'up': 0, 'down': 0, 'mid': 0};
77 + switch (options.size) {
78 + case 'mini':
79 + counts.up = randomNumber(8);
80 + counts.mid = randomNumber(2);
81 + counts.down = randomNumber(8);
82 + break;
83 + case 'maxi':
84 + counts.up = randomNumber(16) + 3;
85 + counts.mid = randomNumber(4) + 1;
86 + counts.down = randomNumber(64) + 3;
87 + break;
88 + default:
89 + counts.up = randomNumber(8) + 1;
90 + counts.mid = randomNumber(6) / 2;
91 + counts.down = randomNumber(8) + 1;
92 + break;
93 + }
94 +
95 + var arr = ['up', 'mid', 'down'];
96 + for (var d in arr) {
97 + var index = arr[d];
98 + for (var i = 0; i <= counts[index]; i++) {
99 + if (options[index]) {
100 + result = result + soul[index][randomNumber(soul[index].length)];
101 + }
102 + }
103 + }
104 + }
105 + return result;
106 + }
107 + // don't summon him
108 + return heComes(text, options);
109 +};
110 +
1 +var colors = require('./colors');
2 +
3 +module['exports'] = function() {
4 + //
5 + // Extends prototype of native string object to allow for "foo".red syntax
6 + //
7 + var addProperty = function(color, func) {
8 + String.prototype.__defineGetter__(color, func);
9 + };
10 +
11 + addProperty('strip', function() {
12 + return colors.strip(this);
13 + });
14 +
15 + addProperty('stripColors', function() {
16 + return colors.strip(this);
17 + });
18 +
19 + addProperty('trap', function() {
20 + return colors.trap(this);
21 + });
22 +
23 + addProperty('zalgo', function() {
24 + return colors.zalgo(this);
25 + });
26 +
27 + addProperty('zebra', function() {
28 + return colors.zebra(this);
29 + });
30 +
31 + addProperty('rainbow', function() {
32 + return colors.rainbow(this);
33 + });
34 +
35 + addProperty('random', function() {
36 + return colors.random(this);
37 + });
38 +
39 + addProperty('america', function() {
40 + return colors.america(this);
41 + });
42 +
43 + //
44 + // Iterate through all default styles and colors
45 + //
46 + var x = Object.keys(colors.styles);
47 + x.forEach(function(style) {
48 + addProperty(style, function() {
49 + return colors.stylize(this, style);
50 + });
51 + });
52 +
53 + function applyTheme(theme) {
54 + //
55 + // Remark: This is a list of methods that exist
56 + // on String that you should not overwrite.
57 + //
58 + var stringPrototypeBlacklist = [
59 + '__defineGetter__', '__defineSetter__', '__lookupGetter__',
60 + '__lookupSetter__', 'charAt', 'constructor', 'hasOwnProperty',
61 + 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString',
62 + 'valueOf', 'charCodeAt', 'indexOf', 'lastIndexOf', 'length',
63 + 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice',
64 + 'split', 'substring', 'toLocaleLowerCase', 'toLocaleUpperCase',
65 + 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight',
66 + ];
67 +
68 + Object.keys(theme).forEach(function(prop) {
69 + if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
70 + console.log('warn: '.red + ('String.prototype' + prop).magenta +
71 + ' is probably something you don\'t want to override. ' +
72 + 'Ignoring style name');
73 + } else {
74 + if (typeof(theme[prop]) === 'string') {
75 + colors[prop] = colors[theme[prop]];
76 + addProperty(prop, function() {
77 + return colors[prop](this);
78 + });
79 + } else {
80 + var themePropApplicator = function(str) {
81 + var ret = str || this;
82 + for (var t = 0; t < theme[prop].length; t++) {
83 + ret = colors[theme[prop][t]](ret);
84 + }
85 + return ret;
86 + };
87 + addProperty(prop, themePropApplicator);
88 + colors[prop] = function(str) {
89 + return themePropApplicator(str);
90 + };
91 + }
92 + }
93 + });
94 + }
95 +
96 + colors.setTheme = function(theme) {
97 + if (typeof theme === 'string') {
98 + console.log('colors.setTheme now only accepts an object, not a string. ' +
99 + 'If you are trying to set a theme from a file, it is now your (the ' +
100 + 'caller\'s) responsibility to require the file. The old syntax ' +
101 + 'looked like colors.setTheme(__dirname + ' +
102 + '\'/../themes/generic-logging.js\'); The new syntax looks like '+
103 + 'colors.setTheme(require(__dirname + ' +
104 + '\'/../themes/generic-logging.js\'));');
105 + return;
106 + } else {
107 + applyTheme(theme);
108 + }
109 + };
110 +};
1 +var colors = require('./colors');
2 +module['exports'] = colors;
3 +
4 +// Remark: By default, colors will add style properties to String.prototype.
5 +//
6 +// If you don't wish to extend String.prototype, you can do this instead and
7 +// native String will not be touched:
8 +//
9 +// var colors = require('colors/safe);
10 +// colors.red("foo")
11 +//
12 +//
13 +require('./extendStringPrototype')();
1 +module['exports'] = function(colors) {
2 + return function(letter, i, exploded) {
3 + if (letter === ' ') return letter;
4 + switch (i%3) {
5 + case 0: return colors.red(letter);
6 + case 1: return colors.white(letter);
7 + case 2: return colors.blue(letter);
8 + }
9 + };
10 +};
1 +module['exports'] = function(colors) {
2 + // RoY G BiV
3 + var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta'];
4 + return function(letter, i, exploded) {
5 + if (letter === ' ') {
6 + return letter;
7 + } else {
8 + return colors[rainbowColors[i++ % rainbowColors.length]](letter);
9 + }
10 + };
11 +};
12 +
1 +module['exports'] = function(colors) {
2 + var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
3 + 'blue', 'white', 'cyan', 'magenta', 'brightYellow', 'brightRed',
4 + 'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan', 'brightMagenta'];
5 + return function(letter, i, exploded) {
6 + return letter === ' ' ? letter :
7 + colors[
8 + available[Math.round(Math.random() * (available.length - 2))]
9 + ](letter);
10 + };
11 +};
1 +module['exports'] = function(colors) {
2 + return function(letter, i, exploded) {
3 + return i % 2 === 0 ? letter : colors.inverse(letter);
4 + };
5 +};
1 +/*
2 +The MIT License (MIT)
3 +
4 +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
23 +
24 +*/
25 +
26 +var styles = {};
27 +module['exports'] = styles;
28 +
29 +var codes = {
30 + reset: [0, 0],
31 +
32 + bold: [1, 22],
33 + dim: [2, 22],
34 + italic: [3, 23],
35 + underline: [4, 24],
36 + inverse: [7, 27],
37 + hidden: [8, 28],
38 + strikethrough: [9, 29],
39 +
40 + black: [30, 39],
41 + red: [31, 39],
42 + green: [32, 39],
43 + yellow: [33, 39],
44 + blue: [34, 39],
45 + magenta: [35, 39],
46 + cyan: [36, 39],
47 + white: [37, 39],
48 + gray: [90, 39],
49 + grey: [90, 39],
50 +
51 + brightRed: [91, 39],
52 + brightGreen: [92, 39],
53 + brightYellow: [93, 39],
54 + brightBlue: [94, 39],
55 + brightMagenta: [95, 39],
56 + brightCyan: [96, 39],
57 + brightWhite: [97, 39],
58 +
59 + bgBlack: [40, 49],
60 + bgRed: [41, 49],
61 + bgGreen: [42, 49],
62 + bgYellow: [43, 49],
63 + bgBlue: [44, 49],
64 + bgMagenta: [45, 49],
65 + bgCyan: [46, 49],
66 + bgWhite: [47, 49],
67 + bgGray: [100, 49],
68 + bgGrey: [100, 49],
69 +
70 + bgBrightRed: [101, 49],
71 + bgBrightGreen: [102, 49],
72 + bgBrightYellow: [103, 49],
73 + bgBrightBlue: [104, 49],
74 + bgBrightMagenta: [105, 49],
75 + bgBrightCyan: [106, 49],
76 + bgBrightWhite: [107, 49],
77 +
78 + // legacy styles for colors pre v1.0.0
79 + blackBG: [40, 49],
80 + redBG: [41, 49],
81 + greenBG: [42, 49],
82 + yellowBG: [43, 49],
83 + blueBG: [44, 49],
84 + magentaBG: [45, 49],
85 + cyanBG: [46, 49],
86 + whiteBG: [47, 49],
87 +
88 +};
89 +
90 +Object.keys(codes).forEach(function(key) {
91 + var val = codes[key];
92 + var style = styles[key] = [];
93 + style.open = '\u001b[' + val[0] + 'm';
94 + style.close = '\u001b[' + val[1] + 'm';
95 +});
1 +/*
2 +MIT License
3 +
4 +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
7 +this software and associated documentation files (the "Software"), to deal in
8 +the Software without restriction, including without limitation the rights to
9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 +of the Software, and to permit persons to whom the Software is furnished to do
11 +so, subject to the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be included in all
14 +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 THE
22 +SOFTWARE.
23 +*/
24 +
25 +'use strict';
26 +
27 +module.exports = function(flag, argv) {
28 + argv = argv || process.argv;
29 +
30 + var terminatorPos = argv.indexOf('--');
31 + var prefix = /^-{1,2}/.test(flag) ? '' : '--';
32 + var pos = argv.indexOf(prefix + flag);
33 +
34 + return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
35 +};
1 +/*
2 +The MIT License (MIT)
3 +
4 +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
23 +
24 +*/
25 +
26 +'use strict';
27 +
28 +var os = require('os');
29 +var hasFlag = require('./has-flag.js');
30 +
31 +var env = process.env;
32 +
33 +var forceColor = void 0;
34 +if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
35 + forceColor = false;
36 +} else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true')
37 + || hasFlag('color=always')) {
38 + forceColor = true;
39 +}
40 +if ('FORCE_COLOR' in env) {
41 + forceColor = env.FORCE_COLOR.length === 0
42 + || parseInt(env.FORCE_COLOR, 10) !== 0;
43 +}
44 +
45 +function translateLevel(level) {
46 + if (level === 0) {
47 + return false;
48 + }
49 +
50 + return {
51 + level: level,
52 + hasBasic: true,
53 + has256: level >= 2,
54 + has16m: level >= 3,
55 + };
56 +}
57 +
58 +function supportsColor(stream) {
59 + if (forceColor === false) {
60 + return 0;
61 + }
62 +
63 + if (hasFlag('color=16m') || hasFlag('color=full')
64 + || hasFlag('color=truecolor')) {
65 + return 3;
66 + }
67 +
68 + if (hasFlag('color=256')) {
69 + return 2;
70 + }
71 +
72 + if (stream && !stream.isTTY && forceColor !== true) {
73 + return 0;
74 + }
75 +
76 + var min = forceColor ? 1 : 0;
77 +
78 + if (process.platform === 'win32') {
79 + // Node.js 7.5.0 is the first version of Node.js to include a patch to
80 + // libuv that enables 256 color output on Windows. Anything earlier and it
81 + // won't work. However, here we target Node.js 8 at minimum as it is an LTS
82 + // release, and Node.js 7 is not. Windows 10 build 10586 is the first
83 + // Windows release that supports 256 colors. Windows 10 build 14931 is the
84 + // first release that supports 16m/TrueColor.
85 + var osRelease = os.release().split('.');
86 + if (Number(process.versions.node.split('.')[0]) >= 8
87 + && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
88 + return Number(osRelease[2]) >= 14931 ? 3 : 2;
89 + }
90 +
91 + return 1;
92 + }
93 +
94 + if ('CI' in env) {
95 + if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function(sign) {
96 + return sign in env;
97 + }) || env.CI_NAME === 'codeship') {
98 + return 1;
99 + }
100 +
101 + return min;
102 + }
103 +
104 + if ('TEAMCITY_VERSION' in env) {
105 + return (/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0
106 + );
107 + }
108 +
109 + if ('TERM_PROGRAM' in env) {
110 + var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
111 +
112 + switch (env.TERM_PROGRAM) {
113 + case 'iTerm.app':
114 + return version >= 3 ? 3 : 2;
115 + case 'Hyper':
116 + return 3;
117 + case 'Apple_Terminal':
118 + return 2;
119 + // No default
120 + }
121 + }
122 +
123 + if (/-256(color)?$/i.test(env.TERM)) {
124 + return 2;
125 + }
126 +
127 + if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
128 + return 1;
129 + }
130 +
131 + if ('COLORTERM' in env) {
132 + return 1;
133 + }
134 +
135 + if (env.TERM === 'dumb') {
136 + return min;
137 + }
138 +
139 + return min;
140 +}
141 +
142 +function getSupportLevel(stream) {
143 + var level = supportsColor(stream);
144 + return translateLevel(level);
145 +}
146 +
147 +module.exports = {
148 + supportsColor: getSupportLevel,
149 + stdout: getSupportLevel(process.stdout),
150 + stderr: getSupportLevel(process.stderr),
151 +};
1 +{
2 + "name": "@colors/colors",
3 + "description": "get colors in your node.js console",
4 + "version": "1.5.0",
5 + "author": "DABH",
6 + "contributors": [
7 + {
8 + "name": "DABH",
9 + "url": "https://github.com/DABH"
10 + }
11 + ],
12 + "homepage": "https://github.com/DABH/colors.js",
13 + "bugs": "https://github.com/DABH/colors.js/issues",
14 + "keywords": [
15 + "ansi",
16 + "terminal",
17 + "colors"
18 + ],
19 + "repository": {
20 + "type": "git",
21 + "url": "http://github.com/DABH/colors.js.git"
22 + },
23 + "license": "MIT",
24 + "scripts": {
25 + "lint": "eslint . --fix",
26 + "test": "export FORCE_COLOR=1 && node tests/basic-test.js && node tests/safe-test.js"
27 + },
28 + "engines": {
29 + "node": ">=0.1.90"
30 + },
31 + "main": "lib/index.js",
32 + "files": [
33 + "examples",
34 + "lib",
35 + "LICENSE",
36 + "safe.js",
37 + "themes",
38 + "index.d.ts",
39 + "safe.d.ts"
40 + ],
41 + "devDependencies": {
42 + "eslint": "^5.2.0",
43 + "eslint-config-google": "^0.11.0"
44 + }
45 +}
1 +// Type definitions for Colors.js 1.2
2 +// Project: https://github.com/Marak/colors.js
3 +// Definitions by: Bart van der Schoor <https://github.com/Bartvds>, Staffan Eketorp <https://github.com/staeke>
4 +// Definitions: https://github.com/Marak/colors.js
5 +
6 +export const enabled: boolean;
7 +export function enable(): void;
8 +export function disable(): void;
9 +export function setTheme(theme: any): void;
10 +
11 +export function strip(str: string): string;
12 +export function stripColors(str: string): string;
13 +
14 +export function black(str: string): string;
15 +export function red(str: string): string;
16 +export function green(str: string): string;
17 +export function yellow(str: string): string;
18 +export function blue(str: string): string;
19 +export function magenta(str: string): string;
20 +export function cyan(str: string): string;
21 +export function white(str: string): string;
22 +export function gray(str: string): string;
23 +export function grey(str: string): string;
24 +
25 +export function bgBlack(str: string): string;
26 +export function bgRed(str: string): string;
27 +export function bgGreen(str: string): string;
28 +export function bgYellow(str: string): string;
29 +export function bgBlue(str: string): string;
30 +export function bgMagenta(str: string): string;
31 +export function bgCyan(str: string): string;
32 +export function bgWhite(str: string): string;
33 +
34 +export function reset(str: string): string;
35 +export function bold(str: string): string;
36 +export function dim(str: string): string;
37 +export function italic(str: string): string;
38 +export function underline(str: string): string;
39 +export function inverse(str: string): string;
40 +export function hidden(str: string): string;
41 +export function strikethrough(str: string): string;
42 +
43 +export function rainbow(str: string): string;
44 +export function zebra(str: string): string;
45 +export function america(str: string): string;
46 +export function trap(str: string): string;
47 +export function random(str: string): string;
48 +export function zalgo(str: string): string;
1 +//
2 +// Remark: Requiring this file will use the "safe" colors API,
3 +// which will not touch String.prototype.
4 +//
5 +// var colors = require('colors/safe');
6 +// colors.red("foo")
7 +//
8 +//
9 +var colors = require('./lib/colors');
10 +module['exports'] = colors;
1 +module['exports'] = {
2 + silly: 'rainbow',
3 + input: 'grey',
4 + verbose: 'cyan',
5 + prompt: 'grey',
6 + info: 'green',
7 + data: 'grey',
8 + help: 'cyan',
9 + warn: 'yellow',
10 + debug: 'blue',
11 + error: 'red',
12 +};
1 +1.3.8 / 2022-02-02
2 +==================
3 +
4 + * deps: mime-types@~2.1.34
5 + - deps: mime-db@~1.51.0
6 + * deps: negotiator@0.6.3
7 +
8 +1.3.7 / 2019-04-29
9 +==================
10 +
11 + * deps: negotiator@0.6.2
12 + - Fix sorting charset, encoding, and language with extra parameters
13 +
14 +1.3.6 / 2019-04-28
15 +==================
16 +
17 + * deps: mime-types@~2.1.24
18 + - deps: mime-db@~1.40.0
19 +
20 +1.3.5 / 2018-02-28
21 +==================
22 +
23 + * deps: mime-types@~2.1.18
24 + - deps: mime-db@~1.33.0
25 +
26 +1.3.4 / 2017-08-22
27 +==================
28 +
29 + * deps: mime-types@~2.1.16
30 + - deps: mime-db@~1.29.0
31 +
32 +1.3.3 / 2016-05-02
33 +==================
34 +
35 + * deps: mime-types@~2.1.11
36 + - deps: mime-db@~1.23.0
37 + * deps: negotiator@0.6.1
38 + - perf: improve `Accept` parsing speed
39 + - perf: improve `Accept-Charset` parsing speed
40 + - perf: improve `Accept-Encoding` parsing speed
41 + - perf: improve `Accept-Language` parsing speed
42 +
43 +1.3.2 / 2016-03-08
44 +==================
45 +
46 + * deps: mime-types@~2.1.10
47 + - Fix extension of `application/dash+xml`
48 + - Update primary extension for `audio/mp4`
49 + - deps: mime-db@~1.22.0
50 +
51 +1.3.1 / 2016-01-19
52 +==================
53 +
54 + * deps: mime-types@~2.1.9
55 + - deps: mime-db@~1.21.0
56 +
57 +1.3.0 / 2015-09-29
58 +==================
59 +
60 + * deps: mime-types@~2.1.7
61 + - deps: mime-db@~1.19.0
62 + * deps: negotiator@0.6.0
63 + - Fix including type extensions in parameters in `Accept` parsing
64 + - Fix parsing `Accept` parameters with quoted equals
65 + - Fix parsing `Accept` parameters with quoted semicolons
66 + - Lazy-load modules from main entry point
67 + - perf: delay type concatenation until needed
68 + - perf: enable strict mode
69 + - perf: hoist regular expressions
70 + - perf: remove closures getting spec properties
71 + - perf: remove a closure from media type parsing
72 + - perf: remove property delete from media type parsing
73 +
74 +1.2.13 / 2015-09-06
75 +===================
76 +
77 + * deps: mime-types@~2.1.6
78 + - deps: mime-db@~1.18.0
79 +
80 +1.2.12 / 2015-07-30
81 +===================
82 +
83 + * deps: mime-types@~2.1.4
84 + - deps: mime-db@~1.16.0
85 +
86 +1.2.11 / 2015-07-16
87 +===================
88 +
89 + * deps: mime-types@~2.1.3
90 + - deps: mime-db@~1.15.0
91 +
92 +1.2.10 / 2015-07-01
93 +===================
94 +
95 + * deps: mime-types@~2.1.2
96 + - deps: mime-db@~1.14.0
97 +
98 +1.2.9 / 2015-06-08
99 +==================
100 +
101 + * deps: mime-types@~2.1.1
102 + - perf: fix deopt during mapping
103 +
104 +1.2.8 / 2015-06-07
105 +==================
106 +
107 + * deps: mime-types@~2.1.0
108 + - deps: mime-db@~1.13.0
109 + * perf: avoid argument reassignment & argument slice
110 + * perf: avoid negotiator recursive construction
111 + * perf: enable strict mode
112 + * perf: remove unnecessary bitwise operator
113 +
114 +1.2.7 / 2015-05-10
115 +==================
116 +
117 + * deps: negotiator@0.5.3
118 + - Fix media type parameter matching to be case-insensitive
119 +
120 +1.2.6 / 2015-05-07
121 +==================
122 +
123 + * deps: mime-types@~2.0.11
124 + - deps: mime-db@~1.9.1
125 + * deps: negotiator@0.5.2
126 + - Fix comparing media types with quoted values
127 + - Fix splitting media types with quoted commas
128 +
129 +1.2.5 / 2015-03-13
130 +==================
131 +
132 + * deps: mime-types@~2.0.10
133 + - deps: mime-db@~1.8.0
134 +
135 +1.2.4 / 2015-02-14
136 +==================
137 +
138 + * Support Node.js 0.6
139 + * deps: mime-types@~2.0.9
140 + - deps: mime-db@~1.7.0
141 + * deps: negotiator@0.5.1
142 + - Fix preference sorting to be stable for long acceptable lists
143 +
144 +1.2.3 / 2015-01-31
145 +==================
146 +
147 + * deps: mime-types@~2.0.8
148 + - deps: mime-db@~1.6.0
149 +
150 +1.2.2 / 2014-12-30
151 +==================
152 +
153 + * deps: mime-types@~2.0.7
154 + - deps: mime-db@~1.5.0
155 +
156 +1.2.1 / 2014-12-30
157 +==================
158 +
159 + * deps: mime-types@~2.0.5
160 + - deps: mime-db@~1.3.1
161 +
162 +1.2.0 / 2014-12-19
163 +==================
164 +
165 + * deps: negotiator@0.5.0
166 + - Fix list return order when large accepted list
167 + - Fix missing identity encoding when q=0 exists
168 + - Remove dynamic building of Negotiator class
169 +
170 +1.1.4 / 2014-12-10
171 +==================
172 +
173 + * deps: mime-types@~2.0.4
174 + - deps: mime-db@~1.3.0
175 +
176 +1.1.3 / 2014-11-09
177 +==================
178 +
179 + * deps: mime-types@~2.0.3
180 + - deps: mime-db@~1.2.0
181 +
182 +1.1.2 / 2014-10-14
183 +==================
184 +
185 + * deps: negotiator@0.4.9
186 + - Fix error when media type has invalid parameter
187 +
188 +1.1.1 / 2014-09-28
189 +==================
190 +
191 + * deps: mime-types@~2.0.2
192 + - deps: mime-db@~1.1.0
193 + * deps: negotiator@0.4.8
194 + - Fix all negotiations to be case-insensitive
195 + - Stable sort preferences of same quality according to client order
196 +
197 +1.1.0 / 2014-09-02
198 +==================
199 +
200 + * update `mime-types`
201 +
202 +1.0.7 / 2014-07-04
203 +==================
204 +
205 + * Fix wrong type returned from `type` when match after unknown extension
206 +
207 +1.0.6 / 2014-06-24
208 +==================
209 +
210 + * deps: negotiator@0.4.7
211 +
212 +1.0.5 / 2014-06-20
213 +==================
214 +
215 + * fix crash when unknown extension given
216 +
217 +1.0.4 / 2014-06-19
218 +==================
219 +
220 + * use `mime-types`
221 +
222 +1.0.3 / 2014-06-11
223 +==================
224 +
225 + * deps: negotiator@0.4.6
226 + - Order by specificity when quality is the same
227 +
228 +1.0.2 / 2014-05-29
229 +==================
230 +
231 + * Fix interpretation when header not in request
232 + * deps: pin negotiator@0.4.5
233 +
234 +1.0.1 / 2014-01-18
235 +==================
236 +
237 + * Identity encoding isn't always acceptable
238 + * deps: negotiator@~0.4.0
239 +
240 +1.0.0 / 2013-12-27
241 +==================
242 +
243 + * Genesis
1 +(The MIT License)
2 +
3 +Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
4 +Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining
7 +a copy of this software and associated documentation files (the
8 +'Software'), to deal in the Software without restriction, including
9 +without limitation the rights to use, copy, modify, merge, publish,
10 +distribute, sublicense, and/or sell copies of the Software, and to
11 +permit persons to whom the Software is furnished to do so, subject to
12 +the following conditions:
13 +
14 +The above copyright notice and this permission notice shall be
15 +included in all copies or substantial portions of the Software.
16 +
17 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +# accepts
2 +
3 +[![NPM Version][npm-version-image]][npm-url]
4 +[![NPM Downloads][npm-downloads-image]][npm-url]
5 +[![Node.js Version][node-version-image]][node-version-url]
6 +[![Build Status][github-actions-ci-image]][github-actions-ci-url]
7 +[![Test Coverage][coveralls-image]][coveralls-url]
8 +
9 +Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator).
10 +Extracted from [koa](https://www.npmjs.com/package/koa) for general use.
11 +
12 +In addition to negotiator, it allows:
13 +
14 +- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])`
15 + as well as `('text/html', 'application/json')`.
16 +- Allows type shorthands such as `json`.
17 +- Returns `false` when no types match
18 +- Treats non-existent headers as `*`
19 +
20 +## Installation
21 +
22 +This is a [Node.js](https://nodejs.org/en/) module available through the
23 +[npm registry](https://www.npmjs.com/). Installation is done using the
24 +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
25 +
26 +```sh
27 +$ npm install accepts
28 +```
29 +
30 +## API
31 +
32 +```js
33 +var accepts = require('accepts')
34 +```
35 +
36 +### accepts(req)
37 +
38 +Create a new `Accepts` object for the given `req`.
39 +
40 +#### .charset(charsets)
41 +
42 +Return the first accepted charset. If nothing in `charsets` is accepted,
43 +then `false` is returned.
44 +
45 +#### .charsets()
46 +
47 +Return the charsets that the request accepts, in the order of the client's
48 +preference (most preferred first).
49 +
50 +#### .encoding(encodings)
51 +
52 +Return the first accepted encoding. If nothing in `encodings` is accepted,
53 +then `false` is returned.
54 +
55 +#### .encodings()
56 +
57 +Return the encodings that the request accepts, in the order of the client's
58 +preference (most preferred first).
59 +
60 +#### .language(languages)
61 +
62 +Return the first accepted language. If nothing in `languages` is accepted,
63 +then `false` is returned.
64 +
65 +#### .languages()
66 +
67 +Return the languages that the request accepts, in the order of the client's
68 +preference (most preferred first).
69 +
70 +#### .type(types)
71 +
72 +Return the first accepted type (and it is returned as the same text as what
73 +appears in the `types` array). If nothing in `types` is accepted, then `false`
74 +is returned.
75 +
76 +The `types` array can contain full MIME types or file extensions. Any value
77 +that is not a full MIME types is passed to `require('mime-types').lookup`.
78 +
79 +#### .types()
80 +
81 +Return the types that the request accepts, in the order of the client's
82 +preference (most preferred first).
83 +
84 +## Examples
85 +
86 +### Simple type negotiation
87 +
88 +This simple example shows how to use `accepts` to return a different typed
89 +respond body based on what the client wants to accept. The server lists it's
90 +preferences in order and will get back the best match between the client and
91 +server.
92 +
93 +```js
94 +var accepts = require('accepts')
95 +var http = require('http')
96 +
97 +function app (req, res) {
98 + var accept = accepts(req)
99 +
100 + // the order of this list is significant; should be server preferred order
101 + switch (accept.type(['json', 'html'])) {
102 + case 'json':
103 + res.setHeader('Content-Type', 'application/json')
104 + res.write('{"hello":"world!"}')
105 + break
106 + case 'html':
107 + res.setHeader('Content-Type', 'text/html')
108 + res.write('<b>hello, world!</b>')
109 + break
110 + default:
111 + // the fallback is text/plain, so no need to specify it above
112 + res.setHeader('Content-Type', 'text/plain')
113 + res.write('hello, world!')
114 + break
115 + }
116 +
117 + res.end()
118 +}
119 +
120 +http.createServer(app).listen(3000)
121 +```
122 +
123 +You can test this out with the cURL program:
124 +```sh
125 +curl -I -H'Accept: text/html' http://localhost:3000/
126 +```
127 +
128 +## License
129 +
130 +[MIT](LICENSE)
131 +
132 +[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master
133 +[coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master
134 +[github-actions-ci-image]: https://badgen.net/github/checks/jshttp/accepts/master?label=ci
135 +[github-actions-ci-url]: https://github.com/jshttp/accepts/actions/workflows/ci.yml
136 +[node-version-image]: https://badgen.net/npm/node/accepts
137 +[node-version-url]: https://nodejs.org/en/download
138 +[npm-downloads-image]: https://badgen.net/npm/dm/accepts
139 +[npm-url]: https://npmjs.org/package/accepts
140 +[npm-version-image]: https://badgen.net/npm/v/accepts
1 +/*!
2 + * accepts
3 + * Copyright(c) 2014 Jonathan Ong
4 + * Copyright(c) 2015 Douglas Christopher Wilson
5 + * MIT Licensed
6 + */
7 +
8 +'use strict'
9 +
10 +/**
11 + * Module dependencies.
12 + * @private
13 + */
14 +
15 +var Negotiator = require('negotiator')
16 +var mime = require('mime-types')
17 +
18 +/**
19 + * Module exports.
20 + * @public
21 + */
22 +
23 +module.exports = Accepts
24 +
25 +/**
26 + * Create a new Accepts object for the given req.
27 + *
28 + * @param {object} req
29 + * @public
30 + */
31 +
32 +function Accepts (req) {
33 + if (!(this instanceof Accepts)) {
34 + return new Accepts(req)
35 + }
36 +
37 + this.headers = req.headers
38 + this.negotiator = new Negotiator(req)
39 +}
40 +
41 +/**
42 + * Check if the given `type(s)` is acceptable, returning
43 + * the best match when true, otherwise `undefined`, in which
44 + * case you should respond with 406 "Not Acceptable".
45 + *
46 + * The `type` value may be a single mime type string
47 + * such as "application/json", the extension name
48 + * such as "json" or an array `["json", "html", "text/plain"]`. When a list
49 + * or array is given the _best_ match, if any is returned.
50 + *
51 + * Examples:
52 + *
53 + * // Accept: text/html
54 + * this.types('html');
55 + * // => "html"
56 + *
57 + * // Accept: text/*, application/json
58 + * this.types('html');
59 + * // => "html"
60 + * this.types('text/html');
61 + * // => "text/html"
62 + * this.types('json', 'text');
63 + * // => "json"
64 + * this.types('application/json');
65 + * // => "application/json"
66 + *
67 + * // Accept: text/*, application/json
68 + * this.types('image/png');
69 + * this.types('png');
70 + * // => undefined
71 + *
72 + * // Accept: text/*;q=.5, application/json
73 + * this.types(['html', 'json']);
74 + * this.types('html', 'json');
75 + * // => "json"
76 + *
77 + * @param {String|Array} types...
78 + * @return {String|Array|Boolean}
79 + * @public
80 + */
81 +
82 +Accepts.prototype.type =
83 +Accepts.prototype.types = function (types_) {
84 + var types = types_
85 +
86 + // support flattened arguments
87 + if (types && !Array.isArray(types)) {
88 + types = new Array(arguments.length)
89 + for (var i = 0; i < types.length; i++) {
90 + types[i] = arguments[i]
91 + }
92 + }
93 +
94 + // no types, return all requested types
95 + if (!types || types.length === 0) {
96 + return this.negotiator.mediaTypes()
97 + }
98 +
99 + // no accept header, return first given type
100 + if (!this.headers.accept) {
101 + return types[0]
102 + }
103 +
104 + var mimes = types.map(extToMime)
105 + var accepts = this.negotiator.mediaTypes(mimes.filter(validMime))
106 + var first = accepts[0]
107 +
108 + return first
109 + ? types[mimes.indexOf(first)]
110 + : false
111 +}
112 +
113 +/**
114 + * Return accepted encodings or best fit based on `encodings`.
115 + *
116 + * Given `Accept-Encoding: gzip, deflate`
117 + * an array sorted by quality is returned:
118 + *
119 + * ['gzip', 'deflate']
120 + *
121 + * @param {String|Array} encodings...
122 + * @return {String|Array}
123 + * @public
124 + */
125 +
126 +Accepts.prototype.encoding =
127 +Accepts.prototype.encodings = function (encodings_) {
128 + var encodings = encodings_
129 +
130 + // support flattened arguments
131 + if (encodings && !Array.isArray(encodings)) {
132 + encodings = new Array(arguments.length)
133 + for (var i = 0; i < encodings.length; i++) {
134 + encodings[i] = arguments[i]
135 + }
136 + }
137 +
138 + // no encodings, return all requested encodings
139 + if (!encodings || encodings.length === 0) {
140 + return this.negotiator.encodings()
141 + }
142 +
143 + return this.negotiator.encodings(encodings)[0] || false
144 +}
145 +
146 +/**
147 + * Return accepted charsets or best fit based on `charsets`.
148 + *
149 + * Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
150 + * an array sorted by quality is returned:
151 + *
152 + * ['utf-8', 'utf-7', 'iso-8859-1']
153 + *
154 + * @param {String|Array} charsets...
155 + * @return {String|Array}
156 + * @public
157 + */
158 +
159 +Accepts.prototype.charset =
160 +Accepts.prototype.charsets = function (charsets_) {
161 + var charsets = charsets_
162 +
163 + // support flattened arguments
164 + if (charsets && !Array.isArray(charsets)) {
165 + charsets = new Array(arguments.length)
166 + for (var i = 0; i < charsets.length; i++) {
167 + charsets[i] = arguments[i]
168 + }
169 + }
170 +
171 + // no charsets, return all requested charsets
172 + if (!charsets || charsets.length === 0) {
173 + return this.negotiator.charsets()
174 + }
175 +
176 + return this.negotiator.charsets(charsets)[0] || false
177 +}
178 +
179 +/**
180 + * Return accepted languages or best fit based on `langs`.
181 + *
182 + * Given `Accept-Language: en;q=0.8, es, pt`
183 + * an array sorted by quality is returned:
184 + *
185 + * ['es', 'pt', 'en']
186 + *
187 + * @param {String|Array} langs...
188 + * @return {Array|String}
189 + * @public
190 + */
191 +
192 +Accepts.prototype.lang =
193 +Accepts.prototype.langs =
194 +Accepts.prototype.language =
195 +Accepts.prototype.languages = function (languages_) {
196 + var languages = languages_
197 +
198 + // support flattened arguments
199 + if (languages && !Array.isArray(languages)) {
200 + languages = new Array(arguments.length)
201 + for (var i = 0; i < languages.length; i++) {
202 + languages[i] = arguments[i]
203 + }
204 + }
205 +
206 + // no languages, return all requested languages
207 + if (!languages || languages.length === 0) {
208 + return this.negotiator.languages()
209 + }
210 +
211 + return this.negotiator.languages(languages)[0] || false
212 +}
213 +
214 +/**
215 + * Convert extnames to mime.
216 + *
217 + * @param {String} type
218 + * @return {String}
219 + * @private
220 + */
221 +
222 +function extToMime (type) {
223 + return type.indexOf('/') === -1
224 + ? mime.lookup(type)
225 + : type
226 +}
227 +
228 +/**
229 + * Check if mime is valid.
230 + *
231 + * @param {String} type
232 + * @return {String}
233 + * @private
234 + */
235 +
236 +function validMime (type) {
237 + return typeof type === 'string'
238 +}
1 +{
2 + "name": "accepts",
3 + "description": "Higher-level content negotiation",
4 + "version": "1.3.8",
5 + "contributors": [
6 + "Douglas Christopher Wilson <doug@somethingdoug.com>",
7 + "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
8 + ],
9 + "license": "MIT",
10 + "repository": "jshttp/accepts",
11 + "dependencies": {
12 + "mime-types": "~2.1.34",
13 + "negotiator": "0.6.3"
14 + },
15 + "devDependencies": {
16 + "deep-equal": "1.0.1",
17 + "eslint": "7.32.0",
18 + "eslint-config-standard": "14.1.1",
19 + "eslint-plugin-import": "2.25.4",
20 + "eslint-plugin-markdown": "2.2.1",
21 + "eslint-plugin-node": "11.1.0",
22 + "eslint-plugin-promise": "4.3.1",
23 + "eslint-plugin-standard": "4.1.0",
24 + "mocha": "9.2.0",
25 + "nyc": "15.1.0"
26 + },
27 + "files": [
28 + "LICENSE",
29 + "HISTORY.md",
30 + "index.js"
31 + ],
32 + "engines": {
33 + "node": ">= 0.6"
34 + },
35 + "scripts": {
36 + "lint": "eslint .",
37 + "test": "mocha --reporter spec --check-leaks --bail test/",
38 + "test-ci": "nyc --reporter=lcov --reporter=text npm test",
39 + "test-cov": "nyc --reporter=html --reporter=text npm test"
40 + },
41 + "keywords": [
42 + "content",
43 + "negotiation",
44 + "accept",
45 + "accepts"
46 + ]
47 +}
1 +var Ajv = require('ajv');
2 +var ajv = new Ajv({allErrors: true});
3 +
4 +var schema = {
5 + "properties": {
6 + "foo": { "type": "string" },
7 + "bar": { "type": "number", "maximum": 3 }
8 + }
9 +};
10 +
11 +var validate = ajv.compile(schema);
12 +
13 +test({"foo": "abc", "bar": 2});
14 +test({"foo": 2, "bar": 4});
15 +
16 +function test(data) {
17 + var valid = validate(data);
18 + if (valid) console.log('Valid!');
19 + else console.log('Invalid: ' + ajv.errorsText(validate.errors));
20 +}
...\ No newline at end of file ...\ No newline at end of file
1 +The MIT License (MIT)
2 +
3 +Copyright (c) 2015-2017 Evgeny Poberezkin
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.
22 +
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
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.
1 +'use strict';
2 +
3 +
4 +var Cache = module.exports = function Cache() {
5 + this._cache = {};
6 +};
7 +
8 +
9 +Cache.prototype.put = function Cache_put(key, value) {
10 + this._cache[key] = value;
11 +};
12 +
13 +
14 +Cache.prototype.get = function Cache_get(key) {
15 + return this._cache[key];
16 +};
17 +
18 +
19 +Cache.prototype.del = function Cache_del(key) {
20 + delete this._cache[key];
21 +};
22 +
23 +
24 +Cache.prototype.clear = function Cache_clear() {
25 + this._cache = {};
26 +};
1 +'use strict';
2 +
3 +var MissingRefError = require('./error_classes').MissingRef;
4 +
5 +module.exports = compileAsync;
6 +
7 +
8 +/**
9 + * Creates validating function for passed schema with asynchronous loading of missing schemas.
10 + * `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema.
11 + * @this Ajv
12 + * @param {Object} schema schema object
13 + * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
14 + * @param {Function} callback an optional node-style callback, it is called with 2 parameters: error (or null) and validating function.
15 + * @return {Promise} promise that resolves with a validating function.
16 + */
17 +function compileAsync(schema, meta, callback) {
18 + /* eslint no-shadow: 0 */
19 + /* global Promise */
20 + /* jshint validthis: true */
21 + var self = this;
22 + if (typeof this._opts.loadSchema != 'function')
23 + throw new Error('options.loadSchema should be a function');
24 +
25 + if (typeof meta == 'function') {
26 + callback = meta;
27 + meta = undefined;
28 + }
29 +
30 + var p = loadMetaSchemaOf(schema).then(function () {
31 + var schemaObj = self._addSchema(schema, undefined, meta);
32 + return schemaObj.validate || _compileAsync(schemaObj);
33 + });
34 +
35 + if (callback) {
36 + p.then(
37 + function(v) { callback(null, v); },
38 + callback
39 + );
40 + }
41 +
42 + return p;
43 +
44 +
45 + function loadMetaSchemaOf(sch) {
46 + var $schema = sch.$schema;
47 + return $schema && !self.getSchema($schema)
48 + ? compileAsync.call(self, { $ref: $schema }, true)
49 + : Promise.resolve();
50 + }
51 +
52 +
53 + function _compileAsync(schemaObj) {
54 + try { return self._compile(schemaObj); }
55 + catch(e) {
56 + if (e instanceof MissingRefError) return loadMissingSchema(e);
57 + throw e;
58 + }
59 +
60 +
61 + function loadMissingSchema(e) {
62 + var ref = e.missingSchema;
63 + if (added(ref)) throw new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved');
64 +
65 + var schemaPromise = self._loadingSchemas[ref];
66 + if (!schemaPromise) {
67 + schemaPromise = self._loadingSchemas[ref] = self._opts.loadSchema(ref);
68 + schemaPromise.then(removePromise, removePromise);
69 + }
70 +
71 + return schemaPromise.then(function (sch) {
72 + if (!added(ref)) {
73 + return loadMetaSchemaOf(sch).then(function () {
74 + if (!added(ref)) self.addSchema(sch, ref, undefined, meta);
75 + });
76 + }
77 + }).then(function() {
78 + return _compileAsync(schemaObj);
79 + });
80 +
81 + function removePromise() {
82 + delete self._loadingSchemas[ref];
83 + }
84 +
85 + function added(ref) {
86 + return self._refs[ref] || self._schemas[ref];
87 + }
88 + }
89 + }
90 +}
1 +'use strict';
2 +
3 +// do NOT remove this file - it would break pre-compiled schemas
4 +// https://github.com/ajv-validator/ajv/issues/889
5 +module.exports = require('fast-deep-equal');
1 +'use strict';
2 +
3 +var resolve = require('./resolve');
4 +
5 +module.exports = {
6 + Validation: errorSubclass(ValidationError),
7 + MissingRef: errorSubclass(MissingRefError)
8 +};
9 +
10 +
11 +function ValidationError(errors) {
12 + this.message = 'validation failed';
13 + this.errors = errors;
14 + this.ajv = this.validation = true;
15 +}
16 +
17 +
18 +MissingRefError.message = function (baseId, ref) {
19 + return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
20 +};
21 +
22 +
23 +function MissingRefError(baseId, ref, message) {
24 + this.message = message || MissingRefError.message(baseId, ref);
25 + this.missingRef = resolve.url(baseId, ref);
26 + this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
27 +}
28 +
29 +
30 +function errorSubclass(Subclass) {
31 + Subclass.prototype = Object.create(Error.prototype);
32 + Subclass.prototype.constructor = Subclass;
33 + return Subclass;
34 +}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +'use strict';
2 +
3 +var URI = require('uri-js')
4 + , equal = require('fast-deep-equal')
5 + , util = require('./util')
6 + , SchemaObject = require('./schema_obj')
7 + , traverse = require('json-schema-traverse');
8 +
9 +module.exports = resolve;
10 +
11 +resolve.normalizeId = normalizeId;
12 +resolve.fullPath = getFullPath;
13 +resolve.url = resolveUrl;
14 +resolve.ids = resolveIds;
15 +resolve.inlineRef = inlineRef;
16 +resolve.schema = resolveSchema;
17 +
18 +/**
19 + * [resolve and compile the references ($ref)]
20 + * @this Ajv
21 + * @param {Function} compile reference to schema compilation funciton (localCompile)
22 + * @param {Object} root object with information about the root schema for the current schema
23 + * @param {String} ref reference to resolve
24 + * @return {Object|Function} schema object (if the schema can be inlined) or validation function
25 + */
26 +function resolve(compile, root, ref) {
27 + /* jshint validthis: true */
28 + var refVal = this._refs[ref];
29 + if (typeof refVal == 'string') {
30 + if (this._refs[refVal]) refVal = this._refs[refVal];
31 + else return resolve.call(this, compile, root, refVal);
32 + }
33 +
34 + refVal = refVal || this._schemas[ref];
35 + if (refVal instanceof SchemaObject) {
36 + return inlineRef(refVal.schema, this._opts.inlineRefs)
37 + ? refVal.schema
38 + : refVal.validate || this._compile(refVal);
39 + }
40 +
41 + var res = resolveSchema.call(this, root, ref);
42 + var schema, v, baseId;
43 + if (res) {
44 + schema = res.schema;
45 + root = res.root;
46 + baseId = res.baseId;
47 + }
48 +
49 + if (schema instanceof SchemaObject) {
50 + v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
51 + } else if (schema !== undefined) {
52 + v = inlineRef(schema, this._opts.inlineRefs)
53 + ? schema
54 + : compile.call(this, schema, root, undefined, baseId);
55 + }
56 +
57 + return v;
58 +}
59 +
60 +
61 +/**
62 + * Resolve schema, its root and baseId
63 + * @this Ajv
64 + * @param {Object} root root object with properties schema, refVal, refs
65 + * @param {String} ref reference to resolve
66 + * @return {Object} object with properties schema, root, baseId
67 + */
68 +function resolveSchema(root, ref) {
69 + /* jshint validthis: true */
70 + var p = URI.parse(ref)
71 + , refPath = _getFullPath(p)
72 + , baseId = getFullPath(this._getId(root.schema));
73 + if (Object.keys(root.schema).length === 0 || refPath !== baseId) {
74 + var id = normalizeId(refPath);
75 + var refVal = this._refs[id];
76 + if (typeof refVal == 'string') {
77 + return resolveRecursive.call(this, root, refVal, p);
78 + } else if (refVal instanceof SchemaObject) {
79 + if (!refVal.validate) this._compile(refVal);
80 + root = refVal;
81 + } else {
82 + refVal = this._schemas[id];
83 + if (refVal instanceof SchemaObject) {
84 + if (!refVal.validate) this._compile(refVal);
85 + if (id == normalizeId(ref))
86 + return { schema: refVal, root: root, baseId: baseId };
87 + root = refVal;
88 + } else {
89 + return;
90 + }
91 + }
92 + if (!root.schema) return;
93 + baseId = getFullPath(this._getId(root.schema));
94 + }
95 + return getJsonPointer.call(this, p, baseId, root.schema, root);
96 +}
97 +
98 +
99 +/* @this Ajv */
100 +function resolveRecursive(root, ref, parsedRef) {
101 + /* jshint validthis: true */
102 + var res = resolveSchema.call(this, root, ref);
103 + if (res) {
104 + var schema = res.schema;
105 + var baseId = res.baseId;
106 + root = res.root;
107 + var id = this._getId(schema);
108 + if (id) baseId = resolveUrl(baseId, id);
109 + return getJsonPointer.call(this, parsedRef, baseId, schema, root);
110 + }
111 +}
112 +
113 +
114 +var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
115 +/* @this Ajv */
116 +function getJsonPointer(parsedRef, baseId, schema, root) {
117 + /* jshint validthis: true */
118 + parsedRef.fragment = parsedRef.fragment || '';
119 + if (parsedRef.fragment.slice(0,1) != '/') return;
120 + var parts = parsedRef.fragment.split('/');
121 +
122 + for (var i = 1; i < parts.length; i++) {
123 + var part = parts[i];
124 + if (part) {
125 + part = util.unescapeFragment(part);
126 + schema = schema[part];
127 + if (schema === undefined) break;
128 + var id;
129 + if (!PREVENT_SCOPE_CHANGE[part]) {
130 + id = this._getId(schema);
131 + if (id) baseId = resolveUrl(baseId, id);
132 + if (schema.$ref) {
133 + var $ref = resolveUrl(baseId, schema.$ref);
134 + var res = resolveSchema.call(this, root, $ref);
135 + if (res) {
136 + schema = res.schema;
137 + root = res.root;
138 + baseId = res.baseId;
139 + }
140 + }
141 + }
142 + }
143 + }
144 + if (schema !== undefined && schema !== root.schema)
145 + return { schema: schema, root: root, baseId: baseId };
146 +}
147 +
148 +
149 +var SIMPLE_INLINED = util.toHash([
150 + 'type', 'format', 'pattern',
151 + 'maxLength', 'minLength',
152 + 'maxProperties', 'minProperties',
153 + 'maxItems', 'minItems',
154 + 'maximum', 'minimum',
155 + 'uniqueItems', 'multipleOf',
156 + 'required', 'enum'
157 +]);
158 +function inlineRef(schema, limit) {
159 + if (limit === false) return false;
160 + if (limit === undefined || limit === true) return checkNoRef(schema);
161 + else if (limit) return countKeys(schema) <= limit;
162 +}
163 +
164 +
165 +function checkNoRef(schema) {
166 + var item;
167 + if (Array.isArray(schema)) {
168 + for (var i=0; i<schema.length; i++) {
169 + item = schema[i];
170 + if (typeof item == 'object' && !checkNoRef(item)) return false;
171 + }
172 + } else {
173 + for (var key in schema) {
174 + if (key == '$ref') return false;
175 + item = schema[key];
176 + if (typeof item == 'object' && !checkNoRef(item)) return false;
177 + }
178 + }
179 + return true;
180 +}
181 +
182 +
183 +function countKeys(schema) {
184 + var count = 0, item;
185 + if (Array.isArray(schema)) {
186 + for (var i=0; i<schema.length; i++) {
187 + item = schema[i];
188 + if (typeof item == 'object') count += countKeys(item);
189 + if (count == Infinity) return Infinity;
190 + }
191 + } else {
192 + for (var key in schema) {
193 + if (key == '$ref') return Infinity;
194 + if (SIMPLE_INLINED[key]) {
195 + count++;
196 + } else {
197 + item = schema[key];
198 + if (typeof item == 'object') count += countKeys(item) + 1;
199 + if (count == Infinity) return Infinity;
200 + }
201 + }
202 + }
203 + return count;
204 +}
205 +
206 +
207 +function getFullPath(id, normalize) {
208 + if (normalize !== false) id = normalizeId(id);
209 + var p = URI.parse(id);
210 + return _getFullPath(p);
211 +}
212 +
213 +
214 +function _getFullPath(p) {
215 + return URI.serialize(p).split('#')[0] + '#';
216 +}
217 +
218 +
219 +var TRAILING_SLASH_HASH = /#\/?$/;
220 +function normalizeId(id) {
221 + return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
222 +}
223 +
224 +
225 +function resolveUrl(baseId, id) {
226 + id = normalizeId(id);
227 + return URI.resolve(baseId, id);
228 +}
229 +
230 +
231 +/* @this Ajv */
232 +function resolveIds(schema) {
233 + var schemaId = normalizeId(this._getId(schema));
234 + var baseIds = {'': schemaId};
235 + var fullPaths = {'': getFullPath(schemaId, false)};
236 + var localRefs = {};
237 + var self = this;
238 +
239 + traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
240 + if (jsonPtr === '') return;
241 + var id = self._getId(sch);
242 + var baseId = baseIds[parentJsonPtr];
243 + var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword;
244 + if (keyIndex !== undefined)
245 + fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex));
246 +
247 + if (typeof id == 'string') {
248 + id = baseId = normalizeId(baseId ? URI.resolve(baseId, id) : id);
249 +
250 + var refVal = self._refs[id];
251 + if (typeof refVal == 'string') refVal = self._refs[refVal];
252 + if (refVal && refVal.schema) {
253 + if (!equal(sch, refVal.schema))
254 + throw new Error('id "' + id + '" resolves to more than one schema');
255 + } else if (id != normalizeId(fullPath)) {
256 + if (id[0] == '#') {
257 + if (localRefs[id] && !equal(sch, localRefs[id]))
258 + throw new Error('id "' + id + '" resolves to more than one schema');
259 + localRefs[id] = sch;
260 + } else {
261 + self._refs[id] = fullPath;
262 + }
263 + }
264 + }
265 + baseIds[jsonPtr] = baseId;
266 + fullPaths[jsonPtr] = fullPath;
267 + });
268 +
269 + return localRefs;
270 +}
1 +'use strict';
2 +
3 +var ruleModules = require('../dotjs')
4 + , toHash = require('./util').toHash;
5 +
6 +module.exports = function rules() {
7 + var RULES = [
8 + { type: 'number',
9 + rules: [ { 'maximum': ['exclusiveMaximum'] },
10 + { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
11 + { type: 'string',
12 + rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
13 + { type: 'array',
14 + rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
15 + { type: 'object',
16 + rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
17 + { 'properties': ['additionalProperties', 'patternProperties'] } ] },
18 + { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
19 + ];
20 +
21 + var ALL = [ 'type', '$comment' ];
22 + var KEYWORDS = [
23 + '$schema', '$id', 'id', '$data', '$async', 'title',
24 + 'description', 'default', 'definitions',
25 + 'examples', 'readOnly', 'writeOnly',
26 + 'contentMediaType', 'contentEncoding',
27 + 'additionalItems', 'then', 'else'
28 + ];
29 + var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
30 + RULES.all = toHash(ALL);
31 + RULES.types = toHash(TYPES);
32 +
33 + RULES.forEach(function (group) {
34 + group.rules = group.rules.map(function (keyword) {
35 + var implKeywords;
36 + if (typeof keyword == 'object') {
37 + var key = Object.keys(keyword)[0];
38 + implKeywords = keyword[key];
39 + keyword = key;
40 + implKeywords.forEach(function (k) {
41 + ALL.push(k);
42 + RULES.all[k] = true;
43 + });
44 + }
45 + ALL.push(keyword);
46 + var rule = RULES.all[keyword] = {
47 + keyword: keyword,
48 + code: ruleModules[keyword],
49 + implements: implKeywords
50 + };
51 + return rule;
52 + });
53 +
54 + RULES.all.$comment = {
55 + keyword: '$comment',
56 + code: ruleModules.$comment
57 + };
58 +
59 + if (group.type) RULES.types[group.type] = group;
60 + });
61 +
62 + RULES.keywords = toHash(ALL.concat(KEYWORDS));
63 + RULES.custom = {};
64 +
65 + return RULES;
66 +};
1 +'use strict';
2 +
3 +var util = require('./util');
4 +
5 +module.exports = SchemaObject;
6 +
7 +function SchemaObject(obj) {
8 + util.copy(obj, this);
9 +}
1 +'use strict';
2 +
3 +// https://mathiasbynens.be/notes/javascript-encoding
4 +// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
5 +module.exports = function ucs2length(str) {
6 + var length = 0
7 + , len = str.length
8 + , pos = 0
9 + , value;
10 + while (pos < len) {
11 + length++;
12 + value = str.charCodeAt(pos++);
13 + if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
14 + // high surrogate, and there is a next character
15 + value = str.charCodeAt(pos);
16 + if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
17 + }
18 + }
19 + return length;
20 +};
1 +'use strict';
2 +
3 +
4 +module.exports = {
5 + copy: copy,
6 + checkDataType: checkDataType,
7 + checkDataTypes: checkDataTypes,
8 + coerceToTypes: coerceToTypes,
9 + toHash: toHash,
10 + getProperty: getProperty,
11 + escapeQuotes: escapeQuotes,
12 + equal: require('fast-deep-equal'),
13 + ucs2length: require('./ucs2length'),
14 + varOccurences: varOccurences,
15 + varReplace: varReplace,
16 + schemaHasRules: schemaHasRules,
17 + schemaHasRulesExcept: schemaHasRulesExcept,
18 + schemaUnknownRules: schemaUnknownRules,
19 + toQuotedString: toQuotedString,
20 + getPathExpr: getPathExpr,
21 + getPath: getPath,
22 + getData: getData,
23 + unescapeFragment: unescapeFragment,
24 + unescapeJsonPointer: unescapeJsonPointer,
25 + escapeFragment: escapeFragment,
26 + escapeJsonPointer: escapeJsonPointer
27 +};
28 +
29 +
30 +function copy(o, to) {
31 + to = to || {};
32 + for (var key in o) to[key] = o[key];
33 + return to;
34 +}
35 +
36 +
37 +function checkDataType(dataType, data, strictNumbers, negate) {
38 + var EQUAL = negate ? ' !== ' : ' === '
39 + , AND = negate ? ' || ' : ' && '
40 + , OK = negate ? '!' : ''
41 + , NOT = negate ? '' : '!';
42 + switch (dataType) {
43 + case 'null': return data + EQUAL + 'null';
44 + case 'array': return OK + 'Array.isArray(' + data + ')';
45 + case 'object': return '(' + OK + data + AND +
46 + 'typeof ' + data + EQUAL + '"object"' + AND +
47 + NOT + 'Array.isArray(' + data + '))';
48 + case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
49 + NOT + '(' + data + ' % 1)' +
50 + AND + data + EQUAL + data +
51 + (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
52 + case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' +
53 + (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
54 + default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
55 + }
56 +}
57 +
58 +
59 +function checkDataTypes(dataTypes, data, strictNumbers) {
60 + switch (dataTypes.length) {
61 + case 1: return checkDataType(dataTypes[0], data, strictNumbers, true);
62 + default:
63 + var code = '';
64 + var types = toHash(dataTypes);
65 + if (types.array && types.object) {
66 + code = types.null ? '(': '(!' + data + ' || ';
67 + code += 'typeof ' + data + ' !== "object")';
68 + delete types.null;
69 + delete types.array;
70 + delete types.object;
71 + }
72 + if (types.number) delete types.integer;
73 + for (var t in types)
74 + code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true);
75 +
76 + return code;
77 + }
78 +}
79 +
80 +
81 +var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
82 +function coerceToTypes(optionCoerceTypes, dataTypes) {
83 + if (Array.isArray(dataTypes)) {
84 + var types = [];
85 + for (var i=0; i<dataTypes.length; i++) {
86 + var t = dataTypes[i];
87 + if (COERCE_TO_TYPES[t]) types[types.length] = t;
88 + else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
89 + }
90 + if (types.length) return types;
91 + } else if (COERCE_TO_TYPES[dataTypes]) {
92 + return [dataTypes];
93 + } else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
94 + return ['array'];
95 + }
96 +}
97 +
98 +
99 +function toHash(arr) {
100 + var hash = {};
101 + for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
102 + return hash;
103 +}
104 +
105 +
106 +var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
107 +var SINGLE_QUOTE = /'|\\/g;
108 +function getProperty(key) {
109 + return typeof key == 'number'
110 + ? '[' + key + ']'
111 + : IDENTIFIER.test(key)
112 + ? '.' + key
113 + : "['" + escapeQuotes(key) + "']";
114 +}
115 +
116 +
117 +function escapeQuotes(str) {
118 + return str.replace(SINGLE_QUOTE, '\\$&')
119 + .replace(/\n/g, '\\n')
120 + .replace(/\r/g, '\\r')
121 + .replace(/\f/g, '\\f')
122 + .replace(/\t/g, '\\t');
123 +}
124 +
125 +
126 +function varOccurences(str, dataVar) {
127 + dataVar += '[^0-9]';
128 + var matches = str.match(new RegExp(dataVar, 'g'));
129 + return matches ? matches.length : 0;
130 +}
131 +
132 +
133 +function varReplace(str, dataVar, expr) {
134 + dataVar += '([^0-9])';
135 + expr = expr.replace(/\$/g, '$$$$');
136 + return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
137 +}
138 +
139 +
140 +function schemaHasRules(schema, rules) {
141 + if (typeof schema == 'boolean') return !schema;
142 + for (var key in schema) if (rules[key]) return true;
143 +}
144 +
145 +
146 +function schemaHasRulesExcept(schema, rules, exceptKeyword) {
147 + if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not';
148 + for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
149 +}
150 +
151 +
152 +function schemaUnknownRules(schema, rules) {
153 + if (typeof schema == 'boolean') return;
154 + for (var key in schema) if (!rules[key]) return key;
155 +}
156 +
157 +
158 +function toQuotedString(str) {
159 + return '\'' + escapeQuotes(str) + '\'';
160 +}
161 +
162 +
163 +function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
164 + var path = jsonPointers // false by default
165 + ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
166 + : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
167 + return joinPaths(currentPath, path);
168 +}
169 +
170 +
171 +function getPath(currentPath, prop, jsonPointers) {
172 + var path = jsonPointers // false by default
173 + ? toQuotedString('/' + escapeJsonPointer(prop))
174 + : toQuotedString(getProperty(prop));
175 + return joinPaths(currentPath, path);
176 +}
177 +
178 +
179 +var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
180 +var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
181 +function getData($data, lvl, paths) {
182 + var up, jsonPointer, data, matches;
183 + if ($data === '') return 'rootData';
184 + if ($data[0] == '/') {
185 + if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
186 + jsonPointer = $data;
187 + data = 'rootData';
188 + } else {
189 + matches = $data.match(RELATIVE_JSON_POINTER);
190 + if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
191 + up = +matches[1];
192 + jsonPointer = matches[2];
193 + if (jsonPointer == '#') {
194 + if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
195 + return paths[lvl - up];
196 + }
197 +
198 + if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
199 + data = 'data' + ((lvl - up) || '');
200 + if (!jsonPointer) return data;
201 + }
202 +
203 + var expr = data;
204 + var segments = jsonPointer.split('/');
205 + for (var i=0; i<segments.length; i++) {
206 + var segment = segments[i];
207 + if (segment) {
208 + data += getProperty(unescapeJsonPointer(segment));
209 + expr += ' && ' + data;
210 + }
211 + }
212 + return expr;
213 +}
214 +
215 +
216 +function joinPaths (a, b) {
217 + if (a == '""') return b;
218 + return (a + ' + ' + b).replace(/([^\\])' \+ '/g, '$1');
219 +}
220 +
221 +
222 +function unescapeFragment(str) {
223 + return unescapeJsonPointer(decodeURIComponent(str));
224 +}
225 +
226 +
227 +function escapeFragment(str) {
228 + return encodeURIComponent(escapeJsonPointer(str));
229 +}
230 +
231 +
232 +function escapeJsonPointer(str) {
233 + return str.replace(/~/g, '~0').replace(/\//g, '~1');
234 +}
235 +
236 +
237 +function unescapeJsonPointer(str) {
238 + return str.replace(/~1/g, '/').replace(/~0/g, '~');
239 +}
1 +'use strict';
2 +
3 +var KEYWORDS = [
4 + 'multipleOf',
5 + 'maximum',
6 + 'exclusiveMaximum',
7 + 'minimum',
8 + 'exclusiveMinimum',
9 + 'maxLength',
10 + 'minLength',
11 + 'pattern',
12 + 'additionalItems',
13 + 'maxItems',
14 + 'minItems',
15 + 'uniqueItems',
16 + 'maxProperties',
17 + 'minProperties',
18 + 'required',
19 + 'additionalProperties',
20 + 'enum',
21 + 'format',
22 + 'const'
23 +];
24 +
25 +module.exports = function (metaSchema, keywordsJsonPointers) {
26 + for (var i=0; i<keywordsJsonPointers.length; i++) {
27 + metaSchema = JSON.parse(JSON.stringify(metaSchema));
28 + var segments = keywordsJsonPointers[i].split('/');
29 + var keywords = metaSchema;
30 + var j;
31 + for (j=1; j<segments.length; j++)
32 + keywords = keywords[segments[j]];
33 +
34 + for (j=0; j<KEYWORDS.length; j++) {
35 + var key = KEYWORDS[j];
36 + var schema = keywords[key];
37 + if (schema) {
38 + keywords[key] = {
39 + anyOf: [
40 + schema,
41 + { $ref: 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
42 + ]
43 + };
44 + }
45 + }
46 + }
47 +
48 + return metaSchema;
49 +};
1 +'use strict';
2 +
3 +var metaSchema = require('./refs/json-schema-draft-07.json');
4 +
5 +module.exports = {
6 + $id: 'https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js',
7 + definitions: {
8 + simpleTypes: metaSchema.definitions.simpleTypes
9 + },
10 + type: 'object',
11 + dependencies: {
12 + schema: ['validate'],
13 + $data: ['validate'],
14 + statements: ['inline'],
15 + valid: {not: {required: ['macro']}}
16 + },
17 + properties: {
18 + type: metaSchema.properties.type,
19 + schema: {type: 'boolean'},
20 + statements: {type: 'boolean'},
21 + dependencies: {
22 + type: 'array',
23 + items: {type: 'string'}
24 + },
25 + metaSchema: {type: 'object'},
26 + modifying: {type: 'boolean'},
27 + valid: {type: 'boolean'},
28 + $data: {type: 'boolean'},
29 + async: {type: 'boolean'},
30 + errors: {
31 + anyOf: [
32 + {type: 'boolean'},
33 + {const: 'full'}
34 + ]
35 + }
36 + }
37 +};
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.$data }}
5 +
6 +{{## def.setExclusiveLimit:
7 + $exclusive = true;
8 + $errorKeyword = $exclusiveKeyword;
9 + $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
10 +#}}
11 +
12 +{{
13 + var $isMax = $keyword == 'maximum'
14 + , $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum'
15 + , $schemaExcl = it.schema[$exclusiveKeyword]
16 + , $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data
17 + , $op = $isMax ? '<' : '>'
18 + , $notOp = $isMax ? '>' : '<'
19 + , $errorKeyword = undefined;
20 +
21 + if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
22 + throw new Error($keyword + ' must be number');
23 + }
24 + if (!($isDataExcl || $schemaExcl === undefined
25 + || typeof $schemaExcl == 'number'
26 + || typeof $schemaExcl == 'boolean')) {
27 + throw new Error($exclusiveKeyword + ' must be number or boolean');
28 + }
29 +}}
30 +
31 +{{? $isDataExcl }}
32 + {{
33 + var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
34 + , $exclusive = 'exclusive' + $lvl
35 + , $exclType = 'exclType' + $lvl
36 + , $exclIsNumber = 'exclIsNumber' + $lvl
37 + , $opExpr = 'op' + $lvl
38 + , $opStr = '\' + ' + $opExpr + ' + \'';
39 + }}
40 + var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
41 + {{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
42 +
43 + var {{=$exclusive}};
44 + var {{=$exclType}} = typeof {{=$schemaValueExcl}};
45 + if ({{=$exclType}} != 'boolean' && {{=$exclType}} != 'undefined' && {{=$exclType}} != 'number') {
46 + {{ var $errorKeyword = $exclusiveKeyword; }}
47 + {{# def.error:'_exclusiveLimit' }}
48 + } else if ({{# def.$dataNotType:'number' }}
49 + {{=$exclType}} == 'number'
50 + ? (
51 + ({{=$exclusive}} = {{=$schemaValue}} === undefined || {{=$schemaValueExcl}} {{=$op}}= {{=$schemaValue}})
52 + ? {{=$data}} {{=$notOp}}= {{=$schemaValueExcl}}
53 + : {{=$data}} {{=$notOp}} {{=$schemaValue}}
54 + )
55 + : (
56 + ({{=$exclusive}} = {{=$schemaValueExcl}} === true)
57 + ? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
58 + : {{=$data}} {{=$notOp}} {{=$schemaValue}}
59 + )
60 + || {{=$data}} !== {{=$data}}) {
61 + var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
62 + {{
63 + if ($schema === undefined) {
64 + $errorKeyword = $exclusiveKeyword;
65 + $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
66 + $schemaValue = $schemaValueExcl;
67 + $isData = $isDataExcl;
68 + }
69 + }}
70 +{{??}}
71 + {{
72 + var $exclIsNumber = typeof $schemaExcl == 'number'
73 + , $opStr = $op; /*used in error*/
74 + }}
75 +
76 + {{? $exclIsNumber && $isData }}
77 + {{ var $opExpr = '\'' + $opStr + '\''; /*used in error*/ }}
78 + if ({{# def.$dataNotType:'number' }}
79 + ( {{=$schemaValue}} === undefined
80 + || {{=$schemaExcl}} {{=$op}}= {{=$schemaValue}}
81 + ? {{=$data}} {{=$notOp}}= {{=$schemaExcl}}
82 + : {{=$data}} {{=$notOp}} {{=$schemaValue}} )
83 + || {{=$data}} !== {{=$data}}) {
84 + {{??}}
85 + {{
86 + if ($exclIsNumber && $schema === undefined) {
87 + {{# def.setExclusiveLimit }}
88 + $schemaValue = $schemaExcl;
89 + $notOp += '=';
90 + } else {
91 + if ($exclIsNumber)
92 + $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
93 +
94 + if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
95 + {{# def.setExclusiveLimit }}
96 + $notOp += '=';
97 + } else {
98 + $exclusive = false;
99 + $opStr += '=';
100 + }
101 + }
102 +
103 + var $opExpr = '\'' + $opStr + '\''; /*used in error*/
104 + }}
105 +
106 + if ({{# def.$dataNotType:'number' }}
107 + {{=$data}} {{=$notOp}} {{=$schemaValue}}
108 + || {{=$data}} !== {{=$data}}) {
109 + {{?}}
110 +{{?}}
111 + {{ $errorKeyword = $errorKeyword || $keyword; }}
112 + {{# def.error:'_limit' }}
113 + } {{? $breakOnError }} else { {{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.$data }}
5 +
6 +{{# def.numberKeyword }}
7 +
8 +{{ var $op = $keyword == 'maxItems' ? '>' : '<'; }}
9 +if ({{# def.$dataNotType:'number' }} {{=$data}}.length {{=$op}} {{=$schemaValue}}) {
10 + {{ var $errorKeyword = $keyword; }}
11 + {{# def.error:'_limitItems' }}
12 +} {{? $breakOnError }} else { {{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.$data }}
5 +
6 +{{# def.numberKeyword }}
7 +
8 +{{ var $op = $keyword == 'maxLength' ? '>' : '<'; }}
9 +if ({{# def.$dataNotType:'number' }} {{# def.strLength }} {{=$op}} {{=$schemaValue}}) {
10 + {{ var $errorKeyword = $keyword; }}
11 + {{# def.error:'_limitLength' }}
12 +} {{? $breakOnError }} else { {{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.$data }}
5 +
6 +{{# def.numberKeyword }}
7 +
8 +{{ var $op = $keyword == 'maxProperties' ? '>' : '<'; }}
9 +if ({{# def.$dataNotType:'number' }} Object.keys({{=$data}}).length {{=$op}} {{=$schemaValue}}) {
10 + {{ var $errorKeyword = $keyword; }}
11 + {{# def.error:'_limitProperties' }}
12 +} {{? $breakOnError }} else { {{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.setupNextLevel }}
5 +
6 +{{
7 + var $currentBaseId = $it.baseId
8 + , $allSchemasEmpty = true;
9 +}}
10 +
11 +{{~ $schema:$sch:$i }}
12 + {{? {{# def.nonEmptySchema:$sch }} }}
13 + {{
14 + $allSchemasEmpty = false;
15 + $it.schema = $sch;
16 + $it.schemaPath = $schemaPath + '[' + $i + ']';
17 + $it.errSchemaPath = $errSchemaPath + '/' + $i;
18 + }}
19 +
20 + {{# def.insertSubschemaCode }}
21 +
22 + {{# def.ifResultValid }}
23 + {{?}}
24 +{{~}}
25 +
26 +{{? $breakOnError }}
27 + {{? $allSchemasEmpty }}
28 + if (true) {
29 + {{??}}
30 + {{= $closingBraces.slice(0,-1) }}
31 + {{?}}
32 +{{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.setupNextLevel }}
5 +
6 +{{
7 + var $noEmptySchema = $schema.every(function($sch) {
8 + return {{# def.nonEmptySchema:$sch }};
9 + });
10 +}}
11 +{{? $noEmptySchema }}
12 + {{ var $currentBaseId = $it.baseId; }}
13 + var {{=$errs}} = errors;
14 + var {{=$valid}} = false;
15 +
16 + {{# def.setCompositeRule }}
17 +
18 + {{~ $schema:$sch:$i }}
19 + {{
20 + $it.schema = $sch;
21 + $it.schemaPath = $schemaPath + '[' + $i + ']';
22 + $it.errSchemaPath = $errSchemaPath + '/' + $i;
23 + }}
24 +
25 + {{# def.insertSubschemaCode }}
26 +
27 + {{=$valid}} = {{=$valid}} || {{=$nextValid}};
28 +
29 + if (!{{=$valid}}) {
30 + {{ $closingBraces += '}'; }}
31 + {{~}}
32 +
33 + {{# def.resetCompositeRule }}
34 +
35 + {{= $closingBraces }}
36 +
37 + if (!{{=$valid}}) {
38 + {{# def.extraError:'anyOf' }}
39 + } else {
40 + {{# def.resetErrors }}
41 + {{? it.opts.allErrors }} } {{?}}
42 +{{??}}
43 + {{? $breakOnError }}
44 + if (true) {
45 + {{?}}
46 +{{?}}
1 +{{## def.coerceType:
2 + {{
3 + var $dataType = 'dataType' + $lvl
4 + , $coerced = 'coerced' + $lvl;
5 + }}
6 + var {{=$dataType}} = typeof {{=$data}};
7 + var {{=$coerced}} = undefined;
8 +
9 + {{? it.opts.coerceTypes == 'array' }}
10 + if ({{=$dataType}} == 'object' && Array.isArray({{=$data}}) && {{=$data}}.length == 1) {
11 + {{=$data}} = {{=$data}}[0];
12 + {{=$dataType}} = typeof {{=$data}};
13 + if ({{=it.util.checkDataType(it.schema.type, $data, it.opts.strictNumbers)}}) {{=$coerced}} = {{=$data}};
14 + }
15 + {{?}}
16 +
17 + if ({{=$coerced}} !== undefined) ;
18 + {{~ $coerceToTypes:$type:$i }}
19 + {{? $type == 'string' }}
20 + else if ({{=$dataType}} == 'number' || {{=$dataType}} == 'boolean')
21 + {{=$coerced}} = '' + {{=$data}};
22 + else if ({{=$data}} === null) {{=$coerced}} = '';
23 + {{?? $type == 'number' || $type == 'integer' }}
24 + else if ({{=$dataType}} == 'boolean' || {{=$data}} === null
25 + || ({{=$dataType}} == 'string' && {{=$data}} && {{=$data}} == +{{=$data}}
26 + {{? $type == 'integer' }} && !({{=$data}} % 1){{?}}))
27 + {{=$coerced}} = +{{=$data}};
28 + {{?? $type == 'boolean' }}
29 + else if ({{=$data}} === 'false' || {{=$data}} === 0 || {{=$data}} === null)
30 + {{=$coerced}} = false;
31 + else if ({{=$data}} === 'true' || {{=$data}} === 1)
32 + {{=$coerced}} = true;
33 + {{?? $type == 'null' }}
34 + else if ({{=$data}} === '' || {{=$data}} === 0 || {{=$data}} === false)
35 + {{=$coerced}} = null;
36 + {{?? it.opts.coerceTypes == 'array' && $type == 'array' }}
37 + else if ({{=$dataType}} == 'string' || {{=$dataType}} == 'number' || {{=$dataType}} == 'boolean' || {{=$data}} == null)
38 + {{=$coerced}} = [{{=$data}}];
39 + {{?}}
40 + {{~}}
41 + else {
42 + {{# def.error:'type' }}
43 + }
44 +
45 + if ({{=$coerced}} !== undefined) {
46 + {{# def.setParentData }}
47 + {{=$data}} = {{=$coerced}};
48 + {{? !$dataLvl }}if ({{=$parentData}} !== undefined){{?}}
49 + {{=$parentData}}[{{=$parentDataProperty}}] = {{=$coerced}};
50 + }
51 +#}}
1 +{{# def.definitions }}
2 +{{# def.setupKeyword }}
3 +
4 +{{ var $comment = it.util.toQuotedString($schema); }}
5 +{{? it.opts.$comment === true }}
6 + console.log({{=$comment}});
7 +{{?? typeof it.opts.$comment == 'function' }}
8 + self._opts.$comment({{=$comment}}, {{=it.util.toQuotedString($errSchemaPath)}}, validate.root.schema);
9 +{{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.$data }}
5 +
6 +{{? !$isData }}
7 + var schema{{=$lvl}} = validate.schema{{=$schemaPath}};
8 +{{?}}
9 +var {{=$valid}} = equal({{=$data}}, schema{{=$lvl}});
10 +{{# def.checkError:'const' }}
11 +{{? $breakOnError }} else { {{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.setupNextLevel }}
5 +
6 +
7 +{{
8 + var $idx = 'i' + $lvl
9 + , $dataNxt = $it.dataLevel = it.dataLevel + 1
10 + , $nextData = 'data' + $dataNxt
11 + , $currentBaseId = it.baseId
12 + , $nonEmptySchema = {{# def.nonEmptySchema:$schema }};
13 +}}
14 +
15 +var {{=$errs}} = errors;
16 +var {{=$valid}};
17 +
18 +{{? $nonEmptySchema }}
19 + {{# def.setCompositeRule }}
20 +
21 + {{
22 + $it.schema = $schema;
23 + $it.schemaPath = $schemaPath;
24 + $it.errSchemaPath = $errSchemaPath;
25 + }}
26 +
27 + var {{=$nextValid}} = false;
28 +
29 + for (var {{=$idx}} = 0; {{=$idx}} < {{=$data}}.length; {{=$idx}}++) {
30 + {{
31 + $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
32 + var $passData = $data + '[' + $idx + ']';
33 + $it.dataPathArr[$dataNxt] = $idx;
34 + }}
35 +
36 + {{# def.generateSubschemaCode }}
37 + {{# def.optimizeValidate }}
38 +
39 + if ({{=$nextValid}}) break;
40 + }
41 +
42 + {{# def.resetCompositeRule }}
43 + {{= $closingBraces }}
44 +
45 + if (!{{=$nextValid}}) {
46 +{{??}}
47 + if ({{=$data}}.length == 0) {
48 +{{?}}
49 +
50 + {{# def.error:'contains' }}
51 + } else {
52 + {{? $nonEmptySchema }}
53 + {{# def.resetErrors }}
54 + {{?}}
55 + {{? it.opts.allErrors }} } {{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.$data }}
5 +
6 +{{
7 + var $rule = this
8 + , $definition = 'definition' + $lvl
9 + , $rDef = $rule.definition
10 + , $closingBraces = '';
11 + var $validate = $rDef.validate;
12 + var $compile, $inline, $macro, $ruleValidate, $validateCode;
13 +}}
14 +
15 +{{? $isData && $rDef.$data }}
16 + {{
17 + $validateCode = 'keywordValidate' + $lvl;
18 + var $validateSchema = $rDef.validateSchema;
19 + }}
20 + var {{=$definition}} = RULES.custom['{{=$keyword}}'].definition;
21 + var {{=$validateCode}} = {{=$definition}}.validate;
22 +{{??}}
23 + {{
24 + $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
25 + if (!$ruleValidate) return;
26 + $schemaValue = 'validate.schema' + $schemaPath;
27 + $validateCode = $ruleValidate.code;
28 + $compile = $rDef.compile;
29 + $inline = $rDef.inline;
30 + $macro = $rDef.macro;
31 + }}
32 +{{?}}
33 +
34 +{{
35 + var $ruleErrs = $validateCode + '.errors'
36 + , $i = 'i' + $lvl
37 + , $ruleErr = 'ruleErr' + $lvl
38 + , $asyncKeyword = $rDef.async;
39 +
40 + if ($asyncKeyword && !it.async)
41 + throw new Error('async keyword in sync schema');
42 +}}
43 +
44 +
45 +{{? !($inline || $macro) }}{{=$ruleErrs}} = null;{{?}}
46 +var {{=$errs}} = errors;
47 +var {{=$valid}};
48 +
49 +{{## def.callRuleValidate:
50 + {{=$validateCode}}.call(
51 + {{? it.opts.passContext }}this{{??}}self{{?}}
52 + {{? $compile || $rDef.schema === false }}
53 + , {{=$data}}
54 + {{??}}
55 + , {{=$schemaValue}}
56 + , {{=$data}}
57 + , validate.schema{{=it.schemaPath}}
58 + {{?}}
59 + , {{# def.dataPath }}
60 + {{# def.passParentData }}
61 + , rootData
62 + )
63 +#}}
64 +
65 +{{## def.extendErrors:_inline:
66 + for (var {{=$i}}={{=$errs}}; {{=$i}}<errors; {{=$i}}++) {
67 + var {{=$ruleErr}} = vErrors[{{=$i}}];
68 + if ({{=$ruleErr}}.dataPath === undefined)
69 + {{=$ruleErr}}.dataPath = (dataPath || '') + {{= it.errorPath }};
70 + {{# _inline ? 'if (\{\{=$ruleErr\}\}.schemaPath === undefined) {' : '' }}
71 + {{=$ruleErr}}.schemaPath = "{{=$errSchemaPath}}";
72 + {{# _inline ? '}' : '' }}
73 + {{? it.opts.verbose }}
74 + {{=$ruleErr}}.schema = {{=$schemaValue}};
75 + {{=$ruleErr}}.data = {{=$data}};
76 + {{?}}
77 + }
78 +#}}
79 +
80 +
81 +{{? $isData && $rDef.$data }}
82 + {{ $closingBraces += '}'; }}
83 + if ({{=$schemaValue}} === undefined) {
84 + {{=$valid}} = true;
85 + } else {
86 + {{? $validateSchema }}
87 + {{ $closingBraces += '}'; }}
88 + {{=$valid}} = {{=$definition}}.validateSchema({{=$schemaValue}});
89 + if ({{=$valid}}) {
90 + {{?}}
91 +{{?}}
92 +
93 +{{? $inline }}
94 + {{? $rDef.statements }}
95 + {{= $ruleValidate.validate }}
96 + {{??}}
97 + {{=$valid}} = {{= $ruleValidate.validate }};
98 + {{?}}
99 +{{?? $macro }}
100 + {{# def.setupNextLevel }}
101 + {{
102 + $it.schema = $ruleValidate.validate;
103 + $it.schemaPath = '';
104 + }}
105 + {{# def.setCompositeRule }}
106 + {{ var $code = it.validate($it).replace(/validate\.schema/g, $validateCode); }}
107 + {{# def.resetCompositeRule }}
108 + {{= $code }}
109 +{{??}}
110 + {{# def.beginDefOut}}
111 + {{# def.callRuleValidate }}
112 + {{# def.storeDefOut:def_callRuleValidate }}
113 +
114 + {{? $rDef.errors === false }}
115 + {{=$valid}} = {{? $asyncKeyword }}await {{?}}{{= def_callRuleValidate }};
116 + {{??}}
117 + {{? $asyncKeyword }}
118 + {{ $ruleErrs = 'customErrors' + $lvl; }}
119 + var {{=$ruleErrs}} = null;
120 + try {
121 + {{=$valid}} = await {{= def_callRuleValidate }};
122 + } catch (e) {
123 + {{=$valid}} = false;
124 + if (e instanceof ValidationError) {{=$ruleErrs}} = e.errors;
125 + else throw e;
126 + }
127 + {{??}}
128 + {{=$ruleErrs}} = null;
129 + {{=$valid}} = {{= def_callRuleValidate }};
130 + {{?}}
131 + {{?}}
132 +{{?}}
133 +
134 +{{? $rDef.modifying }}
135 + if ({{=$parentData}}) {{=$data}} = {{=$parentData}}[{{=$parentDataProperty}}];
136 +{{?}}
137 +
138 +{{= $closingBraces }}
139 +
140 +{{## def.notValidationResult:
141 + {{? $rDef.valid === undefined }}
142 + !{{? $macro }}{{=$nextValid}}{{??}}{{=$valid}}{{?}}
143 + {{??}}
144 + {{= !$rDef.valid }}
145 + {{?}}
146 +#}}
147 +
148 +{{? $rDef.valid }}
149 + {{? $breakOnError }} if (true) { {{?}}
150 +{{??}}
151 + if ({{# def.notValidationResult }}) {
152 + {{ $errorKeyword = $rule.keyword; }}
153 + {{# def.beginDefOut}}
154 + {{# def.error:'custom' }}
155 + {{# def.storeDefOut:def_customError }}
156 +
157 + {{? $inline }}
158 + {{? $rDef.errors }}
159 + {{? $rDef.errors != 'full' }}
160 + {{# def.extendErrors:true }}
161 + {{?}}
162 + {{??}}
163 + {{? $rDef.errors === false}}
164 + {{= def_customError }}
165 + {{??}}
166 + if ({{=$errs}} == errors) {
167 + {{= def_customError }}
168 + } else {
169 + {{# def.extendErrors:true }}
170 + }
171 + {{?}}
172 + {{?}}
173 + {{?? $macro }}
174 + {{# def.extraError:'custom' }}
175 + {{??}}
176 + {{? $rDef.errors === false}}
177 + {{= def_customError }}
178 + {{??}}
179 + if (Array.isArray({{=$ruleErrs}})) {
180 + if (vErrors === null) vErrors = {{=$ruleErrs}};
181 + else vErrors = vErrors.concat({{=$ruleErrs}});
182 + errors = vErrors.length;
183 + {{# def.extendErrors:false }}
184 + } else {
185 + {{= def_customError }}
186 + }
187 + {{?}}
188 + {{?}}
189 +
190 + } {{? $breakOnError }} else { {{?}}
191 +{{?}}
1 +{{## def.assignDefault:
2 + {{? it.compositeRule }}
3 + {{
4 + if (it.opts.strictDefaults) {
5 + var $defaultMsg = 'default is ignored for: ' + $passData;
6 + if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
7 + else throw new Error($defaultMsg);
8 + }
9 + }}
10 + {{??}}
11 + if ({{=$passData}} === undefined
12 + {{? it.opts.useDefaults == 'empty' }}
13 + || {{=$passData}} === null
14 + || {{=$passData}} === ''
15 + {{?}}
16 + )
17 + {{=$passData}} = {{? it.opts.useDefaults == 'shared' }}
18 + {{= it.useDefault($sch.default) }}
19 + {{??}}
20 + {{= JSON.stringify($sch.default) }}
21 + {{?}};
22 + {{?}}
23 +#}}
24 +
25 +
26 +{{## def.defaultProperties:
27 + {{
28 + var $schema = it.schema.properties
29 + , $schemaKeys = Object.keys($schema); }}
30 + {{~ $schemaKeys:$propertyKey }}
31 + {{ var $sch = $schema[$propertyKey]; }}
32 + {{? $sch.default !== undefined }}
33 + {{ var $passData = $data + it.util.getProperty($propertyKey); }}
34 + {{# def.assignDefault }}
35 + {{?}}
36 + {{~}}
37 +#}}
38 +
39 +
40 +{{## def.defaultItems:
41 + {{~ it.schema.items:$sch:$i }}
42 + {{? $sch.default !== undefined }}
43 + {{ var $passData = $data + '[' + $i + ']'; }}
44 + {{# def.assignDefault }}
45 + {{?}}
46 + {{~}}
47 +#}}
1 +{{## def.setupKeyword:
2 + {{
3 + var $lvl = it.level;
4 + var $dataLvl = it.dataLevel;
5 + var $schema = it.schema[$keyword];
6 + var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
7 + var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
8 + var $breakOnError = !it.opts.allErrors;
9 + var $errorKeyword;
10 +
11 + var $data = 'data' + ($dataLvl || '');
12 + var $valid = 'valid' + $lvl;
13 + var $errs = 'errs__' + $lvl;
14 + }}
15 +#}}
16 +
17 +
18 +{{## def.setCompositeRule:
19 + {{
20 + var $wasComposite = it.compositeRule;
21 + it.compositeRule = $it.compositeRule = true;
22 + }}
23 +#}}
24 +
25 +
26 +{{## def.resetCompositeRule:
27 + {{ it.compositeRule = $it.compositeRule = $wasComposite; }}
28 +#}}
29 +
30 +
31 +{{## def.setupNextLevel:
32 + {{
33 + var $it = it.util.copy(it);
34 + var $closingBraces = '';
35 + $it.level++;
36 + var $nextValid = 'valid' + $it.level;
37 + }}
38 +#}}
39 +
40 +
41 +{{## def.ifValid:
42 + {{? $breakOnError }}
43 + if ({{=$valid}}) {
44 + {{ $closingBraces += '}'; }}
45 + {{?}}
46 +#}}
47 +
48 +
49 +{{## def.ifResultValid:
50 + {{? $breakOnError }}
51 + if ({{=$nextValid}}) {
52 + {{ $closingBraces += '}'; }}
53 + {{?}}
54 +#}}
55 +
56 +
57 +{{## def.elseIfValid:
58 + {{? $breakOnError }}
59 + {{ $closingBraces += '}'; }}
60 + else {
61 + {{?}}
62 +#}}
63 +
64 +
65 +{{## def.nonEmptySchema:_schema:
66 + (it.opts.strictKeywords
67 + ? (typeof _schema == 'object' && Object.keys(_schema).length > 0)
68 + || _schema === false
69 + : it.util.schemaHasRules(_schema, it.RULES.all))
70 +#}}
71 +
72 +
73 +{{## def.strLength:
74 + {{? it.opts.unicode === false }}
75 + {{=$data}}.length
76 + {{??}}
77 + ucs2length({{=$data}})
78 + {{?}}
79 +#}}
80 +
81 +
82 +{{## def.willOptimize:
83 + it.util.varOccurences($code, $nextData) < 2
84 +#}}
85 +
86 +
87 +{{## def.generateSubschemaCode:
88 + {{
89 + var $code = it.validate($it);
90 + $it.baseId = $currentBaseId;
91 + }}
92 +#}}
93 +
94 +
95 +{{## def.insertSubschemaCode:
96 + {{= it.validate($it) }}
97 + {{ $it.baseId = $currentBaseId; }}
98 +#}}
99 +
100 +
101 +{{## def._optimizeValidate:
102 + it.util.varReplace($code, $nextData, $passData)
103 +#}}
104 +
105 +
106 +{{## def.optimizeValidate:
107 + {{? {{# def.willOptimize}} }}
108 + {{= {{# def._optimizeValidate }} }}
109 + {{??}}
110 + var {{=$nextData}} = {{=$passData}};
111 + {{= $code }}
112 + {{?}}
113 +#}}
114 +
115 +
116 +{{## def.$data:
117 + {{
118 + var $isData = it.opts.$data && $schema && $schema.$data
119 + , $schemaValue;
120 + }}
121 + {{? $isData }}
122 + var schema{{=$lvl}} = {{= it.util.getData($schema.$data, $dataLvl, it.dataPathArr) }};
123 + {{ $schemaValue = 'schema' + $lvl; }}
124 + {{??}}
125 + {{ $schemaValue = $schema; }}
126 + {{?}}
127 +#}}
128 +
129 +
130 +{{## def.$dataNotType:_type:
131 + {{?$isData}} ({{=$schemaValue}} !== undefined && typeof {{=$schemaValue}} != _type) || {{?}}
132 +#}}
133 +
134 +
135 +{{## def.check$dataIsArray:
136 + if (schema{{=$lvl}} === undefined) {{=$valid}} = true;
137 + else if (!Array.isArray(schema{{=$lvl}})) {{=$valid}} = false;
138 + else {
139 +#}}
140 +
141 +
142 +{{## def.numberKeyword:
143 + {{? !($isData || typeof $schema == 'number') }}
144 + {{ throw new Error($keyword + ' must be number'); }}
145 + {{?}}
146 +#}}
147 +
148 +
149 +{{## def.beginDefOut:
150 + {{
151 + var $$outStack = $$outStack || [];
152 + $$outStack.push(out);
153 + out = '';
154 + }}
155 +#}}
156 +
157 +
158 +{{## def.storeDefOut:_variable:
159 + {{
160 + var _variable = out;
161 + out = $$outStack.pop();
162 + }}
163 +#}}
164 +
165 +
166 +{{## def.dataPath:(dataPath || ''){{? it.errorPath != '""'}} + {{= it.errorPath }}{{?}}#}}
167 +
168 +{{## def.setParentData:
169 + {{
170 + var $parentData = $dataLvl ? 'data' + (($dataLvl-1)||'') : 'parentData'
171 + , $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
172 + }}
173 +#}}
174 +
175 +{{## def.passParentData:
176 + {{# def.setParentData }}
177 + , {{= $parentData }}
178 + , {{= $parentDataProperty }}
179 +#}}
180 +
181 +
182 +{{## def.iterateProperties:
183 + {{? $ownProperties }}
184 + {{=$dataProperties}} = {{=$dataProperties}} || Object.keys({{=$data}});
185 + for (var {{=$idx}}=0; {{=$idx}}<{{=$dataProperties}}.length; {{=$idx}}++) {
186 + var {{=$key}} = {{=$dataProperties}}[{{=$idx}}];
187 + {{??}}
188 + for (var {{=$key}} in {{=$data}}) {
189 + {{?}}
190 +#}}
191 +
192 +
193 +{{## def.noPropertyInData:
194 + {{=$useData}} === undefined
195 + {{? $ownProperties }}
196 + || !{{# def.isOwnProperty }}
197 + {{?}}
198 +#}}
199 +
200 +
201 +{{## def.isOwnProperty:
202 + Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
203 +#}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.missing }}
4 +{{# def.setupKeyword }}
5 +{{# def.setupNextLevel }}
6 +
7 +
8 +{{## def.propertyInData:
9 + {{=$data}}{{= it.util.getProperty($property) }} !== undefined
10 + {{? $ownProperties }}
11 + && Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($property)}}')
12 + {{?}}
13 +#}}
14 +
15 +
16 +{{
17 + var $schemaDeps = {}
18 + , $propertyDeps = {}
19 + , $ownProperties = it.opts.ownProperties;
20 +
21 + for ($property in $schema) {
22 + if ($property == '__proto__') continue;
23 + var $sch = $schema[$property];
24 + var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
25 + $deps[$property] = $sch;
26 + }
27 +}}
28 +
29 +var {{=$errs}} = errors;
30 +
31 +{{ var $currentErrorPath = it.errorPath; }}
32 +
33 +var missing{{=$lvl}};
34 +{{ for (var $property in $propertyDeps) { }}
35 + {{ $deps = $propertyDeps[$property]; }}
36 + {{? $deps.length }}
37 + if ({{# def.propertyInData }}
38 + {{? $breakOnError }}
39 + && ({{# def.checkMissingProperty:$deps }})) {
40 + {{# def.errorMissingProperty:'dependencies' }}
41 + {{??}}
42 + ) {
43 + {{~ $deps:$propertyKey }}
44 + {{# def.allErrorsMissingProperty:'dependencies' }}
45 + {{~}}
46 + {{?}}
47 + } {{# def.elseIfValid }}
48 + {{?}}
49 +{{ } }}
50 +
51 +{{
52 + it.errorPath = $currentErrorPath;
53 + var $currentBaseId = $it.baseId;
54 +}}
55 +
56 +
57 +{{ for (var $property in $schemaDeps) { }}
58 + {{ var $sch = $schemaDeps[$property]; }}
59 + {{? {{# def.nonEmptySchema:$sch }} }}
60 + {{=$nextValid}} = true;
61 +
62 + if ({{# def.propertyInData }}) {
63 + {{
64 + $it.schema = $sch;
65 + $it.schemaPath = $schemaPath + it.util.getProperty($property);
66 + $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
67 + }}
68 +
69 + {{# def.insertSubschemaCode }}
70 + }
71 +
72 + {{# def.ifResultValid }}
73 + {{?}}
74 +{{ } }}
75 +
76 +{{? $breakOnError }}
77 + {{= $closingBraces }}
78 + if ({{=$errs}} == errors) {
79 +{{?}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +{{# def.$data }}
5 +
6 +{{
7 + var $i = 'i' + $lvl
8 + , $vSchema = 'schema' + $lvl;
9 +}}
10 +
11 +{{? !$isData }}
12 + var {{=$vSchema}} = validate.schema{{=$schemaPath}};
13 +{{?}}
14 +var {{=$valid}};
15 +
16 +{{?$isData}}{{# def.check$dataIsArray }}{{?}}
17 +
18 +{{=$valid}} = false;
19 +
20 +for (var {{=$i}}=0; {{=$i}}<{{=$vSchema}}.length; {{=$i}}++)
21 + if (equal({{=$data}}, {{=$vSchema}}[{{=$i}}])) {
22 + {{=$valid}} = true;
23 + break;
24 + }
25 +
26 +{{? $isData }} } {{?}}
27 +
28 +{{# def.checkError:'enum' }}
29 +
30 +{{? $breakOnError }} else { {{?}}
1 +{{# def.definitions }}
2 +
3 +{{## def._error:_rule:
4 + {{ 'istanbul ignore else'; }}
5 + {{? it.createErrors !== false }}
6 + {
7 + keyword: '{{= $errorKeyword || _rule }}'
8 + , dataPath: (dataPath || '') + {{= it.errorPath }}
9 + , schemaPath: {{=it.util.toQuotedString($errSchemaPath)}}
10 + , params: {{# def._errorParams[_rule] }}
11 + {{? it.opts.messages !== false }}
12 + , message: {{# def._errorMessages[_rule] }}
13 + {{?}}
14 + {{? it.opts.verbose }}
15 + , schema: {{# def._errorSchemas[_rule] }}
16 + , parentSchema: validate.schema{{=it.schemaPath}}
17 + , data: {{=$data}}
18 + {{?}}
19 + }
20 + {{??}}
21 + {}
22 + {{?}}
23 +#}}
24 +
25 +
26 +{{## def._addError:_rule:
27 + if (vErrors === null) vErrors = [err];
28 + else vErrors.push(err);
29 + errors++;
30 +#}}
31 +
32 +
33 +{{## def.addError:_rule:
34 + var err = {{# def._error:_rule }};
35 + {{# def._addError:_rule }}
36 +#}}
37 +
38 +
39 +{{## def.error:_rule:
40 + {{# def.beginDefOut}}
41 + {{# def._error:_rule }}
42 + {{# def.storeDefOut:__err }}
43 +
44 + {{? !it.compositeRule && $breakOnError }}
45 + {{ 'istanbul ignore if'; }}
46 + {{? it.async }}
47 + throw new ValidationError([{{=__err}}]);
48 + {{??}}
49 + validate.errors = [{{=__err}}];
50 + return false;
51 + {{?}}
52 + {{??}}
53 + var err = {{=__err}};
54 + {{# def._addError:_rule }}
55 + {{?}}
56 +#}}
57 +
58 +
59 +{{## def.extraError:_rule:
60 + {{# def.addError:_rule}}
61 + {{? !it.compositeRule && $breakOnError }}
62 + {{ 'istanbul ignore if'; }}
63 + {{? it.async }}
64 + throw new ValidationError(vErrors);
65 + {{??}}
66 + validate.errors = vErrors;
67 + return false;
68 + {{?}}
69 + {{?}}
70 +#}}
71 +
72 +
73 +{{## def.checkError:_rule:
74 + if (!{{=$valid}}) {
75 + {{# def.error:_rule }}
76 + }
77 +#}}
78 +
79 +
80 +{{## def.resetErrors:
81 + errors = {{=$errs}};
82 + if (vErrors !== null) {
83 + if ({{=$errs}}) vErrors.length = {{=$errs}};
84 + else vErrors = null;
85 + }
86 +#}}
87 +
88 +
89 +{{## def.concatSchema:{{?$isData}}' + {{=$schemaValue}} + '{{??}}{{=$schema}}{{?}}#}}
90 +{{## def.appendSchema:{{?$isData}}' + {{=$schemaValue}}{{??}}{{=$schemaValue}}'{{?}}#}}
91 +{{## def.concatSchemaEQ:{{?$isData}}' + {{=$schemaValue}} + '{{??}}{{=it.util.escapeQuotes($schema)}}{{?}}#}}
92 +
93 +{{## def._errorMessages = {
94 + 'false schema': "'boolean schema is false'",
95 + $ref: "'can\\\'t resolve reference {{=it.util.escapeQuotes($schema)}}'",
96 + additionalItems: "'should NOT have more than {{=$schema.length}} items'",
97 + additionalProperties: "'{{? it.opts._errorDataPathProperty }}is an invalid additional property{{??}}should NOT have additional properties{{?}}'",
98 + anyOf: "'should match some schema in anyOf'",
99 + const: "'should be equal to constant'",
100 + contains: "'should contain a valid item'",
101 + dependencies: "'should have {{? $deps.length == 1 }}property {{= it.util.escapeQuotes($deps[0]) }}{{??}}properties {{= it.util.escapeQuotes($deps.join(\", \")) }}{{?}} when property {{= it.util.escapeQuotes($property) }} is present'",
102 + 'enum': "'should be equal to one of the allowed values'",
103 + format: "'should match format \"{{#def.concatSchemaEQ}}\"'",
104 + 'if': "'should match \"' + {{=$ifClause}} + '\" schema'",
105 + _limit: "'should be {{=$opStr}} {{#def.appendSchema}}",
106 + _exclusiveLimit: "'{{=$exclusiveKeyword}} should be boolean'",
107 + _limitItems: "'should NOT have {{?$keyword=='maxItems'}}more{{??}}fewer{{?}} than {{#def.concatSchema}} items'",
108 + _limitLength: "'should NOT be {{?$keyword=='maxLength'}}longer{{??}}shorter{{?}} than {{#def.concatSchema}} characters'",
109 + _limitProperties:"'should NOT have {{?$keyword=='maxProperties'}}more{{??}}fewer{{?}} than {{#def.concatSchema}} properties'",
110 + multipleOf: "'should be multiple of {{#def.appendSchema}}",
111 + not: "'should NOT be valid'",
112 + oneOf: "'should match exactly one schema in oneOf'",
113 + pattern: "'should match pattern \"{{#def.concatSchemaEQ}}\"'",
114 + propertyNames: "'property name \\'{{=$invalidName}}\\' is invalid'",
115 + required: "'{{? it.opts._errorDataPathProperty }}is a required property{{??}}should have required property \\'{{=$missingProperty}}\\'{{?}}'",
116 + type: "'should be {{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}'",
117 + uniqueItems: "'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)'",
118 + custom: "'should pass \"{{=$rule.keyword}}\" keyword validation'",
119 + patternRequired: "'should have property matching pattern \\'{{=$missingPattern}}\\''",
120 + switch: "'should pass \"switch\" keyword validation'",
121 + _formatLimit: "'should be {{=$opStr}} \"{{#def.concatSchemaEQ}}\"'",
122 + _formatExclusiveLimit: "'{{=$exclusiveKeyword}} should be boolean'"
123 +} #}}
124 +
125 +
126 +{{## def.schemaRefOrVal: {{?$isData}}validate.schema{{=$schemaPath}}{{??}}{{=$schema}}{{?}} #}}
127 +{{## def.schemaRefOrQS: {{?$isData}}validate.schema{{=$schemaPath}}{{??}}{{=it.util.toQuotedString($schema)}}{{?}} #}}
128 +
129 +{{## def._errorSchemas = {
130 + 'false schema': "false",
131 + $ref: "{{=it.util.toQuotedString($schema)}}",
132 + additionalItems: "false",
133 + additionalProperties: "false",
134 + anyOf: "validate.schema{{=$schemaPath}}",
135 + const: "validate.schema{{=$schemaPath}}",
136 + contains: "validate.schema{{=$schemaPath}}",
137 + dependencies: "validate.schema{{=$schemaPath}}",
138 + 'enum': "validate.schema{{=$schemaPath}}",
139 + format: "{{#def.schemaRefOrQS}}",
140 + 'if': "validate.schema{{=$schemaPath}}",
141 + _limit: "{{#def.schemaRefOrVal}}",
142 + _exclusiveLimit: "validate.schema{{=$schemaPath}}",
143 + _limitItems: "{{#def.schemaRefOrVal}}",
144 + _limitLength: "{{#def.schemaRefOrVal}}",
145 + _limitProperties:"{{#def.schemaRefOrVal}}",
146 + multipleOf: "{{#def.schemaRefOrVal}}",
147 + not: "validate.schema{{=$schemaPath}}",
148 + oneOf: "validate.schema{{=$schemaPath}}",
149 + pattern: "{{#def.schemaRefOrQS}}",
150 + propertyNames: "validate.schema{{=$schemaPath}}",
151 + required: "validate.schema{{=$schemaPath}}",
152 + type: "validate.schema{{=$schemaPath}}",
153 + uniqueItems: "{{#def.schemaRefOrVal}}",
154 + custom: "validate.schema{{=$schemaPath}}",
155 + patternRequired: "validate.schema{{=$schemaPath}}",
156 + switch: "validate.schema{{=$schemaPath}}",
157 + _formatLimit: "{{#def.schemaRefOrQS}}",
158 + _formatExclusiveLimit: "validate.schema{{=$schemaPath}}"
159 +} #}}
160 +
161 +
162 +{{## def.schemaValueQS: {{?$isData}}{{=$schemaValue}}{{??}}{{=it.util.toQuotedString($schema)}}{{?}} #}}
163 +
164 +{{## def._errorParams = {
165 + 'false schema': "{}",
166 + $ref: "{ ref: '{{=it.util.escapeQuotes($schema)}}' }",
167 + additionalItems: "{ limit: {{=$schema.length}} }",
168 + additionalProperties: "{ additionalProperty: '{{=$additionalProperty}}' }",
169 + anyOf: "{}",
170 + const: "{ allowedValue: schema{{=$lvl}} }",
171 + contains: "{}",
172 + dependencies: "{ property: '{{= it.util.escapeQuotes($property) }}', missingProperty: '{{=$missingProperty}}', depsCount: {{=$deps.length}}, deps: '{{= it.util.escapeQuotes($deps.length==1 ? $deps[0] : $deps.join(\", \")) }}' }",
173 + 'enum': "{ allowedValues: schema{{=$lvl}} }",
174 + format: "{ format: {{#def.schemaValueQS}} }",
175 + 'if': "{ failingKeyword: {{=$ifClause}} }",
176 + _limit: "{ comparison: {{=$opExpr}}, limit: {{=$schemaValue}}, exclusive: {{=$exclusive}} }",
177 + _exclusiveLimit: "{}",
178 + _limitItems: "{ limit: {{=$schemaValue}} }",
179 + _limitLength: "{ limit: {{=$schemaValue}} }",
180 + _limitProperties:"{ limit: {{=$schemaValue}} }",
181 + multipleOf: "{ multipleOf: {{=$schemaValue}} }",
182 + not: "{}",
183 + oneOf: "{ passingSchemas: {{=$passingSchemas}} }",
184 + pattern: "{ pattern: {{#def.schemaValueQS}} }",
185 + propertyNames: "{ propertyName: '{{=$invalidName}}' }",
186 + required: "{ missingProperty: '{{=$missingProperty}}' }",
187 + type: "{ type: '{{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}' }",
188 + uniqueItems: "{ i: i, j: j }",
189 + custom: "{ keyword: '{{=$rule.keyword}}' }",
190 + patternRequired: "{ missingPattern: '{{=$missingPattern}}' }",
191 + switch: "{ caseIndex: {{=$caseIndex}} }",
192 + _formatLimit: "{ comparison: {{=$opExpr}}, limit: {{#def.schemaValueQS}}, exclusive: {{=$exclusive}} }",
193 + _formatExclusiveLimit: "{}"
194 +} #}}
1 +{{# def.definitions }}
2 +{{# def.errors }}
3 +{{# def.setupKeyword }}
4 +
5 +{{## def.skipFormat:
6 + {{? $breakOnError }} if (true) { {{?}}
7 + {{ return out; }}
8 +#}}
9 +
10 +{{? it.opts.format === false }}{{# def.skipFormat }}{{?}}
11 +
12 +
13 +{{# def.$data }}
14 +
15 +
16 +{{## def.$dataCheckFormat:
17 + {{# def.$dataNotType:'string' }}
18 + ({{? $unknownFormats != 'ignore' }}
19 + ({{=$schemaValue}} && !{{=$format}}
20 + {{? $allowUnknown }}
21 + && self._opts.unknownFormats.indexOf({{=$schemaValue}}) == -1
22 + {{?}}) ||
23 + {{?}}
24 + ({{=$format}} && {{=$formatType}} == '{{=$ruleType}}'
25 + && !(typeof {{=$format}} == 'function'
26 + ? {{? it.async}}
27 + (async{{=$lvl}} ? await {{=$format}}({{=$data}}) : {{=$format}}({{=$data}}))
28 + {{??}}
29 + {{=$format}}({{=$data}})
30 + {{?}}
31 + : {{=$format}}.test({{=$data}}))))
32 +#}}
33 +
34 +{{## def.checkFormat:
35 + {{
36 + var $formatRef = 'formats' + it.util.getProperty($schema);
37 + if ($isObject) $formatRef += '.validate';
38 + }}
39 + {{? typeof $format == 'function' }}
40 + {{=$formatRef}}({{=$data}})
41 + {{??}}
42 + {{=$formatRef}}.test({{=$data}})
43 + {{?}}
44 +#}}
45 +
46 +
47 +{{
48 + var $unknownFormats = it.opts.unknownFormats
49 + , $allowUnknown = Array.isArray($unknownFormats);
50 +}}
51 +
52 +{{? $isData }}
53 + {{
54 + var $format = 'format' + $lvl
55 + , $isObject = 'isObject' + $lvl
56 + , $formatType = 'formatType' + $lvl;
57 + }}
58 + var {{=$format}} = formats[{{=$schemaValue}}];
59 + var {{=$isObject}} = typeof {{=$format}} == 'object'
60 + && !({{=$format}} instanceof RegExp)
61 + && {{=$format}}.validate;
62 + var {{=$formatType}} = {{=$isObject}} && {{=$format}}.type || 'string';
63 + if ({{=$isObject}}) {
64 + {{? it.async}}
65 + var async{{=$lvl}} = {{=$format}}.async;
66 + {{?}}
67 + {{=$format}} = {{=$format}}.validate;
68 + }
69 + if ({{# def.$dataCheckFormat }}) {
70 +{{??}}
71 + {{ var $format = it.formats[$schema]; }}
72 + {{? !$format }}
73 + {{? $unknownFormats == 'ignore' }}
74 + {{ it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); }}
75 + {{# def.skipFormat }}
76 + {{?? $allowUnknown && $unknownFormats.indexOf($schema) >= 0 }}
77 + {{# def.skipFormat }}
78 + {{??}}
79 + {{ throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"'); }}
80 + {{?}}
81 + {{?}}
82 + {{
83 + var $isObject = typeof $format == 'object'
84 + && !($format instanceof RegExp)
85 + && $format.validate;
86 + var $formatType = $isObject && $format.type || 'string';
87 + if ($isObject) {
88 + var $async = $format.async === true;
89 + $format = $format.validate;
90 + }
91 + }}
92 + {{? $formatType != $ruleType }}
93 + {{# def.skipFormat }}
94 + {{?}}
95 + {{? $async }}
96 + {{
97 + if (!it.async) throw new Error('async format in sync schema');
98 + var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
99 + }}
100 + if (!(await {{=$formatRef}}({{=$data}}))) {
101 + {{??}}
102 + if (!{{# def.checkFormat }}) {
103 + {{?}}
104 +{{?}}
105 + {{# def.error:'format' }}
106 + } {{? $breakOnError }} else { {{?}}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff 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 could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff 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 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 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.