@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../mocha/bin/_mocha" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../mocha/bin/_mocha" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\mocha\bin\_mocha" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../mocha/bin/_mocha" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../mocha/bin/_mocha" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../atob/bin/atob.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../atob/bin/atob.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\atob\bin\atob.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../atob/bin/atob.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../atob/bin/atob.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../esprima/bin/esparse.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../esprima/bin/esparse.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\esprima\bin\esparse.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../esprima/bin/esparse.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../esprima/bin/esparse.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../esprima/bin/esvalidate.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../esprima/bin/esvalidate.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\esprima\bin\esvalidate.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../esprima/bin/esvalidate.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../esprima/bin/esvalidate.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../flat/cli.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../flat/cli.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\flat\cli.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../flat/cli.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../flat/cli.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../he/bin/he" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../he/bin/he" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\he\bin\he" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../he/bin/he" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../he/bin/he" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../js-yaml/bin/js-yaml.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../js-yaml/bin/js-yaml.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\js-yaml\bin\js-yaml.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../js-yaml/bin/js-yaml.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../js-yaml/bin/js-yaml.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../live-server/live-server.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../live-server/live-server.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\live-server\live-server.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../live-server/live-server.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../live-server/live-server.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../mime/cli.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../mime/cli.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\mime\cli.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../mime/cli.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../mime/cli.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../mkdirp/bin/cmd.js" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../mkdirp/bin/cmd.js" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\mkdirp\bin\cmd.js" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../mkdirp/bin/cmd.js" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../mkdirp/bin/cmd.js" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../mocha/bin/mocha" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../mocha/bin/mocha" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\mocha\bin\mocha" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../mocha/bin/mocha" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../mocha/bin/mocha" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../semver/bin/semver" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../semver/bin/semver" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\semver\bin\semver" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../semver/bin/semver" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../semver/bin/semver" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../uuid/bin/uuid" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../uuid/bin/uuid" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\uuid\bin\uuid" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../uuid/bin/uuid" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../uuid/bin/uuid" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,15 @@ | |||
#!/bin/sh | |||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | |||
case `uname` in | |||
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; | |||
esac | |||
if [ -x "$basedir/node" ]; then | |||
"$basedir/node" "$basedir/../which/bin/which" "$@" | |||
ret=$? | |||
else | |||
node "$basedir/../which/bin/which" "$@" | |||
ret=$? | |||
fi | |||
exit $ret |
@@ -0,0 +1,17 @@ | |||
@ECHO off | |||
SETLOCAL | |||
CALL :find_dp0 | |||
IF EXIST "%dp0%\node.exe" ( | |||
SET "_prog=%dp0%\node.exe" | |||
) ELSE ( | |||
SET "_prog=node" | |||
SET PATHEXT=%PATHEXT:;.JS;=;% | |||
) | |||
"%_prog%" "%dp0%\..\which\bin\which" %* | |||
ENDLOCAL | |||
EXIT /b %errorlevel% | |||
:find_dp0 | |||
SET dp0=%~dp0 | |||
EXIT /b |
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env pwsh | |||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | |||
$exe="" | |||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | |||
# Fix case when both the Windows and Linux builds of Node | |||
# are installed in the same directory | |||
$exe=".exe" | |||
} | |||
$ret=0 | |||
if (Test-Path "$basedir/node$exe") { | |||
& "$basedir/node$exe" "$basedir/../which/bin/which" $args | |||
$ret=$LASTEXITCODE | |||
} else { | |||
& "node$exe" "$basedir/../which/bin/which" $args | |||
$ret=$LASTEXITCODE | |||
} | |||
exit $ret |
@@ -0,0 +1,236 @@ | |||
1.3.7 / 2019-04-29 | |||
================== | |||
* deps: negotiator@0.6.2 | |||
- Fix sorting charset, encoding, and language with extra parameters | |||
1.3.6 / 2019-04-28 | |||
================== | |||
* deps: mime-types@~2.1.24 | |||
- deps: mime-db@~1.40.0 | |||
1.3.5 / 2018-02-28 | |||
================== | |||
* deps: mime-types@~2.1.18 | |||
- deps: mime-db@~1.33.0 | |||
1.3.4 / 2017-08-22 | |||
================== | |||
* deps: mime-types@~2.1.16 | |||
- deps: mime-db@~1.29.0 | |||
1.3.3 / 2016-05-02 | |||
================== | |||
* deps: mime-types@~2.1.11 | |||
- deps: mime-db@~1.23.0 | |||
* deps: negotiator@0.6.1 | |||
- perf: improve `Accept` parsing speed | |||
- perf: improve `Accept-Charset` parsing speed | |||
- perf: improve `Accept-Encoding` parsing speed | |||
- perf: improve `Accept-Language` parsing speed | |||
1.3.2 / 2016-03-08 | |||
================== | |||
* deps: mime-types@~2.1.10 | |||
- Fix extension of `application/dash+xml` | |||
- Update primary extension for `audio/mp4` | |||
- deps: mime-db@~1.22.0 | |||
1.3.1 / 2016-01-19 | |||
================== | |||
* deps: mime-types@~2.1.9 | |||
- deps: mime-db@~1.21.0 | |||
1.3.0 / 2015-09-29 | |||
================== | |||
* deps: mime-types@~2.1.7 | |||
- deps: mime-db@~1.19.0 | |||
* deps: negotiator@0.6.0 | |||
- Fix including type extensions in parameters in `Accept` parsing | |||
- Fix parsing `Accept` parameters with quoted equals | |||
- Fix parsing `Accept` parameters with quoted semicolons | |||
- Lazy-load modules from main entry point | |||
- perf: delay type concatenation until needed | |||
- perf: enable strict mode | |||
- perf: hoist regular expressions | |||
- perf: remove closures getting spec properties | |||
- perf: remove a closure from media type parsing | |||
- perf: remove property delete from media type parsing | |||
1.2.13 / 2015-09-06 | |||
=================== | |||
* deps: mime-types@~2.1.6 | |||
- deps: mime-db@~1.18.0 | |||
1.2.12 / 2015-07-30 | |||
=================== | |||
* deps: mime-types@~2.1.4 | |||
- deps: mime-db@~1.16.0 | |||
1.2.11 / 2015-07-16 | |||
=================== | |||
* deps: mime-types@~2.1.3 | |||
- deps: mime-db@~1.15.0 | |||
1.2.10 / 2015-07-01 | |||
=================== | |||
* deps: mime-types@~2.1.2 | |||
- deps: mime-db@~1.14.0 | |||
1.2.9 / 2015-06-08 | |||
================== | |||
* deps: mime-types@~2.1.1 | |||
- perf: fix deopt during mapping | |||
1.2.8 / 2015-06-07 | |||
================== | |||
* deps: mime-types@~2.1.0 | |||
- deps: mime-db@~1.13.0 | |||
* perf: avoid argument reassignment & argument slice | |||
* perf: avoid negotiator recursive construction | |||
* perf: enable strict mode | |||
* perf: remove unnecessary bitwise operator | |||
1.2.7 / 2015-05-10 | |||
================== | |||
* deps: negotiator@0.5.3 | |||
- Fix media type parameter matching to be case-insensitive | |||
1.2.6 / 2015-05-07 | |||
================== | |||
* deps: mime-types@~2.0.11 | |||
- deps: mime-db@~1.9.1 | |||
* deps: negotiator@0.5.2 | |||
- Fix comparing media types with quoted values | |||
- Fix splitting media types with quoted commas | |||
1.2.5 / 2015-03-13 | |||
================== | |||
* deps: mime-types@~2.0.10 | |||
- deps: mime-db@~1.8.0 | |||
1.2.4 / 2015-02-14 | |||
================== | |||
* Support Node.js 0.6 | |||
* deps: mime-types@~2.0.9 | |||
- deps: mime-db@~1.7.0 | |||
* deps: negotiator@0.5.1 | |||
- Fix preference sorting to be stable for long acceptable lists | |||
1.2.3 / 2015-01-31 | |||
================== | |||
* deps: mime-types@~2.0.8 | |||
- deps: mime-db@~1.6.0 | |||
1.2.2 / 2014-12-30 | |||
================== | |||
* deps: mime-types@~2.0.7 | |||
- deps: mime-db@~1.5.0 | |||
1.2.1 / 2014-12-30 | |||
================== | |||
* deps: mime-types@~2.0.5 | |||
- deps: mime-db@~1.3.1 | |||
1.2.0 / 2014-12-19 | |||
================== | |||
* deps: negotiator@0.5.0 | |||
- Fix list return order when large accepted list | |||
- Fix missing identity encoding when q=0 exists | |||
- Remove dynamic building of Negotiator class | |||
1.1.4 / 2014-12-10 | |||
================== | |||
* deps: mime-types@~2.0.4 | |||
- deps: mime-db@~1.3.0 | |||
1.1.3 / 2014-11-09 | |||
================== | |||
* deps: mime-types@~2.0.3 | |||
- deps: mime-db@~1.2.0 | |||
1.1.2 / 2014-10-14 | |||
================== | |||
* deps: negotiator@0.4.9 | |||
- Fix error when media type has invalid parameter | |||
1.1.1 / 2014-09-28 | |||
================== | |||
* deps: mime-types@~2.0.2 | |||
- deps: mime-db@~1.1.0 | |||
* deps: negotiator@0.4.8 | |||
- Fix all negotiations to be case-insensitive | |||
- Stable sort preferences of same quality according to client order | |||
1.1.0 / 2014-09-02 | |||
================== | |||
* update `mime-types` | |||
1.0.7 / 2014-07-04 | |||
================== | |||
* Fix wrong type returned from `type` when match after unknown extension | |||
1.0.6 / 2014-06-24 | |||
================== | |||
* deps: negotiator@0.4.7 | |||
1.0.5 / 2014-06-20 | |||
================== | |||
* fix crash when unknown extension given | |||
1.0.4 / 2014-06-19 | |||
================== | |||
* use `mime-types` | |||
1.0.3 / 2014-06-11 | |||
================== | |||
* deps: negotiator@0.4.6 | |||
- Order by specificity when quality is the same | |||
1.0.2 / 2014-05-29 | |||
================== | |||
* Fix interpretation when header not in request | |||
* deps: pin negotiator@0.4.5 | |||
1.0.1 / 2014-01-18 | |||
================== | |||
* Identity encoding isn't always acceptable | |||
* deps: negotiator@~0.4.0 | |||
1.0.0 / 2013-12-27 | |||
================== | |||
* Genesis |
@@ -0,0 +1,23 @@ | |||
(The MIT License) | |||
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com> | |||
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com> | |||
Permission is hereby granted, free of charge, to any person obtaining | |||
a copy of this software and associated documentation files (the | |||
'Software'), to deal in the Software without restriction, including | |||
without limitation the rights to use, copy, modify, merge, publish, | |||
distribute, sublicense, and/or sell copies of the Software, and to | |||
permit persons to whom the Software is furnished to do so, subject to | |||
the following conditions: | |||
The above copyright notice and this permission notice shall be | |||
included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | |||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,142 @@ | |||
# accepts | |||
[![NPM Version][npm-version-image]][npm-url] | |||
[![NPM Downloads][npm-downloads-image]][npm-url] | |||
[![Node.js Version][node-version-image]][node-version-url] | |||
[![Build Status][travis-image]][travis-url] | |||
[![Test Coverage][coveralls-image]][coveralls-url] | |||
Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator). | |||
Extracted from [koa](https://www.npmjs.com/package/koa) for general use. | |||
In addition to negotiator, it allows: | |||
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` | |||
as well as `('text/html', 'application/json')`. | |||
- Allows type shorthands such as `json`. | |||
- Returns `false` when no types match | |||
- Treats non-existent headers as `*` | |||
## Installation | |||
This is a [Node.js](https://nodejs.org/en/) module available through the | |||
[npm registry](https://www.npmjs.com/). Installation is done using the | |||
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): | |||
```sh | |||
$ npm install accepts | |||
``` | |||
## API | |||
<!-- eslint-disable no-unused-vars --> | |||
```js | |||
var accepts = require('accepts') | |||
``` | |||
### accepts(req) | |||
Create a new `Accepts` object for the given `req`. | |||
#### .charset(charsets) | |||
Return the first accepted charset. If nothing in `charsets` is accepted, | |||
then `false` is returned. | |||
#### .charsets() | |||
Return the charsets that the request accepts, in the order of the client's | |||
preference (most preferred first). | |||
#### .encoding(encodings) | |||
Return the first accepted encoding. If nothing in `encodings` is accepted, | |||
then `false` is returned. | |||
#### .encodings() | |||
Return the encodings that the request accepts, in the order of the client's | |||
preference (most preferred first). | |||
#### .language(languages) | |||
Return the first accepted language. If nothing in `languages` is accepted, | |||
then `false` is returned. | |||
#### .languages() | |||
Return the languages that the request accepts, in the order of the client's | |||
preference (most preferred first). | |||
#### .type(types) | |||
Return the first accepted type (and it is returned as the same text as what | |||
appears in the `types` array). If nothing in `types` is accepted, then `false` | |||
is returned. | |||
The `types` array can contain full MIME types or file extensions. Any value | |||
that is not a full MIME types is passed to `require('mime-types').lookup`. | |||
#### .types() | |||
Return the types that the request accepts, in the order of the client's | |||
preference (most preferred first). | |||
## Examples | |||
### Simple type negotiation | |||
This simple example shows how to use `accepts` to return a different typed | |||
respond body based on what the client wants to accept. The server lists it's | |||
preferences in order and will get back the best match between the client and | |||
server. | |||
```js | |||
var accepts = require('accepts') | |||
var http = require('http') | |||
function app (req, res) { | |||
var accept = accepts(req) | |||
// the order of this list is significant; should be server preferred order | |||
switch (accept.type(['json', 'html'])) { | |||
case 'json': | |||
res.setHeader('Content-Type', 'application/json') | |||
res.write('{"hello":"world!"}') | |||
break | |||
case 'html': | |||
res.setHeader('Content-Type', 'text/html') | |||
res.write('<b>hello, world!</b>') | |||
break | |||
default: | |||
// the fallback is text/plain, so no need to specify it above | |||
res.setHeader('Content-Type', 'text/plain') | |||
res.write('hello, world!') | |||
break | |||
} | |||
res.end() | |||
} | |||
http.createServer(app).listen(3000) | |||
``` | |||
You can test this out with the cURL program: | |||
```sh | |||
curl -I -H'Accept: text/html' http://localhost:3000/ | |||
``` | |||
## License | |||
[MIT](LICENSE) | |||
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master | |||
[coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master | |||
[node-version-image]: https://badgen.net/npm/node/accepts | |||
[node-version-url]: https://nodejs.org/en/download | |||
[npm-downloads-image]: https://badgen.net/npm/dm/accepts | |||
[npm-url]: https://npmjs.org/package/accepts | |||
[npm-version-image]: https://badgen.net/npm/v/accepts | |||
[travis-image]: https://badgen.net/travis/jshttp/accepts/master | |||
[travis-url]: https://travis-ci.org/jshttp/accepts |
@@ -0,0 +1,238 @@ | |||
/*! | |||
* accepts | |||
* Copyright(c) 2014 Jonathan Ong | |||
* Copyright(c) 2015 Douglas Christopher Wilson | |||
* MIT Licensed | |||
*/ | |||
'use strict' | |||
/** | |||
* Module dependencies. | |||
* @private | |||
*/ | |||
var Negotiator = require('negotiator') | |||
var mime = require('mime-types') | |||
/** | |||
* Module exports. | |||
* @public | |||
*/ | |||
module.exports = Accepts | |||
/** | |||
* Create a new Accepts object for the given req. | |||
* | |||
* @param {object} req | |||
* @public | |||
*/ | |||
function Accepts (req) { | |||
if (!(this instanceof Accepts)) { | |||
return new Accepts(req) | |||
} | |||
this.headers = req.headers | |||
this.negotiator = new Negotiator(req) | |||
} | |||
/** | |||
* Check if the given `type(s)` is acceptable, returning | |||
* the best match when true, otherwise `undefined`, in which | |||
* case you should respond with 406 "Not Acceptable". | |||
* | |||
* The `type` value may be a single mime type string | |||
* such as "application/json", the extension name | |||
* such as "json" or an array `["json", "html", "text/plain"]`. When a list | |||
* or array is given the _best_ match, if any is returned. | |||
* | |||
* Examples: | |||
* | |||
* // Accept: text/html | |||
* this.types('html'); | |||
* // => "html" | |||
* | |||
* // Accept: text/*, application/json | |||
* this.types('html'); | |||
* // => "html" | |||
* this.types('text/html'); | |||
* // => "text/html" | |||
* this.types('json', 'text'); | |||
* // => "json" | |||
* this.types('application/json'); | |||
* // => "application/json" | |||
* | |||
* // Accept: text/*, application/json | |||
* this.types('image/png'); | |||
* this.types('png'); | |||
* // => undefined | |||
* | |||
* // Accept: text/*;q=.5, application/json | |||
* this.types(['html', 'json']); | |||
* this.types('html', 'json'); | |||
* // => "json" | |||
* | |||
* @param {String|Array} types... | |||
* @return {String|Array|Boolean} | |||
* @public | |||
*/ | |||
Accepts.prototype.type = | |||
Accepts.prototype.types = function (types_) { | |||
var types = types_ | |||
// support flattened arguments | |||
if (types && !Array.isArray(types)) { | |||
types = new Array(arguments.length) | |||
for (var i = 0; i < types.length; i++) { | |||
types[i] = arguments[i] | |||
} | |||
} | |||
// no types, return all requested types | |||
if (!types || types.length === 0) { | |||
return this.negotiator.mediaTypes() | |||
} | |||
// no accept header, return first given type | |||
if (!this.headers.accept) { | |||
return types[0] | |||
} | |||
var mimes = types.map(extToMime) | |||
var accepts = this.negotiator.mediaTypes(mimes.filter(validMime)) | |||
var first = accepts[0] | |||
return first | |||
? types[mimes.indexOf(first)] | |||
: false | |||
} | |||
/** | |||
* Return accepted encodings or best fit based on `encodings`. | |||
* | |||
* Given `Accept-Encoding: gzip, deflate` | |||
* an array sorted by quality is returned: | |||
* | |||
* ['gzip', 'deflate'] | |||
* | |||
* @param {String|Array} encodings... | |||
* @return {String|Array} | |||
* @public | |||
*/ | |||
Accepts.prototype.encoding = | |||
Accepts.prototype.encodings = function (encodings_) { | |||
var encodings = encodings_ | |||
// support flattened arguments | |||
if (encodings && !Array.isArray(encodings)) { | |||
encodings = new Array(arguments.length) | |||
for (var i = 0; i < encodings.length; i++) { | |||
encodings[i] = arguments[i] | |||
} | |||
} | |||
// no encodings, return all requested encodings | |||
if (!encodings || encodings.length === 0) { | |||
return this.negotiator.encodings() | |||
} | |||
return this.negotiator.encodings(encodings)[0] || false | |||
} | |||
/** | |||
* Return accepted charsets or best fit based on `charsets`. | |||
* | |||
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5` | |||
* an array sorted by quality is returned: | |||
* | |||
* ['utf-8', 'utf-7', 'iso-8859-1'] | |||
* | |||
* @param {String|Array} charsets... | |||
* @return {String|Array} | |||
* @public | |||
*/ | |||
Accepts.prototype.charset = | |||
Accepts.prototype.charsets = function (charsets_) { | |||
var charsets = charsets_ | |||
// support flattened arguments | |||
if (charsets && !Array.isArray(charsets)) { | |||
charsets = new Array(arguments.length) | |||
for (var i = 0; i < charsets.length; i++) { | |||
charsets[i] = arguments[i] | |||
} | |||
} | |||
// no charsets, return all requested charsets | |||
if (!charsets || charsets.length === 0) { | |||
return this.negotiator.charsets() | |||
} | |||
return this.negotiator.charsets(charsets)[0] || false | |||
} | |||
/** | |||
* Return accepted languages or best fit based on `langs`. | |||
* | |||
* Given `Accept-Language: en;q=0.8, es, pt` | |||
* an array sorted by quality is returned: | |||
* | |||
* ['es', 'pt', 'en'] | |||
* | |||
* @param {String|Array} langs... | |||
* @return {Array|String} | |||
* @public | |||
*/ | |||
Accepts.prototype.lang = | |||
Accepts.prototype.langs = | |||
Accepts.prototype.language = | |||
Accepts.prototype.languages = function (languages_) { | |||
var languages = languages_ | |||
// support flattened arguments | |||
if (languages && !Array.isArray(languages)) { | |||
languages = new Array(arguments.length) | |||
for (var i = 0; i < languages.length; i++) { | |||
languages[i] = arguments[i] | |||
} | |||
} | |||
// no languages, return all requested languages | |||
if (!languages || languages.length === 0) { | |||
return this.negotiator.languages() | |||
} | |||
return this.negotiator.languages(languages)[0] || false | |||
} | |||
/** | |||
* Convert extnames to mime. | |||
* | |||
* @param {String} type | |||
* @return {String} | |||
* @private | |||
*/ | |||
function extToMime (type) { | |||
return type.indexOf('/') === -1 | |||
? mime.lookup(type) | |||
: type | |||
} | |||
/** | |||
* Check if mime is valid. | |||
* | |||
* @param {String} type | |||
* @return {String} | |||
* @private | |||
*/ | |||
function validMime (type) { | |||
return typeof type === 'string' | |||
} |
@@ -0,0 +1,86 @@ | |||
{ | |||
"_from": "accepts@~1.3.4", | |||
"_id": "accepts@1.3.7", | |||
"_inBundle": false, | |||
"_integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", | |||
"_location": "/accepts", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"type": "range", | |||
"registry": true, | |||
"raw": "accepts@~1.3.4", | |||
"name": "accepts", | |||
"escapedName": "accepts", | |||
"rawSpec": "~1.3.4", | |||
"saveSpec": null, | |||
"fetchSpec": "~1.3.4" | |||
}, | |||
"_requiredBy": [ | |||
"/serve-index" | |||
], | |||
"_resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", | |||
"_shasum": "531bc726517a3b2b41f850021c6cc15eaab507cd", | |||
"_spec": "accepts@~1.3.4", | |||
"_where": "C:\\Repos\\mdt5_webApplicationen\\StartMochaTutorial\\node_modules\\serve-index", | |||
"bugs": { | |||
"url": "https://github.com/jshttp/accepts/issues" | |||
}, | |||
"bundleDependencies": false, | |||
"contributors": [ | |||
{ | |||
"name": "Douglas Christopher Wilson", | |||
"email": "doug@somethingdoug.com" | |||
}, | |||
{ | |||
"name": "Jonathan Ong", | |||
"email": "me@jongleberry.com", | |||
"url": "http://jongleberry.com" | |||
} | |||
], | |||
"dependencies": { | |||
"mime-types": "~2.1.24", | |||
"negotiator": "0.6.2" | |||
}, | |||
"deprecated": false, | |||
"description": "Higher-level content negotiation", | |||
"devDependencies": { | |||
"deep-equal": "1.0.1", | |||
"eslint": "5.16.0", | |||
"eslint-config-standard": "12.0.0", | |||
"eslint-plugin-import": "2.17.2", | |||
"eslint-plugin-markdown": "1.0.0", | |||
"eslint-plugin-node": "8.0.1", | |||
"eslint-plugin-promise": "4.1.1", | |||
"eslint-plugin-standard": "4.0.0", | |||
"mocha": "6.1.4", | |||
"nyc": "14.0.0" | |||
}, | |||
"engines": { | |||
"node": ">= 0.6" | |||
}, | |||
"files": [ | |||
"LICENSE", | |||
"HISTORY.md", | |||
"index.js" | |||
], | |||
"homepage": "https://github.com/jshttp/accepts#readme", | |||
"keywords": [ | |||
"content", | |||
"negotiation", | |||
"accept", | |||
"accepts" | |||
], | |||
"license": "MIT", | |||
"name": "accepts", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/jshttp/accepts.git" | |||
}, | |||
"scripts": { | |||
"lint": "eslint --plugin markdown --ext js,md .", | |||
"test": "mocha --reporter spec --check-leaks --bail test/", | |||
"test-cov": "nyc --reporter=html --reporter=text npm test", | |||
"test-travis": "nyc --reporter=text npm test" | |||
}, | |||
"version": "1.3.7" | |||
} |
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
Copyright (c) 2015-present, Brian Woodward. | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,274 @@ | |||
# ansi-colors [![NPM version](https://img.shields.io/npm/v/ansi-colors.svg?style=flat)](https://www.npmjs.com/package/ansi-colors) [![NPM monthly downloads](https://img.shields.io/npm/dm/ansi-colors.svg?style=flat)](https://npmjs.org/package/ansi-colors) [![NPM total downloads](https://img.shields.io/npm/dt/ansi-colors.svg?style=flat)](https://npmjs.org/package/ansi-colors) [![Linux Build Status](https://img.shields.io/travis/doowb/ansi-colors.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/ansi-colors) [![Windows Build Status](https://img.shields.io/appveyor/ci/doowb/ansi-colors.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/doowb/ansi-colors) | |||
> Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs). | |||
Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support. | |||
## Install | |||
Install with [npm](https://www.npmjs.com/): | |||
```sh | |||
$ npm install --save ansi-colors | |||
``` | |||
![image](https://user-images.githubusercontent.com/383994/39635445-8a98a3a6-4f8b-11e8-89c1-068c45d4fff8.png) | |||
## Why use this? | |||
ansi-colors is _the fastest Node.js library for terminal styling_. A more performant drop-in replacement for chalk, with no dependencies. | |||
* _Blazing fast_ - Fastest terminal styling library in node.js, 10-20x faster than chalk! | |||
* _Drop-in replacement_ for [chalk](https://github.com/chalk/chalk). | |||
* _No dependencies_ (Chalk has 7 dependencies in its tree!) | |||
* _Safe_ - Does not modify the `String.prototype` like [colors](https://github.com/Marak/colors.js). | |||
* Supports [nested colors](#nested-colors), **and does not have the [nested styling bug](#nested-styling-bug) that is present in [colorette](https://github.com/jorgebucaran/colorette), [chalk](https://github.com/chalk/chalk), and [kleur](https://github.com/lukeed/kleur)**. | |||
* Supports [chained colors](#chained-colors). | |||
* [Toggle color support](#toggle-color-support) on or off. | |||
## Usage | |||
```js | |||
const c = require('ansi-colors'); | |||
console.log(c.red('This is a red string!')); | |||
console.log(c.green('This is a red string!')); | |||
console.log(c.cyan('This is a cyan string!')); | |||
console.log(c.yellow('This is a yellow string!')); | |||
``` | |||
![image](https://user-images.githubusercontent.com/383994/39653848-a38e67da-4fc0-11e8-89ae-98c65ebe9dcf.png) | |||
## Chained colors | |||
```js | |||
console.log(c.bold.red('this is a bold red message')); | |||
console.log(c.bold.yellow.italic('this is a bold yellow italicized message')); | |||
console.log(c.green.bold.underline('this is a bold green underlined message')); | |||
``` | |||
![image](https://user-images.githubusercontent.com/383994/39635780-7617246a-4f8c-11e8-89e9-05216cc54e38.png) | |||
## Nested colors | |||
```js | |||
console.log(c.yellow(`foo ${c.red.bold('red')} bar ${c.cyan('cyan')} baz`)); | |||
``` | |||
![image](https://user-images.githubusercontent.com/383994/39635817-8ed93d44-4f8c-11e8-8afd-8c3ea35f5fbe.png) | |||
### Nested styling bug | |||
`ansi-colors` does not have the nested styling bug found in [colorette](https://github.com/jorgebucaran/colorette), [chalk](https://github.com/chalk/chalk), and [kleur](https://github.com/lukeed/kleur). | |||
```js | |||
const { bold, red } = require('ansi-styles'); | |||
console.log(bold(`foo ${red.dim('bar')} baz`)); | |||
const colorette = require('colorette'); | |||
console.log(colorette.bold(`foo ${colorette.red(colorette.dim('bar'))} baz`)); | |||
const kleur = require('kleur'); | |||
console.log(kleur.bold(`foo ${kleur.red.dim('bar')} baz`)); | |||
const chalk = require('chalk'); | |||
console.log(chalk.bold(`foo ${chalk.red.dim('bar')} baz`)); | |||
``` | |||
**Results in the following** | |||
(sans icons and labels) | |||
![image](https://user-images.githubusercontent.com/383994/47280326-d2ee0580-d5a3-11e8-9611-ea6010f0a253.png) | |||
## Toggle color support | |||
Easily enable/disable colors. | |||
```js | |||
const c = require('ansi-colors'); | |||
// disable colors manually | |||
c.enabled = false; | |||
// or use a library to automatically detect support | |||
c.enabled = require('color-support').hasBasic; | |||
console.log(c.red('I will only be colored red if the terminal supports colors')); | |||
``` | |||
## Strip ANSI codes | |||
Use the `.unstyle` method to strip ANSI codes from a string. | |||
```js | |||
console.log(c.unstyle(c.blue.bold('foo bar baz'))); | |||
//=> 'foo bar baz' | |||
``` | |||
## Available styles | |||
**Note** that bright and bright-background colors are not always supported. | |||
| Colors | Background Colors | Bright Colors | Bright Background Colors | | |||
| ------- | ----------------- | ------------- | ------------------------ | | |||
| black | bgBlack | blackBright | bgBlackBright | | |||
| red | bgRed | redBright | bgRedBright | | |||
| green | bgGreen | greenBright | bgGreenBright | | |||
| yellow | bgYellow | yellowBright | bgYellowBright | | |||
| blue | bgBlue | blueBright | bgBlueBright | | |||
| magenta | bgMagenta | magentaBright | bgMagentaBright | | |||
| cyan | bgCyan | cyanBright | bgCyanBright | | |||
| white | bgWhite | whiteBright | bgWhiteBright | | |||
| gray | | | | | |||
| grey | | | | | |||
_(`gray` is the U.S. spelling, `grey` is more commonly used in the Canada and U.K.)_ | |||
### Style modifiers | |||
* dim | |||
* **bold** | |||
* hidden | |||
* _italic_ | |||
* underline | |||
* inverse | |||
* ~~strikethrough~~ | |||
* reset | |||
## Performance | |||
**Libraries tested** | |||
* ansi-colors v3.0.4 | |||
* chalk v2.4.1 | |||
### Mac | |||
> MacBook Pro, Intel Core i7, 2.3 GHz, 16 GB. | |||
**Load time** | |||
Time it takes to load the first time `require()` is called: | |||
* ansi-colors - `1.915ms` | |||
* chalk - `12.437ms` | |||
**Benchmarks** | |||
``` | |||
# All Colors | |||
ansi-colors x 173,851 ops/sec ±0.42% (91 runs sampled) | |||
chalk x 9,944 ops/sec ±2.53% (81 runs sampled))) | |||
# Chained colors | |||
ansi-colors x 20,791 ops/sec ±0.60% (88 runs sampled) | |||
chalk x 2,111 ops/sec ±2.34% (83 runs sampled) | |||
# Nested colors | |||
ansi-colors x 59,304 ops/sec ±0.98% (92 runs sampled) | |||
chalk x 4,590 ops/sec ±2.08% (82 runs sampled) | |||
``` | |||
### Windows | |||
> Windows 10, Intel Core i7-7700k CPU @ 4.2 GHz, 32 GB | |||
**Load time** | |||
Time it takes to load the first time `require()` is called: | |||
* ansi-colors - `1.494ms` | |||
* chalk - `11.523ms` | |||
**Benchmarks** | |||
``` | |||
# All Colors | |||
ansi-colors x 193,088 ops/sec ±0.51% (95 runs sampled)) | |||
chalk x 9,612 ops/sec ±3.31% (77 runs sampled))) | |||
# Chained colors | |||
ansi-colors x 26,093 ops/sec ±1.13% (94 runs sampled) | |||
chalk x 2,267 ops/sec ±2.88% (80 runs sampled)) | |||
# Nested colors | |||
ansi-colors x 67,747 ops/sec ±0.49% (93 runs sampled) | |||
chalk x 4,446 ops/sec ±3.01% (82 runs sampled)) | |||
``` | |||
## About | |||
<details> | |||
<summary><strong>Contributing</strong></summary> | |||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | |||
</details> | |||
<details> | |||
<summary><strong>Running Tests</strong></summary> | |||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: | |||
```sh | |||
$ npm install && npm test | |||
``` | |||
</details> | |||
<details> | |||
<summary><strong>Building docs</strong></summary> | |||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ | |||
To generate the readme, run the following command: | |||
```sh | |||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | |||
``` | |||
</details> | |||
### Related projects | |||
You might also be interested in these projects: | |||
* [ansi-wrap](https://www.npmjs.com/package/ansi-wrap): Create ansi colors by passing the open and close codes. | [homepage](https://github.com/jonschlinkert/ansi-wrap "Create ansi colors by passing the open and close codes.") | |||
* [strip-color](https://www.npmjs.com/package/strip-color): Strip ANSI color codes from a string. No dependencies. | [homepage](https://github.com/jonschlinkert/strip-color "Strip ANSI color codes from a string. No dependencies.") | |||
### Contributors | |||
| **Commits** | **Contributor** | | |||
| --- | --- | | |||
| 38 | [jonschlinkert](https://github.com/jonschlinkert) | | |||
| 38 | [doowb](https://github.com/doowb) | | |||
| 6 | [lukeed](https://github.com/lukeed) | | |||
| 2 | [Silic0nS0ldier](https://github.com/Silic0nS0ldier) | | |||
| 1 | [dwieeb](https://github.com/dwieeb) | | |||
| 1 | [jorgebucaran](https://github.com/jorgebucaran) | | |||
| 1 | [madhavarshney](https://github.com/madhavarshney) | | |||
| 1 | [Weishi93](https://github.com/Weishi93) | | |||
| 1 | [chapterjason](https://github.com/chapterjason) | | |||
### Author | |||
**Brian Woodward** | |||
* [GitHub Profile](https://github.com/doowb) | |||
* [Twitter Profile](https://twitter.com/doowb) | |||
* [LinkedIn Profile](https://linkedin.com/in/woodwardbrian) | |||
### License | |||
Copyright © 2018, [Brian Woodward](https://github.com/doowb). | |||
Released under the [MIT License](LICENSE). | |||
*** | |||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on December 03, 2018._ |
@@ -0,0 +1,114 @@ | |||
'use strict'; | |||
const colors = { enabled: true, visible: true, styles: {}, keys: {} }; | |||
if ('FORCE_COLOR' in process.env) { | |||
colors.enabled = process.env.FORCE_COLOR !== '0'; | |||
} | |||
const ansi = style => { | |||
style.open = `\u001b[${style.codes[0]}m`; | |||
style.close = `\u001b[${style.codes[1]}m`; | |||
style.regex = new RegExp(`\\u001b\\[${style.codes[1]}m`, 'g'); | |||
return style; | |||
}; | |||
const wrap = (style, str, nl) => { | |||
let { open, close, regex } = style; | |||
str = open + (str.includes(close) ? str.replace(regex, close + open) : str) + close; | |||
// see https://github.com/chalk/chalk/pull/92, thanks to the | |||
// chalk contributors for this fix. However, we've confirmed that | |||
// this issue is also present in Windows terminals | |||
return nl ? str.replace(/\r?\n/g, `${close}$&${open}`) : str; | |||
}; | |||
const style = (input, stack) => { | |||
if (input === '' || input == null) return ''; | |||
if (colors.enabled === false) return input; | |||
if (colors.visible === false) return ''; | |||
let str = '' + input; | |||
let nl = str.includes('\n'); | |||
let n = stack.length; | |||
while (n-- > 0) str = wrap(colors.styles[stack[n]], str, nl); | |||
return str; | |||
}; | |||
const define = (name, codes, type) => { | |||
colors.styles[name] = ansi({ name, codes }); | |||
let t = colors.keys[type] || (colors.keys[type] = []); | |||
t.push(name); | |||
Reflect.defineProperty(colors, name, { | |||
get() { | |||
let color = input => style(input, color.stack); | |||
Reflect.setPrototypeOf(color, colors); | |||
color.stack = this.stack ? this.stack.concat(name) : [name]; | |||
return color; | |||
} | |||
}); | |||
}; | |||
define('reset', [0, 0], 'modifier'); | |||
define('bold', [1, 22], 'modifier'); | |||
define('dim', [2, 22], 'modifier'); | |||
define('italic', [3, 23], 'modifier'); | |||
define('underline', [4, 24], 'modifier'); | |||
define('inverse', [7, 27], 'modifier'); | |||
define('hidden', [8, 28], 'modifier'); | |||
define('strikethrough', [9, 29], 'modifier'); | |||
define('black', [30, 39], 'color'); | |||
define('red', [31, 39], 'color'); | |||
define('green', [32, 39], 'color'); | |||
define('yellow', [33, 39], 'color'); | |||
define('blue', [34, 39], 'color'); | |||
define('magenta', [35, 39], 'color'); | |||
define('cyan', [36, 39], 'color'); | |||
define('white', [37, 39], 'color'); | |||
define('gray', [90, 39], 'color'); | |||
define('grey', [90, 39], 'color'); | |||
define('bgBlack', [40, 49], 'bg'); | |||
define('bgRed', [41, 49], 'bg'); | |||
define('bgGreen', [42, 49], 'bg'); | |||
define('bgYellow', [43, 49], 'bg'); | |||
define('bgBlue', [44, 49], 'bg'); | |||
define('bgMagenta', [45, 49], 'bg'); | |||
define('bgCyan', [46, 49], 'bg'); | |||
define('bgWhite', [47, 49], 'bg'); | |||
define('blackBright', [90, 39], 'bright'); | |||
define('redBright', [91, 39], 'bright'); | |||
define('greenBright', [92, 39], 'bright'); | |||
define('yellowBright', [93, 39], 'bright'); | |||
define('blueBright', [94, 39], 'bright'); | |||
define('magentaBright', [95, 39], 'bright'); | |||
define('cyanBright', [96, 39], 'bright'); | |||
define('whiteBright', [97, 39], 'bright'); | |||
define('bgBlackBright', [100, 49], 'bgBright'); | |||
define('bgRedBright', [101, 49], 'bgBright'); | |||
define('bgGreenBright', [102, 49], 'bgBright'); | |||
define('bgYellowBright', [103, 49], 'bgBright'); | |||
define('bgBlueBright', [104, 49], 'bgBright'); | |||
define('bgMagentaBright', [105, 49], 'bgBright'); | |||
define('bgCyanBright', [106, 49], 'bgBright'); | |||
define('bgWhiteBright', [107, 49], 'bgBright'); | |||
/* eslint-disable no-control-regex */ | |||
const re = colors.ansiRegex = /\u001b\[\d+m/gm; | |||
colors.hasColor = colors.hasAnsi = str => { | |||
re.lastIndex = 0; | |||
return !!str && typeof str === 'string' && re.test(str); | |||
}; | |||
colors.unstyle = str => { | |||
re.lastIndex = 0; | |||
return typeof str === 'string' ? str.replace(re, '') : str; | |||
}; | |||
colors.none = colors.clear = colors.noop = str => str; // no-op, for programmatic usage | |||
colors.stripColor = colors.unstyle; | |||
colors.symbols = require('./symbols'); | |||
colors.define = define; | |||
module.exports = colors; |
@@ -0,0 +1,152 @@ | |||
{ | |||
"_from": "ansi-colors@3.2.3", | |||
"_id": "ansi-colors@3.2.3", | |||
"_inBundle": false, | |||
"_integrity": "sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==", | |||
"_location": "/ansi-colors", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"type": "version", | |||
"registry": true, | |||
"raw": "ansi-colors@3.2.3", | |||
"name": "ansi-colors", | |||
"escapedName": "ansi-colors", | |||
"rawSpec": "3.2.3", | |||
"saveSpec": null, | |||
"fetchSpec": "3.2.3" | |||
}, | |||
"_requiredBy": [ | |||
"/mocha" | |||
], | |||
"_resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", | |||
"_shasum": "57d35b8686e851e2cc04c403f1c00203976a1813", | |||
"_spec": "ansi-colors@3.2.3", | |||
"_where": "C:\\Repos\\mdt5_webApplicationen\\StartMochaTutorial\\node_modules\\mocha", | |||
"author": { | |||
"name": "Brian Woodward", | |||
"url": "https://github.com/doowb" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/doowb/ansi-colors/issues" | |||
}, | |||
"bundleDependencies": false, | |||
"contributors": [ | |||
{ | |||
"name": "Brian Woodward", | |||
"url": "https://twitter.com/doowb" | |||
}, | |||
{ | |||
"name": "Jason Schilling", | |||
"url": "https://sourecode.de" | |||
}, | |||
{ | |||
"name": "Jon Schlinkert", | |||
"url": "http://twitter.com/jonschlinkert" | |||
}, | |||
{ | |||
"name": "Jordan", | |||
"url": "https://github.com/Silic0nS0ldier" | |||
} | |||
], | |||
"deprecated": false, | |||
"description": "Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).", | |||
"devDependencies": { | |||
"decache": "^4.4.0", | |||
"gulp-format-md": "^1.0.0", | |||
"justified": "^1.0.1", | |||
"mocha": "^5.2.0", | |||
"text-table": "^0.2.0" | |||
}, | |||
"engines": { | |||
"node": ">=6" | |||
}, | |||
"files": [ | |||
"index.js", | |||
"symbols.js", | |||
"types/index.d.ts" | |||
], | |||
"homepage": "https://github.com/doowb/ansi-colors", | |||
"keywords": [ | |||
"ansi", | |||
"bgblack", | |||
"bgBlack", | |||
"bgblue", | |||
"bgBlue", | |||
"bgcyan", | |||
"bgCyan", | |||
"bggreen", | |||
"bgGreen", | |||
"bgmagenta", | |||
"bgMagenta", | |||
"bgred", | |||
"bgRed", | |||
"bgwhite", | |||
"bgWhite", | |||
"bgyellow", | |||
"bgYellow", | |||
"black", | |||
"blue", | |||
"bold", | |||
"clorox", | |||
"colors", | |||
"cyan", | |||
"dim", | |||
"gray", | |||
"green", | |||
"grey", | |||
"hidden", | |||
"inverse", | |||
"italic", | |||
"kleur", | |||
"magenta", | |||
"red", | |||
"reset", | |||
"strikethrough", | |||
"underline", | |||
"white", | |||
"yellow" | |||
], | |||
"license": "MIT", | |||
"main": "index.js", | |||
"name": "ansi-colors", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/doowb/ansi-colors.git" | |||
}, | |||
"scripts": { | |||
"test": "mocha" | |||
}, | |||
"types": "./types/index.d.ts", | |||
"verb": { | |||
"toc": false, | |||
"layout": "default", | |||
"tasks": [ | |||
"readme" | |||
], | |||
"data": { | |||
"author": { | |||
"linkedin": "woodwardbrian", | |||
"twitter": "doowb" | |||
} | |||
}, | |||
"plugins": [ | |||
"gulp-format-md" | |||
], | |||
"lint": { | |||
"reflinks": true | |||
}, | |||
"related": { | |||
"list": [ | |||
"ansi-wrap", | |||
"strip-color" | |||
] | |||
}, | |||
"reflinks": [ | |||
"chalk", | |||
"colorette", | |||
"colors", | |||
"kleur" | |||
] | |||
}, | |||
"version": "3.2.3" | |||
} |
@@ -0,0 +1,46 @@ | |||
'use strict'; | |||
const isWindows = process.platform === 'win32'; | |||
const isLinux = process.platform === 'linux'; | |||
const windows = { | |||
bullet: '•', | |||
check: '√', | |||
cross: '×', | |||
ellipsis: '...', | |||
heart: '❤', | |||
info: 'i', | |||
line: '─', | |||
middot: '·', | |||
minus: '-', | |||
plus: '+', | |||
question: '?', | |||
questionSmall: '﹖', | |||
pointer: '>', | |||
pointerSmall: '»', | |||
warning: '‼' | |||
}; | |||
const other = { | |||
ballotCross: '✘', | |||
bullet: '•', | |||
check: '✔', | |||
cross: '✖', | |||
ellipsis: '…', | |||
heart: '❤', | |||
info: 'ℹ', | |||
line: '─', | |||
middot: '·', | |||
minus: '-', | |||
plus: '+', | |||
question: '?', | |||
questionFull: '?', | |||
questionSmall: '﹖', | |||
pointer: isLinux ? '▸' : '❯', | |||
pointerSmall: isLinux ? '‣' : '›', | |||
warning: '⚠' | |||
}; | |||
module.exports = isWindows ? windows : other; | |||
Reflect.defineProperty(module.exports, 'windows', { enumerable: false, value: windows }); | |||
Reflect.defineProperty(module.exports, 'other', { enumerable: false, value: other }); |
@@ -0,0 +1,161 @@ | |||
// Imported from DefinitelyTyped project. | |||
// TypeScript definitions for ansi-colors | |||
// Definitions by: Rogier Schouten <https://github.com/rogierschouten> | |||
// Integrated by: Jordan Mele <https://github.com/Silic0nS0ldier> | |||
interface SymbolsType { | |||
check: string; | |||
cross: string; | |||
info: string; | |||
line: string; | |||
pointer: string; | |||
pointerSmall: string; | |||
question: string; | |||
warning: string; | |||
} | |||
type StyleArrayStructure = [number, number]; | |||
interface StyleArrayProperties { | |||
open: string; | |||
close: string; | |||
closeRe: string; | |||
} | |||
type StyleType = StyleArrayStructure & StyleArrayProperties; | |||
export interface StyleFunction extends StylesType<StyleFunction> { | |||
(s: string): string; | |||
} | |||
interface StylesType<T> { | |||
// modifiers | |||
reset: T; | |||
bold: T; | |||
dim: T; | |||
italic: T; | |||
underline: T; | |||
inverse: T; | |||
hidden: T; | |||
strikethrough: T; | |||
// colors | |||
black: T; | |||
red: T; | |||
green: T; | |||
yellow: T; | |||
blue: T; | |||
magenta: T; | |||
cyan: T; | |||
white: T; | |||
gray: T; | |||
grey: T; | |||
// bright colors | |||
blackBright: T; | |||
redBright: T; | |||
greenBright: T; | |||
yellowBright: T; | |||
blueBright: T; | |||
magentaBright: T; | |||
cyanBright: T; | |||
whiteBright: T; | |||
// background colors | |||
bgBlack: T; | |||
bgRed: T; | |||
bgGreen: T; | |||
bgYellow: T; | |||
bgBlue: T; | |||
bgMagenta: T; | |||
bgCyan: T; | |||
bgWhite: T; | |||
// bright background colors | |||
bgBlackBright: T; | |||
bgRedBright: T; | |||
bgGreenBright: T; | |||
bgYellowBright: T; | |||
bgBlueBright: T; | |||
bgMagentaBright: T; | |||
bgCyanBright: T; | |||
bgWhiteBright: T; | |||
} | |||
// modifiers | |||
export const reset: StyleFunction; | |||
export const bold: StyleFunction; | |||
export const dim: StyleFunction; | |||
export const italic: StyleFunction; | |||
export const underline: StyleFunction; | |||
export const inverse: StyleFunction; | |||
export const hidden: StyleFunction; | |||
export const strikethrough: StyleFunction; | |||
// colors | |||
export const black: StyleFunction; | |||
export const red: StyleFunction; | |||
export const green: StyleFunction; | |||
export const yellow: StyleFunction; | |||
export const blue: StyleFunction; | |||
export const magenta: StyleFunction; | |||
export const cyan: StyleFunction; | |||
export const white: StyleFunction; | |||
export const gray: StyleFunction; | |||
export const grey: StyleFunction; | |||
// bright colors | |||
export const blackBright: StyleFunction; | |||
export const redBright: StyleFunction; | |||
export const greenBright: StyleFunction; | |||
export const yellowBright: StyleFunction; | |||
export const blueBright: StyleFunction; | |||
export const magentaBright: StyleFunction; | |||
export const cyanBright: StyleFunction; | |||
export const whiteBright: StyleFunction; | |||
// background colors | |||
export const bgBlack: StyleFunction; | |||
export const bgRed: StyleFunction; | |||
export const bgGreen: StyleFunction; | |||
export const bgYellow: StyleFunction; | |||
export const bgBlue: StyleFunction; | |||
export const bgMagenta: StyleFunction; | |||
export const bgCyan: StyleFunction; | |||
export const bgWhite: StyleFunction; | |||
// bright background colors | |||
export const bgBlackBright: StyleFunction; | |||
export const bgRedBright: StyleFunction; | |||
export const bgGreenBright: StyleFunction; | |||
export const bgYellowBright: StyleFunction; | |||
export const bgBlueBright: StyleFunction; | |||
export const bgMagentaBright: StyleFunction; | |||
export const bgCyanBright: StyleFunction; | |||
export const bgWhiteBright: StyleFunction; | |||
export let enabled: boolean; | |||
export let visible: boolean; | |||
export const ansiRegex: RegExp; | |||
/** | |||
* Remove styles from string | |||
*/ | |||
export function stripColor(s: string): string; | |||
/** | |||
* Remove styles from string | |||
*/ | |||
export function strip(s: string): string; | |||
/** | |||
* Remove styles from string | |||
*/ | |||
export function unstyle(s: string): string; | |||
export const styles: StylesType<StyleType>; | |||
export const symbols: SymbolsType; | |||
/** | |||
* Outputs a string with check-symbol as prefix | |||
*/ | |||
export function ok(...args: string[]): string; |
@@ -0,0 +1,10 @@ | |||
'use strict'; | |||
module.exports = () => { | |||
const pattern = [ | |||
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', | |||
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))' | |||
].join('|'); | |||
return new RegExp(pattern, 'g'); | |||
}; |
@@ -0,0 +1,9 @@ | |||
MIT License | |||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,85 @@ | |||
{ | |||
"_from": "ansi-regex@^3.0.0", | |||
"_id": "ansi-regex@3.0.0", | |||
"_inBundle": false, | |||
"_integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", | |||
"_location": "/ansi-regex", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"type": "range", | |||
"registry": true, | |||
"raw": "ansi-regex@^3.0.0", | |||
"name": "ansi-regex", | |||
"escapedName": "ansi-regex", | |||
"rawSpec": "^3.0.0", | |||
"saveSpec": null, | |||
"fetchSpec": "^3.0.0" | |||
}, | |||
"_requiredBy": [ | |||
"/strip-ansi" | |||
], | |||
"_resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", | |||
"_shasum": "ed0317c322064f79466c02966bddb605ab37d998", | |||
"_spec": "ansi-regex@^3.0.0", | |||
"_where": "C:\\Repos\\mdt5_webApplicationen\\StartMochaTutorial\\node_modules\\strip-ansi", | |||
"author": { | |||
"name": "Sindre Sorhus", | |||
"email": "sindresorhus@gmail.com", | |||
"url": "sindresorhus.com" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/chalk/ansi-regex/issues" | |||
}, | |||
"bundleDependencies": false, | |||
"deprecated": false, | |||
"description": "Regular expression for matching ANSI escape codes", | |||
"devDependencies": { | |||
"ava": "*", | |||
"xo": "*" | |||
}, | |||
"engines": { | |||
"node": ">=4" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"homepage": "https://github.com/chalk/ansi-regex#readme", | |||
"keywords": [ | |||
"ansi", | |||
"styles", | |||
"color", | |||
"colour", | |||
"colors", | |||
"terminal", | |||
"console", | |||
"cli", | |||
"string", | |||
"tty", | |||
"escape", | |||
"formatting", | |||
"rgb", | |||
"256", | |||
"shell", | |||
"xterm", | |||
"command-line", | |||
"text", | |||
"regex", | |||
"regexp", | |||
"re", | |||
"match", | |||
"test", | |||
"find", | |||
"pattern" | |||
], | |||
"license": "MIT", | |||
"name": "ansi-regex", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/chalk/ansi-regex.git" | |||
}, | |||
"scripts": { | |||
"test": "xo && ava", | |||
"view-supported": "node fixtures/view-codes.js" | |||
}, | |||
"version": "3.0.0" | |||
} |
@@ -0,0 +1,46 @@ | |||
# ansi-regex [![Build Status](https://travis-ci.org/chalk/ansi-regex.svg?branch=master)](https://travis-ci.org/chalk/ansi-regex) | |||
> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) | |||
## Install | |||
``` | |||
$ npm install ansi-regex | |||
``` | |||
## Usage | |||
```js | |||
const ansiRegex = require('ansi-regex'); | |||
ansiRegex().test('\u001B[4mcake\u001B[0m'); | |||
//=> true | |||
ansiRegex().test('cake'); | |||
//=> false | |||
'\u001B[4mcake\u001B[0m'.match(ansiRegex()); | |||
//=> ['\u001B[4m', '\u001B[0m'] | |||
``` | |||
## FAQ | |||
### Why do you test for codes not in the ECMA 48 standard? | |||
Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them. | |||
On the historical side, those ECMA standards were established in the early 90's whereas the VT100, for example, was designed in the mid/late 70's. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar 'anarchy' of codes is in the x86 architecture for processors; there are a ton of "interrupts" that can mean different things on certain brands of processors, most of which have been phased out. | |||
## Maintainers | |||
- [Sindre Sorhus](https://github.com/sindresorhus) | |||
- [Josh Junon](https://github.com/qix-) | |||
## License | |||
MIT |
@@ -0,0 +1,165 @@ | |||
'use strict'; | |||
const colorConvert = require('color-convert'); | |||
const wrapAnsi16 = (fn, offset) => function () { | |||
const code = fn.apply(colorConvert, arguments); | |||
return `\u001B[${code + offset}m`; | |||
}; | |||
const wrapAnsi256 = (fn, offset) => function () { | |||
const code = fn.apply(colorConvert, arguments); | |||
return `\u001B[${38 + offset};5;${code}m`; | |||
}; | |||
const wrapAnsi16m = (fn, offset) => function () { | |||
const rgb = fn.apply(colorConvert, arguments); | |||
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`; | |||
}; | |||
function assembleStyles() { | |||
const codes = new Map(); | |||
const styles = { | |||
modifier: { | |||
reset: [0, 0], | |||
// 21 isn't widely supported and 22 does the same thing | |||
bold: [1, 22], | |||
dim: [2, 22], | |||
italic: [3, 23], | |||
underline: [4, 24], | |||
inverse: [7, 27], | |||
hidden: [8, 28], | |||
strikethrough: [9, 29] | |||
}, | |||
color: { | |||
black: [30, 39], | |||
red: [31, 39], | |||
green: [32, 39], | |||
yellow: [33, 39], | |||
blue: [34, 39], | |||
magenta: [35, 39], | |||
cyan: [36, 39], | |||
white: [37, 39], | |||
gray: [90, 39], | |||
// Bright color | |||
redBright: [91, 39], | |||
greenBright: [92, 39], | |||
yellowBright: [93, 39], | |||
blueBright: [94, 39], | |||
magentaBright: [95, 39], | |||
cyanBright: [96, 39], | |||
whiteBright: [97, 39] | |||
}, | |||
bgColor: { | |||
bgBlack: [40, 49], | |||
bgRed: [41, 49], | |||
bgGreen: [42, 49], | |||
bgYellow: [43, 49], | |||
bgBlue: [44, 49], | |||
bgMagenta: [45, 49], | |||
bgCyan: [46, 49], | |||
bgWhite: [47, 49], | |||
// Bright color | |||
bgBlackBright: [100, 49], | |||
bgRedBright: [101, 49], | |||
bgGreenBright: [102, 49], | |||
bgYellowBright: [103, 49], | |||
bgBlueBright: [104, 49], | |||
bgMagentaBright: [105, 49], | |||
bgCyanBright: [106, 49], | |||
bgWhiteBright: [107, 49] | |||
} | |||
}; | |||
// Fix humans | |||
styles.color.grey = styles.color.gray; | |||
for (const groupName of Object.keys(styles)) { | |||
const group = styles[groupName]; | |||
for (const styleName of Object.keys(group)) { | |||
const style = group[styleName]; | |||
styles[styleName] = { | |||
open: `\u001B[${style[0]}m`, | |||
close: `\u001B[${style[1]}m` | |||
}; | |||
group[styleName] = styles[styleName]; | |||
codes.set(style[0], style[1]); | |||
} | |||
Object.defineProperty(styles, groupName, { | |||
value: group, | |||
enumerable: false | |||
}); | |||
Object.defineProperty(styles, 'codes', { | |||
value: codes, | |||
enumerable: false | |||
}); | |||
} | |||
const ansi2ansi = n => n; | |||
const rgb2rgb = (r, g, b) => [r, g, b]; | |||
styles.color.close = '\u001B[39m'; | |||
styles.bgColor.close = '\u001B[49m'; | |||
styles.color.ansi = { | |||
ansi: wrapAnsi16(ansi2ansi, 0) | |||
}; | |||
styles.color.ansi256 = { | |||
ansi256: wrapAnsi256(ansi2ansi, 0) | |||
}; | |||
styles.color.ansi16m = { | |||
rgb: wrapAnsi16m(rgb2rgb, 0) | |||
}; | |||
styles.bgColor.ansi = { | |||
ansi: wrapAnsi16(ansi2ansi, 10) | |||
}; | |||
styles.bgColor.ansi256 = { | |||
ansi256: wrapAnsi256(ansi2ansi, 10) | |||
}; | |||
styles.bgColor.ansi16m = { | |||
rgb: wrapAnsi16m(rgb2rgb, 10) | |||
}; | |||
for (let key of Object.keys(colorConvert)) { | |||
if (typeof colorConvert[key] !== 'object') { | |||
continue; | |||
} | |||
const suite = colorConvert[key]; | |||
if (key === 'ansi16') { | |||
key = 'ansi'; | |||
} | |||
if ('ansi16' in suite) { | |||
styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0); | |||
styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10); | |||
} | |||
if ('ansi256' in suite) { | |||
styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0); | |||
styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10); | |||
} | |||
if ('rgb' in suite) { | |||
styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0); | |||
styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10); | |||
} | |||
} | |||
return styles; | |||
} | |||
// Make the export immutable | |||
Object.defineProperty(module, 'exports', { | |||
enumerable: true, | |||
get: assembleStyles | |||
}); |
@@ -0,0 +1,9 @@ | |||
MIT License | |||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,89 @@ | |||
{ | |||
"_from": "ansi-styles@^3.2.1", | |||
"_id": "ansi-styles@3.2.1", | |||
"_inBundle": false, | |||
"_integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", | |||
"_location": "/ansi-styles", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"type": "range", | |||
"registry": true, | |||
"raw": "ansi-styles@^3.2.1", | |||
"name": "ansi-styles", | |||
"escapedName": "ansi-styles", | |||
"rawSpec": "^3.2.1", | |||
"saveSpec": null, | |||
"fetchSpec": "^3.2.1" | |||
}, | |||
"_requiredBy": [ | |||
"/chalk", | |||
"/wrap-ansi" | |||
], | |||
"_resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", | |||
"_shasum": "41fbb20243e50b12be0f04b8dedbf07520ce841d", | |||
"_spec": "ansi-styles@^3.2.1", | |||
"_where": "C:\\Repos\\mdt5_webApplicationen\\StartMochaTutorial\\node_modules\\chalk", | |||
"author": { | |||
"name": "Sindre Sorhus", | |||
"email": "sindresorhus@gmail.com", | |||
"url": "sindresorhus.com" | |||
}, | |||
"ava": { | |||
"require": "babel-polyfill" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/chalk/ansi-styles/issues" | |||
}, | |||
"bundleDependencies": false, | |||
"dependencies": { | |||
"color-convert": "^1.9.0" | |||
}, | |||
"deprecated": false, | |||
"description": "ANSI escape codes for styling strings in the terminal", | |||
"devDependencies": { | |||
"ava": "*", | |||
"babel-polyfill": "^6.23.0", | |||
"svg-term-cli": "^2.1.1", | |||
"xo": "*" | |||
}, | |||
"engines": { | |||
"node": ">=4" | |||
}, | |||
"files": [ | |||
"index.js" | |||
], | |||
"homepage": "https://github.com/chalk/ansi-styles#readme", | |||
"keywords": [ | |||
"ansi", | |||
"styles", | |||
"color", | |||
"colour", | |||
"colors", | |||
"terminal", | |||
"console", | |||
"cli", | |||
"string", | |||
"tty", | |||
"escape", | |||
"formatting", | |||
"rgb", | |||
"256", | |||
"shell", | |||
"xterm", | |||
"log", | |||
"logging", | |||
"command-line", | |||
"text" | |||
], | |||
"license": "MIT", | |||
"name": "ansi-styles", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/chalk/ansi-styles.git" | |||
}, | |||
"scripts": { | |||
"screenshot": "svg-term --command='node screenshot' --out=screenshot.svg --padding=3 --width=55 --height=3 --at=1000 --no-cursor", | |||
"test": "xo && ava" | |||
}, | |||
"version": "3.2.1" | |||
} |
@@ -0,0 +1,147 @@ | |||
# ansi-styles [![Build Status](https://travis-ci.org/chalk/ansi-styles.svg?branch=master)](https://travis-ci.org/chalk/ansi-styles) | |||
> [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal | |||
You probably want the higher-level [chalk](https://github.com/chalk/chalk) module for styling your strings. | |||
<img src="https://cdn.rawgit.com/chalk/ansi-styles/8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" width="900"> | |||
## Install | |||
``` | |||
$ npm install ansi-styles | |||
``` | |||
## Usage | |||
```js | |||
const style = require('ansi-styles'); | |||
console.log(`${style.green.open}Hello world!${style.green.close}`); | |||
// Color conversion between 16/256/truecolor | |||
// NOTE: If conversion goes to 16 colors or 256 colors, the original color | |||
// may be degraded to fit that color palette. This means terminals | |||
// that do not support 16 million colors will best-match the | |||
// original color. | |||
console.log(style.bgColor.ansi.hsl(120, 80, 72) + 'Hello world!' + style.bgColor.close); | |||
console.log(style.color.ansi256.rgb(199, 20, 250) + 'Hello world!' + style.color.close); | |||
console.log(style.color.ansi16m.hex('#ABCDEF') + 'Hello world!' + style.color.close); | |||
``` | |||
## API | |||
Each style has an `open` and `close` property. | |||
## Styles | |||
### Modifiers | |||
- `reset` | |||
- `bold` | |||
- `dim` | |||
- `italic` *(Not widely supported)* | |||
- `underline` | |||
- `inverse` | |||
- `hidden` | |||
- `strikethrough` *(Not widely supported)* | |||
### Colors | |||
- `black` | |||
- `red` | |||
- `green` | |||
- `yellow` | |||
- `blue` | |||
- `magenta` | |||
- `cyan` | |||
- `white` | |||
- `gray` ("bright black") | |||
- `redBright` | |||
- `greenBright` | |||
- `yellowBright` | |||
- `blueBright` | |||
- `magentaBright` | |||
- `cyanBright` | |||
- `whiteBright` | |||
### Background colors | |||
- `bgBlack` | |||
- `bgRed` | |||
- `bgGreen` | |||
- `bgYellow` | |||
- `bgBlue` | |||
- `bgMagenta` | |||
- `bgCyan` | |||
- `bgWhite` | |||
- `bgBlackBright` | |||
- `bgRedBright` | |||
- `bgGreenBright` | |||
- `bgYellowBright` | |||
- `bgBlueBright` | |||
- `bgMagentaBright` | |||
- `bgCyanBright` | |||
- `bgWhiteBright` | |||
## Advanced usage | |||
By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module. | |||
- `style.modifier` | |||
- `style.color` | |||
- `style.bgColor` | |||
###### Example | |||
```js | |||
console.log(style.color.green.open); | |||
``` | |||
Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `style.codes`, which returns a `Map` with the open codes as keys and close codes as values. | |||
###### Example | |||
```js | |||
console.log(style.codes.get(36)); | |||
//=> 39 | |||
``` | |||
## [256 / 16 million (TrueColor) support](https://gist.github.com/XVilka/8346728) | |||
`ansi-styles` uses the [`color-convert`](https://github.com/Qix-/color-convert) package to allow for converting between various colors and ANSI escapes, with support for 256 and 16 million colors. | |||
To use these, call the associated conversion function with the intended output, for example: | |||
```js | |||
style.color.ansi.rgb(100, 200, 15); // RGB to 16 color ansi foreground code | |||
style.bgColor.ansi.rgb(100, 200, 15); // RGB to 16 color ansi background code | |||
style.color.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code | |||
style.bgColor.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code | |||
style.color.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color foreground code | |||
style.bgColor.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color background code | |||
``` | |||
## Related | |||
- [ansi-escapes](https://github.com/sindresorhus/ansi-escapes) - ANSI escape codes for manipulating the terminal | |||
## Maintainers | |||
- [Sindre Sorhus](https://github.com/sindresorhus) | |||
- [Josh Junon](https://github.com/qix-) | |||
## License | |||
MIT |
@@ -0,0 +1,15 @@ | |||
The ISC License | |||
Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com) | |||
Permission to use, copy, modify, and/or distribute this software for any | |||
purpose with or without fee is hereby granted, provided that the above | |||
copyright notice and this permission notice appear in all copies. | |||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | |||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
@@ -0,0 +1,87 @@ | |||
anymatch [![Build Status](https://travis-ci.org/micromatch/anymatch.svg?branch=master)](https://travis-ci.org/micromatch/anymatch) [![Coverage Status](https://img.shields.io/coveralls/micromatch/anymatch.svg?branch=master)](https://coveralls.io/r/micromatch/anymatch?branch=master) | |||
====== | |||
Javascript module to match a string against a regular expression, glob, string, | |||
or function that takes the string as an argument and returns a truthy or falsy | |||
value. The matcher can also be an array of any or all of these. Useful for | |||
allowing a very flexible user-defined config to define things like file paths. | |||
__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__ | |||
Usage | |||
----- | |||
```sh | |||
npm install anymatch | |||
``` | |||
#### anymatch(matchers, testString, [returnIndex], [options]) | |||
* __matchers__: (_Array|String|RegExp|Function_) | |||
String to be directly matched, string with glob patterns, regular expression | |||
test, function that takes the testString as an argument and returns a truthy | |||
value if it should be matched, or an array of any number and mix of these types. | |||
* __testString__: (_String|Array_) The string to test against the matchers. If | |||
passed as an array, the first element of the array will be used as the | |||
`testString` for non-function matchers, while the entire array will be applied | |||
as the arguments for function matchers. | |||
* __options__: (_Object_ [optional]_) Any of the [picomatch](https://github.com/micromatch/picomatch#options) options. | |||
* __returnIndex__: (_Boolean [optional]_) If true, return the array index of | |||
the first matcher that that testString matched, or -1 if no match, instead of a | |||
boolean result. | |||
```js | |||
const anymatch = require('anymatch'); | |||
const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ; | |||
anymatch(matchers, 'path/to/file.js'); // true | |||
anymatch(matchers, 'path/anyjs/baz.js'); // true | |||
anymatch(matchers, 'path/to/foo.js'); // true | |||
anymatch(matchers, 'path/to/bar.js'); // true | |||
anymatch(matchers, 'bar.js'); // false | |||
// returnIndex = true | |||
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2 | |||
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1 | |||
// any picomatc | |||
// using globs to match directories and their children | |||
anymatch('node_modules', 'node_modules'); // true | |||
anymatch('node_modules', 'node_modules/somelib/index.js'); // false | |||
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true | |||
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false | |||
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true | |||
const matcher = anymatch(matchers); | |||
['foo.js', 'bar.js'].filter(matcher); // [ 'foo.js' ] | |||
anymatch master* ❯ | |||
``` | |||
#### anymatch(matchers) | |||
You can also pass in only your matcher(s) to get a curried function that has | |||
already been bound to the provided matching criteria. This can be used as an | |||
`Array#filter` callback. | |||
```js | |||
var matcher = anymatch(matchers); | |||
matcher('path/to/file.js'); // true | |||
matcher('path/anyjs/baz.js', true); // 1 | |||
['foo.js', 'bar.js'].filter(matcher); // ['foo.js'] | |||
``` | |||
Changelog | |||
---------- | |||
[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases) | |||
- **v3.0:** Removed `startIndex` and `endIndex` arguments. Node 8.x-only. | |||
- **v2.0:** [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information). | |||
- **v1.2:** anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch) | |||
for glob pattern matching. Issues with glob pattern matching should be | |||
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues). | |||
License | |||
------- | |||
[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE) |
@@ -0,0 +1,19 @@ | |||
type AnymatchFn = (testString: string) => boolean; | |||
type AnymatchPattern = string|RegExp|AnymatchFn; | |||
type AnymatchMatcher = AnymatchPattern|AnymatchPattern[] | |||
type AnymatchTester = { | |||
(testString: string|any[], returnIndex: true): number; | |||
(testString: string|any[]): boolean; | |||
} | |||
type PicomatchOptions = {dot: boolean}; | |||
declare const anymatch: { | |||
(matchers: AnymatchMatcher): AnymatchTester; | |||
(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number; | |||
(matchers: AnymatchMatcher, testString: string|any[]): boolean; | |||
} | |||
export {AnymatchMatcher as Matcher} | |||
export {AnymatchTester as Tester} | |||
export default anymatch |
@@ -0,0 +1,102 @@ | |||
'use strict'; | |||
Object.defineProperty(exports, "__esModule", { value: true }); | |||
const picomatch = require('picomatch'); | |||
const normalizePath = require('normalize-path'); | |||
/** | |||
* @typedef {(testString: string) => boolean} AnymatchFn | |||
* @typedef {string|RegExp|AnymatchFn} AnymatchPattern | |||
* @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher | |||
*/ | |||
const BANG = '!'; | |||
const DEFAULT_OPTIONS = {returnIndex: false}; | |||
const arrify = (item) => Array.isArray(item) ? item : [item]; | |||
/** | |||
* @param {AnymatchPattern} matcher | |||
* @param {object} options | |||
* @returns {AnymatchFn} | |||
*/ | |||
const createPattern = (matcher, options) => { | |||
if (typeof matcher === 'function') { | |||
return matcher; | |||
} | |||
if (typeof matcher === 'string') { | |||
const glob = picomatch(matcher, options); | |||
return (string) => matcher === string || glob(string); | |||
} | |||
if (matcher instanceof RegExp) { | |||
return (string) => matcher.test(string); | |||
} | |||
return (string) => false; | |||
}; | |||
/** | |||
* @param {Array<Function>} patterns | |||
* @param {Array<Function>} negPatterns | |||
* @param {String|Array} args | |||
* @param {Boolean} returnIndex | |||
* @returns {boolean|number} | |||
*/ | |||
const matchPatterns = (patterns, negPatterns, args, returnIndex) => { | |||
const isList = Array.isArray(args); | |||
const _path = isList ? args[0] : args; | |||
if (!isList && typeof _path !== 'string') { | |||
throw new TypeError('anymatch: second argument must be a string: got ' + | |||
Object.prototype.toString.call(_path)) | |||
} | |||
const path = normalizePath(_path); | |||
for (let index = 0; index < negPatterns.length; index++) { | |||
const nglob = negPatterns[index]; | |||
if (nglob(path)) { | |||
return returnIndex ? -1 : false; | |||
} | |||
} | |||
const applied = isList && [path].concat(args.slice(1)); | |||
for (let index = 0; index < patterns.length; index++) { | |||
const pattern = patterns[index]; | |||
if (isList ? pattern(...applied) : pattern(path)) { | |||
return returnIndex ? index : true; | |||
} | |||
} | |||
return returnIndex ? -1 : false; | |||
}; | |||
/** | |||
* @param {AnymatchMatcher} matchers | |||
* @param {Array|string} testString | |||
* @param {object} options | |||
* @returns {boolean|number|Function} | |||
*/ | |||
const anymatch = (matchers, testString, options = DEFAULT_OPTIONS) => { | |||
if (matchers == null) { | |||
throw new TypeError('anymatch: specify first argument'); | |||
} | |||
const opts = typeof options === 'boolean' ? {returnIndex: options} : options; | |||
const returnIndex = opts.returnIndex || false; | |||
// Early cache for matchers. | |||
const mtchers = arrify(matchers); | |||
const negatedGlobs = mtchers | |||
.filter(item => typeof item === 'string' && item.charAt(0) === BANG) | |||
.map(item => item.slice(1)) | |||
.map(item => picomatch(item, opts)); | |||
const patterns = mtchers.map(matcher => createPattern(matcher, opts)); | |||
if (testString == null) { | |||
return (testString, ri = false) => { | |||
const returnIndex = typeof ri === 'boolean' ? ri : false; | |||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex); | |||
} | |||
} | |||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex); | |||
}; | |||
anymatch.default = anymatch; | |||
module.exports = anymatch; |
@@ -0,0 +1,76 @@ | |||
{ | |||
"_from": "anymatch@~3.1.1", | |||
"_id": "anymatch@3.1.1", | |||
"_inBundle": false, | |||
"_integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", | |||
"_location": "/anymatch", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"type": "range", | |||
"registry": true, | |||
"raw": "anymatch@~3.1.1", | |||
"name": "anymatch", | |||
"escapedName": "anymatch", | |||
"rawSpec": "~3.1.1", | |||
"saveSpec": null, | |||
"fetchSpec": "~3.1.1" | |||
}, | |||
"_requiredBy": [ | |||
"/chokidar" | |||
], | |||
"_resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", | |||
"_shasum": "c55ecf02185e2469259399310c173ce31233b142", | |||
"_spec": "anymatch@~3.1.1", | |||
"_where": "C:\\Repos\\mdt5_webApplicationen\\StartMochaTutorial\\node_modules\\chokidar", | |||
"author": { | |||
"name": "Elan Shanker", | |||
"url": "https://github.com/es128" | |||
}, | |||
"bugs": { | |||
"url": "https://github.com/micromatch/anymatch/issues" | |||
}, | |||
"bundleDependencies": false, | |||
"dependencies": { | |||
"normalize-path": "^3.0.0", | |||
"picomatch": "^2.0.4" | |||
}, | |||
"deprecated": false, | |||
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions", | |||
"devDependencies": { | |||
"mocha": "^6.1.3", | |||
"nyc": "^14.0.0" | |||
}, | |||
"engines": { | |||
"node": ">= 8" | |||
}, | |||
"files": [ | |||
"index.js", | |||
"index.d.ts" | |||
], | |||
"homepage": "https://github.com/micromatch/anymatch", | |||
"keywords": [ | |||
"match", | |||
"any", | |||
"string", | |||
"file", | |||
"fs", | |||
"list", | |||
"glob", | |||
"regex", | |||
"regexp", | |||
"regular", | |||
"expression", | |||
"function" | |||
], | |||
"license": "ISC", | |||
"name": "anymatch", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+https://github.com/micromatch/anymatch.git" | |||
}, | |||
"scripts": { | |||
"mocha": "mocha", | |||
"test": "nyc mocha" | |||
}, | |||
"version": "3.1.1" | |||
} |
@@ -0,0 +1,20 @@ | |||
The MIT License (MIT) | |||
Copyright (c) Gevorg Harutyunyan | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
this software and associated documentation files (the "Software"), to deal in | |||
the Software without restriction, including without limitation the rights to | |||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |||
the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,75 @@ | |||
# apache-crypt | |||
[Node.js](http://nodejs.org/) package for Apache style password encryption using crypt(3). | |||
[![build](https://github.com/http-auth/apache-crypt/workflows/build/badge.svg)](https://github.com/http-auth/apache-crypt/actions?query=workflow%3Abuild) | |||
## Installation | |||
Via git (or downloaded tarball): | |||
```bash | |||
$ git clone git://github.com/http-auth/apache-crypt.git | |||
``` | |||
Via [npm](http://npmjs.org/): | |||
```bash | |||
$ npm install apache-crypt | |||
``` | |||
## Usage | |||
```javascript | |||
const crypt = require("apache-crypt"); | |||
// Encrypting password using auto-generated 2 char salt. | |||
const encryptedPassword = crypt("mypass"); | |||
// Should print true. | |||
console.log(crypt("mypass", encryptedPassword) == encryptedPassword); | |||
// Should print false. | |||
console.log(crypt("notmypass", encryptedPassword) == encryptedPassword); | |||
``` | |||
## Running tests | |||
It uses [mocha](https://mochajs.org/), so just run following command in package directory: | |||
```bash | |||
$ npm test | |||
``` | |||
## Issues | |||
You can find list of issues using **[this link](http://github.com/http-auth/apache-crypt/issues)**. | |||
## Requirements | |||
- **[Node.js](http://nodejs.org)** - Event-driven I/O server-side JavaScript environment based on V8. | |||
- **[npm](http://npmjs.org)** - Package manager. Installs, publishes and manages node programs. | |||
## Dependencies | |||
- **[unix-crypt-td-js](https://github.com/TimDumol/unix-crypt-td-js/)** - Javascript implementation of the Unix crypt(3) DES-based hash. | |||
## License | |||
The MIT License (MIT) | |||
Copyright (c) Gevorg Harutyunyan | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
this software and associated documentation files (the "Software"), to deal in | |||
the Software without restriction, including without limitation the rights to | |||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |||
the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,78 @@ | |||
{ | |||
"_from": "apache-crypt@^1.1.2", | |||
"_id": "apache-crypt@1.2.4", | |||
"_inBundle": false, | |||
"_integrity": "sha512-Icze5ny5W5uv3xgMgl8U+iGmRCC0iIDrb2PVPuRBtL3Zy1Y5TMewXP1Vtc4r5X9eNNBEk7KYPu0Qby9m/PmcHg==", | |||
"_location": "/apache-crypt", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"type": "range", | |||
"registry": true, | |||
"raw": "apache-crypt@^1.1.2", | |||
"name": "apache-crypt", | |||
"escapedName": "apache-crypt", | |||
"rawSpec": "^1.1.2", | |||
"saveSpec": null, | |||
"fetchSpec": "^1.1.2" | |||
}, | |||
"_requiredBy": [ | |||
"/http-auth" | |||
], | |||
"_resolved": "https://registry.npmjs.org/apache-crypt/-/apache-crypt-1.2.4.tgz", | |||
"_shasum": "fc0aacb7877d64d26420cadf923bcd53e79fb34e", | |||
"_spec": "apache-crypt@^1.1.2", | |||
"_where": "C:\\Repos\\mdt5_webApplicationen\\StartMochaTutorial\\node_modules\\http-auth", | |||
"author": { | |||
"name": "Gevorg Harutyunyan", | |||
"url": "http://github.com/gevorg" | |||
}, | |||
"bugs": { | |||
"url": "http://github.com/http-auth/apache-crypt/issues" | |||
}, | |||
"bundleDependencies": false, | |||
"dependencies": { | |||
"unix-crypt-td-js": "^1.1.4" | |||
}, | |||
"deprecated": false, | |||
"description": "Node.js module for Apache style password encryption using crypt(3).", | |||
"devDependencies": { | |||
"chai": "^4.2.0", | |||
"eslint": "^6.8.0", | |||
"eslint-plugin-node": "^11.0.0", | |||
"mocha": "^7.0.1" | |||
}, | |||
"engines": { | |||
"node": ">=8" | |||
}, | |||
"homepage": "http://github.com/http-auth/apache-crypt", | |||
"keywords": [ | |||
"apache", | |||
"crypt", | |||
"password", | |||
"htpasswd" | |||
], | |||
"license": "MIT", | |||
"licenses": [ | |||
{ | |||
"type": "MIT", | |||
"url": "http://github.com/http-auth/apache-crypt/blob/master/LICENSE" | |||
} | |||
], | |||
"main": "./src/index.js", | |||
"maintainers": [ | |||
{ | |||
"name": "gevorg", | |||
"email": "gevorg.ha@gmail.com" | |||
} | |||
], | |||
"name": "apache-crypt", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+ssh://git@github.com/http-auth/apache-crypt.git" | |||
}, | |||
"scripts": { | |||
"pretest": "eslint --ignore-path .gitignore .", | |||
"test": "mocha" | |||
}, | |||
"version": "1.2.4" | |||
} |
@@ -0,0 +1,18 @@ | |||
"use strict"; | |||
// Des module. | |||
const des = require('unix-crypt-td-js'); | |||
// Hash generation string. | |||
const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | |||
// Salt generation method. | |||
function getSalt() { | |||
return itoa64[ parseInt(Math.random() * 64) ] + | |||
itoa64[ parseInt(Math.random() * 64) ]; | |||
} | |||
// Exporting old style. | |||
module.exports = (password, salt) => { | |||
return salt ? des(password, salt) : des(password, getSalt()); | |||
}; |
@@ -0,0 +1,20 @@ | |||
The MIT License (MIT) | |||
Copyright (c) Gevorg Harutyunyan | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
this software and associated documentation files (the "Software"), to deal in | |||
the Software without restriction, including without limitation the rights to | |||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |||
the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,71 @@ | |||
# apache-md5 | |||
[Node.js](http://nodejs.org/) package for Apache style password encryption using md5.. | |||
[![build](https://github.com/http-auth/apache-md5/workflows/build/badge.svg)](https://github.com/http-auth/apache-md5/actions?query=workflow%3Abuild) | |||
## Installation | |||
Via git (or downloaded tarball): | |||
```bash | |||
$ git clone git://github.com/http-auth/apache-md5.git | |||
``` | |||
Via [npm](http://npmjs.org/): | |||
```bash | |||
$ npm install apache-md5 | |||
``` | |||
## Usage | |||
```javascript | |||
const md5 = require("apache-md5"); | |||
// Encrypting password using apache's md5 algorithm. | |||
const encryptedPassword = md5("mypass"); | |||
// Should print true. | |||
console.log(md5("mypass", encryptedPassword) == encryptedPassword); | |||
// Should print false. | |||
console.log(md5("notmypass", encryptedPassword) == encryptedPassword); | |||
``` | |||
## Running tests | |||
It uses [mocha](https://mochajs.org/), so just run following command in package directory: | |||
```bash | |||
$ npm test | |||
``` | |||
## Issues | |||
You can find list of issues using **[this link](http://github.com/http-auth/apache-md5/issues)**. | |||
## Requirements | |||
- **[Node.js](http://nodejs.org)** - Event-driven I/O server-side JavaScript environment based on V8. | |||
- **[npm](http://npmjs.org)** - Package manager. Installs, publishes and manages node programs. | |||
## License | |||
The MIT License (MIT) | |||
Copyright (c) Gevorg Harutyunyan | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
this software and associated documentation files (the "Software"), to deal in | |||
the Software without restriction, including without limitation the rights to | |||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |||
the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,75 @@ | |||
{ | |||
"_from": "apache-md5@^1.0.6", | |||
"_id": "apache-md5@1.1.5", | |||
"_inBundle": false, | |||
"_integrity": "sha512-sbLEIMQrkV7RkIruqTPXxeCMkAAycv4yzTkBzRgOR1BrR5UB7qZtupqxkersTJSf0HZ3sbaNRrNV80TnnM7cUw==", | |||
"_location": "/apache-md5", | |||
"_phantomChildren": {}, | |||
"_requested": { | |||
"type": "range", | |||
"registry": true, | |||
"raw": "apache-md5@^1.0.6", | |||
"name": "apache-md5", | |||
"escapedName": "apache-md5", | |||
"rawSpec": "^1.0.6", | |||
"saveSpec": null, | |||
"fetchSpec": "^1.0.6" | |||
}, | |||
"_requiredBy": [ | |||
"/http-auth" | |||
], | |||
"_resolved": "https://registry.npmjs.org/apache-md5/-/apache-md5-1.1.5.tgz", | |||
"_shasum": "5d6365ece2ccc32b612f886b2b292e1c96ff3ffb", | |||
"_spec": "apache-md5@^1.0.6", | |||
"_where": "C:\\Repos\\mdt5_webApplicationen\\StartMochaTutorial\\node_modules\\http-auth", | |||
"author": { | |||
"name": "Gevorg Harutyunyan", | |||
"url": "http://github.com/gevorg" | |||
}, | |||
"bugs": { | |||
"url": "http://github.com/http-auth/apache-md5/issues" | |||
}, | |||
"bundleDependencies": false, | |||
"deprecated": false, | |||
"description": "Node.js module for Apache style password encryption using md5.", | |||
"devDependencies": { | |||
"chai": "^4.2.0", | |||
"eslint": "^6.8.0", | |||
"eslint-plugin-node": "^11.0.0", | |||
"mocha": "^7.0.1" | |||
}, | |||
"engines": { | |||
"node": ">=8" | |||
}, | |||
"homepage": "http://github.com/http-auth/apache-md5", | |||
"keywords": [ | |||
"apache", | |||
"md5", | |||
"password", | |||
"htpasswd" | |||
], | |||
"license": "MIT", | |||
"licenses": [ | |||
{ | |||
"type": "MIT", | |||
"url": "http://github.com/http-auth/apache-md5/blob/master/LICENSE" | |||
} | |||
], | |||
"main": "./src/index.js", | |||
"maintainers": [ | |||
{ | |||
"name": "gevorg", | |||
"email": "gevorg.ha@gmail.com" | |||
} | |||
], | |||
"name": "apache-md5", | |||
"repository": { | |||
"type": "git", | |||
"url": "git+ssh://git@github.com/http-auth/apache-md5.git" | |||
}, | |||
"scripts": { | |||
"pretest": "eslint --ignore-path .gitignore .", | |||
"test": "mocha" | |||
}, | |||
"version": "1.1.5" | |||
} |
@@ -0,0 +1,111 @@ | |||
"use strict"; | |||
// Crypto module import. | |||
const crypto = require('crypto'); | |||
// Hash generation string. | |||
const itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |||
// To 64 bit version. | |||
function to64(index, count) { | |||
let result = ''; | |||
while (--count >= 0) { // Result char count. | |||
result += itoa64[index & 63]; // Get corresponding char. | |||
index = index >> 6; // Move to next one. | |||
} | |||
return result; | |||
} | |||
// Returns salt. | |||
function getSalt(inputSalt) { | |||
let salt = ''; | |||
if (inputSalt) { | |||
// Remove $apr1$ token and extract salt. | |||
salt = inputSalt.split('$')[2]; | |||
} else { | |||
while(salt.length < 8) { // Random 8 chars. | |||
let rchIndex = Math.floor((Math.random() * 64)); | |||
salt += itoa64[rchIndex]; | |||
} | |||
} | |||
return salt; | |||
} | |||
// Returns password. | |||
function getPassword(final) { | |||
// Encrypted pass. | |||
let epass = ''; | |||
epass += to64((final.charCodeAt(0) << 16) | (final.charCodeAt(6) << 8) | final.charCodeAt(12), 4); | |||
epass += to64((final.charCodeAt(1) << 16) | (final.charCodeAt(7) << 8) | final.charCodeAt(13), 4); | |||
epass += to64((final.charCodeAt(2) << 16) | (final.charCodeAt(8) << 8) | final.charCodeAt(14), 4); | |||
epass += to64((final.charCodeAt(3) << 16) | (final.charCodeAt(9) << 8) | final.charCodeAt(15), 4); | |||
epass += to64((final.charCodeAt(4) << 16) | (final.charCodeAt(10) << 8) | final.charCodeAt(5), 4); | |||
epass += to64(final.charCodeAt(11), 2); | |||
return epass; | |||
} | |||
// Exporting old style. | |||
module.exports = (password, salt) => { | |||
let magic = ''; | |||
if (salt && salt.split('$')[1] === '1') { | |||
magic = '$1$'; | |||
} else { | |||
magic = '$apr1$'; | |||
} | |||
salt = getSalt(salt); | |||
let ctx = password + magic + salt; | |||
let final = crypto.createHash('md5').update(password + salt + password, 'ascii').digest('binary'); | |||
for (let pl = password.length; pl > 0; pl -= 16) { | |||
ctx += final.substr(0, (pl > 16) ? 16 : pl); | |||
} | |||
for (let i = password.length; i; i >>= 1) { | |||
if (i % 2) { | |||
ctx += String.fromCharCode(0); | |||
} else { | |||
ctx += password.charAt(0); | |||
} | |||
} | |||
final = crypto.createHash('md5').update(ctx, 'ascii').digest('binary'); | |||
// 1000 loop. | |||
for (let i = 0; i < 1000; ++i) { | |||
// Weird stuff. | |||
let ctxl = ''; | |||
if (i % 2) { | |||
ctxl += password; | |||
} else { | |||
ctxl += final.substr(0, 16); | |||
} | |||
if (i % 3) { | |||
ctxl += salt; | |||
} | |||
if (i % 7) { | |||
ctxl += password; | |||
} | |||
if (i % 2) { | |||
ctxl += final.substr(0, 16); | |||
} else { | |||
ctxl += password; | |||
} | |||
// Final assignment after each loop. | |||
final = crypto.createHash('md5').update(ctxl, 'ascii').digest('binary'); | |||
} | |||
return magic + salt + '$' + getPassword(final); | |||
}; |
@@ -0,0 +1,185 @@ | |||
1.0.10 / 2018-02-15 | |||
------------------ | |||
- Use .concat instead of + for arrays, #122. | |||
1.0.9 / 2016-09-29 | |||
------------------ | |||
- Rerelease after 1.0.8 - deps cleanup. | |||
1.0.8 / 2016-09-29 | |||
------------------ | |||
- Maintenance (deps bump, fix node 6.5+ tests, coverage report). | |||
1.0.7 / 2016-03-17 | |||
------------------ | |||
- Teach `addArgument` to accept string arg names. #97, @tomxtobin. | |||
1.0.6 / 2016-02-06 | |||
------------------ | |||
- Maintenance: moved to eslint & updated CS. | |||
1.0.5 / 2016-02-05 | |||
------------------ | |||
- Removed lodash dependency to significantly reduce install size. | |||
Thanks to @mourner. | |||
1.0.4 / 2016-01-17 | |||
------------------ | |||
- Maintenance: lodash update to 4.0.0. | |||
1.0.3 / 2015-10-27 | |||
------------------ | |||
- Fix parse `=` in args: `--examplepath="C:\myfolder\env=x64"`. #84, @CatWithApple. | |||
1.0.2 / 2015-03-22 | |||
------------------ | |||
- Relaxed lodash version dependency. | |||
1.0.1 / 2015-02-20 | |||
------------------ | |||
- Changed dependencies to be compatible with ancient nodejs. | |||
1.0.0 / 2015-02-19 | |||
------------------ | |||
- Maintenance release. | |||
- Replaced `underscore` with `lodash`. | |||
- Bumped version to 1.0.0 to better reflect semver meaning. | |||
- HISTORY.md -> CHANGELOG.md | |||
0.1.16 / 2013-12-01 | |||
------------------- | |||
- Maintenance release. Updated dependencies and docs. | |||
0.1.15 / 2013-05-13 | |||
------------------- | |||
- Fixed #55, @trebor89 | |||
0.1.14 / 2013-05-12 | |||
------------------- | |||
- Fixed #62, @maxtaco | |||
0.1.13 / 2013-04-08 | |||
------------------- | |||
- Added `.npmignore` to reduce package size | |||
0.1.12 / 2013-02-10 | |||
------------------- | |||
- Fixed conflictHandler (#46), @hpaulj | |||
0.1.11 / 2013-02-07 | |||
------------------- | |||
- Multiple bugfixes, @hpaulj | |||
- Added 70+ tests (ported from python), @hpaulj | |||
- Added conflictHandler, @applepicke | |||
- Added fromfilePrefixChar, @hpaulj | |||
0.1.10 / 2012-12-30 | |||
------------------- | |||
- Added [mutual exclusion](http://docs.python.org/dev/library/argparse.html#mutual-exclusion) | |||
support, thanks to @hpaulj | |||
- Fixed options check for `storeConst` & `appendConst` actions, thanks to @hpaulj | |||
0.1.9 / 2012-12-27 | |||
------------------ | |||
- Fixed option dest interferens with other options (issue #23), thanks to @hpaulj | |||
- Fixed default value behavior with `*` positionals, thanks to @hpaulj | |||
- Improve `getDefault()` behavior, thanks to @hpaulj | |||
- Imrove negative argument parsing, thanks to @hpaulj | |||
0.1.8 / 2012-12-01 | |||
------------------ | |||
- Fixed parser parents (issue #19), thanks to @hpaulj | |||
- Fixed negative argument parse (issue #20), thanks to @hpaulj | |||
0.1.7 / 2012-10-14 | |||
------------------ | |||
- Fixed 'choices' argument parse (issue #16) | |||
- Fixed stderr output (issue #15) | |||
0.1.6 / 2012-09-09 | |||
------------------ | |||
- Fixed check for conflict of options (thanks to @tomxtobin) | |||
0.1.5 / 2012-09-03 | |||
------------------ | |||
- Fix parser #setDefaults method (thanks to @tomxtobin) | |||
0.1.4 / 2012-07-30 | |||
------------------ | |||
- Fixed pseudo-argument support (thanks to @CGamesPlay) | |||
- Fixed addHelp default (should be true), if not set (thanks to @benblank) | |||
0.1.3 / 2012-06-27 | |||
------------------ | |||
- Fixed formatter api name: Formatter -> HelpFormatter | |||
0.1.2 / 2012-05-29 | |||
------------------ | |||
- Added basic tests | |||
- Removed excess whitespace in help | |||
- Fixed error reporting, when parcer with subcommands | |||
called with empty arguments | |||
0.1.1 / 2012-05-23 | |||
------------------ | |||
- Fixed line wrapping in help formatter | |||
- Added better error reporting on invalid arguments | |||
0.1.0 / 2012-05-16 | |||
------------------ | |||
- First release. |
@@ -0,0 +1,21 @@ | |||
(The MIT License) | |||
Copyright (C) 2012 by Vitaly Puzrin | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,257 @@ | |||
argparse | |||
======== | |||
[![Build Status](https://secure.travis-ci.org/nodeca/argparse.svg?branch=master)](http://travis-ci.org/nodeca/argparse) | |||
[![NPM version](https://img.shields.io/npm/v/argparse.svg)](https://www.npmjs.org/package/argparse) | |||
CLI arguments parser for node.js. Javascript port of python's | |||
[argparse](http://docs.python.org/dev/library/argparse.html) module | |||
(original version 3.2). That's a full port, except some very rare options, | |||
recorded in issue tracker. | |||
**NB. Difference with original.** | |||
- Method names changed to camelCase. See [generated docs](http://nodeca.github.com/argparse/). | |||
- Use `defaultValue` instead of `default`. | |||
- Use `argparse.Const.REMAINDER` instead of `argparse.REMAINDER`, and | |||
similarly for constant values `OPTIONAL`, `ZERO_OR_MORE`, and `ONE_OR_MORE` | |||
(aliases for `nargs` values `'?'`, `'*'`, `'+'`, respectively), and | |||
`SUPPRESS`. | |||
Example | |||
======= | |||
test.js file: | |||
```javascript | |||
#!/usr/bin/env node | |||
'use strict'; | |||
var ArgumentParser = require('../lib/argparse').ArgumentParser; | |||
var parser = new ArgumentParser({ | |||
version: '0.0.1', | |||
addHelp:true, | |||
description: 'Argparse example' | |||
}); | |||
parser.addArgument( | |||
[ '-f', '--foo' ], | |||
{ | |||
help: 'foo bar' | |||
} | |||
); | |||
parser.addArgument( | |||
[ '-b', '--bar' ], | |||
{ | |||
help: 'bar foo' | |||
} | |||
); | |||
parser.addArgument( | |||
'--baz', | |||
{ | |||
help: 'baz bar' | |||
} | |||
); | |||
var args = parser.parseArgs(); | |||
console.dir(args); | |||
``` | |||
Display help: | |||
``` | |||
$ ./test.js -h | |||
usage: example.js [-h] [-v] [-f FOO] [-b BAR] [--baz BAZ] | |||
Argparse example | |||
Optional arguments: | |||
-h, --help Show this help message and exit. | |||
-v, --version Show program's version number and exit. | |||
-f FOO, --foo FOO foo bar | |||
-b BAR, --bar BAR bar foo | |||
--baz BAZ baz bar | |||
``` | |||
Parse arguments: | |||
``` | |||
$ ./test.js -f=3 --bar=4 --baz 5 | |||
{ foo: '3', bar: '4', baz: '5' } | |||
``` | |||
More [examples](https://github.com/nodeca/argparse/tree/master/examples). | |||
ArgumentParser objects | |||
====================== | |||
``` | |||
new ArgumentParser({parameters hash}); | |||
``` | |||
Creates a new ArgumentParser object. | |||
**Supported params:** | |||
- ```description``` - Text to display before the argument help. | |||
- ```epilog``` - Text to display after the argument help. | |||
- ```addHelp``` - Add a -h/–help option to the parser. (default: true) | |||
- ```argumentDefault``` - Set the global default value for arguments. (default: null) | |||
- ```parents``` - A list of ArgumentParser objects whose arguments should also be included. | |||
- ```prefixChars``` - The set of characters that prefix optional arguments. (default: ‘-‘) | |||
- ```formatterClass``` - A class for customizing the help output. | |||
- ```prog``` - The name of the program (default: `path.basename(process.argv[1])`) | |||
- ```usage``` - The string describing the program usage (default: generated) | |||
- ```conflictHandler``` - Usually unnecessary, defines strategy for resolving conflicting optionals. | |||
**Not supported yet** | |||
- ```fromfilePrefixChars``` - The set of characters that prefix files from which additional arguments should be read. | |||
Details in [original ArgumentParser guide](http://docs.python.org/dev/library/argparse.html#argumentparser-objects) | |||
addArgument() method | |||
==================== | |||
``` | |||
ArgumentParser.addArgument(name or flag or [name] or [flags...], {options}) | |||
``` | |||
Defines how a single command-line argument should be parsed. | |||
- ```name or flag or [name] or [flags...]``` - Either a positional name | |||
(e.g., `'foo'`), a single option (e.g., `'-f'` or `'--foo'`), an array | |||
of a single positional name (e.g., `['foo']`), or an array of options | |||
(e.g., `['-f', '--foo']`). | |||
Options: | |||
- ```action``` - The basic type of action to be taken when this argument is encountered at the command line. | |||
- ```nargs```- The number of command-line arguments that should be consumed. | |||
- ```constant``` - A constant value required by some action and nargs selections. | |||
- ```defaultValue``` - The value produced if the argument is absent from the command line. | |||
- ```type``` - The type to which the command-line argument should be converted. | |||
- ```choices``` - A container of the allowable values for the argument. | |||
- ```required``` - Whether or not the command-line option may be omitted (optionals only). | |||
- ```help``` - A brief description of what the argument does. | |||
- ```metavar``` - A name for the argument in usage messages. | |||
- ```dest``` - The name of the attribute to be added to the object returned by parseArgs(). | |||
Details in [original add_argument guide](http://docs.python.org/dev/library/argparse.html#the-add-argument-method) | |||
Action (some details) | |||
================ | |||
ArgumentParser objects associate command-line arguments with actions. | |||
These actions can do just about anything with the command-line arguments associated | |||
with them, though most actions simply add an attribute to the object returned by | |||
parseArgs(). The action keyword argument specifies how the command-line arguments | |||
should be handled. The supported actions are: | |||
- ```store``` - Just stores the argument’s value. This is the default action. | |||
- ```storeConst``` - Stores value, specified by the const keyword argument. | |||
(Note that the const keyword argument defaults to the rather unhelpful None.) | |||
The 'storeConst' action is most commonly used with optional arguments, that | |||
specify some sort of flag. | |||
- ```storeTrue``` and ```storeFalse``` - Stores values True and False | |||
respectively. These are special cases of 'storeConst'. | |||
- ```append``` - Stores a list, and appends each argument value to the list. | |||
This is useful to allow an option to be specified multiple times. | |||
- ```appendConst``` - Stores a list, and appends value, specified by the | |||
const keyword argument to the list. (Note, that the const keyword argument defaults | |||
is None.) The 'appendConst' action is typically used when multiple arguments need | |||
to store constants to the same list. | |||
- ```count``` - Counts the number of times a keyword argument occurs. For example, | |||
used for increasing verbosity levels. | |||
- ```help``` - Prints a complete help message for all the options in the current | |||
parser and then exits. By default a help action is automatically added to the parser. | |||
See ArgumentParser for details of how the output is created. | |||
- ```version``` - Prints version information and exit. Expects a `version=` | |||
keyword argument in the addArgument() call. | |||
Details in [original action guide](http://docs.python.org/dev/library/argparse.html#action) | |||
Sub-commands | |||
============ | |||
ArgumentParser.addSubparsers() | |||
Many programs split their functionality into a number of sub-commands, for | |||
example, the svn program can invoke sub-commands like `svn checkout`, `svn update`, | |||
and `svn commit`. Splitting up functionality this way can be a particularly good | |||
idea when a program performs several different functions which require different | |||
kinds of command-line arguments. `ArgumentParser` supports creation of such | |||
sub-commands with `addSubparsers()` method. The `addSubparsers()` method is | |||
normally called with no arguments and returns an special action object. | |||
This object has a single method `addParser()`, which takes a command name and | |||
any `ArgumentParser` constructor arguments, and returns an `ArgumentParser` object | |||
that can be modified as usual. | |||
Example: | |||
sub_commands.js | |||
```javascript | |||
#!/usr/bin/env node | |||
'use strict'; | |||
var ArgumentParser = require('../lib/argparse').ArgumentParser; | |||
var parser = new ArgumentParser({ | |||
version: '0.0.1', | |||
addHelp:true, | |||
description: 'Argparse examples: sub-commands', | |||
}); | |||
var subparsers = parser.addSubparsers({ | |||
title:'subcommands', | |||
dest:"subcommand_name" | |||
}); | |||
var bar = subparsers.addParser('c1', {addHelp:true}); | |||
bar.addArgument( | |||
[ '-f', '--foo' ], | |||
{ | |||
action: 'store', | |||
help: 'foo3 bar3' | |||
} | |||
); | |||
var bar = subparsers.addParser( | |||
'c2', | |||
{aliases:['co'], addHelp:true} | |||
); | |||
bar.addArgument( | |||
[ '-b', '--bar' ], | |||
{ | |||
action: 'store', | |||
type: 'int', | |||
help: 'foo3 bar3' | |||
} | |||
); | |||
var args = parser.parseArgs(); | |||
console.dir(args); | |||
``` | |||
Details in [original sub-commands guide](http://docs.python.org/dev/library/argparse.html#sub-commands) | |||
Contributors | |||
============ | |||
- [Eugene Shkuropat](https://github.com/shkuropat) | |||
- [Paul Jacobson](https://github.com/hpaulj) | |||
[others](https://github.com/nodeca/argparse/graphs/contributors) | |||
License | |||
======= | |||
Copyright (c) 2012 [Vitaly Puzrin](https://github.com/puzrin). | |||
Released under the MIT license. See | |||
[LICENSE](https://github.com/nodeca/argparse/blob/master/LICENSE) for details. | |||
@@ -0,0 +1,3 @@ | |||
'use strict'; | |||
module.exports = require('./lib/argparse'); |
@@ -0,0 +1,146 @@ | |||
/** | |||
* class Action | |||
* | |||
* Base class for all actions | |||
* Do not call in your code, use this class only for inherits your own action | |||
* | |||
* Information about how to convert command line strings to Javascript objects. | |||
* Action objects are used by an ArgumentParser to represent the information | |||
* needed to parse a single argument from one or more strings from the command | |||
* line. The keyword arguments to the Action constructor are also all attributes | |||
* of Action instances. | |||
* | |||
* ##### Allowed keywords: | |||
* | |||
* - `store` | |||
* - `storeConstant` | |||
* - `storeTrue` | |||
* - `storeFalse` | |||
* - `append` | |||
* - `appendConstant` | |||
* - `count` | |||
* - `help` | |||
* - `version` | |||
* | |||
* Information about action options see [[Action.new]] | |||
* | |||
* See also [original guide](http://docs.python.org/dev/library/argparse.html#action) | |||
* | |||
**/ | |||
'use strict'; | |||
// Constants | |||
var c = require('./const'); | |||
/** | |||
* new Action(options) | |||
* | |||
* Base class for all actions. Used only for inherits | |||
* | |||
* | |||
* ##### Options: | |||
* | |||
* - `optionStrings` A list of command-line option strings for the action. | |||
* - `dest` Attribute to hold the created object(s) | |||
* - `nargs` The number of command-line arguments that should be consumed. | |||
* By default, one argument will be consumed and a single value will be | |||
* produced. | |||
* - `constant` Default value for an action with no value. | |||
* - `defaultValue` The value to be produced if the option is not specified. | |||
* - `type` Cast to 'string'|'int'|'float'|'complex'|function (string). If | |||
* None, 'string'. | |||
* - `choices` The choices available. | |||
* - `required` True if the action must always be specified at the command | |||
* line. | |||
* - `help` The help describing the argument. | |||
* - `metavar` The name to be used for the option's argument with the help | |||
* string. If None, the 'dest' value will be used as the name. | |||
* | |||
* ##### nargs supported values: | |||
* | |||
* - `N` (an integer) consumes N arguments (and produces a list) | |||
* - `?` consumes zero or one arguments | |||
* - `*` consumes zero or more arguments (and produces a list) | |||
* - `+` consumes one or more arguments (and produces a list) | |||
* | |||
* Note: that the difference between the default and nargs=1 is that with the | |||
* default, a single value will be produced, while with nargs=1, a list | |||
* containing a single value will be produced. | |||
**/ | |||
var Action = module.exports = function Action(options) { | |||
options = options || {}; | |||
this.optionStrings = options.optionStrings || []; | |||
this.dest = options.dest; | |||
this.nargs = typeof options.nargs !== 'undefined' ? options.nargs : null; | |||
this.constant = typeof options.constant !== 'undefined' ? options.constant : null; | |||
this.defaultValue = options.defaultValue; | |||
this.type = typeof options.type !== 'undefined' ? options.type : null; | |||
this.choices = typeof options.choices !== 'undefined' ? options.choices : null; | |||
this.required = typeof options.required !== 'undefined' ? options.required : false; | |||
this.help = typeof options.help !== 'undefined' ? options.help : null; | |||
this.metavar = typeof options.metavar !== 'undefined' ? options.metavar : null; | |||
if (!(this.optionStrings instanceof Array)) { | |||
throw new Error('optionStrings should be an array'); | |||
} | |||
if (typeof this.required !== 'undefined' && typeof this.required !== 'boolean') { | |||
throw new Error('required should be a boolean'); | |||
} | |||
}; | |||
/** | |||
* Action#getName -> String | |||
* | |||
* Tells action name | |||
**/ | |||
Action.prototype.getName = function () { | |||
if (this.optionStrings.length > 0) { | |||
return this.optionStrings.join('/'); | |||
} else if (this.metavar !== null && this.metavar !== c.SUPPRESS) { | |||
return this.metavar; | |||
} else if (typeof this.dest !== 'undefined' && this.dest !== c.SUPPRESS) { | |||
return this.dest; | |||
} | |||
return null; | |||
}; | |||
/** | |||
* Action#isOptional -> Boolean | |||
* | |||
* Return true if optional | |||
**/ | |||
Action.prototype.isOptional = function () { | |||
return !this.isPositional(); | |||
}; | |||
/** | |||
* Action#isPositional -> Boolean | |||
* | |||
* Return true if positional | |||
**/ | |||
Action.prototype.isPositional = function () { | |||
return (this.optionStrings.length === 0); | |||
}; | |||
/** | |||
* Action#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Call the action. Should be implemented in inherited classes | |||
* | |||
* ##### Example | |||
* | |||
* ActionCount.prototype.call = function (parser, namespace, values, optionString) { | |||
* namespace.set(this.dest, (namespace[this.dest] || 0) + 1); | |||
* }; | |||
* | |||
**/ | |||
Action.prototype.call = function () { | |||
throw new Error('.call() not defined');// Not Implemented error | |||
}; |
@@ -0,0 +1,53 @@ | |||
/*:nodoc:* | |||
* class ActionAppend | |||
* | |||
* This action stores a list, and appends each argument value to the list. | |||
* This is useful to allow an option to be specified multiple times. | |||
* This class inherided from [[Action]] | |||
* | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var Action = require('../action'); | |||
// Constants | |||
var c = require('../const'); | |||
/*:nodoc:* | |||
* new ActionAppend(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
* Note: options.nargs should be optional for constants | |||
* and more then zero for other | |||
**/ | |||
var ActionAppend = module.exports = function ActionAppend(options) { | |||
options = options || {}; | |||
if (this.nargs <= 0) { | |||
throw new Error('nargs for append actions must be > 0; if arg ' + | |||
'strings are not supplying the value to append, ' + | |||
'the append const action may be more appropriate'); | |||
} | |||
if (!!this.constant && this.nargs !== c.OPTIONAL) { | |||
throw new Error('nargs must be OPTIONAL to supply const'); | |||
} | |||
Action.call(this, options); | |||
}; | |||
util.inherits(ActionAppend, Action); | |||
/*:nodoc:* | |||
* ActionAppend#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Call the action. Save result in namespace object | |||
**/ | |||
ActionAppend.prototype.call = function (parser, namespace, values) { | |||
var items = (namespace[this.dest] || []).slice(); | |||
items.push(values); | |||
namespace.set(this.dest, items); | |||
}; |
@@ -0,0 +1,47 @@ | |||
/*:nodoc:* | |||
* class ActionAppendConstant | |||
* | |||
* This stores a list, and appends the value specified by | |||
* the const keyword argument to the list. | |||
* (Note that the const keyword argument defaults to null.) | |||
* The 'appendConst' action is typically useful when multiple | |||
* arguments need to store constants to the same list. | |||
* | |||
* This class inherited from [[Action]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var Action = require('../../action'); | |||
/*:nodoc:* | |||
* new ActionAppendConstant(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
var ActionAppendConstant = module.exports = function ActionAppendConstant(options) { | |||
options = options || {}; | |||
options.nargs = 0; | |||
if (typeof options.constant === 'undefined') { | |||
throw new Error('constant option is required for appendAction'); | |||
} | |||
Action.call(this, options); | |||
}; | |||
util.inherits(ActionAppendConstant, Action); | |||
/*:nodoc:* | |||
* ActionAppendConstant#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Call the action. Save result in namespace object | |||
**/ | |||
ActionAppendConstant.prototype.call = function (parser, namespace) { | |||
var items = [].concat(namespace[this.dest] || []); | |||
items.push(this.constant); | |||
namespace.set(this.dest, items); | |||
}; |
@@ -0,0 +1,40 @@ | |||
/*:nodoc:* | |||
* class ActionCount | |||
* | |||
* This counts the number of times a keyword argument occurs. | |||
* For example, this is useful for increasing verbosity levels | |||
* | |||
* This class inherided from [[Action]] | |||
* | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var Action = require('../action'); | |||
/*:nodoc:* | |||
* new ActionCount(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
var ActionCount = module.exports = function ActionCount(options) { | |||
options = options || {}; | |||
options.nargs = 0; | |||
Action.call(this, options); | |||
}; | |||
util.inherits(ActionCount, Action); | |||
/*:nodoc:* | |||
* ActionCount#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Call the action. Save result in namespace object | |||
**/ | |||
ActionCount.prototype.call = function (parser, namespace) { | |||
namespace.set(this.dest, (namespace[this.dest] || 0) + 1); | |||
}; |
@@ -0,0 +1,47 @@ | |||
/*:nodoc:* | |||
* class ActionHelp | |||
* | |||
* Support action for printing help | |||
* This class inherided from [[Action]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var Action = require('../action'); | |||
// Constants | |||
var c = require('../const'); | |||
/*:nodoc:* | |||
* new ActionHelp(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
var ActionHelp = module.exports = function ActionHelp(options) { | |||
options = options || {}; | |||
if (options.defaultValue !== null) { | |||
options.defaultValue = options.defaultValue; | |||
} else { | |||
options.defaultValue = c.SUPPRESS; | |||
} | |||
options.dest = (options.dest !== null ? options.dest : c.SUPPRESS); | |||
options.nargs = 0; | |||
Action.call(this, options); | |||
}; | |||
util.inherits(ActionHelp, Action); | |||
/*:nodoc:* | |||
* ActionHelp#call(parser, namespace, values, optionString) | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Print help and exit | |||
**/ | |||
ActionHelp.prototype.call = function (parser) { | |||
parser.printHelp(); | |||
parser.exit(); | |||
}; |
@@ -0,0 +1,50 @@ | |||
/*:nodoc:* | |||
* class ActionStore | |||
* | |||
* This action just stores the argument’s value. This is the default action. | |||
* | |||
* This class inherited from [[Action]] | |||
* | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var Action = require('../action'); | |||
// Constants | |||
var c = require('../const'); | |||
/*:nodoc:* | |||
* new ActionStore(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
var ActionStore = module.exports = function ActionStore(options) { | |||
options = options || {}; | |||
if (this.nargs <= 0) { | |||
throw new Error('nargs for store actions must be > 0; if you ' + | |||
'have nothing to store, actions such as store ' + | |||
'true or store const may be more appropriate'); | |||
} | |||
if (typeof this.constant !== 'undefined' && this.nargs !== c.OPTIONAL) { | |||
throw new Error('nargs must be OPTIONAL to supply const'); | |||
} | |||
Action.call(this, options); | |||
}; | |||
util.inherits(ActionStore, Action); | |||
/*:nodoc:* | |||
* ActionStore#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Call the action. Save result in namespace object | |||
**/ | |||
ActionStore.prototype.call = function (parser, namespace, values) { | |||
namespace.set(this.dest, values); | |||
}; |
@@ -0,0 +1,43 @@ | |||
/*:nodoc:* | |||
* class ActionStoreConstant | |||
* | |||
* This action stores the value specified by the const keyword argument. | |||
* (Note that the const keyword argument defaults to the rather unhelpful null.) | |||
* The 'store_const' action is most commonly used with optional | |||
* arguments that specify some sort of flag. | |||
* | |||
* This class inherited from [[Action]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var Action = require('../../action'); | |||
/*:nodoc:* | |||
* new ActionStoreConstant(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
var ActionStoreConstant = module.exports = function ActionStoreConstant(options) { | |||
options = options || {}; | |||
options.nargs = 0; | |||
if (typeof options.constant === 'undefined') { | |||
throw new Error('constant option is required for storeAction'); | |||
} | |||
Action.call(this, options); | |||
}; | |||
util.inherits(ActionStoreConstant, Action); | |||
/*:nodoc:* | |||
* ActionStoreConstant#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Call the action. Save result in namespace object | |||
**/ | |||
ActionStoreConstant.prototype.call = function (parser, namespace) { | |||
namespace.set(this.dest, this.constant); | |||
}; |
@@ -0,0 +1,27 @@ | |||
/*:nodoc:* | |||
* class ActionStoreFalse | |||
* | |||
* This action store the values False respectively. | |||
* This is special cases of 'storeConst' | |||
* | |||
* This class inherited from [[Action]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var ActionStoreConstant = require('./constant'); | |||
/*:nodoc:* | |||
* new ActionStoreFalse(options) | |||
* - options (object): hash of options see [[Action.new]] | |||
* | |||
**/ | |||
var ActionStoreFalse = module.exports = function ActionStoreFalse(options) { | |||
options = options || {}; | |||
options.constant = false; | |||
options.defaultValue = options.defaultValue !== null ? options.defaultValue : true; | |||
ActionStoreConstant.call(this, options); | |||
}; | |||
util.inherits(ActionStoreFalse, ActionStoreConstant); |
@@ -0,0 +1,26 @@ | |||
/*:nodoc:* | |||
* class ActionStoreTrue | |||
* | |||
* This action store the values True respectively. | |||
* This isspecial cases of 'storeConst' | |||
* | |||
* This class inherited from [[Action]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var ActionStoreConstant = require('./constant'); | |||
/*:nodoc:* | |||
* new ActionStoreTrue(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
var ActionStoreTrue = module.exports = function ActionStoreTrue(options) { | |||
options = options || {}; | |||
options.constant = true; | |||
options.defaultValue = options.defaultValue !== null ? options.defaultValue : false; | |||
ActionStoreConstant.call(this, options); | |||
}; | |||
util.inherits(ActionStoreTrue, ActionStoreConstant); |
@@ -0,0 +1,149 @@ | |||
/** internal | |||
* class ActionSubparsers | |||
* | |||
* Support the creation of such sub-commands with the addSubparsers() | |||
* | |||
* This class inherited from [[Action]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var format = require('util').format; | |||
var Action = require('../action'); | |||
// Constants | |||
var c = require('../const'); | |||
// Errors | |||
var argumentErrorHelper = require('../argument/error'); | |||
/*:nodoc:* | |||
* new ChoicesPseudoAction(name, help) | |||
* | |||
* Create pseudo action for correct help text | |||
* | |||
**/ | |||
function ChoicesPseudoAction(name, help) { | |||
var options = { | |||
optionStrings: [], | |||
dest: name, | |||
help: help | |||
}; | |||
Action.call(this, options); | |||
} | |||
util.inherits(ChoicesPseudoAction, Action); | |||
/** | |||
* new ActionSubparsers(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
function ActionSubparsers(options) { | |||
options = options || {}; | |||
options.dest = options.dest || c.SUPPRESS; | |||
options.nargs = c.PARSER; | |||
this.debug = (options.debug === true); | |||
this._progPrefix = options.prog; | |||
this._parserClass = options.parserClass; | |||
this._nameParserMap = {}; | |||
this._choicesActions = []; | |||
options.choices = this._nameParserMap; | |||
Action.call(this, options); | |||
} | |||
util.inherits(ActionSubparsers, Action); | |||
/*:nodoc:* | |||
* ActionSubparsers#addParser(name, options) -> ArgumentParser | |||
* - name (string): sub-command name | |||
* - options (object): see [[ArgumentParser.new]] | |||
* | |||
* Note: | |||
* addParser supports an additional aliases option, | |||
* which allows multiple strings to refer to the same subparser. | |||
* This example, like svn, aliases co as a shorthand for checkout | |||
* | |||
**/ | |||
ActionSubparsers.prototype.addParser = function (name, options) { | |||
var parser; | |||
var self = this; | |||
options = options || {}; | |||
options.debug = (this.debug === true); | |||
// set program from the existing prefix | |||
if (!options.prog) { | |||
options.prog = this._progPrefix + ' ' + name; | |||
} | |||
var aliases = options.aliases || []; | |||
// create a pseudo-action to hold the choice help | |||
if (!!options.help || typeof options.help === 'string') { | |||
var help = options.help; | |||
delete options.help; | |||
var choiceAction = new ChoicesPseudoAction(name, help); | |||
this._choicesActions.push(choiceAction); | |||
} | |||
// create the parser and add it to the map | |||
parser = new this._parserClass(options); | |||
this._nameParserMap[name] = parser; | |||
// make parser available under aliases also | |||
aliases.forEach(function (alias) { | |||
self._nameParserMap[alias] = parser; | |||
}); | |||
return parser; | |||
}; | |||
ActionSubparsers.prototype._getSubactions = function () { | |||
return this._choicesActions; | |||
}; | |||
/*:nodoc:* | |||
* ActionSubparsers#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Call the action. Parse input aguments | |||
**/ | |||
ActionSubparsers.prototype.call = function (parser, namespace, values) { | |||
var parserName = values[0]; | |||
var argStrings = values.slice(1); | |||
// set the parser name if requested | |||
if (this.dest !== c.SUPPRESS) { | |||
namespace[this.dest] = parserName; | |||
} | |||
// select the parser | |||
if (this._nameParserMap[parserName]) { | |||
parser = this._nameParserMap[parserName]; | |||
} else { | |||
throw argumentErrorHelper(format( | |||
'Unknown parser "%s" (choices: [%s]).', | |||
parserName, | |||
Object.keys(this._nameParserMap).join(', ') | |||
)); | |||
} | |||
// parse all the remaining options into the namespace | |||
parser.parseArgs(argStrings, namespace); | |||
}; | |||
module.exports = ActionSubparsers; |
@@ -0,0 +1,47 @@ | |||
/*:nodoc:* | |||
* class ActionVersion | |||
* | |||
* Support action for printing program version | |||
* This class inherited from [[Action]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var Action = require('../action'); | |||
// | |||
// Constants | |||
// | |||
var c = require('../const'); | |||
/*:nodoc:* | |||
* new ActionVersion(options) | |||
* - options (object): options hash see [[Action.new]] | |||
* | |||
**/ | |||
var ActionVersion = module.exports = function ActionVersion(options) { | |||
options = options || {}; | |||
options.defaultValue = (options.defaultValue ? options.defaultValue : c.SUPPRESS); | |||
options.dest = (options.dest || c.SUPPRESS); | |||
options.nargs = 0; | |||
this.version = options.version; | |||
Action.call(this, options); | |||
}; | |||
util.inherits(ActionVersion, Action); | |||
/*:nodoc:* | |||
* ActionVersion#call(parser, namespace, values, optionString) -> Void | |||
* - parser (ArgumentParser): current parser | |||
* - namespace (Namespace): namespace for output data | |||
* - values (Array): parsed values | |||
* - optionString (Array): input option string(not parsed) | |||
* | |||
* Print version and exit | |||
**/ | |||
ActionVersion.prototype.call = function (parser) { | |||
var version = this.version || parser.version; | |||
var formatter = parser._getFormatter(); | |||
formatter.addText(version); | |||
parser.exit(0, formatter.formatHelp()); | |||
}; |
@@ -0,0 +1,482 @@ | |||
/** internal | |||
* class ActionContainer | |||
* | |||
* Action container. Parent for [[ArgumentParser]] and [[ArgumentGroup]] | |||
**/ | |||
'use strict'; | |||
var format = require('util').format; | |||
// Constants | |||
var c = require('./const'); | |||
var $$ = require('./utils'); | |||
//Actions | |||
var ActionHelp = require('./action/help'); | |||
var ActionAppend = require('./action/append'); | |||
var ActionAppendConstant = require('./action/append/constant'); | |||
var ActionCount = require('./action/count'); | |||
var ActionStore = require('./action/store'); | |||
var ActionStoreConstant = require('./action/store/constant'); | |||
var ActionStoreTrue = require('./action/store/true'); | |||
var ActionStoreFalse = require('./action/store/false'); | |||
var ActionVersion = require('./action/version'); | |||
var ActionSubparsers = require('./action/subparsers'); | |||
// Errors | |||
var argumentErrorHelper = require('./argument/error'); | |||
/** | |||
* new ActionContainer(options) | |||
* | |||
* Action container. Parent for [[ArgumentParser]] and [[ArgumentGroup]] | |||
* | |||
* ##### Options: | |||
* | |||
* - `description` -- A description of what the program does | |||
* - `prefixChars` -- Characters that prefix optional arguments | |||
* - `argumentDefault` -- The default value for all arguments | |||
* - `conflictHandler` -- The conflict handler to use for duplicate arguments | |||
**/ | |||
var ActionContainer = module.exports = function ActionContainer(options) { | |||
options = options || {}; | |||
this.description = options.description; | |||
this.argumentDefault = options.argumentDefault; | |||
this.prefixChars = options.prefixChars || ''; | |||
this.conflictHandler = options.conflictHandler; | |||
// set up registries | |||
this._registries = {}; | |||
// register actions | |||
this.register('action', null, ActionStore); | |||
this.register('action', 'store', ActionStore); | |||
this.register('action', 'storeConst', ActionStoreConstant); | |||
this.register('action', 'storeTrue', ActionStoreTrue); | |||
this.register('action', 'storeFalse', ActionStoreFalse); | |||
this.register('action', 'append', ActionAppend); | |||
this.register('action', 'appendConst', ActionAppendConstant); | |||
this.register('action', 'count', ActionCount); | |||
this.register('action', 'help', ActionHelp); | |||
this.register('action', 'version', ActionVersion); | |||
this.register('action', 'parsers', ActionSubparsers); | |||
// raise an exception if the conflict handler is invalid | |||
this._getHandler(); | |||
// action storage | |||
this._actions = []; | |||
this._optionStringActions = {}; | |||
// groups | |||
this._actionGroups = []; | |||
this._mutuallyExclusiveGroups = []; | |||
// defaults storage | |||
this._defaults = {}; | |||
// determines whether an "option" looks like a negative number | |||
// -1, -1.5 -5e+4 | |||
this._regexpNegativeNumber = new RegExp('^[-]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$'); | |||
// whether or not there are any optionals that look like negative | |||
// numbers -- uses a list so it can be shared and edited | |||
this._hasNegativeNumberOptionals = []; | |||
}; | |||
// Groups must be required, then ActionContainer already defined | |||
var ArgumentGroup = require('./argument/group'); | |||
var MutuallyExclusiveGroup = require('./argument/exclusive'); | |||
// | |||
// Registration methods | |||
// | |||
/** | |||
* ActionContainer#register(registryName, value, object) -> Void | |||
* - registryName (String) : object type action|type | |||
* - value (string) : keyword | |||
* - object (Object|Function) : handler | |||
* | |||
* Register handlers | |||
**/ | |||
ActionContainer.prototype.register = function (registryName, value, object) { | |||
this._registries[registryName] = this._registries[registryName] || {}; | |||
this._registries[registryName][value] = object; | |||
}; | |||
ActionContainer.prototype._registryGet = function (registryName, value, defaultValue) { | |||
if (arguments.length < 3) { | |||
defaultValue = null; | |||
} | |||
return this._registries[registryName][value] || defaultValue; | |||
}; | |||
// | |||
// Namespace default accessor methods | |||
// | |||
/** | |||
* ActionContainer#setDefaults(options) -> Void | |||
* - options (object):hash of options see [[Action.new]] | |||
* | |||
* Set defaults | |||
**/ | |||
ActionContainer.prototype.setDefaults = function (options) { | |||
options = options || {}; | |||
for (var property in options) { | |||
if ($$.has(options, property)) { | |||
this._defaults[property] = options[property]; | |||
} | |||
} | |||
// if these defaults match any existing arguments, replace the previous | |||
// default on the object with the new one | |||
this._actions.forEach(function (action) { | |||
if ($$.has(options, action.dest)) { | |||
action.defaultValue = options[action.dest]; | |||
} | |||
}); | |||
}; | |||
/** | |||
* ActionContainer#getDefault(dest) -> Mixed | |||
* - dest (string): action destination | |||
* | |||
* Return action default value | |||
**/ | |||
ActionContainer.prototype.getDefault = function (dest) { | |||
var result = $$.has(this._defaults, dest) ? this._defaults[dest] : null; | |||
this._actions.forEach(function (action) { | |||
if (action.dest === dest && $$.has(action, 'defaultValue')) { | |||
result = action.defaultValue; | |||
} | |||
}); | |||
return result; | |||
}; | |||
// | |||
// Adding argument actions | |||
// | |||
/** | |||
* ActionContainer#addArgument(args, options) -> Object | |||
* - args (String|Array): argument key, or array of argument keys | |||
* - options (Object): action objects see [[Action.new]] | |||
* | |||
* #### Examples | |||
* - addArgument([ '-f', '--foo' ], { action: 'store', defaultValue: 1, ... }) | |||
* - addArgument([ 'bar' ], { action: 'store', nargs: 1, ... }) | |||
* - addArgument('--baz', { action: 'store', nargs: 1, ... }) | |||
**/ | |||
ActionContainer.prototype.addArgument = function (args, options) { | |||
args = args; | |||
options = options || {}; | |||
if (typeof args === 'string') { | |||
args = [ args ]; | |||
} | |||
if (!Array.isArray(args)) { | |||
throw new TypeError('addArgument first argument should be a string or an array'); | |||
} | |||
if (typeof options !== 'object' || Array.isArray(options)) { | |||
throw new TypeError('addArgument second argument should be a hash'); | |||
} | |||
// if no positional args are supplied or only one is supplied and | |||
// it doesn't look like an option string, parse a positional argument | |||
if (!args || args.length === 1 && this.prefixChars.indexOf(args[0][0]) < 0) { | |||
if (args && !!options.dest) { | |||
throw new Error('dest supplied twice for positional argument'); | |||
} | |||
options = this._getPositional(args, options); | |||
// otherwise, we're adding an optional argument | |||
} else { | |||
options = this._getOptional(args, options); | |||
} | |||
// if no default was supplied, use the parser-level default | |||
if (typeof options.defaultValue === 'undefined') { | |||
var dest = options.dest; | |||
if ($$.has(this._defaults, dest)) { | |||
options.defaultValue = this._defaults[dest]; | |||
} else if (typeof this.argumentDefault !== 'undefined') { | |||
options.defaultValue = this.argumentDefault; | |||
} | |||
} | |||
// create the action object, and add it to the parser | |||
var ActionClass = this._popActionClass(options); | |||
if (typeof ActionClass !== 'function') { | |||
throw new Error(format('Unknown action "%s".', ActionClass)); | |||
} | |||
var action = new ActionClass(options); | |||
// throw an error if the action type is not callable | |||
var typeFunction = this._registryGet('type', action.type, action.type); | |||
if (typeof typeFunction !== 'function') { | |||
throw new Error(format('"%s" is not callable', typeFunction)); | |||
} | |||
return this._addAction(action); | |||
}; | |||
/** | |||
* ActionContainer#addArgumentGroup(options) -> ArgumentGroup | |||
* - options (Object): hash of options see [[ArgumentGroup.new]] | |||
* | |||
* Create new arguments groups | |||
**/ | |||
ActionContainer.prototype.addArgumentGroup = function (options) { | |||
var group = new ArgumentGroup(this, options); | |||
this._actionGroups.push(group); | |||
return group; | |||
}; | |||
/** | |||
* ActionContainer#addMutuallyExclusiveGroup(options) -> ArgumentGroup | |||
* - options (Object): {required: false} | |||
* | |||
* Create new mutual exclusive groups | |||
**/ | |||
ActionContainer.prototype.addMutuallyExclusiveGroup = function (options) { | |||
var group = new MutuallyExclusiveGroup(this, options); | |||
this._mutuallyExclusiveGroups.push(group); | |||
return group; | |||
}; | |||
ActionContainer.prototype._addAction = function (action) { | |||
var self = this; | |||
// resolve any conflicts | |||
this._checkConflict(action); | |||
// add to actions list | |||
this._actions.push(action); | |||
action.container = this; | |||
// index the action by any option strings it has | |||
action.optionStrings.forEach(function (optionString) { | |||
self._optionStringActions[optionString] = action; | |||
}); | |||
// set the flag if any option strings look like negative numbers | |||
action.optionStrings.forEach(function (optionString) { | |||
if (optionString.match(self._regexpNegativeNumber)) { | |||
if (!self._hasNegativeNumberOptionals.some(Boolean)) { | |||
self._hasNegativeNumberOptionals.push(true); | |||
} | |||
} | |||
}); | |||
// return the created action | |||
return action; | |||
}; | |||
ActionContainer.prototype._removeAction = function (action) { | |||
var actionIndex = this._actions.indexOf(action); | |||
if (actionIndex >= 0) { | |||
this._actions.splice(actionIndex, 1); | |||
} | |||
}; | |||
ActionContainer.prototype._addContainerActions = function (container) { | |||
// collect groups by titles | |||
var titleGroupMap = {}; | |||
this._actionGroups.forEach(function (group) { | |||
if (titleGroupMap[group.title]) { | |||
throw new Error(format('Cannot merge actions - two groups are named "%s".', group.title)); | |||
} | |||
titleGroupMap[group.title] = group; | |||
}); | |||
// map each action to its group | |||
var groupMap = {}; | |||
function actionHash(action) { | |||
// unique (hopefully?) string suitable as dictionary key | |||
return action.getName(); | |||
} | |||
container._actionGroups.forEach(function (group) { | |||
// if a group with the title exists, use that, otherwise | |||
// create a new group matching the container's group | |||
if (!titleGroupMap[group.title]) { | |||
titleGroupMap[group.title] = this.addArgumentGroup({ | |||
title: group.title, | |||
description: group.description | |||
}); | |||
} | |||
// map the actions to their new group | |||
group._groupActions.forEach(function (action) { | |||
groupMap[actionHash(action)] = titleGroupMap[group.title]; | |||
}); | |||
}, this); | |||
// add container's mutually exclusive groups | |||
// NOTE: if add_mutually_exclusive_group ever gains title= and | |||
// description= then this code will need to be expanded as above | |||
var mutexGroup; | |||
container._mutuallyExclusiveGroups.forEach(function (group) { | |||
mutexGroup = this.addMutuallyExclusiveGroup({ | |||
required: group.required | |||
}); | |||
// map the actions to their new mutex group | |||
group._groupActions.forEach(function (action) { | |||
groupMap[actionHash(action)] = mutexGroup; | |||
}); | |||
}, this); // forEach takes a 'this' argument | |||
// add all actions to this container or their group | |||
container._actions.forEach(function (action) { | |||
var key = actionHash(action); | |||
if (groupMap[key]) { | |||
groupMap[key]._addAction(action); | |||
} else { | |||
this._addAction(action); | |||
} | |||
}); | |||
}; | |||
ActionContainer.prototype._getPositional = function (dest, options) { | |||
if (Array.isArray(dest)) { | |||
dest = dest[0]; | |||
} | |||
// make sure required is not specified | |||
if (options.required) { | |||
throw new Error('"required" is an invalid argument for positionals.'); | |||
} | |||
// mark positional arguments as required if at least one is | |||
// always required | |||
if (options.nargs !== c.OPTIONAL && options.nargs !== c.ZERO_OR_MORE) { | |||
options.required = true; | |||
} | |||
if (options.nargs === c.ZERO_OR_MORE && typeof options.defaultValue === 'undefined') { | |||
options.required = true; | |||
} | |||
// return the keyword arguments with no option strings | |||
options.dest = dest; | |||
options.optionStrings = []; | |||
return options; | |||
}; | |||
ActionContainer.prototype._getOptional = function (args, options) { | |||
var prefixChars = this.prefixChars; | |||
var optionStrings = []; | |||
var optionStringsLong = []; | |||
// determine short and long option strings | |||
args.forEach(function (optionString) { | |||
// error on strings that don't start with an appropriate prefix | |||
if (prefixChars.indexOf(optionString[0]) < 0) { | |||
throw new Error(format('Invalid option string "%s": must start with a "%s".', | |||
optionString, | |||
prefixChars | |||
)); | |||
} | |||
// strings starting with two prefix characters are long options | |||
optionStrings.push(optionString); | |||
if (optionString.length > 1 && prefixChars.indexOf(optionString[1]) >= 0) { | |||
optionStringsLong.push(optionString); | |||
} | |||
}); | |||
// infer dest, '--foo-bar' -> 'foo_bar' and '-x' -> 'x' | |||
var dest = options.dest || null; | |||
delete options.dest; | |||
if (!dest) { | |||
var optionStringDest = optionStringsLong.length ? optionStringsLong[0] : optionStrings[0]; | |||
dest = $$.trimChars(optionStringDest, this.prefixChars); | |||
if (dest.length === 0) { | |||
throw new Error( | |||
format('dest= is required for options like "%s"', optionStrings.join(', ')) | |||
); | |||
} | |||
dest = dest.replace(/-/g, '_'); | |||
} | |||
// return the updated keyword arguments | |||
options.dest = dest; | |||
options.optionStrings = optionStrings; | |||
return options; | |||
}; | |||
ActionContainer.prototype._popActionClass = function (options, defaultValue) { | |||
defaultValue = defaultValue || null; | |||
var action = (options.action || defaultValue); | |||
delete options.action; | |||
var actionClass = this._registryGet('action', action, action); | |||
return actionClass; | |||
}; | |||
ActionContainer.prototype._getHandler = function () { | |||
var handlerString = this.conflictHandler; | |||
var handlerFuncName = '_handleConflict' + $$.capitalize(handlerString); | |||
var func = this[handlerFuncName]; | |||
if (typeof func === 'undefined') { | |||
var msg = 'invalid conflict resolution value: ' + handlerString; | |||
throw new Error(msg); | |||
} else { | |||
return func; | |||
} | |||
}; | |||
ActionContainer.prototype._checkConflict = function (action) { | |||
var optionStringActions = this._optionStringActions; | |||
var conflictOptionals = []; | |||
// find all options that conflict with this option | |||
// collect pairs, the string, and an existing action that it conflicts with | |||
action.optionStrings.forEach(function (optionString) { | |||
var conflOptional = optionStringActions[optionString]; | |||
if (typeof conflOptional !== 'undefined') { | |||
conflictOptionals.push([ optionString, conflOptional ]); | |||
} | |||
}); | |||
if (conflictOptionals.length > 0) { | |||
var conflictHandler = this._getHandler(); | |||
conflictHandler.call(this, action, conflictOptionals); | |||
} | |||
}; | |||
ActionContainer.prototype._handleConflictError = function (action, conflOptionals) { | |||
var conflicts = conflOptionals.map(function (pair) { return pair[0]; }); | |||
conflicts = conflicts.join(', '); | |||
throw argumentErrorHelper( | |||
action, | |||
format('Conflicting option string(s): %s', conflicts) | |||
); | |||
}; | |||
ActionContainer.prototype._handleConflictResolve = function (action, conflOptionals) { | |||
// remove all conflicting options | |||
var self = this; | |||
conflOptionals.forEach(function (pair) { | |||
var optionString = pair[0]; | |||
var conflictingAction = pair[1]; | |||
// remove the conflicting option string | |||
var i = conflictingAction.optionStrings.indexOf(optionString); | |||
if (i >= 0) { | |||
conflictingAction.optionStrings.splice(i, 1); | |||
} | |||
delete self._optionStringActions[optionString]; | |||
// if the option now has no option string, remove it from the | |||
// container holding it | |||
if (conflictingAction.optionStrings.length === 0) { | |||
conflictingAction.container._removeAction(conflictingAction); | |||
} | |||
}); | |||
}; |
@@ -0,0 +1,14 @@ | |||
'use strict'; | |||
module.exports.ArgumentParser = require('./argument_parser.js'); | |||
module.exports.Namespace = require('./namespace'); | |||
module.exports.Action = require('./action'); | |||
module.exports.HelpFormatter = require('./help/formatter.js'); | |||
module.exports.Const = require('./const.js'); | |||
module.exports.ArgumentDefaultsHelpFormatter = | |||
require('./help/added_formatters.js').ArgumentDefaultsHelpFormatter; | |||
module.exports.RawDescriptionHelpFormatter = | |||
require('./help/added_formatters.js').RawDescriptionHelpFormatter; | |||
module.exports.RawTextHelpFormatter = | |||
require('./help/added_formatters.js').RawTextHelpFormatter; |
@@ -0,0 +1,50 @@ | |||
'use strict'; | |||
var format = require('util').format; | |||
var ERR_CODE = 'ARGError'; | |||
/*:nodoc:* | |||
* argumentError(argument, message) -> TypeError | |||
* - argument (Object): action with broken argument | |||
* - message (String): error message | |||
* | |||
* Error format helper. An error from creating or using an argument | |||
* (optional or positional). The string value of this exception | |||
* is the message, augmented with information | |||
* about the argument that caused it. | |||
* | |||
* #####Example | |||
* | |||
* var argumentErrorHelper = require('./argument/error'); | |||
* if (conflictOptionals.length > 0) { | |||
* throw argumentErrorHelper( | |||
* action, | |||
* format('Conflicting option string(s): %s', conflictOptionals.join(', ')) | |||
* ); | |||
* } | |||
* | |||
**/ | |||
module.exports = function (argument, message) { | |||
var argumentName = null; | |||
var errMessage; | |||
var err; | |||
if (argument.getName) { | |||
argumentName = argument.getName(); | |||
} else { | |||
argumentName = '' + argument; | |||
} | |||
if (!argumentName) { | |||
errMessage = message; | |||
} else { | |||
errMessage = format('argument "%s": %s', argumentName, message); | |||
} | |||
err = new TypeError(errMessage); | |||
err.code = ERR_CODE; | |||
return err; | |||
}; |
@@ -0,0 +1,54 @@ | |||
/** internal | |||
* class MutuallyExclusiveGroup | |||
* | |||
* Group arguments. | |||
* By default, ArgumentParser groups command-line arguments | |||
* into “positional arguments” and “optional arguments” | |||
* when displaying help messages. When there is a better | |||
* conceptual grouping of arguments than this default one, | |||
* appropriate groups can be created using the addArgumentGroup() method | |||
* | |||
* This class inherited from [[ArgumentContainer]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var ArgumentGroup = require('./group'); | |||
/** | |||
* new MutuallyExclusiveGroup(container, options) | |||
* - container (object): main container | |||
* - options (object): options.required -> true/false | |||
* | |||
* `required` could be an argument itself, but making it a property of | |||
* the options argument is more consistent with the JS adaptation of the Python) | |||
**/ | |||
var MutuallyExclusiveGroup = module.exports = function MutuallyExclusiveGroup(container, options) { | |||
var required; | |||
options = options || {}; | |||
required = options.required || false; | |||
ArgumentGroup.call(this, container); | |||
this.required = required; | |||
}; | |||
util.inherits(MutuallyExclusiveGroup, ArgumentGroup); | |||
MutuallyExclusiveGroup.prototype._addAction = function (action) { | |||
var msg; | |||
if (action.required) { | |||
msg = 'mutually exclusive arguments must be optional'; | |||
throw new Error(msg); | |||
} | |||
action = this._container._addAction(action); | |||
this._groupActions.push(action); | |||
return action; | |||
}; | |||
MutuallyExclusiveGroup.prototype._removeAction = function (action) { | |||
this._container._removeAction(action); | |||
this._groupActions.remove(action); | |||
}; | |||
@@ -0,0 +1,75 @@ | |||
/** internal | |||
* class ArgumentGroup | |||
* | |||
* Group arguments. | |||
* By default, ArgumentParser groups command-line arguments | |||
* into “positional arguments” and “optional arguments” | |||
* when displaying help messages. When there is a better | |||
* conceptual grouping of arguments than this default one, | |||
* appropriate groups can be created using the addArgumentGroup() method | |||
* | |||
* This class inherited from [[ArgumentContainer]] | |||
**/ | |||
'use strict'; | |||
var util = require('util'); | |||
var ActionContainer = require('../action_container'); | |||
/** | |||
* new ArgumentGroup(container, options) | |||
* - container (object): main container | |||
* - options (object): hash of group options | |||
* | |||
* #### options | |||
* - **prefixChars** group name prefix | |||
* - **argumentDefault** default argument value | |||
* - **title** group title | |||
* - **description** group description | |||
* | |||
**/ | |||
var ArgumentGroup = module.exports = function ArgumentGroup(container, options) { | |||
options = options || {}; | |||
// add any missing keyword arguments by checking the container | |||
options.conflictHandler = (options.conflictHandler || container.conflictHandler); | |||
options.prefixChars = (options.prefixChars || container.prefixChars); | |||
options.argumentDefault = (options.argumentDefault || container.argumentDefault); | |||
ActionContainer.call(this, options); | |||
// group attributes | |||
this.title = options.title; | |||
this._groupActions = []; | |||
// share most attributes with the container | |||
this._container = container; | |||
this._registries = container._registries; | |||
this._actions = container._actions; | |||
this._optionStringActions = container._optionStringActions; | |||
this._defaults = container._defaults; | |||
this._hasNegativeNumberOptionals = container._hasNegativeNumberOptionals; | |||
this._mutuallyExclusiveGroups = container._mutuallyExclusiveGroups; | |||
}; | |||
util.inherits(ArgumentGroup, ActionContainer); | |||
ArgumentGroup.prototype._addAction = function (action) { | |||
// Parent add action | |||
action = ActionContainer.prototype._addAction.call(this, action); | |||
this._groupActions.push(action); | |||
return action; | |||
}; | |||
ArgumentGroup.prototype._removeAction = function (action) { | |||
// Parent remove action | |||
ActionContainer.prototype._removeAction.call(this, action); | |||
var actionIndex = this._groupActions.indexOf(action); | |||
if (actionIndex >= 0) { | |||
this._groupActions.splice(actionIndex, 1); | |||
} | |||
}; | |||
@@ -0,0 +1,21 @@ | |||
// | |||
// Constants | |||
// | |||
'use strict'; | |||
module.exports.EOL = '\n'; | |||
module.exports.SUPPRESS = '==SUPPRESS=='; | |||
module.exports.OPTIONAL = '?'; | |||
module.exports.ZERO_OR_MORE = '*'; | |||
module.exports.ONE_OR_MORE = '+'; | |||
module.exports.PARSER = 'A...'; | |||
module.exports.REMAINDER = '...'; | |||
module.exports._UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args'; |
@@ -0,0 +1,87 @@ | |||
'use strict'; | |||
var util = require('util'); | |||
// Constants | |||
var c = require('../const'); | |||
var $$ = require('../utils'); | |||
var HelpFormatter = require('./formatter.js'); | |||
/** | |||
* new RawDescriptionHelpFormatter(options) | |||
* new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...}) | |||
* | |||
* Help message formatter which adds default values to argument help. | |||
* | |||
* Only the name of this class is considered a public API. All the methods | |||
* provided by the class are considered an implementation detail. | |||
**/ | |||
function ArgumentDefaultsHelpFormatter(options) { | |||
HelpFormatter.call(this, options); | |||
} | |||
util.inherits(ArgumentDefaultsHelpFormatter, HelpFormatter); | |||
ArgumentDefaultsHelpFormatter.prototype._getHelpString = function (action) { | |||
var help = action.help; | |||
if (action.help.indexOf('%(defaultValue)s') === -1) { | |||
if (action.defaultValue !== c.SUPPRESS) { | |||
var defaulting_nargs = [ c.OPTIONAL, c.ZERO_OR_MORE ]; | |||
if (action.isOptional() || (defaulting_nargs.indexOf(action.nargs) >= 0)) { | |||
help += ' (default: %(defaultValue)s)'; | |||
} | |||
} | |||
} | |||
return help; | |||
}; | |||
module.exports.ArgumentDefaultsHelpFormatter = ArgumentDefaultsHelpFormatter; | |||
/** | |||
* new RawDescriptionHelpFormatter(options) | |||
* new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...}) | |||
* | |||
* Help message formatter which retains any formatting in descriptions. | |||
* | |||
* Only the name of this class is considered a public API. All the methods | |||
* provided by the class are considered an implementation detail. | |||
**/ | |||
function RawDescriptionHelpFormatter(options) { | |||
HelpFormatter.call(this, options); | |||
} | |||
util.inherits(RawDescriptionHelpFormatter, HelpFormatter); | |||
RawDescriptionHelpFormatter.prototype._fillText = function (text, width, indent) { | |||
var lines = text.split('\n'); | |||
lines = lines.map(function (line) { | |||
return $$.trimEnd(indent + line); | |||
}); | |||
return lines.join('\n'); | |||
}; | |||
module.exports.RawDescriptionHelpFormatter = RawDescriptionHelpFormatter; | |||
/** | |||
* new RawTextHelpFormatter(options) | |||
* new ArgumentParser({formatterClass: argparse.RawTextHelpFormatter, ...}) | |||
* | |||
* Help message formatter which retains formatting of all help text. | |||
* | |||
* Only the name of this class is considered a public API. All the methods | |||
* provided by the class are considered an implementation detail. | |||
**/ | |||
function RawTextHelpFormatter(options) { | |||
RawDescriptionHelpFormatter.call(this, options); | |||
} | |||
util.inherits(RawTextHelpFormatter, RawDescriptionHelpFormatter); | |||
RawTextHelpFormatter.prototype._splitLines = function (text) { | |||
return text.split('\n'); | |||
}; | |||
module.exports.RawTextHelpFormatter = RawTextHelpFormatter; |
@@ -0,0 +1,795 @@ | |||
/** | |||
* class HelpFormatter | |||
* | |||
* Formatter for generating usage messages and argument help strings. Only the | |||
* name of this class is considered a public API. All the methods provided by | |||
* the class are considered an implementation detail. | |||
* | |||
* Do not call in your code, use this class only for inherits your own forvatter | |||
* | |||
* ToDo add [additonal formatters][1] | |||
* | |||
* [1]:http://docs.python.org/dev/library/argparse.html#formatter-class | |||
**/ | |||
'use strict'; | |||
var sprintf = require('sprintf-js').sprintf; | |||
// Constants | |||
var c = require('../const'); | |||
var $$ = require('../utils'); | |||
/*:nodoc:* internal | |||
* new Support(parent, heding) | |||
* - parent (object): parent section | |||
* - heading (string): header string | |||
* | |||
**/ | |||
function Section(parent, heading) { | |||
this._parent = parent; | |||
this._heading = heading; | |||
this._items = []; | |||
} | |||
/*:nodoc:* internal | |||
* Section#addItem(callback) -> Void | |||
* - callback (array): tuple with function and args | |||
* | |||
* Add function for single element | |||
**/ | |||
Section.prototype.addItem = function (callback) { | |||
this._items.push(callback); | |||
}; | |||
/*:nodoc:* internal | |||
* Section#formatHelp(formatter) -> string | |||
* - formatter (HelpFormatter): current formatter | |||
* | |||
* Form help section string | |||
* | |||
**/ | |||
Section.prototype.formatHelp = function (formatter) { | |||
var itemHelp, heading; | |||
// format the indented section | |||
if (this._parent) { | |||
formatter._indent(); | |||
} | |||
itemHelp = this._items.map(function (item) { | |||
var obj, func, args; | |||
obj = formatter; | |||
func = item[0]; | |||
args = item[1]; | |||
return func.apply(obj, args); | |||
}); | |||
itemHelp = formatter._joinParts(itemHelp); | |||
if (this._parent) { | |||
formatter._dedent(); | |||
} | |||
// return nothing if the section was empty | |||
if (!itemHelp) { | |||
return ''; | |||
} | |||
// add the heading if the section was non-empty | |||
heading = ''; | |||
if (this._heading && this._heading !== c.SUPPRESS) { | |||
var currentIndent = formatter.currentIndent; | |||
heading = $$.repeat(' ', currentIndent) + this._heading + ':' + c.EOL; | |||
} | |||
// join the section-initialize newline, the heading and the help | |||
return formatter._joinParts([ c.EOL, heading, itemHelp, c.EOL ]); | |||
}; | |||
/** | |||
* new HelpFormatter(options) | |||
* | |||
* #### Options: | |||
* - `prog`: program name | |||
* - `indentIncriment`: indent step, default value 2 | |||
* - `maxHelpPosition`: max help position, default value = 24 | |||
* - `width`: line width | |||
* | |||
**/ | |||
var HelpFormatter = module.exports = function HelpFormatter(options) { | |||
options = options || {}; | |||
this._prog = options.prog; | |||
this._maxHelpPosition = options.maxHelpPosition || 24; | |||
this._width = (options.width || ((process.env.COLUMNS || 80) - 2)); | |||
this._currentIndent = 0; | |||
this._indentIncriment = options.indentIncriment || 2; | |||
this._level = 0; | |||
this._actionMaxLength = 0; | |||
this._rootSection = new Section(null); | |||
this._currentSection = this._rootSection; | |||
this._whitespaceMatcher = new RegExp('\\s+', 'g'); | |||
this._longBreakMatcher = new RegExp(c.EOL + c.EOL + c.EOL + '+', 'g'); | |||
}; | |||
HelpFormatter.prototype._indent = function () { | |||
this._currentIndent += this._indentIncriment; | |||
this._level += 1; | |||
}; | |||
HelpFormatter.prototype._dedent = function () { | |||
this._currentIndent -= this._indentIncriment; | |||
this._level -= 1; | |||
if (this._currentIndent < 0) { | |||
throw new Error('Indent decreased below 0.'); | |||
} | |||
}; | |||
HelpFormatter.prototype._addItem = function (func, args) { | |||
this._currentSection.addItem([ func, args ]); | |||
}; | |||
// | |||
// Message building methods | |||
// | |||
/** | |||
* HelpFormatter#startSection(heading) -> Void | |||
* - heading (string): header string | |||
* | |||
* Start new help section | |||
* | |||
* See alse [code example][1] | |||
* | |||
* ##### Example | |||
* | |||
* formatter.startSection(actionGroup.title); | |||
* formatter.addText(actionGroup.description); | |||
* formatter.addArguments(actionGroup._groupActions); | |||
* formatter.endSection(); | |||
* | |||
**/ | |||
HelpFormatter.prototype.startSection = function (heading) { | |||
this._indent(); | |||
var section = new Section(this._currentSection, heading); | |||
var func = section.formatHelp.bind(section); | |||
this._addItem(func, [ this ]); | |||
this._currentSection = section; | |||
}; | |||
/** | |||
* HelpFormatter#endSection -> Void | |||
* | |||
* End help section | |||
* | |||
* ##### Example | |||
* | |||
* formatter.startSection(actionGroup.title); | |||
* formatter.addText(actionGroup.description); | |||
* formatter.addArguments(actionGroup._groupActions); | |||
* formatter.endSection(); | |||
**/ | |||
HelpFormatter.prototype.endSection = function () { | |||
this._currentSection = this._currentSection._parent; | |||
this._dedent(); | |||
}; | |||
/** | |||
* HelpFormatter#addText(text) -> Void | |||
* - text (string): plain text | |||
* | |||
* Add plain text into current section | |||
* | |||
* ##### Example | |||
* | |||
* formatter.startSection(actionGroup.title); | |||
* formatter.addText(actionGroup.description); | |||
* formatter.addArguments(actionGroup._groupActions); | |||
* formatter.endSection(); | |||
* | |||
**/ | |||
HelpFormatter.prototype.addText = function (text) { | |||
if (text && text !== c.SUPPRESS) { | |||
this._addItem(this._formatText, [ text ]); | |||
} | |||
}; | |||
/** | |||
* HelpFormatter#addUsage(usage, actions, groups, prefix) -> Void | |||
* - usage (string): usage text | |||
* - actions (array): actions list | |||
* - groups (array): groups list | |||
* - prefix (string): usage prefix | |||
* | |||
* Add usage data into current section | |||
* | |||
* ##### Example | |||
* | |||
* formatter.addUsage(this.usage, this._actions, []); | |||
* return formatter.formatHelp(); | |||
* | |||
**/ | |||
HelpFormatter.prototype.addUsage = function (usage, actions, groups, prefix) { | |||
if (usage !== c.SUPPRESS) { | |||
this._addItem(this._formatUsage, [ usage, actions, groups, prefix ]); | |||
} | |||
}; | |||
/** | |||
* HelpFormatter#addArgument(action) -> Void | |||
* - action (object): action | |||
* | |||
* Add argument into current section | |||
* | |||
* Single variant of [[HelpFormatter#addArguments]] | |||
**/ | |||
HelpFormatter.prototype.addArgument = function (action) { | |||
if (action.help !== c.SUPPRESS) { | |||
var self = this; | |||
// find all invocations | |||
var invocations = [ this._formatActionInvocation(action) ]; | |||
var invocationLength = invocations[0].length; | |||
var actionLength; | |||
if (action._getSubactions) { | |||
this._indent(); | |||
action._getSubactions().forEach(function (subaction) { | |||
var invocationNew = self._formatActionInvocation(subaction); | |||
invocations.push(invocationNew); | |||
invocationLength = Math.max(invocationLength, invocationNew.length); | |||
}); | |||
this._dedent(); | |||
} | |||
// update the maximum item length | |||
actionLength = invocationLength + this._currentIndent; | |||
this._actionMaxLength = Math.max(this._actionMaxLength, actionLength); | |||
// add the item to the list | |||
this._addItem(this._formatAction, [ action ]); | |||
} | |||
}; | |||
/** | |||
* HelpFormatter#addArguments(actions) -> Void | |||
* - actions (array): actions list | |||
* | |||
* Mass add arguments into current section | |||
* | |||
* ##### Example | |||
* | |||
* formatter.startSection(actionGroup.title); | |||
* formatter.addText(actionGroup.description); | |||
* formatter.addArguments(actionGroup._groupActions); | |||
* formatter.endSection(); | |||
* | |||
**/ | |||
HelpFormatter.prototype.addArguments = function (actions) { | |||
var self = this; | |||
actions.forEach(function (action) { | |||
self.addArgument(action); | |||
}); | |||
}; | |||
// | |||
// Help-formatting methods | |||
// | |||
/** | |||
* HelpFormatter#formatHelp -> string | |||
* | |||
* Format help | |||
* | |||
* ##### Example | |||
* | |||
* formatter.addText(this.epilog); | |||
* return formatter.formatHelp(); | |||
* | |||
**/ | |||
HelpFormatter.prototype.formatHelp = function () { | |||
var help = this._rootSection.formatHelp(this); | |||
if (help) { | |||
help = help.replace(this._longBreakMatcher, c.EOL + c.EOL); | |||
help = $$.trimChars(help, c.EOL) + c.EOL; | |||
} | |||
return help; | |||
}; | |||
HelpFormatter.prototype._joinParts = function (partStrings) { | |||
return partStrings.filter(function (part) { | |||
return (part && part !== c.SUPPRESS); | |||
}).join(''); | |||
}; | |||
HelpFormatter.prototype._formatUsage = function (usage, actions, groups, prefix) { | |||
if (!prefix && typeof prefix !== 'string') { | |||
prefix = 'usage: '; | |||
} | |||
actions = actions || []; | |||
groups = groups || []; | |||
// if usage is specified, use that | |||
if (usage) { | |||
usage = sprintf(usage, { prog: this._prog }); | |||
// if no optionals or positionals are available, usage is just prog | |||
} else if (!usage && actions.length === 0) { | |||
usage = this._prog; | |||
// if optionals and positionals are available, calculate usage | |||
} else if (!usage) { | |||
var prog = this._prog; | |||
var optionals = []; | |||
var positionals = []; | |||
var actionUsage; | |||
var textWidth; | |||
// split optionals from positionals | |||
actions.forEach(function (action) { | |||
if (action.isOptional()) { | |||
optionals.push(action); | |||
} else { | |||
positionals.push(action); | |||
} | |||
}); | |||
// build full usage string | |||
actionUsage = this._formatActionsUsage([].concat(optionals, positionals), groups); | |||
usage = [ prog, actionUsage ].join(' '); | |||
// wrap the usage parts if it's too long | |||
textWidth = this._width - this._currentIndent; | |||
if ((prefix.length + usage.length) > textWidth) { | |||
// break usage into wrappable parts | |||
var regexpPart = new RegExp('\\(.*?\\)+|\\[.*?\\]+|\\S+', 'g'); | |||
var optionalUsage = this._formatActionsUsage(optionals, groups); | |||
var positionalUsage = this._formatActionsUsage(positionals, groups); | |||
var optionalParts = optionalUsage.match(regexpPart); | |||
var positionalParts = positionalUsage.match(regexpPart) || []; | |||
if (optionalParts.join(' ') !== optionalUsage) { | |||
throw new Error('assert "optionalParts.join(\' \') === optionalUsage"'); | |||
} | |||
if (positionalParts.join(' ') !== positionalUsage) { | |||
throw new Error('assert "positionalParts.join(\' \') === positionalUsage"'); | |||
} | |||
// helper for wrapping lines | |||
/*eslint-disable func-style*/ // node 0.10 compat | |||
var _getLines = function (parts, indent, prefix) { | |||
var lines = []; | |||
var line = []; | |||
var lineLength = prefix ? prefix.length - 1 : indent.length - 1; | |||
parts.forEach(function (part) { | |||
if (lineLength + 1 + part.length > textWidth) { | |||
lines.push(indent + line.join(' ')); | |||
line = []; | |||
lineLength = indent.length - 1; | |||
} | |||
line.push(part); | |||
lineLength += part.length + 1; | |||
}); | |||
if (line) { | |||
lines.push(indent + line.join(' ')); | |||
} | |||
if (prefix) { | |||
lines[0] = lines[0].substr(indent.length); | |||
} | |||
return lines; | |||
}; | |||
var lines, indent, parts; | |||
// if prog is short, follow it with optionals or positionals | |||
if (prefix.length + prog.length <= 0.75 * textWidth) { | |||
indent = $$.repeat(' ', (prefix.length + prog.length + 1)); | |||
if (optionalParts) { | |||
lines = [].concat( | |||
_getLines([ prog ].concat(optionalParts), indent, prefix), | |||
_getLines(positionalParts, indent) | |||
); | |||
} else if (positionalParts) { | |||
lines = _getLines([ prog ].concat(positionalParts), indent, prefix); | |||
} else { | |||
lines = [ prog ]; | |||
} | |||
// if prog is long, put it on its own line | |||
} else { | |||
indent = $$.repeat(' ', prefix.length); | |||
parts = optionalParts.concat(positionalParts); | |||
lines = _getLines(parts, indent); | |||
if (lines.length > 1) { | |||
lines = [].concat( | |||
_getLines(optionalParts, indent), | |||
_getLines(positionalParts, indent) | |||
); | |||
} | |||
lines = [ prog ].concat(lines); | |||
} | |||
// join lines into usage | |||
usage = lines.join(c.EOL); | |||
} | |||
} | |||
// prefix with 'usage:' | |||
return prefix + usage + c.EOL + c.EOL; | |||
}; | |||
HelpFormatter.prototype._formatActionsUsage = function (actions, groups) { | |||
// find group indices and identify actions in groups | |||
var groupActions = []; | |||
var inserts = []; | |||
var self = this; | |||
groups.forEach(function (group) { | |||
var end; | |||
var i; | |||
var start = actions.indexOf(group._groupActions[0]); | |||
if (start >= 0) { | |||
end = start + group._groupActions.length; | |||
//if (actions.slice(start, end) === group._groupActions) { | |||
if ($$.arrayEqual(actions.slice(start, end), group._groupActions)) { | |||
group._groupActions.forEach(function (action) { | |||
groupActions.push(action); | |||
}); | |||
if (!group.required) { | |||
if (inserts[start]) { | |||
inserts[start] += ' ['; | |||
} else { | |||
inserts[start] = '['; | |||
} | |||
inserts[end] = ']'; | |||
} else { | |||
if (inserts[start]) { | |||
inserts[start] += ' ('; | |||
} else { | |||
inserts[start] = '('; | |||
} | |||
inserts[end] = ')'; | |||
} | |||
for (i = start + 1; i < end; i += 1) { | |||
inserts[i] = '|'; | |||
} | |||
} | |||
} | |||
}); | |||
// collect all actions format strings | |||
var parts = []; | |||
actions.forEach(function (action, actionIndex) { | |||
var part; | |||
var optionString; | |||
var argsDefault; | |||
var argsString; | |||
// suppressed arguments are marked with None | |||
// remove | separators for suppressed arguments | |||
if (action.help === c.SUPPRESS) { | |||
parts.push(null); | |||
if (inserts[actionIndex] === '|') { | |||
inserts.splice(actionIndex, actionIndex); | |||
} else if (inserts[actionIndex + 1] === '|') { | |||
inserts.splice(actionIndex + 1, actionIndex + 1); | |||
} | |||
// produce all arg strings | |||
} else if (!action.isOptional()) { | |||
part = self._formatArgs(action, action.dest); | |||
// if it's in a group, strip the outer [] | |||
if (groupActions.indexOf(action) >= 0) { | |||
if (part[0] === '[' && part[part.length - 1] === ']') { | |||
part = part.slice(1, -1); | |||
} | |||
} | |||
// add the action string to the list | |||
parts.push(part); | |||
// produce the first way to invoke the option in brackets | |||
} else { | |||
optionString = action.optionStrings[0]; | |||
// if the Optional doesn't take a value, format is: -s or --long | |||
if (action.nargs === 0) { | |||
part = '' + optionString; | |||
// if the Optional takes a value, format is: -s ARGS or --long ARGS | |||
} else { | |||
argsDefault = action.dest.toUpperCase(); | |||
argsString = self._formatArgs(action, argsDefault); | |||
part = optionString + ' ' + argsString; | |||
} | |||
// make it look optional if it's not required or in a group | |||
if (!action.required && groupActions.indexOf(action) < 0) { | |||
part = '[' + part + ']'; | |||
} | |||
// add the action string to the list | |||
parts.push(part); | |||
} | |||
}); | |||
// insert things at the necessary indices | |||
for (var i = inserts.length - 1; i >= 0; --i) { | |||
if (inserts[i] !== null) { | |||
parts.splice(i, 0, inserts[i]); | |||
} | |||
} | |||
// join all the action items with spaces | |||
var text = parts.filter(function (part) { | |||
return !!part; | |||
}).join(' '); | |||
// clean up separators for mutually exclusive groups | |||
text = text.replace(/([\[(]) /g, '$1'); // remove spaces | |||
text = text.replace(/ ([\])])/g, '$1'); | |||
text = text.replace(/\[ *\]/g, ''); // remove empty groups | |||
text = text.replace(/\( *\)/g, ''); | |||
text = text.replace(/\(([^|]*)\)/g, '$1'); // remove () from single action groups | |||
text = text.trim(); | |||
// return the text | |||
return text; | |||
}; | |||
HelpFormatter.prototype._formatText = function (text) { | |||
text = sprintf(text, { prog: this._prog }); | |||
var textWidth = this._width - this._currentIndent; | |||
var indentIncriment = $$.repeat(' ', this._currentIndent); | |||
return this._fillText(text, textWidth, indentIncriment) + c.EOL + c.EOL; | |||
}; | |||
HelpFormatter.prototype._formatAction = function (action) { | |||
var self = this; | |||
var helpText; | |||
var helpLines; | |||
var parts; | |||
var indentFirst; | |||
// determine the required width and the entry label | |||
var helpPosition = Math.min(this._actionMaxLength + 2, this._maxHelpPosition); | |||
var helpWidth = this._width - helpPosition; | |||
var actionWidth = helpPosition - this._currentIndent - 2; | |||
var actionHeader = this._formatActionInvocation(action); | |||
// no help; start on same line and add a final newline | |||
if (!action.help) { | |||
actionHeader = $$.repeat(' ', this._currentIndent) + actionHeader + c.EOL; | |||
// short action name; start on the same line and pad two spaces | |||
} else if (actionHeader.length <= actionWidth) { | |||
actionHeader = $$.repeat(' ', this._currentIndent) + | |||
actionHeader + | |||
' ' + | |||
$$.repeat(' ', actionWidth - actionHeader.length); | |||
indentFirst = 0; | |||
// long action name; start on the next line | |||
} else { | |||
actionHeader = $$.repeat(' ', this._currentIndent) + actionHeader + c.EOL; | |||
indentFirst = helpPosition; | |||
} | |||
// collect the pieces of the action help | |||
parts = [ actionHeader ]; | |||
// if there was help for the action, add lines of help text | |||
if (action.help) { | |||
helpText = this._expandHelp(action); | |||
helpLines = this._splitLines(helpText, helpWidth); | |||
parts.push($$.repeat(' ', indentFirst) + helpLines[0] + c.EOL); | |||
helpLines.slice(1).forEach(function (line) { | |||
parts.push($$.repeat(' ', helpPosition) + line + c.EOL); | |||
}); | |||
// or add a newline if the description doesn't end with one | |||
} else if (actionHeader.charAt(actionHeader.length - 1) !== c.EOL) { | |||
parts.push(c.EOL); | |||
} | |||
// if there are any sub-actions, add their help as well | |||
if (action._getSubactions) { | |||
this._indent(); | |||
action._getSubactions().forEach(function (subaction) { | |||
parts.push(self._formatAction(subaction)); | |||
}); | |||
this._dedent(); | |||
} | |||
// return a single string | |||
return this._joinParts(parts); | |||
}; | |||
HelpFormatter.prototype._formatActionInvocation = function (action) { | |||
if (!action.isOptional()) { | |||
var format_func = this._metavarFormatter(action, action.dest); | |||
var metavars = format_func(1); | |||
return metavars[0]; | |||
} | |||
var parts = []; | |||
var argsDefault; | |||
var argsString; | |||
// if the Optional doesn't take a value, format is: -s, --long | |||
if (action.nargs === 0) { | |||
parts = parts.concat(action.optionStrings); | |||
// if the Optional takes a value, format is: -s ARGS, --long ARGS | |||
} else { | |||
argsDefault = action.dest.toUpperCase(); | |||
argsString = this._formatArgs(action, argsDefault); | |||
action.optionStrings.forEach(function (optionString) { | |||
parts.push(optionString + ' ' + argsString); | |||
}); | |||
} | |||
return parts.join(', '); | |||
}; | |||
HelpFormatter.prototype._metavarFormatter = function (action, metavarDefault) { | |||
var result; | |||
if (action.metavar || action.metavar === '') { | |||
result = action.metavar; | |||
} else if (action.choices) { | |||
var choices = action.choices; | |||
if (typeof choices === 'string') { | |||
choices = choices.split('').join(', '); | |||
} else if (Array.isArray(choices)) { | |||
choices = choices.join(','); | |||
} else { | |||
choices = Object.keys(choices).join(','); | |||
} | |||
result = '{' + choices + '}'; | |||
} else { | |||
result = metavarDefault; | |||
} | |||
return function (size) { | |||
if (Array.isArray(result)) { | |||
return result; | |||
} | |||
var metavars = []; | |||
for (var i = 0; i < size; i += 1) { | |||
metavars.push(result); | |||
} | |||
return metavars; | |||
}; | |||
}; | |||
HelpFormatter.prototype._formatArgs = function (action, metavarDefault) { | |||
var result; | |||
var metavars; | |||
var buildMetavar = this._metavarFormatter(action, metavarDefault); | |||
switch (action.nargs) { | |||
/*eslint-disable no-undefined*/ | |||
case undefined: | |||
case null: | |||
metavars = buildMetavar(1); | |||
result = '' + metavars[0]; | |||
break; | |||
case c.OPTIONAL: | |||
metavars = buildMetavar(1); | |||
result = '[' + metavars[0] + ']'; | |||
break; | |||
case c.ZERO_OR_MORE: | |||
metavars = buildMetavar(2); | |||
result = '[' + metavars[0] + ' [' + metavars[1] + ' ...]]'; | |||
break; | |||
case c.ONE_OR_MORE: | |||
metavars = buildMetavar(2); | |||
result = '' + metavars[0] + ' [' + metavars[1] + ' ...]'; | |||
break; | |||
case c.REMAINDER: | |||
result = '...'; | |||
break; | |||
case c.PARSER: | |||
metavars = buildMetavar(1); | |||
result = metavars[0] + ' ...'; | |||
break; | |||
default: | |||
metavars = buildMetavar(action.nargs); | |||
result = metavars.join(' '); | |||
} | |||
return result; | |||
}; | |||
HelpFormatter.prototype._expandHelp = function (action) { | |||
var params = { prog: this._prog }; | |||
Object.keys(action).forEach(function (actionProperty) { | |||
var actionValue = action[actionProperty]; | |||
if (actionValue !== c.SUPPRESS) { | |||
params[actionProperty] = actionValue; | |||
} | |||
}); | |||
if (params.choices) { | |||
if (typeof params.choices === 'string') { | |||
params.choices = params.choices.split('').join(', '); | |||
} else if (Array.isArray(params.choices)) { | |||
params.choices = params.choices.join(', '); | |||
} else { | |||
params.choices = Object.keys(params.choices).join(', '); | |||
} | |||
} | |||
return sprintf(this._getHelpString(action), params); | |||
}; | |||
HelpFormatter.prototype._splitLines = function (text, width) { | |||
var lines = []; | |||
var delimiters = [ ' ', '.', ',', '!', '?' ]; | |||
var re = new RegExp('[' + delimiters.join('') + '][^' + delimiters.join('') + ']*$'); | |||
text = text.replace(/[\n\|\t]/g, ' '); | |||
text = text.trim(); | |||
text = text.replace(this._whitespaceMatcher, ' '); | |||
// Wraps the single paragraph in text (a string) so every line | |||
// is at most width characters long. | |||
text.split(c.EOL).forEach(function (line) { | |||
if (width >= line.length) { | |||
lines.push(line); | |||
return; | |||
} | |||
var wrapStart = 0; | |||
var wrapEnd = width; | |||
var delimiterIndex = 0; | |||
while (wrapEnd <= line.length) { | |||
if (wrapEnd !== line.length && delimiters.indexOf(line[wrapEnd] < -1)) { | |||
delimiterIndex = (re.exec(line.substring(wrapStart, wrapEnd)) || {}).index; | |||
wrapEnd = wrapStart + delimiterIndex + 1; | |||
} | |||
lines.push(line.substring(wrapStart, wrapEnd)); | |||
wrapStart = wrapEnd; | |||
wrapEnd += width; | |||
} | |||
if (wrapStart < line.length) { | |||
lines.push(line.substring(wrapStart, wrapEnd)); | |||
} | |||
}); | |||
return lines; | |||
}; | |||
HelpFormatter.prototype._fillText = function (text, width, indent) { | |||
var lines = this._splitLines(text, width); | |||
lines = lines.map(function (line) { | |||
return indent + line; | |||
}); | |||
return lines.join(c.EOL); | |||
}; | |||
HelpFormatter.prototype._getHelpString = function (action) { | |||
return action.help; | |||
}; |