First upload version 0.0.1
This commit is contained in:
BIN
model/Vikhr-Qwen-2.5-0.5b-Instruct-Q3_K_M.gguf
Normal file
BIN
model/Vikhr-Qwen-2.5-0.5b-Instruct-Q3_K_M.gguf
Normal file
Binary file not shown.
16
node_modules/.bin/cmake-js
generated
vendored
Normal file
16
node_modules/.bin/cmake-js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../cmake-js/bin/cmake-js" "$@"
|
||||
else
|
||||
exec node "$basedir/../cmake-js/bin/cmake-js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/cmake-js.cmd
generated
vendored
Normal file
17
node_modules/.bin/cmake-js.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\cmake-js\bin\cmake-js" %*
|
||||
28
node_modules/.bin/cmake-js.ps1
generated
vendored
Normal file
28
node_modules/.bin/cmake-js.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../cmake-js/bin/cmake-js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../cmake-js/bin/cmake-js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../cmake-js/bin/cmake-js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../cmake-js/bin/cmake-js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/color-support
generated
vendored
Normal file
16
node_modules/.bin/color-support
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../color-support/bin.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../color-support/bin.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/color-support.cmd
generated
vendored
Normal file
17
node_modules/.bin/color-support.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\color-support\bin.js" %*
|
||||
28
node_modules/.bin/color-support.ps1
generated
vendored
Normal file
28
node_modules/.bin/color-support.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../color-support/bin.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../color-support/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../color-support/bin.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../color-support/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/ipull
generated
vendored
Normal file
16
node_modules/.bin/ipull
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../ipull/dist/cli/cli.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../ipull/dist/cli/cli.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/ipull.cmd
generated
vendored
Normal file
17
node_modules/.bin/ipull.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\ipull\dist\cli\cli.js" %*
|
||||
28
node_modules/.bin/ipull.ps1
generated
vendored
Normal file
28
node_modules/.bin/ipull.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../ipull/dist/cli/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../ipull/dist/cli/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../ipull/dist/cli/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../ipull/dist/cli/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/mime
generated
vendored
Normal file
16
node_modules/.bin/mime
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../mime/cli.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../mime/cli.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/mime.cmd
generated
vendored
Normal file
17
node_modules/.bin/mime.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mime\cli.js" %*
|
||||
28
node_modules/.bin/mime.ps1
generated
vendored
Normal file
28
node_modules/.bin/mime.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../mime/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../mime/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../mime/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../mime/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/mkdirp
generated
vendored
Normal file
16
node_modules/.bin/mkdirp
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/mkdirp.cmd
generated
vendored
Normal file
17
node_modules/.bin/mkdirp.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mkdirp\bin\cmd.js" %*
|
||||
28
node_modules/.bin/mkdirp.ps1
generated
vendored
Normal file
28
node_modules/.bin/mkdirp.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/nanoid
generated
vendored
Normal file
16
node_modules/.bin/nanoid
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../nanoid/bin/nanoid.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../nanoid/bin/nanoid.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/nanoid.cmd
generated
vendored
Normal file
17
node_modules/.bin/nanoid.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\nanoid\bin\nanoid.js" %*
|
||||
28
node_modules/.bin/nanoid.ps1
generated
vendored
Normal file
28
node_modules/.bin/nanoid.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../nanoid/bin/nanoid.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../nanoid/bin/nanoid.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../nanoid/bin/nanoid.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../nanoid/bin/nanoid.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/nlc
generated
vendored
Normal file
16
node_modules/.bin/nlc
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../node-llama-cpp/dist/cli/cli.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../node-llama-cpp/dist/cli/cli.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/nlc.cmd
generated
vendored
Normal file
17
node_modules/.bin/nlc.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\node-llama-cpp\dist\cli\cli.js" %*
|
||||
28
node_modules/.bin/nlc.ps1
generated
vendored
Normal file
28
node_modules/.bin/nlc.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/node-llama-cpp
generated
vendored
Normal file
16
node_modules/.bin/node-llama-cpp
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../node-llama-cpp/dist/cli/cli.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../node-llama-cpp/dist/cli/cli.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/node-llama-cpp.cmd
generated
vendored
Normal file
17
node_modules/.bin/node-llama-cpp.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\node-llama-cpp\dist\cli\cli.js" %*
|
||||
28
node_modules/.bin/node-llama-cpp.ps1
generated
vendored
Normal file
28
node_modules/.bin/node-llama-cpp.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../node-llama-cpp/dist/cli/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/node-which
generated
vendored
Normal file
16
node_modules/.bin/node-which
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../which/bin/which.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../which/bin/which.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/node-which.cmd
generated
vendored
Normal file
17
node_modules/.bin/node-which.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\which\bin\which.js" %*
|
||||
28
node_modules/.bin/node-which.ps1
generated
vendored
Normal file
28
node_modules/.bin/node-which.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../which/bin/which.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../which/bin/which.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../which/bin/which.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../which/bin/which.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/rc
generated
vendored
Normal file
16
node_modules/.bin/rc
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../rc/cli.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../rc/cli.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/rc.cmd
generated
vendored
Normal file
17
node_modules/.bin/rc.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\rc\cli.js" %*
|
||||
28
node_modules/.bin/rc.ps1
generated
vendored
Normal file
28
node_modules/.bin/rc.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../rc/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../rc/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../rc/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../rc/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
16
node_modules/.bin/semver
generated
vendored
Normal file
16
node_modules/.bin/semver
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../semver/bin/semver.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../semver/bin/semver.js" "$@"
|
||||
fi
|
||||
17
node_modules/.bin/semver.cmd
generated
vendored
Normal file
17
node_modules/.bin/semver.cmd
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\semver\bin\semver.js" %*
|
||||
28
node_modules/.bin/semver.ps1
generated
vendored
Normal file
28
node_modules/.bin/semver.ps1
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
3107
node_modules/.package-lock.json
generated
vendored
Normal file
3107
node_modules/.package-lock.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
21
node_modules/@huggingface/jinja/LICENSE
generated
vendored
Normal file
21
node_modules/@huggingface/jinja/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Hugging Face
|
||||
|
||||
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.
|
||||
78
node_modules/@huggingface/jinja/README.md
generated
vendored
Normal file
78
node_modules/@huggingface/jinja/README.md
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# Jinja
|
||||
|
||||
A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.
|
||||
|
||||
## Usage
|
||||
|
||||
### Load template from a model on the Hugging Face Hub
|
||||
|
||||
First, install the jinja and hub packages:
|
||||
|
||||
```sh
|
||||
npm i @huggingface/jinja
|
||||
npm i @huggingface/hub
|
||||
```
|
||||
|
||||
You can then load a tokenizer from the Hugging Face Hub and render a list of chat messages, as follows:
|
||||
|
||||
```js
|
||||
import { Template } from "@huggingface/jinja";
|
||||
import { downloadFile } from "@huggingface/hub";
|
||||
|
||||
const config = await (
|
||||
await downloadFile({
|
||||
repo: "mistralai/Mistral-7B-Instruct-v0.1",
|
||||
path: "tokenizer_config.json",
|
||||
})
|
||||
).json();
|
||||
|
||||
const chat = [
|
||||
{ role: "user", content: "Hello, how are you?" },
|
||||
{ role: "assistant", content: "I'm doing great. How can I help you today?" },
|
||||
{ role: "user", content: "I'd like to show off how chat templating works!" },
|
||||
];
|
||||
|
||||
const template = new Template(config.chat_template);
|
||||
const result = template.render({
|
||||
messages: chat,
|
||||
bos_token: config.bos_token,
|
||||
eos_token: config.eos_token,
|
||||
});
|
||||
// "<s>[INST] Hello, how are you? [/INST]I'm doing great. How can I help you today?</s> [INST] I'd like to show off how chat templating works! [/INST]"
|
||||
```
|
||||
|
||||
### Transformers.js
|
||||
|
||||
First, install `@huggingface/transformers`:
|
||||
|
||||
```sh
|
||||
npm i @huggingface/transformers
|
||||
```
|
||||
|
||||
You can then render a list of chat messages using a tokenizer's `apply_chat_template` method.
|
||||
|
||||
```js
|
||||
import { AutoTokenizer } from "@huggingface/transformers";
|
||||
|
||||
// Load tokenizer from the Hugging Face Hub
|
||||
const tokenizer = await AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1");
|
||||
|
||||
// Define chat messages
|
||||
const chat = [
|
||||
{ role: "user", content: "Hello, how are you?" },
|
||||
{ role: "assistant", content: "I'm doing great. How can I help you today?" },
|
||||
{ role: "user", content: "I'd like to show off how chat templating works!" },
|
||||
];
|
||||
|
||||
const text = tokenizer.apply_chat_template(chat, { tokenize: false });
|
||||
// "<s>[INST] Hello, how are you? [/INST]I'm doing great. How can I help you today?</s> [INST] I'd like to show off how chat templating works! [/INST]"
|
||||
```
|
||||
|
||||
Notice how the entire chat is condensed into a single string. If you would instead like to return the tokenized version (i.e., a list of token IDs), you can use the following:
|
||||
|
||||
```js
|
||||
const input_ids = tokenizer.apply_chat_template(chat, { tokenize: true, return_tensor: false });
|
||||
// [1, 733, 16289, 28793, 22557, 28725, 910, 460, 368, 28804, 733, 28748, 16289, 28793, 28737, 28742, 28719, 2548, 1598, 28723, 1602, 541, 315, 1316, 368, 3154, 28804, 2, 28705, 733, 16289, 28793, 315, 28742, 28715, 737, 298, 1347, 805, 910, 10706, 5752, 1077, 3791, 28808, 733, 28748, 16289, 28793]
|
||||
```
|
||||
|
||||
For more information about chat templates, check out the transformers [documentation](https://huggingface.co/docs/transformers/main/en/chat_templating).
|
||||
221
node_modules/@huggingface/jinja/dist/ast.d.ts
generated
vendored
Normal file
221
node_modules/@huggingface/jinja/dist/ast.d.ts
generated
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
import type { Token } from "./lexer";
|
||||
/**
|
||||
* Statements do not result in a value at runtime. They contain one or more expressions internally.
|
||||
*/
|
||||
export declare class Statement {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Defines a block which contains many statements. Each chat template corresponds to one Program.
|
||||
*/
|
||||
export declare class Program extends Statement {
|
||||
body: Statement[];
|
||||
type: string;
|
||||
constructor(body: Statement[]);
|
||||
}
|
||||
export declare class If extends Statement {
|
||||
test: Expression;
|
||||
body: Statement[];
|
||||
alternate: Statement[];
|
||||
type: string;
|
||||
constructor(test: Expression, body: Statement[], alternate: Statement[]);
|
||||
}
|
||||
/**
|
||||
* Loop over each item in a sequence
|
||||
* https://jinja.palletsprojects.com/en/3.0.x/templates/#for
|
||||
*/
|
||||
export declare class For extends Statement {
|
||||
loopvar: Identifier | TupleLiteral;
|
||||
iterable: Expression;
|
||||
body: Statement[];
|
||||
defaultBlock: Statement[];
|
||||
type: string;
|
||||
constructor(loopvar: Identifier | TupleLiteral, iterable: Expression, body: Statement[], defaultBlock: Statement[]);
|
||||
}
|
||||
export declare class Break extends Statement {
|
||||
type: string;
|
||||
}
|
||||
export declare class Continue extends Statement {
|
||||
type: string;
|
||||
}
|
||||
export declare class SetStatement extends Statement {
|
||||
assignee: Expression;
|
||||
value: Expression | null;
|
||||
body: Statement[];
|
||||
type: string;
|
||||
constructor(assignee: Expression, value: Expression | null, body: Statement[]);
|
||||
}
|
||||
export declare class Macro extends Statement {
|
||||
name: Identifier;
|
||||
args: Expression[];
|
||||
body: Statement[];
|
||||
type: string;
|
||||
constructor(name: Identifier, args: Expression[], body: Statement[]);
|
||||
}
|
||||
export declare class Comment extends Statement {
|
||||
value: string;
|
||||
type: string;
|
||||
constructor(value: string);
|
||||
}
|
||||
/**
|
||||
* Expressions will result in a value at runtime (unlike statements).
|
||||
*/
|
||||
export declare class Expression extends Statement {
|
||||
type: string;
|
||||
}
|
||||
export declare class MemberExpression extends Expression {
|
||||
object: Expression;
|
||||
property: Expression;
|
||||
computed: boolean;
|
||||
type: string;
|
||||
constructor(object: Expression, property: Expression, computed: boolean);
|
||||
}
|
||||
export declare class CallExpression extends Expression {
|
||||
callee: Expression;
|
||||
args: Expression[];
|
||||
type: string;
|
||||
constructor(callee: Expression, args: Expression[]);
|
||||
}
|
||||
/**
|
||||
* Represents a user-defined variable or symbol in the template.
|
||||
*/
|
||||
export declare class Identifier extends Expression {
|
||||
value: string;
|
||||
type: string;
|
||||
/**
|
||||
* @param {string} value The name of the identifier
|
||||
*/
|
||||
constructor(value: string);
|
||||
}
|
||||
/**
|
||||
* Abstract base class for all Literal expressions.
|
||||
* Should not be instantiated directly.
|
||||
*/
|
||||
declare abstract class Literal<T> extends Expression {
|
||||
value: T;
|
||||
type: string;
|
||||
constructor(value: T);
|
||||
}
|
||||
export declare class IntegerLiteral extends Literal<number> {
|
||||
type: string;
|
||||
}
|
||||
export declare class FloatLiteral extends Literal<number> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents a text constant in the template.
|
||||
*/
|
||||
export declare class StringLiteral extends Literal<string> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents an array literal in the template.
|
||||
*/
|
||||
export declare class ArrayLiteral extends Literal<Expression[]> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents a tuple literal in the template.
|
||||
*/
|
||||
export declare class TupleLiteral extends Literal<Expression[]> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents an object literal in the template.
|
||||
*/
|
||||
export declare class ObjectLiteral extends Literal<Map<Expression, Expression>> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* An operation with two sides, separated by an operator.
|
||||
* Note: Either side can be a Complex Expression, with order
|
||||
* of operations being determined by the operator.
|
||||
*/
|
||||
export declare class BinaryExpression extends Expression {
|
||||
operator: Token;
|
||||
left: Expression;
|
||||
right: Expression;
|
||||
type: string;
|
||||
constructor(operator: Token, left: Expression, right: Expression);
|
||||
}
|
||||
/**
|
||||
* An operation with two sides, separated by the | operator.
|
||||
* Operator precedence: https://github.com/pallets/jinja/issues/379#issuecomment-168076202
|
||||
*/
|
||||
export declare class FilterExpression extends Expression {
|
||||
operand: Expression;
|
||||
filter: Identifier | CallExpression;
|
||||
type: string;
|
||||
constructor(operand: Expression, filter: Identifier | CallExpression);
|
||||
}
|
||||
export declare class FilterStatement extends Statement {
|
||||
filter: Identifier | CallExpression;
|
||||
body: Statement[];
|
||||
type: string;
|
||||
constructor(filter: Identifier | CallExpression, body: Statement[]);
|
||||
}
|
||||
/**
|
||||
* An operation which filters a sequence of objects by applying a test to each object,
|
||||
* and only selecting the objects with the test succeeding.
|
||||
*
|
||||
* It may also be used as a shortcut for a ternary operator.
|
||||
*/
|
||||
export declare class SelectExpression extends Expression {
|
||||
lhs: Expression;
|
||||
test: Expression;
|
||||
type: string;
|
||||
constructor(lhs: Expression, test: Expression);
|
||||
}
|
||||
/**
|
||||
* An operation with two sides, separated by the "is" operator.
|
||||
*/
|
||||
export declare class TestExpression extends Expression {
|
||||
operand: Expression;
|
||||
negate: boolean;
|
||||
test: Identifier;
|
||||
type: string;
|
||||
constructor(operand: Expression, negate: boolean, test: Identifier);
|
||||
}
|
||||
/**
|
||||
* An operation with one side (operator on the left).
|
||||
*/
|
||||
export declare class UnaryExpression extends Expression {
|
||||
operator: Token;
|
||||
argument: Expression;
|
||||
type: string;
|
||||
constructor(operator: Token, argument: Expression);
|
||||
}
|
||||
export declare class SliceExpression extends Expression {
|
||||
start: Expression | undefined;
|
||||
stop: Expression | undefined;
|
||||
step: Expression | undefined;
|
||||
type: string;
|
||||
constructor(start?: Expression | undefined, stop?: Expression | undefined, step?: Expression | undefined);
|
||||
}
|
||||
export declare class KeywordArgumentExpression extends Expression {
|
||||
key: Identifier;
|
||||
value: Expression;
|
||||
type: string;
|
||||
constructor(key: Identifier, value: Expression);
|
||||
}
|
||||
export declare class SpreadExpression extends Expression {
|
||||
argument: Expression;
|
||||
type: string;
|
||||
constructor(argument: Expression);
|
||||
}
|
||||
export declare class CallStatement extends Statement {
|
||||
call: CallExpression;
|
||||
callerArgs: Expression[] | null;
|
||||
body: Statement[];
|
||||
type: string;
|
||||
constructor(call: CallExpression, callerArgs: Expression[] | null, body: Statement[]);
|
||||
}
|
||||
export declare class Ternary extends Expression {
|
||||
condition: Expression;
|
||||
trueExpr: Expression;
|
||||
falseExpr: Expression;
|
||||
type: string;
|
||||
constructor(condition: Expression, trueExpr: Expression, falseExpr: Expression);
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=ast.d.ts.map
|
||||
1
node_modules/@huggingface/jinja/dist/ast.d.ts.map
generated
vendored
Normal file
1
node_modules/@huggingface/jinja/dist/ast.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"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"}
|
||||
3
node_modules/@huggingface/jinja/dist/format.d.ts
generated
vendored
Normal file
3
node_modules/@huggingface/jinja/dist/format.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { Program } from "./ast";
|
||||
export declare function format(program: Program, indent?: string | number): string;
|
||||
//# sourceMappingURL=format.d.ts.map
|
||||
1
node_modules/@huggingface/jinja/dist/format.d.ts.map
generated
vendored
Normal file
1
node_modules/@huggingface/jinja/dist/format.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,OAAO,EA4BP,MAAM,OAAO,CAAC;AAsBf,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,MAAM,GAAG,MAAa,GAAG,MAAM,CAI/E"}
|
||||
2857
node_modules/@huggingface/jinja/dist/index.cjs
generated
vendored
Normal file
2857
node_modules/@huggingface/jinja/dist/index.cjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
29
node_modules/@huggingface/jinja/dist/index.d.ts
generated
vendored
Normal file
29
node_modules/@huggingface/jinja/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @file Jinja templating engine
|
||||
*
|
||||
* A minimalistic JavaScript reimplementation of the [Jinja](https://github.com/pallets/jinja) templating engine,
|
||||
* to support the chat templates. Special thanks to [Tyler Laceby](https://github.com/tlaceby) for his amazing
|
||||
* ["Guide to Interpreters"](https://github.com/tlaceby/guide-to-interpreters-series) tutorial series,
|
||||
* which provided the basis for this implementation.
|
||||
*
|
||||
* See the [Transformers documentation](https://huggingface.co/docs/transformers/main/en/chat_templating) for more information.
|
||||
*
|
||||
* @module index
|
||||
*/
|
||||
import { tokenize } from "./lexer";
|
||||
import { parse } from "./parser";
|
||||
import { Environment, Interpreter } from "./runtime";
|
||||
import type { Program } from "./ast";
|
||||
export declare class Template {
|
||||
parsed: Program;
|
||||
/**
|
||||
* @param {string} template The template string
|
||||
*/
|
||||
constructor(template: string);
|
||||
render(items?: Record<string, unknown>): string;
|
||||
format(options?: {
|
||||
indent: string | number;
|
||||
}): string;
|
||||
}
|
||||
export { Environment, Interpreter, tokenize, parse };
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/@huggingface/jinja/dist/index.d.ts.map
generated
vendored
Normal file
1
node_modules/@huggingface/jinja/dist/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAgB,MAAM,WAAW,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAIrC,qBAAa,QAAQ;IACpB,MAAM,EAAE,OAAO,CAAC;IAEhB;;OAEG;gBACS,QAAQ,EAAE,MAAM;IAQ5B,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;IAkB/C,MAAM,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,MAAM;CAGrD;AAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC"}
|
||||
2826
node_modules/@huggingface/jinja/dist/index.js
generated
vendored
Normal file
2826
node_modules/@huggingface/jinja/dist/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
53
node_modules/@huggingface/jinja/dist/lexer.d.ts
generated
vendored
Normal file
53
node_modules/@huggingface/jinja/dist/lexer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Represents tokens that our language understands in parsing.
|
||||
*/
|
||||
export declare const TOKEN_TYPES: Readonly<{
|
||||
Text: "Text";
|
||||
NumericLiteral: "NumericLiteral";
|
||||
StringLiteral: "StringLiteral";
|
||||
Identifier: "Identifier";
|
||||
Equals: "Equals";
|
||||
OpenParen: "OpenParen";
|
||||
CloseParen: "CloseParen";
|
||||
OpenStatement: "OpenStatement";
|
||||
CloseStatement: "CloseStatement";
|
||||
OpenExpression: "OpenExpression";
|
||||
CloseExpression: "CloseExpression";
|
||||
OpenSquareBracket: "OpenSquareBracket";
|
||||
CloseSquareBracket: "CloseSquareBracket";
|
||||
OpenCurlyBracket: "OpenCurlyBracket";
|
||||
CloseCurlyBracket: "CloseCurlyBracket";
|
||||
Comma: "Comma";
|
||||
Dot: "Dot";
|
||||
Colon: "Colon";
|
||||
Pipe: "Pipe";
|
||||
CallOperator: "CallOperator";
|
||||
AdditiveBinaryOperator: "AdditiveBinaryOperator";
|
||||
MultiplicativeBinaryOperator: "MultiplicativeBinaryOperator";
|
||||
ComparisonBinaryOperator: "ComparisonBinaryOperator";
|
||||
UnaryOperator: "UnaryOperator";
|
||||
Comment: "Comment";
|
||||
}>;
|
||||
export type TokenType = keyof typeof TOKEN_TYPES;
|
||||
/**
|
||||
* Represents a single token in the template.
|
||||
*/
|
||||
export declare class Token {
|
||||
value: string;
|
||||
type: TokenType;
|
||||
/**
|
||||
* Constructs a new Token.
|
||||
* @param {string} value The raw value as seen inside the source code.
|
||||
* @param {TokenType} type The type of token.
|
||||
*/
|
||||
constructor(value: string, type: TokenType);
|
||||
}
|
||||
export interface PreprocessOptions {
|
||||
trim_blocks?: boolean;
|
||||
lstrip_blocks?: boolean;
|
||||
}
|
||||
/**
|
||||
* Generate a list of tokens from a source string.
|
||||
*/
|
||||
export declare function tokenize(source: string, options?: PreprocessOptions): Token[];
|
||||
//# sourceMappingURL=lexer.d.ts.map
|
||||
1
node_modules/@huggingface/jinja/dist/lexer.d.ts.map
generated
vendored
Normal file
1
node_modules/@huggingface/jinja/dist/lexer.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../src/lexer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BtB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,WAAW,CAAC;AAEjD;;GAEG;AACH,qBAAa,KAAK;IAOT,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,SAAS;IAPvB;;;;OAIG;gBAEK,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,SAAS;CAEvB;AAgED,MAAM,WAAW,iBAAiB;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AA8BD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,KAAK,EAAE,CAqPjF"}
|
||||
8
node_modules/@huggingface/jinja/dist/parser.d.ts
generated
vendored
Normal file
8
node_modules/@huggingface/jinja/dist/parser.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Token } from "./lexer";
|
||||
import { Program } from "./ast";
|
||||
/**
|
||||
* Generate the Abstract Syntax Tree (AST) from a list of tokens.
|
||||
* Operator precedence can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table
|
||||
*/
|
||||
export declare function parse(tokens: Token[]): Program;
|
||||
//# sourceMappingURL=parser.d.ts.map
|
||||
1
node_modules/@huggingface/jinja/dist/parser.d.ts.map
generated
vendored
Normal file
1
node_modules/@huggingface/jinja/dist/parser.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,SAAS,CAAC;AAG7C,OAAO,EACN,OAAO,EA4BP,MAAM,OAAO,CAAC;AAEf;;;GAGG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAunB9C"}
|
||||
201
node_modules/@huggingface/jinja/dist/runtime.d.ts
generated
vendored
Normal file
201
node_modules/@huggingface/jinja/dist/runtime.d.ts
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
import type { Statement, Program } from "./ast";
|
||||
export type AnyRuntimeValue = IntegerValue | FloatValue | StringValue | BooleanValue | ObjectValue | ArrayValue | FunctionValue | NullValue | UndefinedValue;
|
||||
/**
|
||||
* Abstract base class for all Runtime values.
|
||||
* Should not be instantiated directly.
|
||||
*/
|
||||
declare abstract class RuntimeValue<T> {
|
||||
type: string;
|
||||
value: T;
|
||||
/**
|
||||
* A collection of built-in functions for this type.
|
||||
*/
|
||||
builtins: Map<string, AnyRuntimeValue>;
|
||||
/**
|
||||
* Creates a new RuntimeValue.
|
||||
*/
|
||||
constructor(value?: T);
|
||||
/**
|
||||
* Determines truthiness or falsiness of the runtime value.
|
||||
* This function should be overridden by subclasses if it has custom truthiness criteria.
|
||||
* @returns {BooleanValue} BooleanValue(true) if the value is truthy, BooleanValue(false) otherwise.
|
||||
*/
|
||||
__bool__(): BooleanValue;
|
||||
toString(): string;
|
||||
}
|
||||
/**
|
||||
* Represents an integer value at runtime.
|
||||
*/
|
||||
export declare class IntegerValue extends RuntimeValue<number> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents a float value at runtime.
|
||||
*/
|
||||
export declare class FloatValue extends RuntimeValue<number> {
|
||||
type: string;
|
||||
toString(): string;
|
||||
}
|
||||
/**
|
||||
* Represents a string value at runtime.
|
||||
*/
|
||||
export declare class StringValue extends RuntimeValue<string> {
|
||||
type: string;
|
||||
builtins: Map<string, AnyRuntimeValue>;
|
||||
}
|
||||
/**
|
||||
* Represents a boolean value at runtime.
|
||||
*/
|
||||
export declare class BooleanValue extends RuntimeValue<boolean> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents an Object value at runtime.
|
||||
*/
|
||||
export declare class ObjectValue extends RuntimeValue<Map<string, AnyRuntimeValue>> {
|
||||
type: string;
|
||||
/**
|
||||
* NOTE: necessary to override since all JavaScript arrays are considered truthy,
|
||||
* while only non-empty Python arrays are consider truthy.
|
||||
*
|
||||
* e.g.,
|
||||
* - JavaScript: {} && 5 -> 5
|
||||
* - Python: {} and 5 -> {}
|
||||
*/
|
||||
__bool__(): BooleanValue;
|
||||
builtins: Map<string, AnyRuntimeValue>;
|
||||
items(): ArrayValue;
|
||||
keys(): ArrayValue;
|
||||
values(): ArrayValue;
|
||||
toString(): string;
|
||||
}
|
||||
/**
|
||||
* Represents a KeywordArguments value at runtime.
|
||||
*/
|
||||
export declare class KeywordArgumentsValue extends ObjectValue {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents an Array value at runtime.
|
||||
*/
|
||||
export declare class ArrayValue extends RuntimeValue<AnyRuntimeValue[]> {
|
||||
type: string;
|
||||
builtins: Map<string, AnyRuntimeValue>;
|
||||
/**
|
||||
* NOTE: necessary to override since all JavaScript arrays are considered truthy,
|
||||
* while only non-empty Python arrays are consider truthy.
|
||||
*
|
||||
* e.g.,
|
||||
* - JavaScript: [] && 5 -> 5
|
||||
* - Python: [] and 5 -> []
|
||||
*/
|
||||
__bool__(): BooleanValue;
|
||||
toString(): string;
|
||||
}
|
||||
/**
|
||||
* Represents a Tuple value at runtime.
|
||||
* NOTE: We extend ArrayValue since JavaScript does not have a built-in Tuple type.
|
||||
*/
|
||||
export declare class TupleValue extends ArrayValue {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents a Function value at runtime.
|
||||
*/
|
||||
export declare class FunctionValue extends RuntimeValue<(args: AnyRuntimeValue[], scope: Environment) => AnyRuntimeValue> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents a Null value at runtime.
|
||||
*/
|
||||
export declare class NullValue extends RuntimeValue<null> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents an Undefined value at runtime.
|
||||
*/
|
||||
export declare class UndefinedValue extends RuntimeValue<undefined> {
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Represents the current environment (scope) at runtime.
|
||||
*/
|
||||
export declare class Environment {
|
||||
parent?: Environment | undefined;
|
||||
/**
|
||||
* The variables declared in this environment.
|
||||
*/
|
||||
variables: Map<string, AnyRuntimeValue>;
|
||||
/**
|
||||
* The tests available in this environment.
|
||||
*/
|
||||
tests: Map<string, (...value: AnyRuntimeValue[]) => boolean>;
|
||||
constructor(parent?: Environment | undefined);
|
||||
/**
|
||||
* Set the value of a variable in the current environment.
|
||||
*/
|
||||
set(name: string, value: unknown): AnyRuntimeValue;
|
||||
private declareVariable;
|
||||
/**
|
||||
* Set variable in the current scope.
|
||||
* See https://jinja.palletsprojects.com/en/3.0.x/templates/#assignments for more information.
|
||||
*/
|
||||
setVariable(name: string, value: AnyRuntimeValue): AnyRuntimeValue;
|
||||
/**
|
||||
* Resolve the environment in which the variable is declared.
|
||||
* @param {string} name The name of the variable.
|
||||
* @returns {Environment} The environment in which the variable is declared.
|
||||
*/
|
||||
private resolve;
|
||||
lookupVariable(name: string): AnyRuntimeValue;
|
||||
}
|
||||
export declare function setupGlobals(env: Environment): void;
|
||||
export declare class Interpreter {
|
||||
global: Environment;
|
||||
constructor(env?: Environment);
|
||||
/**
|
||||
* Run the program.
|
||||
*/
|
||||
run(program: Program): AnyRuntimeValue;
|
||||
/**
|
||||
* Evaluates expressions following the binary operation type.
|
||||
*/
|
||||
private evaluateBinaryExpression;
|
||||
private evaluateArguments;
|
||||
private applyFilter;
|
||||
/**
|
||||
* Evaluates expressions following the filter operation type.
|
||||
*/
|
||||
private evaluateFilterExpression;
|
||||
/**
|
||||
* Evaluates expressions following the test operation type.
|
||||
*/
|
||||
private evaluateTestExpression;
|
||||
/**
|
||||
* Evaluates expressions following the select operation type.
|
||||
*/
|
||||
private evaluateSelectExpression;
|
||||
/**
|
||||
* Evaluates expressions following the unary operation type.
|
||||
*/
|
||||
private evaluateUnaryExpression;
|
||||
private evaluateTernaryExpression;
|
||||
private evalProgram;
|
||||
private evaluateBlock;
|
||||
private evaluateIdentifier;
|
||||
private evaluateCallExpression;
|
||||
private evaluateSliceExpression;
|
||||
private evaluateMemberExpression;
|
||||
private evaluateSet;
|
||||
private evaluateIf;
|
||||
private evaluateFor;
|
||||
/**
|
||||
* See https://jinja.palletsprojects.com/en/3.1.x/templates/#macros for more information.
|
||||
*/
|
||||
private evaluateMacro;
|
||||
private evaluateCallStatement;
|
||||
private evaluateFilterStatement;
|
||||
evaluate(statement: Statement | undefined, environment: Environment): AnyRuntimeValue;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=runtime.d.ts.map
|
||||
1
node_modules/@huggingface/jinja/dist/runtime.d.ts.map
generated
vendored
Normal file
1
node_modules/@huggingface/jinja/dist/runtime.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"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"}
|
||||
33
node_modules/@huggingface/jinja/dist/utils.d.ts
generated
vendored
Normal file
33
node_modules/@huggingface/jinja/dist/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Function that mimics Python's range() function.
|
||||
* @param start The start value of the range.
|
||||
* @param stop The stop value of the range. If not provided, start will be 0 and stop will be the provided start value.
|
||||
* @param step The step value of the range. Defaults to 1.
|
||||
* @returns The range of numbers.
|
||||
*/
|
||||
export declare function range(start: number, stop?: number, step?: number): number[];
|
||||
/**
|
||||
* Function that mimics Python's array slicing.
|
||||
* @param array The array to slice.
|
||||
* @param start The start index of the slice. Defaults to 0.
|
||||
* @param stop The last index of the slice. Defaults to `array.length`.
|
||||
* @param step The step value of the slice. Defaults to 1.
|
||||
* @returns The sliced array.
|
||||
*/
|
||||
export declare function slice<T>(array: T[], start?: number, stop?: number, step?: number): T[];
|
||||
/**
|
||||
* Function that mimics Python's string.title() function.
|
||||
* @param value The string to title case.
|
||||
* @returns The title cased string.
|
||||
*/
|
||||
export declare function titleCase(value: string): string;
|
||||
export declare function strftime_now(format: string): string;
|
||||
/**
|
||||
* A minimalistic implementation of Python's strftime function.
|
||||
*/
|
||||
export declare function strftime(date: Date, format: string): string;
|
||||
/**
|
||||
* Function that mimics Python's string.replace() function.
|
||||
*/
|
||||
export declare function replace(str: string, oldvalue: string, newvalue: string, count?: number | null): string;
|
||||
//# sourceMappingURL=utils.d.ts.map
|
||||
1
node_modules/@huggingface/jinja/dist/utils.d.ts.map
generated
vendored
Normal file
1
node_modules/@huggingface/jinja/dist/utils.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,MAAM,EAAE,CAqBtE;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,CAAC,EAAE,CAgBjF;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA6B3D;AAMD;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAYtG"}
|
||||
54
node_modules/@huggingface/jinja/package.json
generated
vendored
Normal file
54
node_modules/@huggingface/jinja/package.json
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "@huggingface/jinja",
|
||||
"version": "0.5.5",
|
||||
"description": "A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.",
|
||||
"keywords": [
|
||||
"face",
|
||||
"hugging",
|
||||
"huggingface",
|
||||
"jinja",
|
||||
"templates"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": "Hugging Face",
|
||||
"repository": "https://github.com/huggingface/huggingface.js.git",
|
||||
"source": "src/index.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"README.md",
|
||||
"src",
|
||||
"tsconfig.json"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@huggingface/transformers": "^3.0.0",
|
||||
"typescript": "^5.3.2",
|
||||
"@huggingface/hub": "^2.8.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
|
||||
"lint:check": "eslint --ext .cjs,.ts .",
|
||||
"format": "oxfmt .",
|
||||
"format:check": "oxfmt --check .",
|
||||
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
|
||||
"test": "vitest run",
|
||||
"test:browser": "vitest run --browser.name=chrome --browser.headless",
|
||||
"check": "tsc"
|
||||
}
|
||||
}
|
||||
320
node_modules/@huggingface/jinja/src/ast.ts
generated
vendored
Normal file
320
node_modules/@huggingface/jinja/src/ast.ts
generated
vendored
Normal file
@@ -0,0 +1,320 @@
|
||||
import type { Token } from "./lexer";
|
||||
|
||||
/**
|
||||
* Statements do not result in a value at runtime. They contain one or more expressions internally.
|
||||
*/
|
||||
export class Statement {
|
||||
type = "Statement";
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a block which contains many statements. Each chat template corresponds to one Program.
|
||||
*/
|
||||
export class Program extends Statement {
|
||||
override type = "Program";
|
||||
|
||||
constructor(public body: Statement[]) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class If extends Statement {
|
||||
override type = "If";
|
||||
|
||||
constructor(
|
||||
public test: Expression,
|
||||
public body: Statement[],
|
||||
public alternate: Statement[],
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loop over each item in a sequence
|
||||
* https://jinja.palletsprojects.com/en/3.0.x/templates/#for
|
||||
*/
|
||||
export class For extends Statement {
|
||||
override type = "For";
|
||||
|
||||
constructor(
|
||||
public loopvar: Identifier | TupleLiteral,
|
||||
public iterable: Expression,
|
||||
public body: Statement[],
|
||||
public defaultBlock: Statement[], // if no iteration took place
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class Break extends Statement {
|
||||
override type = "Break";
|
||||
}
|
||||
export class Continue extends Statement {
|
||||
override type = "Continue";
|
||||
}
|
||||
|
||||
export class SetStatement extends Statement {
|
||||
override type = "Set";
|
||||
constructor(
|
||||
public assignee: Expression,
|
||||
public value: Expression | null,
|
||||
public body: Statement[],
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class Macro extends Statement {
|
||||
override type = "Macro";
|
||||
|
||||
constructor(
|
||||
public name: Identifier,
|
||||
public args: Expression[],
|
||||
public body: Statement[],
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class Comment extends Statement {
|
||||
override type = "Comment";
|
||||
constructor(public value: string) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expressions will result in a value at runtime (unlike statements).
|
||||
*/
|
||||
export class Expression extends Statement {
|
||||
override type = "Expression";
|
||||
}
|
||||
|
||||
export class MemberExpression extends Expression {
|
||||
override type = "MemberExpression";
|
||||
|
||||
constructor(
|
||||
public object: Expression,
|
||||
public property: Expression,
|
||||
public computed: boolean,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class CallExpression extends Expression {
|
||||
override type = "CallExpression";
|
||||
|
||||
constructor(
|
||||
public callee: Expression,
|
||||
public args: Expression[],
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a user-defined variable or symbol in the template.
|
||||
*/
|
||||
export class Identifier extends Expression {
|
||||
override type = "Identifier";
|
||||
|
||||
/**
|
||||
* @param {string} value The name of the identifier
|
||||
*/
|
||||
constructor(public value: string) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract base class for all Literal expressions.
|
||||
* Should not be instantiated directly.
|
||||
*/
|
||||
abstract class Literal<T> extends Expression {
|
||||
override type = "Literal";
|
||||
|
||||
constructor(public value: T) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class IntegerLiteral extends Literal<number> {
|
||||
override type = "IntegerLiteral";
|
||||
}
|
||||
|
||||
export class FloatLiteral extends Literal<number> {
|
||||
override type = "FloatLiteral";
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a text constant in the template.
|
||||
*/
|
||||
export class StringLiteral extends Literal<string> {
|
||||
override type = "StringLiteral";
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an array literal in the template.
|
||||
*/
|
||||
export class ArrayLiteral extends Literal<Expression[]> {
|
||||
override type = "ArrayLiteral";
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a tuple literal in the template.
|
||||
*/
|
||||
export class TupleLiteral extends Literal<Expression[]> {
|
||||
override type = "TupleLiteral";
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an object literal in the template.
|
||||
*/
|
||||
export class ObjectLiteral extends Literal<Map<Expression, Expression>> {
|
||||
override type = "ObjectLiteral";
|
||||
}
|
||||
|
||||
/**
|
||||
* An operation with two sides, separated by an operator.
|
||||
* Note: Either side can be a Complex Expression, with order
|
||||
* of operations being determined by the operator.
|
||||
*/
|
||||
export class BinaryExpression extends Expression {
|
||||
override type = "BinaryExpression";
|
||||
|
||||
constructor(
|
||||
public operator: Token,
|
||||
public left: Expression,
|
||||
public right: Expression,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An operation with two sides, separated by the | operator.
|
||||
* Operator precedence: https://github.com/pallets/jinja/issues/379#issuecomment-168076202
|
||||
*/
|
||||
export class FilterExpression extends Expression {
|
||||
override type = "FilterExpression";
|
||||
|
||||
constructor(
|
||||
public operand: Expression,
|
||||
public filter: Identifier | CallExpression,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class FilterStatement extends Statement {
|
||||
override type = "FilterStatement";
|
||||
|
||||
constructor(
|
||||
public filter: Identifier | CallExpression,
|
||||
public body: Statement[],
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An operation which filters a sequence of objects by applying a test to each object,
|
||||
* and only selecting the objects with the test succeeding.
|
||||
*
|
||||
* It may also be used as a shortcut for a ternary operator.
|
||||
*/
|
||||
export class SelectExpression extends Expression {
|
||||
override type = "SelectExpression";
|
||||
|
||||
constructor(
|
||||
public lhs: Expression,
|
||||
public test: Expression,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An operation with two sides, separated by the "is" operator.
|
||||
*/
|
||||
export class TestExpression extends Expression {
|
||||
override type = "TestExpression";
|
||||
|
||||
constructor(
|
||||
public operand: Expression,
|
||||
public negate: boolean,
|
||||
public test: Identifier, // TODO: Add support for non-identifier tests
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An operation with one side (operator on the left).
|
||||
*/
|
||||
export class UnaryExpression extends Expression {
|
||||
override type = "UnaryExpression";
|
||||
|
||||
constructor(
|
||||
public operator: Token,
|
||||
public argument: Expression,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class SliceExpression extends Expression {
|
||||
override type = "SliceExpression";
|
||||
|
||||
constructor(
|
||||
public start: Expression | undefined = undefined,
|
||||
public stop: Expression | undefined = undefined,
|
||||
public step: Expression | undefined = undefined,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class KeywordArgumentExpression extends Expression {
|
||||
override type = "KeywordArgumentExpression";
|
||||
|
||||
constructor(
|
||||
public key: Identifier,
|
||||
public value: Expression,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class SpreadExpression extends Expression {
|
||||
override type = "SpreadExpression";
|
||||
|
||||
constructor(public argument: Expression) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class CallStatement extends Statement {
|
||||
override type = "CallStatement";
|
||||
|
||||
constructor(
|
||||
public call: CallExpression,
|
||||
public callerArgs: Expression[] | null,
|
||||
public body: Statement[],
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class Ternary extends Expression {
|
||||
override type = "Ternary";
|
||||
constructor(
|
||||
public condition: Expression,
|
||||
public trueExpr: Expression,
|
||||
public falseExpr: Expression,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
318
node_modules/@huggingface/jinja/src/format.ts
generated
vendored
Normal file
318
node_modules/@huggingface/jinja/src/format.ts
generated
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
import type {
|
||||
Program,
|
||||
Statement,
|
||||
Comment,
|
||||
If,
|
||||
For,
|
||||
SetStatement,
|
||||
Macro,
|
||||
Expression,
|
||||
MemberExpression,
|
||||
CallExpression,
|
||||
Identifier,
|
||||
FloatLiteral,
|
||||
IntegerLiteral,
|
||||
StringLiteral,
|
||||
ArrayLiteral,
|
||||
TupleLiteral,
|
||||
ObjectLiteral,
|
||||
BinaryExpression,
|
||||
FilterExpression,
|
||||
SelectExpression,
|
||||
TestExpression,
|
||||
UnaryExpression,
|
||||
SliceExpression,
|
||||
KeywordArgumentExpression,
|
||||
CallStatement,
|
||||
FilterStatement,
|
||||
SpreadExpression,
|
||||
Ternary,
|
||||
} from "./ast";
|
||||
|
||||
const NEWLINE = "\n";
|
||||
const OPEN_STATEMENT = "{%- ";
|
||||
const CLOSE_STATEMENT = " -%}";
|
||||
|
||||
function getBinaryOperatorPrecedence(expr: BinaryExpression): number {
|
||||
switch (expr.operator.type) {
|
||||
case "MultiplicativeBinaryOperator":
|
||||
return 4;
|
||||
case "AdditiveBinaryOperator":
|
||||
return 3;
|
||||
case "ComparisonBinaryOperator":
|
||||
return 2;
|
||||
case "Identifier":
|
||||
if (expr.operator.value === "and") return 1;
|
||||
if (expr.operator.value === "in" || expr.operator.value === "not in") return 2;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function format(program: Program, indent: string | number = "\t"): string {
|
||||
const indentStr = typeof indent === "number" ? " ".repeat(indent) : indent;
|
||||
const body = formatStatements(program.body, 0, indentStr);
|
||||
return body.replace(/\n$/, "");
|
||||
}
|
||||
|
||||
function createStatement(...text: string[]): string {
|
||||
return OPEN_STATEMENT + text.join(" ") + CLOSE_STATEMENT;
|
||||
}
|
||||
|
||||
function formatStatements(stmts: Statement[], depth: number, indentStr: string): string {
|
||||
return stmts.map((stmt) => formatStatement(stmt, depth, indentStr)).join(NEWLINE);
|
||||
}
|
||||
|
||||
function formatStatement(node: Statement, depth: number, indentStr: string): string {
|
||||
const pad = indentStr.repeat(depth);
|
||||
switch (node.type) {
|
||||
case "Program":
|
||||
return formatStatements((node as Program).body, depth, indentStr);
|
||||
case "If":
|
||||
return formatIf(node as If, depth, indentStr);
|
||||
case "For":
|
||||
return formatFor(node as For, depth, indentStr);
|
||||
case "Set":
|
||||
return formatSet(node as SetStatement, depth, indentStr);
|
||||
case "Macro":
|
||||
return formatMacro(node as Macro, depth, indentStr);
|
||||
case "Break":
|
||||
return pad + createStatement("break");
|
||||
case "Continue":
|
||||
return pad + createStatement("continue");
|
||||
case "CallStatement":
|
||||
return formatCallStatement(node as CallStatement, depth, indentStr);
|
||||
case "FilterStatement":
|
||||
return formatFilterStatement(node as FilterStatement, depth, indentStr);
|
||||
case "Comment":
|
||||
return pad + "{# " + (node as Comment).value + " #}";
|
||||
default:
|
||||
return pad + "{{- " + formatExpression(node as Expression) + " -}}";
|
||||
}
|
||||
}
|
||||
|
||||
function formatIf(node: If, depth: number, indentStr: string): string {
|
||||
const pad = indentStr.repeat(depth);
|
||||
|
||||
const clauses: { test: Expression; body: Statement[] }[] = [];
|
||||
let current: If | undefined = node;
|
||||
while (current) {
|
||||
clauses.push({ test: current.test, body: current.body });
|
||||
if (current.alternate.length === 1 && current.alternate[0].type === "If") {
|
||||
current = current.alternate[0] as If;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// IF
|
||||
let out =
|
||||
pad +
|
||||
createStatement("if", formatExpression(clauses[0].test)) +
|
||||
NEWLINE +
|
||||
formatStatements(clauses[0].body, depth + 1, indentStr);
|
||||
|
||||
// ELIF(s)
|
||||
for (let i = 1; i < clauses.length; ++i) {
|
||||
out +=
|
||||
NEWLINE +
|
||||
pad +
|
||||
createStatement("elif", formatExpression(clauses[i].test)) +
|
||||
NEWLINE +
|
||||
formatStatements(clauses[i].body, depth + 1, indentStr);
|
||||
}
|
||||
|
||||
// ELSE
|
||||
if (current && current.alternate.length > 0) {
|
||||
out +=
|
||||
NEWLINE + pad + createStatement("else") + NEWLINE + formatStatements(current.alternate, depth + 1, indentStr);
|
||||
}
|
||||
|
||||
// ENDIF
|
||||
out += NEWLINE + pad + createStatement("endif");
|
||||
return out;
|
||||
}
|
||||
|
||||
function formatFor(node: For, depth: number, indentStr: string): string {
|
||||
const pad = indentStr.repeat(depth);
|
||||
let formattedIterable = "";
|
||||
if (node.iterable.type === "SelectExpression") {
|
||||
// Handle special case: e.g., `for x in [1, 2, 3] if x > 2`
|
||||
const n = node.iterable as SelectExpression;
|
||||
formattedIterable = `${formatExpression(n.lhs)} if ${formatExpression(n.test)}`;
|
||||
} else {
|
||||
formattedIterable = formatExpression(node.iterable);
|
||||
}
|
||||
let out =
|
||||
pad +
|
||||
createStatement("for", formatExpression(node.loopvar), "in", formattedIterable) +
|
||||
NEWLINE +
|
||||
formatStatements(node.body, depth + 1, indentStr);
|
||||
|
||||
if (node.defaultBlock.length > 0) {
|
||||
out +=
|
||||
NEWLINE + pad + createStatement("else") + NEWLINE + formatStatements(node.defaultBlock, depth + 1, indentStr);
|
||||
}
|
||||
|
||||
out += NEWLINE + pad + createStatement("endfor");
|
||||
return out;
|
||||
}
|
||||
|
||||
function formatSet(node: SetStatement, depth: number, indentStr: string): string {
|
||||
const pad = indentStr.repeat(depth);
|
||||
const left = formatExpression(node.assignee);
|
||||
const right = node.value ? formatExpression(node.value) : "";
|
||||
|
||||
const value = pad + createStatement("set", `${left}${node.value ? " = " + right : ""}`);
|
||||
if (node.body.length === 0) {
|
||||
return value;
|
||||
}
|
||||
return (
|
||||
value + NEWLINE + formatStatements(node.body, depth + 1, indentStr) + NEWLINE + pad + createStatement("endset")
|
||||
);
|
||||
}
|
||||
|
||||
function formatMacro(node: Macro, depth: number, indentStr: string): string {
|
||||
const pad = indentStr.repeat(depth);
|
||||
const args = node.args.map(formatExpression).join(", ");
|
||||
return (
|
||||
pad +
|
||||
createStatement("macro", `${node.name.value}(${args})`) +
|
||||
NEWLINE +
|
||||
formatStatements(node.body, depth + 1, indentStr) +
|
||||
NEWLINE +
|
||||
pad +
|
||||
createStatement("endmacro")
|
||||
);
|
||||
}
|
||||
|
||||
function formatCallStatement(node: CallStatement, depth: number, indentStr: string): string {
|
||||
const pad = indentStr.repeat(depth);
|
||||
const params =
|
||||
node.callerArgs && node.callerArgs.length > 0 ? `(${node.callerArgs.map(formatExpression).join(", ")})` : "";
|
||||
const callExpr = formatExpression(node.call);
|
||||
let out = pad + createStatement(`call${params}`, callExpr) + NEWLINE;
|
||||
out += formatStatements(node.body, depth + 1, indentStr) + NEWLINE;
|
||||
out += pad + createStatement("endcall");
|
||||
return out;
|
||||
}
|
||||
|
||||
function formatFilterStatement(node: FilterStatement, depth: number, indentStr: string): string {
|
||||
const pad = indentStr.repeat(depth);
|
||||
const spec =
|
||||
node.filter.type === "Identifier"
|
||||
? (node.filter as Identifier).value
|
||||
: formatExpression(node.filter as CallExpression);
|
||||
let out = pad + createStatement("filter", spec) + NEWLINE;
|
||||
out += formatStatements(node.body, depth + 1, indentStr) + NEWLINE;
|
||||
out += pad + createStatement("endfilter");
|
||||
return out;
|
||||
}
|
||||
|
||||
function formatExpression(node: Expression, parentPrec: number = -1): string {
|
||||
switch (node.type) {
|
||||
case "SpreadExpression": {
|
||||
const n = node as SpreadExpression;
|
||||
return `*${formatExpression(n.argument)}`;
|
||||
}
|
||||
case "Identifier":
|
||||
return (node as Identifier).value;
|
||||
case "IntegerLiteral":
|
||||
return `${(node as IntegerLiteral).value}`;
|
||||
case "FloatLiteral":
|
||||
return `${(node as FloatLiteral).value}`;
|
||||
case "StringLiteral":
|
||||
return JSON.stringify((node as StringLiteral).value);
|
||||
case "BinaryExpression": {
|
||||
const n = node as BinaryExpression;
|
||||
const thisPrecedence = getBinaryOperatorPrecedence(n);
|
||||
const left = formatExpression(n.left, thisPrecedence);
|
||||
const right = formatExpression(n.right, thisPrecedence + 1);
|
||||
const expr = `${left} ${n.operator.value} ${right}`;
|
||||
return thisPrecedence < parentPrec ? `(${expr})` : expr;
|
||||
}
|
||||
case "UnaryExpression": {
|
||||
const n = node as UnaryExpression;
|
||||
const val = n.operator.value + (n.operator.value === "not" ? " " : "") + formatExpression(n.argument, Infinity);
|
||||
return val;
|
||||
}
|
||||
case "CallExpression": {
|
||||
const n = node as CallExpression;
|
||||
const args = n.args.map(formatExpression).join(", ");
|
||||
return `${formatExpression(n.callee)}(${args})`;
|
||||
}
|
||||
case "MemberExpression": {
|
||||
const n = node as MemberExpression;
|
||||
let obj = formatExpression(n.object);
|
||||
// only wrap if it's not a simple or chained access/call
|
||||
if (
|
||||
![
|
||||
"Identifier",
|
||||
"MemberExpression",
|
||||
"CallExpression",
|
||||
"StringLiteral",
|
||||
"IntegerLiteral",
|
||||
"FloatLiteral",
|
||||
"ArrayLiteral",
|
||||
"TupleLiteral",
|
||||
"ObjectLiteral",
|
||||
].includes(n.object.type)
|
||||
) {
|
||||
obj = `(${obj})`;
|
||||
}
|
||||
let prop = formatExpression(n.property);
|
||||
if (!n.computed && n.property.type !== "Identifier") {
|
||||
prop = `(${prop})`;
|
||||
}
|
||||
return n.computed ? `${obj}[${prop}]` : `${obj}.${prop}`;
|
||||
}
|
||||
case "FilterExpression": {
|
||||
const n = node as FilterExpression;
|
||||
const operand = formatExpression(n.operand, Infinity);
|
||||
if (n.filter.type === "CallExpression") {
|
||||
return `${operand} | ${formatExpression(n.filter)}`;
|
||||
}
|
||||
return `${operand} | ${(n.filter as Identifier).value}`;
|
||||
}
|
||||
case "SelectExpression": {
|
||||
const n = node as SelectExpression;
|
||||
return `${formatExpression(n.lhs)} if ${formatExpression(n.test)}`;
|
||||
}
|
||||
case "TestExpression": {
|
||||
const n = node as TestExpression;
|
||||
return `${formatExpression(n.operand)} is${n.negate ? " not" : ""} ${n.test.value}`;
|
||||
}
|
||||
case "ArrayLiteral":
|
||||
case "TupleLiteral": {
|
||||
const elems = ((node as ArrayLiteral | TupleLiteral).value as Expression[]).map(formatExpression);
|
||||
const brackets = node.type === "ArrayLiteral" ? "[]" : "()";
|
||||
return `${brackets[0]}${elems.join(", ")}${brackets[1]}`;
|
||||
}
|
||||
case "ObjectLiteral": {
|
||||
const entries = Array.from((node as ObjectLiteral).value.entries()).map(
|
||||
([k, v]) => `${formatExpression(k)}: ${formatExpression(v)}`,
|
||||
);
|
||||
return `{${entries.join(", ")}}`;
|
||||
}
|
||||
case "SliceExpression": {
|
||||
const n = node as SliceExpression;
|
||||
const s = n.start ? formatExpression(n.start) : "";
|
||||
const t = n.stop ? formatExpression(n.stop) : "";
|
||||
const st = n.step ? `:${formatExpression(n.step)}` : "";
|
||||
return `${s}:${t}${st}`;
|
||||
}
|
||||
case "KeywordArgumentExpression": {
|
||||
const n = node as KeywordArgumentExpression;
|
||||
return `${n.key.value}=${formatExpression(n.value)}`;
|
||||
}
|
||||
case "Ternary": {
|
||||
const n = node as Ternary;
|
||||
const expr = `${formatExpression(n.trueExpr)} if ${formatExpression(n.condition, 0)} else ${formatExpression(
|
||||
n.falseExpr,
|
||||
)}`;
|
||||
return parentPrec > -1 ? `(${expr})` : expr;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown expression type: ${node.type}`);
|
||||
}
|
||||
}
|
||||
57
node_modules/@huggingface/jinja/src/index.ts
generated
vendored
Normal file
57
node_modules/@huggingface/jinja/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @file Jinja templating engine
|
||||
*
|
||||
* A minimalistic JavaScript reimplementation of the [Jinja](https://github.com/pallets/jinja) templating engine,
|
||||
* to support the chat templates. Special thanks to [Tyler Laceby](https://github.com/tlaceby) for his amazing
|
||||
* ["Guide to Interpreters"](https://github.com/tlaceby/guide-to-interpreters-series) tutorial series,
|
||||
* which provided the basis for this implementation.
|
||||
*
|
||||
* See the [Transformers documentation](https://huggingface.co/docs/transformers/main/en/chat_templating) for more information.
|
||||
*
|
||||
* @module index
|
||||
*/
|
||||
import { tokenize } from "./lexer";
|
||||
import { parse } from "./parser";
|
||||
import { Environment, Interpreter, setupGlobals } from "./runtime";
|
||||
import type { Program } from "./ast";
|
||||
import type { StringValue } from "./runtime";
|
||||
import { format } from "./format";
|
||||
|
||||
export class Template {
|
||||
parsed: Program;
|
||||
|
||||
/**
|
||||
* @param {string} template The template string
|
||||
*/
|
||||
constructor(template: string) {
|
||||
const tokens = tokenize(template, {
|
||||
lstrip_blocks: true,
|
||||
trim_blocks: true,
|
||||
});
|
||||
this.parsed = parse(tokens);
|
||||
}
|
||||
|
||||
render(items?: Record<string, unknown>): string {
|
||||
// Create a new environment for this template
|
||||
const env = new Environment();
|
||||
setupGlobals(env);
|
||||
|
||||
// Add user-defined variables
|
||||
if (items) {
|
||||
for (const [key, value] of Object.entries(items)) {
|
||||
env.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
const interpreter = new Interpreter(env);
|
||||
|
||||
const result = interpreter.run(this.parsed) as StringValue;
|
||||
return result.value;
|
||||
}
|
||||
|
||||
format(options?: { indent: string | number }): string {
|
||||
return format(this.parsed, options?.indent || "\t");
|
||||
}
|
||||
}
|
||||
|
||||
export { Environment, Interpreter, tokenize, parse };
|
||||
394
node_modules/@huggingface/jinja/src/lexer.ts
generated
vendored
Normal file
394
node_modules/@huggingface/jinja/src/lexer.ts
generated
vendored
Normal file
@@ -0,0 +1,394 @@
|
||||
/**
|
||||
* Represents tokens that our language understands in parsing.
|
||||
*/
|
||||
export const TOKEN_TYPES = Object.freeze({
|
||||
Text: "Text", // The text between Jinja statements or expressions
|
||||
|
||||
NumericLiteral: "NumericLiteral", // e.g., 123, 1.0
|
||||
StringLiteral: "StringLiteral", // 'string'
|
||||
Identifier: "Identifier", // Variables, functions, statements, booleans, etc.
|
||||
Equals: "Equals", // =
|
||||
OpenParen: "OpenParen", // (
|
||||
CloseParen: "CloseParen", // )
|
||||
OpenStatement: "OpenStatement", // {%
|
||||
CloseStatement: "CloseStatement", // %}
|
||||
OpenExpression: "OpenExpression", // {{
|
||||
CloseExpression: "CloseExpression", // }}
|
||||
OpenSquareBracket: "OpenSquareBracket", // [
|
||||
CloseSquareBracket: "CloseSquareBracket", // ]
|
||||
OpenCurlyBracket: "OpenCurlyBracket", // {
|
||||
CloseCurlyBracket: "CloseCurlyBracket", // }
|
||||
Comma: "Comma", // ,
|
||||
Dot: "Dot", // .
|
||||
Colon: "Colon", // :
|
||||
Pipe: "Pipe", // |
|
||||
|
||||
CallOperator: "CallOperator", // ()
|
||||
AdditiveBinaryOperator: "AdditiveBinaryOperator", // + - ~
|
||||
MultiplicativeBinaryOperator: "MultiplicativeBinaryOperator", // * / %
|
||||
ComparisonBinaryOperator: "ComparisonBinaryOperator", // < > <= >= == !=
|
||||
UnaryOperator: "UnaryOperator", // ! - +
|
||||
Comment: "Comment", // {# ... #}
|
||||
});
|
||||
|
||||
export type TokenType = keyof typeof TOKEN_TYPES;
|
||||
|
||||
/**
|
||||
* Represents a single token in the template.
|
||||
*/
|
||||
export class Token {
|
||||
/**
|
||||
* Constructs a new Token.
|
||||
* @param {string} value The raw value as seen inside the source code.
|
||||
* @param {TokenType} type The type of token.
|
||||
*/
|
||||
constructor(
|
||||
public value: string,
|
||||
public type: TokenType,
|
||||
) {}
|
||||
}
|
||||
|
||||
function isWord(char: string): boolean {
|
||||
return /\w/.test(char);
|
||||
}
|
||||
|
||||
function isInteger(char: string): boolean {
|
||||
return /[0-9]/.test(char);
|
||||
}
|
||||
|
||||
function isWhitespace(char: string): boolean {
|
||||
return /\s/.test(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* A data structure which contains a list of rules to test
|
||||
*/
|
||||
const ORDERED_MAPPING_TABLE: [string, TokenType][] = [
|
||||
// Control sequences
|
||||
["{%", TOKEN_TYPES.OpenStatement],
|
||||
["%}", TOKEN_TYPES.CloseStatement],
|
||||
["{{", TOKEN_TYPES.OpenExpression],
|
||||
["}}", TOKEN_TYPES.CloseExpression],
|
||||
// Single character tokens
|
||||
["(", TOKEN_TYPES.OpenParen],
|
||||
[")", TOKEN_TYPES.CloseParen],
|
||||
["{", TOKEN_TYPES.OpenCurlyBracket],
|
||||
["}", TOKEN_TYPES.CloseCurlyBracket],
|
||||
["[", TOKEN_TYPES.OpenSquareBracket],
|
||||
["]", TOKEN_TYPES.CloseSquareBracket],
|
||||
[",", TOKEN_TYPES.Comma],
|
||||
[".", TOKEN_TYPES.Dot],
|
||||
[":", TOKEN_TYPES.Colon],
|
||||
["|", TOKEN_TYPES.Pipe],
|
||||
// Comparison operators
|
||||
["<=", TOKEN_TYPES.ComparisonBinaryOperator],
|
||||
[">=", TOKEN_TYPES.ComparisonBinaryOperator],
|
||||
["==", TOKEN_TYPES.ComparisonBinaryOperator],
|
||||
["!=", TOKEN_TYPES.ComparisonBinaryOperator],
|
||||
["<", TOKEN_TYPES.ComparisonBinaryOperator],
|
||||
[">", TOKEN_TYPES.ComparisonBinaryOperator],
|
||||
// Arithmetic operators
|
||||
["+", TOKEN_TYPES.AdditiveBinaryOperator],
|
||||
["-", TOKEN_TYPES.AdditiveBinaryOperator],
|
||||
["~", TOKEN_TYPES.AdditiveBinaryOperator],
|
||||
["*", TOKEN_TYPES.MultiplicativeBinaryOperator],
|
||||
["/", TOKEN_TYPES.MultiplicativeBinaryOperator],
|
||||
["%", TOKEN_TYPES.MultiplicativeBinaryOperator],
|
||||
// Assignment operator
|
||||
["=", TOKEN_TYPES.Equals],
|
||||
];
|
||||
|
||||
const ESCAPE_CHARACTERS = new Map([
|
||||
["n", "\n"], // New line
|
||||
["t", "\t"], // Horizontal tab
|
||||
["r", "\r"], // Carriage return
|
||||
["b", "\b"], // Backspace
|
||||
["f", "\f"], // Form feed
|
||||
["v", "\v"], // Vertical tab
|
||||
["'", "'"], // Single quote
|
||||
['"', '"'], // Double quote
|
||||
["\\", "\\"], // Backslash
|
||||
]);
|
||||
|
||||
export interface PreprocessOptions {
|
||||
trim_blocks?: boolean;
|
||||
lstrip_blocks?: boolean;
|
||||
}
|
||||
|
||||
function preprocess(template: string, options: PreprocessOptions = {}): string {
|
||||
// According to https://jinja.palletsprojects.com/en/3.0.x/templates/#whitespace-control
|
||||
|
||||
// In the default configuration:
|
||||
// - a single trailing newline is stripped if present
|
||||
// - other whitespace (spaces, tabs, newlines etc.) is returned unchanged
|
||||
if (template.endsWith("\n")) {
|
||||
template = template.slice(0, -1);
|
||||
}
|
||||
|
||||
if (options.lstrip_blocks) {
|
||||
// The lstrip_blocks option can also be set to strip tabs and spaces from the
|
||||
// beginning of a line to the start of a block. (Nothing will be stripped if
|
||||
// there are other characters before the start of the block.)
|
||||
template = template.replace(/^[ \t]*({[#%-])/gm, "$1");
|
||||
}
|
||||
|
||||
if (options.trim_blocks) {
|
||||
// If an application configures Jinja to trim_blocks, the first newline after
|
||||
// a template tag is removed automatically (like in PHP).
|
||||
template = template.replace(/([#%-]})\n/g, "$1");
|
||||
}
|
||||
|
||||
// Handle the custom transformers-specific `generation` tag.
|
||||
// See https://github.com/huggingface/transformers/pull/30650 for more information.
|
||||
return template.replace(/{%\s*(end)?generation\s*%}/gs, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a list of tokens from a source string.
|
||||
*/
|
||||
export function tokenize(source: string, options: PreprocessOptions = {}): Token[] {
|
||||
const tokens: Token[] = [];
|
||||
const src: string = preprocess(source, options);
|
||||
|
||||
let cursorPosition = 0;
|
||||
let curlyBracketDepth = 0;
|
||||
|
||||
const consumeWhile = (predicate: (char: string) => boolean): string => {
|
||||
let str = "";
|
||||
while (predicate(src[cursorPosition])) {
|
||||
// Check for escaped characters
|
||||
if (src[cursorPosition] === "\\") {
|
||||
// Consume the backslash
|
||||
++cursorPosition;
|
||||
// Check for end of input
|
||||
if (cursorPosition >= src.length) throw new SyntaxError("Unexpected end of input");
|
||||
|
||||
// Add the escaped character
|
||||
const escaped = src[cursorPosition++];
|
||||
const unescaped = ESCAPE_CHARACTERS.get(escaped);
|
||||
if (unescaped === undefined) {
|
||||
throw new SyntaxError(`Unexpected escaped character: ${escaped}`);
|
||||
}
|
||||
str += unescaped;
|
||||
continue;
|
||||
}
|
||||
|
||||
str += src[cursorPosition++];
|
||||
if (cursorPosition >= src.length) throw new SyntaxError("Unexpected end of input");
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const stripTrailingWhitespace = () => {
|
||||
const lastToken = tokens.at(-1);
|
||||
if (lastToken && lastToken.type === TOKEN_TYPES.Text) {
|
||||
lastToken.value = lastToken.value.trimEnd();
|
||||
if (lastToken.value === "") {
|
||||
tokens.pop(); // Remove empty text token
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const skipLeadingWhitespace = () => {
|
||||
while (cursorPosition < src.length && isWhitespace(src[cursorPosition])) {
|
||||
++cursorPosition;
|
||||
}
|
||||
};
|
||||
|
||||
// Build each token until end of input
|
||||
main: while (cursorPosition < src.length) {
|
||||
// First, consume all text that is outside of a Jinja statement or expression
|
||||
const lastTokenType = tokens.at(-1)?.type;
|
||||
if (
|
||||
lastTokenType === undefined ||
|
||||
lastTokenType === TOKEN_TYPES.CloseStatement ||
|
||||
lastTokenType === TOKEN_TYPES.CloseExpression ||
|
||||
lastTokenType === TOKEN_TYPES.Comment
|
||||
) {
|
||||
let text = "";
|
||||
while (
|
||||
cursorPosition < src.length &&
|
||||
// Keep going until we hit the next Jinja statement or expression
|
||||
!(
|
||||
src[cursorPosition] === "{" &&
|
||||
(src[cursorPosition + 1] === "%" || src[cursorPosition + 1] === "{" || src[cursorPosition + 1] === "#")
|
||||
)
|
||||
) {
|
||||
// Consume text
|
||||
text += src[cursorPosition++];
|
||||
}
|
||||
|
||||
// There is some text to add
|
||||
if (text.length > 0) {
|
||||
tokens.push(new Token(text, TOKEN_TYPES.Text));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Possibly consume a comment
|
||||
if (src[cursorPosition] === "{" && src[cursorPosition + 1] === "#") {
|
||||
cursorPosition += 2; // Skip the opening {#
|
||||
|
||||
// Check for leading hyphen for whitespace control {#-
|
||||
const stripBefore = src[cursorPosition] === "-";
|
||||
if (stripBefore) {
|
||||
++cursorPosition; // Skip the hyphen
|
||||
}
|
||||
|
||||
let comment = "";
|
||||
while (src[cursorPosition] !== "#" || src[cursorPosition + 1] !== "}") {
|
||||
// Check for end of input
|
||||
if (cursorPosition + 2 >= src.length) {
|
||||
throw new SyntaxError("Missing end of comment tag");
|
||||
}
|
||||
comment += src[cursorPosition++];
|
||||
}
|
||||
|
||||
// Check for trailing hyphen for whitespace control -#}
|
||||
const stripAfter = comment.endsWith("-");
|
||||
if (stripAfter) {
|
||||
comment = comment.slice(0, -1); // Remove the trailing hyphen
|
||||
}
|
||||
|
||||
// Apply whitespace stripping for leading hyphen
|
||||
if (stripBefore) {
|
||||
stripTrailingWhitespace();
|
||||
}
|
||||
|
||||
tokens.push(new Token(comment, TOKEN_TYPES.Comment));
|
||||
cursorPosition += 2; // Skip the closing #}
|
||||
|
||||
// Apply whitespace stripping for trailing hyphen
|
||||
if (stripAfter) {
|
||||
skipLeadingWhitespace();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for opening statement with whitespace control {%-
|
||||
if (src.slice(cursorPosition, cursorPosition + 3) === "{%-") {
|
||||
stripTrailingWhitespace();
|
||||
tokens.push(new Token("{%", TOKEN_TYPES.OpenStatement));
|
||||
cursorPosition += 3; // Skip {%-
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for opening expression with whitespace control {{-
|
||||
if (src.slice(cursorPosition, cursorPosition + 3) === "{{-") {
|
||||
stripTrailingWhitespace();
|
||||
tokens.push(new Token("{{", TOKEN_TYPES.OpenExpression));
|
||||
curlyBracketDepth = 0;
|
||||
cursorPosition += 3; // Skip {{-
|
||||
continue;
|
||||
}
|
||||
|
||||
// Consume (and ignore) all whitespace inside Jinja statements or expressions
|
||||
consumeWhile(isWhitespace);
|
||||
|
||||
// Check for closing statement with whitespace control -%}
|
||||
if (src.slice(cursorPosition, cursorPosition + 3) === "-%}") {
|
||||
tokens.push(new Token("%}", TOKEN_TYPES.CloseStatement));
|
||||
cursorPosition += 3; // Skip -%}
|
||||
skipLeadingWhitespace();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for closing expression with whitespace control -}}
|
||||
if (src.slice(cursorPosition, cursorPosition + 3) === "-}}") {
|
||||
tokens.push(new Token("}}", TOKEN_TYPES.CloseExpression));
|
||||
cursorPosition += 3; // Skip -}}
|
||||
skipLeadingWhitespace();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle multi-character tokens
|
||||
const char = src[cursorPosition];
|
||||
|
||||
// Check for unary operators
|
||||
if (char === "-" || char === "+") {
|
||||
const lastTokenType = tokens.at(-1)?.type;
|
||||
if (lastTokenType === TOKEN_TYPES.Text || lastTokenType === undefined) {
|
||||
throw new SyntaxError(`Unexpected character: ${char}`);
|
||||
}
|
||||
switch (lastTokenType) {
|
||||
case TOKEN_TYPES.Identifier:
|
||||
case TOKEN_TYPES.NumericLiteral:
|
||||
case TOKEN_TYPES.StringLiteral:
|
||||
case TOKEN_TYPES.CloseParen:
|
||||
case TOKEN_TYPES.CloseSquareBracket:
|
||||
// Part of a binary operator
|
||||
// a - 1, 1 - 1, true - 1, "apple" - 1, (1) - 1, a[1] - 1
|
||||
// Continue parsing normally
|
||||
break;
|
||||
|
||||
default: {
|
||||
// Is part of a unary operator
|
||||
// (-1), [-1], (1 + -1), not -1, -apple
|
||||
++cursorPosition; // consume the unary operator
|
||||
|
||||
// Check for numbers following the unary operator
|
||||
const num = consumeWhile(isInteger);
|
||||
tokens.push(
|
||||
new Token(`${char}${num}`, num.length > 0 ? TOKEN_TYPES.NumericLiteral : TOKEN_TYPES.UnaryOperator),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to match one of the tokens in the mapping table
|
||||
for (const [seq, type] of ORDERED_MAPPING_TABLE) {
|
||||
// inside an object literal, don't treat "}}" as expression-end
|
||||
if (seq === "}}" && curlyBracketDepth > 0) {
|
||||
continue;
|
||||
}
|
||||
const slice = src.slice(cursorPosition, cursorPosition + seq.length);
|
||||
if (slice === seq) {
|
||||
tokens.push(new Token(seq, type));
|
||||
|
||||
// possibly adjust the curly bracket depth
|
||||
if (type === TOKEN_TYPES.OpenExpression) {
|
||||
curlyBracketDepth = 0;
|
||||
} else if (type === TOKEN_TYPES.OpenCurlyBracket) {
|
||||
++curlyBracketDepth;
|
||||
} else if (type === TOKEN_TYPES.CloseCurlyBracket) {
|
||||
--curlyBracketDepth;
|
||||
}
|
||||
cursorPosition += seq.length;
|
||||
continue main;
|
||||
}
|
||||
}
|
||||
|
||||
if (char === "'" || char === '"') {
|
||||
++cursorPosition; // Skip the opening quote
|
||||
const str = consumeWhile((c) => c !== char);
|
||||
tokens.push(new Token(str, TOKEN_TYPES.StringLiteral));
|
||||
++cursorPosition; // Skip the closing quote
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isInteger(char)) {
|
||||
// Consume integer part
|
||||
let num = consumeWhile(isInteger);
|
||||
// Possibly, consume fractional part
|
||||
if (src[cursorPosition] === "." && isInteger(src[cursorPosition + 1])) {
|
||||
++cursorPosition; // consume '.'
|
||||
const frac = consumeWhile(isInteger);
|
||||
num = `${num}.${frac}`;
|
||||
}
|
||||
tokens.push(new Token(num, TOKEN_TYPES.NumericLiteral));
|
||||
continue;
|
||||
}
|
||||
if (isWord(char)) {
|
||||
// consume any word characters and always classify as Identifier
|
||||
const word = consumeWhile(isWord);
|
||||
tokens.push(new Token(word, TOKEN_TYPES.Identifier));
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new SyntaxError(`Unexpected character: ${char}`);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
670
node_modules/@huggingface/jinja/src/parser.ts
generated
vendored
Normal file
670
node_modules/@huggingface/jinja/src/parser.ts
generated
vendored
Normal file
@@ -0,0 +1,670 @@
|
||||
import { Token, TOKEN_TYPES } from "./lexer";
|
||||
import type { TokenType } from "./lexer";
|
||||
import type { Statement } from "./ast";
|
||||
import {
|
||||
Program,
|
||||
If,
|
||||
For,
|
||||
Break,
|
||||
Continue,
|
||||
SetStatement,
|
||||
MemberExpression,
|
||||
CallExpression,
|
||||
Identifier,
|
||||
StringLiteral,
|
||||
ArrayLiteral,
|
||||
ObjectLiteral,
|
||||
BinaryExpression,
|
||||
FilterExpression,
|
||||
TestExpression,
|
||||
UnaryExpression,
|
||||
SliceExpression,
|
||||
KeywordArgumentExpression,
|
||||
TupleLiteral,
|
||||
Macro,
|
||||
SelectExpression,
|
||||
CallStatement,
|
||||
FilterStatement,
|
||||
SpreadExpression,
|
||||
IntegerLiteral,
|
||||
FloatLiteral,
|
||||
Ternary,
|
||||
Comment,
|
||||
} from "./ast";
|
||||
|
||||
/**
|
||||
* Generate the Abstract Syntax Tree (AST) from a list of tokens.
|
||||
* Operator precedence can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table
|
||||
*/
|
||||
export function parse(tokens: Token[]): Program {
|
||||
const program = new Program([]);
|
||||
let current = 0;
|
||||
|
||||
/**
|
||||
* Consume the next token if it matches the expected type, otherwise throw an error.
|
||||
* @param type The expected token type
|
||||
* @param error The error message to throw if the token does not match the expected type
|
||||
* @returns The consumed token
|
||||
*/
|
||||
function expect(type: string, error: string): Token {
|
||||
const prev = tokens[current++];
|
||||
if (!prev || prev.type !== type) {
|
||||
throw new Error(`Parser Error: ${error}. ${prev.type} !== ${type}.`);
|
||||
}
|
||||
return prev;
|
||||
}
|
||||
|
||||
function expectIdentifier(name: string): void {
|
||||
if (!isIdentifier(name)) {
|
||||
throw new SyntaxError(`Expected ${name}`);
|
||||
}
|
||||
++current;
|
||||
}
|
||||
|
||||
function parseAny(): Statement {
|
||||
switch (tokens[current].type) {
|
||||
case TOKEN_TYPES.Comment:
|
||||
return new Comment(tokens[current++].value);
|
||||
case TOKEN_TYPES.Text:
|
||||
return parseText();
|
||||
case TOKEN_TYPES.OpenStatement:
|
||||
return parseJinjaStatement();
|
||||
case TOKEN_TYPES.OpenExpression:
|
||||
return parseJinjaExpression();
|
||||
default:
|
||||
throw new SyntaxError(`Unexpected token type: ${tokens[current].type}`);
|
||||
}
|
||||
}
|
||||
|
||||
function is(...types: TokenType[]): boolean {
|
||||
return current + types.length <= tokens.length && types.every((type, i) => type === tokens[current + i].type);
|
||||
}
|
||||
|
||||
function isStatement(...names: string[]): boolean {
|
||||
return (
|
||||
tokens[current]?.type === TOKEN_TYPES.OpenStatement &&
|
||||
tokens[current + 1]?.type === TOKEN_TYPES.Identifier &&
|
||||
names.includes(tokens[current + 1]?.value)
|
||||
);
|
||||
}
|
||||
|
||||
function isIdentifier(...names: string[]): boolean {
|
||||
return (
|
||||
current + names.length <= tokens.length &&
|
||||
names.every((name, i) => tokens[current + i].type === "Identifier" && name === tokens[current + i].value)
|
||||
);
|
||||
}
|
||||
|
||||
function parseText(): StringLiteral {
|
||||
return new StringLiteral(expect(TOKEN_TYPES.Text, "Expected text token").value);
|
||||
}
|
||||
|
||||
function parseJinjaStatement(): Statement {
|
||||
// Consume {% token
|
||||
expect(TOKEN_TYPES.OpenStatement, "Expected opening statement token");
|
||||
|
||||
// next token must be Identifier whose .value tells us which statement
|
||||
if (tokens[current].type !== TOKEN_TYPES.Identifier) {
|
||||
throw new SyntaxError(`Unknown statement, got ${tokens[current].type}`);
|
||||
}
|
||||
const name = tokens[current].value;
|
||||
let result: Statement;
|
||||
switch (name) {
|
||||
case "set":
|
||||
++current;
|
||||
result = parseSetStatement();
|
||||
break;
|
||||
case "if":
|
||||
++current;
|
||||
result = parseIfStatement();
|
||||
// expect {% endif %}
|
||||
expect(TOKEN_TYPES.OpenStatement, "Expected {% token");
|
||||
expectIdentifier("endif");
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected %} token");
|
||||
break;
|
||||
case "macro":
|
||||
++current;
|
||||
result = parseMacroStatement();
|
||||
// expect {% endmacro %}
|
||||
expect(TOKEN_TYPES.OpenStatement, "Expected {% token");
|
||||
expectIdentifier("endmacro");
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected %} token");
|
||||
break;
|
||||
case "for":
|
||||
++current;
|
||||
result = parseForStatement();
|
||||
// expect {% endfor %}
|
||||
expect(TOKEN_TYPES.OpenStatement, "Expected {% token");
|
||||
expectIdentifier("endfor");
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected %} token");
|
||||
break;
|
||||
case "call": {
|
||||
++current; // consume 'call'
|
||||
let callerArgs: Statement[] | null = null;
|
||||
if (is(TOKEN_TYPES.OpenParen)) {
|
||||
// Optional caller arguments, e.g. {% call(user) dump_users(...) %}
|
||||
callerArgs = parseArgs();
|
||||
}
|
||||
const callee = parsePrimaryExpression();
|
||||
if (callee.type !== "Identifier") {
|
||||
throw new SyntaxError(`Expected identifier following call statement`);
|
||||
}
|
||||
const callArgs = parseArgs();
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
const body: Statement[] = [];
|
||||
while (!isStatement("endcall")) {
|
||||
body.push(parseAny());
|
||||
}
|
||||
expect(TOKEN_TYPES.OpenStatement, "Expected '{%'");
|
||||
expectIdentifier("endcall");
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
const callExpr = new CallExpression(callee, callArgs);
|
||||
result = new CallStatement(callExpr, callerArgs, body);
|
||||
break;
|
||||
}
|
||||
case "break":
|
||||
++current;
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
result = new Break();
|
||||
break;
|
||||
case "continue":
|
||||
++current;
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
result = new Continue();
|
||||
break;
|
||||
case "filter": {
|
||||
++current; // consume 'filter'
|
||||
let filterNode = parsePrimaryExpression();
|
||||
if (filterNode instanceof Identifier && is(TOKEN_TYPES.OpenParen)) {
|
||||
filterNode = parseCallExpression(filterNode);
|
||||
}
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
const filterBody: Statement[] = [];
|
||||
while (!isStatement("endfilter")) {
|
||||
filterBody.push(parseAny());
|
||||
}
|
||||
expect(TOKEN_TYPES.OpenStatement, "Expected '{%'");
|
||||
expectIdentifier("endfilter");
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected '%}'");
|
||||
result = new FilterStatement(filterNode as Identifier | CallExpression, filterBody);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new SyntaxError(`Unknown statement type: ${name}`);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseJinjaExpression(): Statement {
|
||||
// Consume {{ }} tokens
|
||||
expect(TOKEN_TYPES.OpenExpression, "Expected opening expression token");
|
||||
|
||||
const result = parseExpression();
|
||||
|
||||
expect(TOKEN_TYPES.CloseExpression, "Expected closing expression token");
|
||||
return result;
|
||||
}
|
||||
|
||||
// NOTE: `set` acts as both declaration statement and assignment expression
|
||||
function parseSetStatement(): Statement {
|
||||
const left = parseExpressionSequence();
|
||||
let value: Statement | null = null;
|
||||
const body: Statement[] = [];
|
||||
if (is(TOKEN_TYPES.Equals)) {
|
||||
++current;
|
||||
value = parseExpressionSequence();
|
||||
} else {
|
||||
// parsing multiline set here
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected %} token");
|
||||
while (!isStatement("endset")) {
|
||||
body.push(parseAny());
|
||||
}
|
||||
expect(TOKEN_TYPES.OpenStatement, "Expected {% token");
|
||||
expectIdentifier("endset");
|
||||
}
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
return new SetStatement(left, value, body);
|
||||
}
|
||||
|
||||
function parseIfStatement(): If {
|
||||
const test = parseExpression();
|
||||
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
|
||||
const body: Statement[] = [];
|
||||
const alternate: Statement[] = [];
|
||||
|
||||
// Keep parsing 'if' body until we reach the first {% elif %} or {% else %} or {% endif %}
|
||||
while (!isStatement("elif", "else", "endif")) {
|
||||
body.push(parseAny());
|
||||
}
|
||||
|
||||
// handle {% elif %}
|
||||
if (isStatement("elif")) {
|
||||
++current; // consume {%
|
||||
++current; // consume 'elif'
|
||||
const result = parseIfStatement(); // nested If
|
||||
alternate.push(result);
|
||||
}
|
||||
// handle {% else %}
|
||||
else if (isStatement("else")) {
|
||||
++current; // consume {%
|
||||
++current; // consume 'else'
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
|
||||
// keep going until we hit {% endif %}
|
||||
while (!isStatement("endif")) {
|
||||
alternate.push(parseAny());
|
||||
}
|
||||
}
|
||||
|
||||
return new If(test, body, alternate);
|
||||
}
|
||||
|
||||
function parseMacroStatement(): Macro {
|
||||
const name = parsePrimaryExpression();
|
||||
if (name.type !== "Identifier") {
|
||||
throw new SyntaxError(`Expected identifier following macro statement`);
|
||||
}
|
||||
const args = parseArgs();
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
|
||||
// Body of macro
|
||||
const body: Statement[] = [];
|
||||
|
||||
// Keep going until we hit {% endmacro
|
||||
while (!isStatement("endmacro")) {
|
||||
body.push(parseAny());
|
||||
}
|
||||
|
||||
return new Macro(name as Identifier, args, body);
|
||||
}
|
||||
|
||||
function parseExpressionSequence(primary = false): Statement {
|
||||
const fn = primary ? parsePrimaryExpression : parseExpression;
|
||||
const expressions = [fn()];
|
||||
const isTuple = is(TOKEN_TYPES.Comma);
|
||||
while (isTuple) {
|
||||
++current; // consume comma
|
||||
expressions.push(fn());
|
||||
if (!is(TOKEN_TYPES.Comma)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isTuple ? new TupleLiteral(expressions) : expressions[0];
|
||||
}
|
||||
|
||||
function parseForStatement(): For {
|
||||
// e.g., `message` in `for message in messages`
|
||||
const loopVariable = parseExpressionSequence(true); // should be an identifier/tuple
|
||||
if (!(loopVariable instanceof Identifier || loopVariable instanceof TupleLiteral)) {
|
||||
throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${loopVariable.type} instead`);
|
||||
}
|
||||
|
||||
if (!isIdentifier("in")) {
|
||||
throw new SyntaxError("Expected `in` keyword following loop variable");
|
||||
}
|
||||
++current;
|
||||
|
||||
// `messages` in `for message in messages`
|
||||
const iterable = parseExpression();
|
||||
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
|
||||
// Body of for loop
|
||||
const body: Statement[] = [];
|
||||
|
||||
// Keep going until we hit {% endfor or {% else
|
||||
while (!isStatement("endfor", "else")) {
|
||||
body.push(parseAny());
|
||||
}
|
||||
|
||||
// (Optional) else block
|
||||
const alternative: Statement[] = [];
|
||||
if (isStatement("else")) {
|
||||
++current; // consume {%
|
||||
++current; // consume 'else'
|
||||
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
||||
while (!isStatement("endfor")) {
|
||||
alternative.push(parseAny());
|
||||
}
|
||||
}
|
||||
|
||||
return new For(loopVariable, iterable, body, alternative);
|
||||
}
|
||||
|
||||
function parseExpression(): Statement {
|
||||
// Choose parse function with lowest precedence
|
||||
return parseIfExpression();
|
||||
}
|
||||
|
||||
function parseIfExpression(): Statement {
|
||||
const a = parseLogicalOrExpression();
|
||||
if (isIdentifier("if")) {
|
||||
// Ternary expression
|
||||
++current; // consume 'if'
|
||||
const test = parseLogicalOrExpression();
|
||||
|
||||
if (isIdentifier("else")) {
|
||||
// Ternary expression with else
|
||||
++current; // consume 'else'
|
||||
const falseExpr = parseIfExpression(); // recurse to support chained ternaries
|
||||
return new Ternary(test, a, falseExpr);
|
||||
} else {
|
||||
// Select expression on iterable
|
||||
return new SelectExpression(a, test);
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
function parseLogicalOrExpression(): Statement {
|
||||
let left = parseLogicalAndExpression();
|
||||
while (isIdentifier("or")) {
|
||||
const operator = tokens[current];
|
||||
++current;
|
||||
const right = parseLogicalAndExpression();
|
||||
left = new BinaryExpression(operator, left, right);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
function parseLogicalAndExpression(): Statement {
|
||||
let left = parseLogicalNegationExpression();
|
||||
while (isIdentifier("and")) {
|
||||
const operator = tokens[current];
|
||||
++current;
|
||||
const right = parseLogicalNegationExpression();
|
||||
left = new BinaryExpression(operator, left, right);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
function parseLogicalNegationExpression(): Statement {
|
||||
let right: UnaryExpression | undefined;
|
||||
|
||||
// Try parse unary operators
|
||||
while (isIdentifier("not")) {
|
||||
// not not ...
|
||||
const operator = tokens[current];
|
||||
++current;
|
||||
const arg = parseLogicalNegationExpression(); // not test.x === not (test.x)
|
||||
right = new UnaryExpression(operator, arg);
|
||||
}
|
||||
|
||||
return right ?? parseComparisonExpression();
|
||||
}
|
||||
|
||||
function parseComparisonExpression(): Statement {
|
||||
// NOTE: membership has same precedence as comparison
|
||||
// e.g., ('a' in 'apple' == 'b' in 'banana') evaluates as ('a' in ('apple' == ('b' in 'banana')))
|
||||
let left = parseAdditiveExpression();
|
||||
while (true) {
|
||||
let operator: Token;
|
||||
if (isIdentifier("not", "in")) {
|
||||
operator = new Token("not in", TOKEN_TYPES.Identifier);
|
||||
current += 2;
|
||||
} else if (isIdentifier("in")) {
|
||||
operator = tokens[current++];
|
||||
} else if (is(TOKEN_TYPES.ComparisonBinaryOperator)) {
|
||||
operator = tokens[current++];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
const right = parseAdditiveExpression();
|
||||
left = new BinaryExpression(operator, left, right);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
function parseAdditiveExpression(): Statement {
|
||||
let left = parseMultiplicativeExpression();
|
||||
while (is(TOKEN_TYPES.AdditiveBinaryOperator)) {
|
||||
const operator = tokens[current];
|
||||
++current;
|
||||
const right = parseMultiplicativeExpression();
|
||||
left = new BinaryExpression(operator, left, right);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
function parseCallMemberExpression(): Statement {
|
||||
// Handle member expressions recursively
|
||||
|
||||
const member = parseMemberExpression(parsePrimaryExpression()); // foo.x
|
||||
|
||||
if (is(TOKEN_TYPES.OpenParen)) {
|
||||
// foo.x()
|
||||
return parseCallExpression(member);
|
||||
}
|
||||
return member;
|
||||
}
|
||||
|
||||
function parseCallExpression(callee: Statement): Statement {
|
||||
let expression: Statement = new CallExpression(callee, parseArgs());
|
||||
|
||||
expression = parseMemberExpression(expression); // foo.x().y
|
||||
|
||||
if (is(TOKEN_TYPES.OpenParen)) {
|
||||
// foo.x()()
|
||||
expression = parseCallExpression(expression);
|
||||
}
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
function parseArgs(): Statement[] {
|
||||
// add (x + 5, foo())
|
||||
expect(TOKEN_TYPES.OpenParen, "Expected opening parenthesis for arguments list");
|
||||
|
||||
const args = parseArgumentsList();
|
||||
|
||||
expect(TOKEN_TYPES.CloseParen, "Expected closing parenthesis for arguments list");
|
||||
return args;
|
||||
}
|
||||
function parseArgumentsList(): Statement[] {
|
||||
// comma-separated arguments list
|
||||
|
||||
const args = [];
|
||||
while (!is(TOKEN_TYPES.CloseParen)) {
|
||||
let argument: Statement;
|
||||
|
||||
// unpacking: *expr
|
||||
if (tokens[current].type === TOKEN_TYPES.MultiplicativeBinaryOperator && tokens[current].value === "*") {
|
||||
++current;
|
||||
const expr = parseExpression();
|
||||
argument = new SpreadExpression(expr);
|
||||
} else {
|
||||
argument = parseExpression();
|
||||
if (is(TOKEN_TYPES.Equals)) {
|
||||
// keyword argument
|
||||
// e.g., func(x = 5, y = a or b)
|
||||
++current; // consume equals
|
||||
if (!(argument instanceof Identifier)) {
|
||||
throw new SyntaxError(`Expected identifier for keyword argument`);
|
||||
}
|
||||
const value = parseExpression();
|
||||
argument = new KeywordArgumentExpression(argument as Identifier, value);
|
||||
}
|
||||
}
|
||||
args.push(argument);
|
||||
if (is(TOKEN_TYPES.Comma)) {
|
||||
++current; // consume comma
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function parseMemberExpressionArgumentsList(): Statement {
|
||||
// NOTE: This also handles slice expressions colon-separated arguments list
|
||||
// e.g., ['test'], [0], [:2], [1:], [1:2], [1:2:3]
|
||||
|
||||
const slices: (Statement | undefined)[] = [];
|
||||
let isSlice = false;
|
||||
while (!is(TOKEN_TYPES.CloseSquareBracket)) {
|
||||
if (is(TOKEN_TYPES.Colon)) {
|
||||
// A case where a default is used
|
||||
// e.g., [:2] will be parsed as [undefined, 2]
|
||||
slices.push(undefined);
|
||||
++current; // consume colon
|
||||
isSlice = true;
|
||||
} else {
|
||||
slices.push(parseExpression());
|
||||
if (is(TOKEN_TYPES.Colon)) {
|
||||
++current; // consume colon after expression, if it exists
|
||||
isSlice = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (slices.length === 0) {
|
||||
// []
|
||||
throw new SyntaxError(`Expected at least one argument for member/slice expression`);
|
||||
}
|
||||
|
||||
if (isSlice) {
|
||||
if (slices.length > 3) {
|
||||
throw new SyntaxError(`Expected 0-3 arguments for slice expression`);
|
||||
}
|
||||
return new SliceExpression(...slices);
|
||||
}
|
||||
|
||||
return slices[0] as Statement; // normal member expression
|
||||
}
|
||||
|
||||
function parseMemberExpression(object: Statement): Statement {
|
||||
while (is(TOKEN_TYPES.Dot) || is(TOKEN_TYPES.OpenSquareBracket)) {
|
||||
const operator = tokens[current]; // . or [
|
||||
++current;
|
||||
let property: Statement;
|
||||
const computed = operator.type === TOKEN_TYPES.OpenSquareBracket;
|
||||
if (computed) {
|
||||
// computed (i.e., bracket notation: obj[expr])
|
||||
property = parseMemberExpressionArgumentsList();
|
||||
expect(TOKEN_TYPES.CloseSquareBracket, "Expected closing square bracket");
|
||||
} else {
|
||||
// non-computed (i.e., dot notation: obj.expr)
|
||||
property = parsePrimaryExpression(); // should be an identifier
|
||||
if (property.type !== "Identifier") {
|
||||
throw new SyntaxError(`Expected identifier following dot operator`);
|
||||
}
|
||||
}
|
||||
object = new MemberExpression(object, property, computed);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
function parseMultiplicativeExpression(): Statement {
|
||||
let left = parseTestExpression();
|
||||
|
||||
// Multiplicative operators have higher precedence than test expressions
|
||||
// e.g., (4 * 4 is divisibleby(2)) evaluates as (4 * (4 is divisibleby(2)))
|
||||
|
||||
while (is(TOKEN_TYPES.MultiplicativeBinaryOperator)) {
|
||||
const operator = tokens[current++];
|
||||
const right = parseTestExpression();
|
||||
left = new BinaryExpression(operator, left, right);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
function parseTestExpression(): Statement {
|
||||
let operand = parseFilterExpression();
|
||||
|
||||
while (isIdentifier("is")) {
|
||||
// Support chaining tests
|
||||
++current; // consume is
|
||||
const negate = isIdentifier("not");
|
||||
if (negate) {
|
||||
++current; // consume not
|
||||
}
|
||||
|
||||
const filter = parsePrimaryExpression();
|
||||
if (!(filter instanceof Identifier)) {
|
||||
throw new SyntaxError(`Expected identifier for the test`);
|
||||
}
|
||||
// TODO: Add support for non-identifier tests
|
||||
operand = new TestExpression(operand, negate, filter);
|
||||
}
|
||||
return operand;
|
||||
}
|
||||
|
||||
function parseFilterExpression(): Statement {
|
||||
let operand = parseCallMemberExpression();
|
||||
|
||||
while (is(TOKEN_TYPES.Pipe)) {
|
||||
// Support chaining filters
|
||||
++current; // consume pipe
|
||||
let filter = parsePrimaryExpression(); // should be an identifier
|
||||
if (!(filter instanceof Identifier)) {
|
||||
throw new SyntaxError(`Expected identifier for the filter`);
|
||||
}
|
||||
if (is(TOKEN_TYPES.OpenParen)) {
|
||||
filter = parseCallExpression(filter);
|
||||
}
|
||||
operand = new FilterExpression(operand, filter as Identifier | CallExpression);
|
||||
}
|
||||
return operand;
|
||||
}
|
||||
|
||||
function parsePrimaryExpression(): Statement {
|
||||
// Primary expression: number, string, identifier, function call, parenthesized expression
|
||||
const token = tokens[current++];
|
||||
switch (token.type) {
|
||||
case TOKEN_TYPES.NumericLiteral: {
|
||||
const num = token.value;
|
||||
return num.includes(".") ? new FloatLiteral(Number(num)) : new IntegerLiteral(Number(num));
|
||||
}
|
||||
case TOKEN_TYPES.StringLiteral: {
|
||||
let value = token.value;
|
||||
while (is(TOKEN_TYPES.StringLiteral)) {
|
||||
value += tokens[current++].value;
|
||||
}
|
||||
return new StringLiteral(value);
|
||||
}
|
||||
case TOKEN_TYPES.Identifier:
|
||||
return new Identifier(token.value);
|
||||
case TOKEN_TYPES.OpenParen: {
|
||||
const expression = parseExpressionSequence();
|
||||
expect(TOKEN_TYPES.CloseParen, "Expected closing parenthesis, got ${tokens[current].type} instead.");
|
||||
return expression;
|
||||
}
|
||||
case TOKEN_TYPES.OpenSquareBracket: {
|
||||
const values = [];
|
||||
while (!is(TOKEN_TYPES.CloseSquareBracket)) {
|
||||
values.push(parseExpression());
|
||||
|
||||
if (is(TOKEN_TYPES.Comma)) {
|
||||
++current; // consume comma
|
||||
}
|
||||
}
|
||||
++current; // consume closing square bracket
|
||||
|
||||
return new ArrayLiteral(values);
|
||||
}
|
||||
case TOKEN_TYPES.OpenCurlyBracket: {
|
||||
const values = new Map();
|
||||
while (!is(TOKEN_TYPES.CloseCurlyBracket)) {
|
||||
const key = parseExpression();
|
||||
expect(TOKEN_TYPES.Colon, "Expected colon between key and value in object literal");
|
||||
const value = parseExpression();
|
||||
values.set(key, value);
|
||||
|
||||
if (is(TOKEN_TYPES.Comma)) {
|
||||
++current; // consume comma
|
||||
}
|
||||
}
|
||||
++current; // consume closing curly bracket
|
||||
|
||||
return new ObjectLiteral(values);
|
||||
}
|
||||
default:
|
||||
throw new SyntaxError(`Unexpected token: ${token.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
while (current < tokens.length) {
|
||||
program.body.push(parseAny());
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
1880
node_modules/@huggingface/jinja/src/runtime.ts
generated
vendored
Normal file
1880
node_modules/@huggingface/jinja/src/runtime.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
123
node_modules/@huggingface/jinja/src/utils.ts
generated
vendored
Normal file
123
node_modules/@huggingface/jinja/src/utils.ts
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Function that mimics Python's range() function.
|
||||
* @param start The start value of the range.
|
||||
* @param stop The stop value of the range. If not provided, start will be 0 and stop will be the provided start value.
|
||||
* @param step The step value of the range. Defaults to 1.
|
||||
* @returns The range of numbers.
|
||||
*/
|
||||
export function range(start: number, stop?: number, step = 1): number[] {
|
||||
if (stop === undefined) {
|
||||
stop = start;
|
||||
start = 0;
|
||||
}
|
||||
|
||||
if (step === 0) {
|
||||
throw new Error("range() step must not be zero");
|
||||
}
|
||||
|
||||
const result: number[] = [];
|
||||
if (step > 0) {
|
||||
for (let i = start; i < stop; i += step) {
|
||||
result.push(i);
|
||||
}
|
||||
} else {
|
||||
for (let i = start; i > stop; i += step) {
|
||||
result.push(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that mimics Python's array slicing.
|
||||
* @param array The array to slice.
|
||||
* @param start The start index of the slice. Defaults to 0.
|
||||
* @param stop The last index of the slice. Defaults to `array.length`.
|
||||
* @param step The step value of the slice. Defaults to 1.
|
||||
* @returns The sliced array.
|
||||
*/
|
||||
export function slice<T>(array: T[], start?: number, stop?: number, step = 1): T[] {
|
||||
const direction = Math.sign(step);
|
||||
|
||||
if (direction >= 0) {
|
||||
start = (start ??= 0) < 0 ? Math.max(array.length + start, 0) : Math.min(start, array.length);
|
||||
stop = (stop ??= array.length) < 0 ? Math.max(array.length + stop, 0) : Math.min(stop, array.length);
|
||||
} else {
|
||||
start = (start ??= array.length - 1) < 0 ? Math.max(array.length + start, -1) : Math.min(start, array.length - 1);
|
||||
stop = (stop ??= -1) < -1 ? Math.max(array.length + stop, -1) : Math.min(stop, array.length - 1);
|
||||
}
|
||||
|
||||
const result: T[] = [];
|
||||
for (let i = start; direction * i < direction * stop; i += step) {
|
||||
result.push(array[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that mimics Python's string.title() function.
|
||||
* @param value The string to title case.
|
||||
* @returns The title cased string.
|
||||
*/
|
||||
export function titleCase(value: string): string {
|
||||
return value.replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
export function strftime_now(format: string): string {
|
||||
return strftime(new Date(), format);
|
||||
}
|
||||
|
||||
/**
|
||||
* A minimalistic implementation of Python's strftime function.
|
||||
*/
|
||||
export function strftime(date: Date, format: string): string {
|
||||
// Set locale to undefined to use the default locale
|
||||
const monthFormatterLong = new Intl.DateTimeFormat(undefined, { month: "long" });
|
||||
const monthFormatterShort = new Intl.DateTimeFormat(undefined, { month: "short" });
|
||||
|
||||
const pad2 = (n: number): string => (n < 10 ? "0" + n : n.toString());
|
||||
|
||||
return format.replace(/%[YmdbBHM%]/g, (token) => {
|
||||
switch (token) {
|
||||
case "%Y":
|
||||
return date.getFullYear().toString();
|
||||
case "%m":
|
||||
return pad2(date.getMonth() + 1);
|
||||
case "%d":
|
||||
return pad2(date.getDate());
|
||||
case "%b":
|
||||
return monthFormatterShort.format(date);
|
||||
case "%B":
|
||||
return monthFormatterLong.format(date);
|
||||
case "%H":
|
||||
return pad2(date.getHours());
|
||||
case "%M":
|
||||
return pad2(date.getMinutes());
|
||||
case "%%":
|
||||
return "%";
|
||||
default:
|
||||
return token;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function escapeRegExp(s: string): string {
|
||||
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that mimics Python's string.replace() function.
|
||||
*/
|
||||
export function replace(str: string, oldvalue: string, newvalue: string, count?: number | null): string {
|
||||
if (count === 0) return str;
|
||||
let remaining = count == null || count < 0 ? Infinity : count;
|
||||
// NB: Use a Unicode-aware global regex so unpaired surrogates won't match
|
||||
const pattern = oldvalue.length === 0 ? new RegExp("(?=)", "gu") : new RegExp(escapeRegExp(oldvalue), "gu");
|
||||
return str.replaceAll(pattern, (match) => {
|
||||
if (remaining > 0) {
|
||||
--remaining;
|
||||
return newvalue;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
}
|
||||
20
node_modules/@huggingface/jinja/tsconfig.json
generated
vendored
Normal file
20
node_modules/@huggingface/jinja/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"lib": ["ES2022", "DOM"],
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"target": "ESNext",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"skipLibCheck": true,
|
||||
"noImplicitOverride": true,
|
||||
"outDir": "./dist",
|
||||
"declaration": true,
|
||||
"declarationMap": true
|
||||
},
|
||||
"include": ["src", "index.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
12
node_modules/@kwsites/file-exists/CHANGELOG.md
generated
vendored
Normal file
12
node_modules/@kwsites/file-exists/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
# Release History
|
||||
|
||||
## 1.1.1
|
||||
|
||||
- Add dependency on `debug` to log results of the file system checks
|
||||
- Add `jest` tests
|
||||
|
||||
# 1.0.0
|
||||
|
||||
- First public release, a simple typescript library for checking whether a path exists
|
||||
on the file system and optionally whether it points to a file or folder.
|
||||
20
node_modules/@kwsites/file-exists/LICENSE
generated
vendored
Normal file
20
node_modules/@kwsites/file-exists/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Steve King
|
||||
|
||||
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.
|
||||
1
node_modules/@kwsites/file-exists/dist/index.d.ts
generated
vendored
Normal file
1
node_modules/@kwsites/file-exists/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './src';
|
||||
7
node_modules/@kwsites/file-exists/dist/index.js
generated
vendored
Normal file
7
node_modules/@kwsites/file-exists/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./src"));
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kwsites/file-exists/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@kwsites/file-exists/dist/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;AACA,2BAAsB"}
|
||||
19
node_modules/@kwsites/file-exists/dist/src/index.d.ts
generated
vendored
Normal file
19
node_modules/@kwsites/file-exists/dist/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Synchronous validation of a path existing either as a file or as a directory.
|
||||
*
|
||||
* @param {string} path The path to check
|
||||
* @param {number} type One or both of the exported numeric constants
|
||||
*/
|
||||
export declare function exists(path: string, type?: number): boolean;
|
||||
/**
|
||||
* Constant representing a file
|
||||
*/
|
||||
export declare const FILE = 1;
|
||||
/**
|
||||
* Constant representing a folder
|
||||
*/
|
||||
export declare const FOLDER = 2;
|
||||
/**
|
||||
* Constant representing either a file or a folder
|
||||
*/
|
||||
export declare const READABLE: number;
|
||||
55
node_modules/@kwsites/file-exists/dist/src/index.js
generated
vendored
Normal file
55
node_modules/@kwsites/file-exists/dist/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const log = debug_1.default('@kwsites/file-exists');
|
||||
function check(path, isFile, isDirectory) {
|
||||
log(`checking %s`, path);
|
||||
try {
|
||||
const stat = fs_1.statSync(path);
|
||||
if (stat.isFile() && isFile) {
|
||||
log(`[OK] path represents a file`);
|
||||
return true;
|
||||
}
|
||||
if (stat.isDirectory() && isDirectory) {
|
||||
log(`[OK] path represents a directory`);
|
||||
return true;
|
||||
}
|
||||
log(`[FAIL] path represents something other than a file or directory`);
|
||||
return false;
|
||||
}
|
||||
catch (e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
log(`[FAIL] path is not accessible: %o`, e);
|
||||
return false;
|
||||
}
|
||||
log(`[FATAL] %o`, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Synchronous validation of a path existing either as a file or as a directory.
|
||||
*
|
||||
* @param {string} path The path to check
|
||||
* @param {number} type One or both of the exported numeric constants
|
||||
*/
|
||||
function exists(path, type = exports.READABLE) {
|
||||
return check(path, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
|
||||
}
|
||||
exports.exists = exists;
|
||||
/**
|
||||
* Constant representing a file
|
||||
*/
|
||||
exports.FILE = 1;
|
||||
/**
|
||||
* Constant representing a folder
|
||||
*/
|
||||
exports.FOLDER = 2;
|
||||
/**
|
||||
* Constant representing either a file or a folder
|
||||
*/
|
||||
exports.READABLE = exports.FILE + exports.FOLDER;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kwsites/file-exists/dist/src/index.js.map
generated
vendored
Normal file
1
node_modules/@kwsites/file-exists/dist/src/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,2BAA8B;AAC9B,kDAA0B;AAE1B,MAAM,GAAG,GAAG,eAAK,CAAC,sBAAsB,CAAC,CAAC;AAE1C,SAAS,KAAK,CAAC,IAAY,EAAE,MAAe,EAAE,WAAoB;IAC/D,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IAEzB,IAAI;QACD,MAAM,IAAI,GAAG,aAAQ,CAAC,IAAI,CAAC,CAAC;QAE5B,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,MAAM,EAAE;YAC1B,GAAG,CAAC,6BAA6B,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC;SACd;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,WAAW,EAAE;YACpC,GAAG,CAAC,kCAAkC,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;SACd;QAED,GAAG,CAAC,iEAAiE,CAAC,CAAC;QACvE,OAAO,KAAK,CAAC;KACf;IAAC,OAAO,CAAC,EAAE;QACT,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE;YACtB,GAAG,CAAC,mCAAmC,EAAE,CAAC,CAAC,CAAC;YAC5C,OAAO,KAAK,CAAC;SACf;QAED,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QACrB,MAAM,CAAC,CAAC;KACV;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,MAAM,CAAC,IAAY,EAAE,OAAe,gBAAQ;IACzD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,GAAG,YAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,cAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9D,CAAC;AAFD,wBAEC;AAED;;GAEG;AACU,QAAA,IAAI,GAAG,CAAC,CAAC;AAEtB;;GAEG;AACU,QAAA,MAAM,GAAG,CAAC,CAAC;AAExB;;GAEG;AACU,QAAA,QAAQ,GAAG,YAAI,GAAG,cAAM,CAAC"}
|
||||
7
node_modules/@kwsites/file-exists/dist/test/__mocks__/fs.d.ts
generated
vendored
Normal file
7
node_modules/@kwsites/file-exists/dist/test/__mocks__/fs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export declare function statSync(...args: any[]): any;
|
||||
export declare function addStatSyncMock(fn: any): void;
|
||||
export declare function assertMocksUsed(): void;
|
||||
declare const mockFs: {
|
||||
statSync: typeof statSync;
|
||||
};
|
||||
export default mockFs;
|
||||
26
node_modules/@kwsites/file-exists/dist/test/__mocks__/fs.js
generated
vendored
Normal file
26
node_modules/@kwsites/file-exists/dist/test/__mocks__/fs.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
let statSyncMocks = [];
|
||||
function statSync(...args) {
|
||||
const mock = statSyncMocks.shift();
|
||||
if (typeof mock !== 'function') {
|
||||
throw new Error(`fs.statSync called without configuring a mock`);
|
||||
}
|
||||
return mock(...args);
|
||||
}
|
||||
exports.statSync = statSync;
|
||||
function addStatSyncMock(fn) {
|
||||
statSyncMocks.push(fn);
|
||||
}
|
||||
exports.addStatSyncMock = addStatSyncMock;
|
||||
function assertMocksUsed() {
|
||||
if (statSyncMocks.length) {
|
||||
throw new Error(`fs.afterEach: statSync has ${statSyncMocks.length} unused mocks`);
|
||||
}
|
||||
}
|
||||
exports.assertMocksUsed = assertMocksUsed;
|
||||
const mockFs = {
|
||||
statSync,
|
||||
};
|
||||
exports.default = mockFs;
|
||||
//# sourceMappingURL=fs.js.map
|
||||
1
node_modules/@kwsites/file-exists/dist/test/__mocks__/fs.js.map
generated
vendored
Normal file
1
node_modules/@kwsites/file-exists/dist/test/__mocks__/fs.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../test/__mocks__/fs.ts"],"names":[],"mappings":";;AACA,IAAI,aAAa,GAAU,EAAE,CAAC;AAE9B,SAAgB,QAAQ,CAAC,GAAG,IAAW;IACpC,MAAO,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,CAAC;IACpC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;KACnE;IAED,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AACxB,CAAC;AAPD,4BAOC;AAED,SAAgB,eAAe,CAAC,EAAO;IACpC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC;AAFD,0CAEC;AAED,SAAgB,eAAe;IAC5B,IAAI,aAAa,CAAC,MAAM,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,aAAa,CAAC,MAAM,eAAe,CAAC,CAAC;KACrF;AACJ,CAAC;AAJD,0CAIC;AAED,MAAM,MAAM,GAAG;IACZ,QAAQ;CACV,CAAA;AAED,kBAAe,MAAM,CAAC"}
|
||||
1
node_modules/@kwsites/file-exists/dist/test/exists.spec.d.ts
generated
vendored
Normal file
1
node_modules/@kwsites/file-exists/dist/test/exists.spec.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
77
node_modules/@kwsites/file-exists/dist/test/exists.spec.js
generated
vendored
Normal file
77
node_modules/@kwsites/file-exists/dist/test/exists.spec.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
jest.mock('fs');
|
||||
//@ts-ignore
|
||||
const fs_1 = require("fs");
|
||||
const src_1 = require("../src");
|
||||
describe(`exists`, () => {
|
||||
let statSync;
|
||||
let statSyncMock;
|
||||
let path;
|
||||
beforeEach(() => {
|
||||
path = `./path/${Math.random()}`;
|
||||
fs_1.addStatSyncMock(statSyncMock = jest.fn(() => statSync()));
|
||||
});
|
||||
afterEach(() => {
|
||||
fs_1.assertMocksUsed();
|
||||
statSync = statSyncMock = undefined;
|
||||
});
|
||||
describe('known errors', () => {
|
||||
beforeEach(() => givenStatSyncThrows({ code: 'ENOENT' }));
|
||||
it('with type', () => {
|
||||
expect(src_1.exists(path, src_1.READABLE)).toBe(false);
|
||||
});
|
||||
it('with type omitted', () => {
|
||||
expect(src_1.exists(path)).toBe(false);
|
||||
});
|
||||
});
|
||||
describe('unknown errors', () => {
|
||||
let err;
|
||||
beforeEach(() => err = givenStatSyncThrows(new Error('something')));
|
||||
it('with type', () => {
|
||||
expect(() => src_1.exists(path, src_1.READABLE)).toThrow(err);
|
||||
});
|
||||
it('with type omitted', () => {
|
||||
expect(() => src_1.exists(path)).toThrow(err);
|
||||
});
|
||||
});
|
||||
describe('path is a file', () => {
|
||||
beforeEach(() => givenStatSyncIsA('file'));
|
||||
existsReturns(true, false, true);
|
||||
});
|
||||
describe('path is a folder', () => {
|
||||
beforeEach(() => givenStatSyncIsA('folder'));
|
||||
existsReturns(false, true, true);
|
||||
});
|
||||
describe('path is unknown', () => {
|
||||
beforeEach(() => givenStatSyncIsA('unknown'));
|
||||
existsReturns(false, false, false);
|
||||
});
|
||||
function existsReturns(file, folder, readable) {
|
||||
it('when searching for a file', () => {
|
||||
expect(src_1.exists(path, src_1.FILE)).toBe(file);
|
||||
});
|
||||
it('when searching for a folder', () => {
|
||||
expect(src_1.exists(path, src_1.FOLDER)).toBe(folder);
|
||||
});
|
||||
it('when searching for either', () => {
|
||||
expect(src_1.exists(path, src_1.READABLE)).toBe(readable);
|
||||
});
|
||||
it('when searching without a type', () => {
|
||||
expect(src_1.exists(path)).toBe(readable);
|
||||
});
|
||||
}
|
||||
function givenStatSyncThrows(err) {
|
||||
statSync = () => { throw err; };
|
||||
return err;
|
||||
}
|
||||
function givenStatSyncIsA(type) {
|
||||
const mockStat = {
|
||||
isFile() { return type === 'file'; },
|
||||
isDirectory() { return type === 'folder'; },
|
||||
};
|
||||
statSync = () => mockStat;
|
||||
return mockStat;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=exists.spec.js.map
|
||||
1
node_modules/@kwsites/file-exists/dist/test/exists.spec.js.map
generated
vendored
Normal file
1
node_modules/@kwsites/file-exists/dist/test/exists.spec.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"exists.spec.js","sourceRoot":"","sources":["../../test/exists.spec.ts"],"names":[],"mappings":"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"}
|
||||
20
node_modules/@kwsites/file-exists/node_modules/debug/LICENSE
generated
vendored
Normal file
20
node_modules/@kwsites/file-exists/node_modules/debug/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
||||
Copyright (c) 2018-2021 Josh Junon
|
||||
|
||||
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.
|
||||
|
||||
481
node_modules/@kwsites/file-exists/node_modules/debug/README.md
generated
vendored
Normal file
481
node_modules/@kwsites/file-exists/node_modules/debug/README.md
generated
vendored
Normal file
@@ -0,0 +1,481 @@
|
||||
# debug
|
||||
[](#backers)
|
||||
[](#sponsors)
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
A tiny JavaScript debugging utility modelled after Node.js core's debugging
|
||||
technique. Works in Node.js and web browsers.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install debug
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
`debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
|
||||
|
||||
Example [_app.js_](./examples/node/app.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug')('http')
|
||||
, http = require('http')
|
||||
, name = 'My App';
|
||||
|
||||
// fake app
|
||||
|
||||
debug('booting %o', name);
|
||||
|
||||
http.createServer(function(req, res){
|
||||
debug(req.method + ' ' + req.url);
|
||||
res.end('hello\n');
|
||||
}).listen(3000, function(){
|
||||
debug('listening');
|
||||
});
|
||||
|
||||
// fake worker of some kind
|
||||
|
||||
require('./worker');
|
||||
```
|
||||
|
||||
Example [_worker.js_](./examples/node/worker.js):
|
||||
|
||||
```js
|
||||
var a = require('debug')('worker:a')
|
||||
, b = require('debug')('worker:b');
|
||||
|
||||
function work() {
|
||||
a('doing lots of uninteresting work');
|
||||
setTimeout(work, Math.random() * 1000);
|
||||
}
|
||||
|
||||
work();
|
||||
|
||||
function workb() {
|
||||
b('doing some work');
|
||||
setTimeout(workb, Math.random() * 2000);
|
||||
}
|
||||
|
||||
workb();
|
||||
```
|
||||
|
||||
The `DEBUG` environment variable is then used to enable these based on space or
|
||||
comma-delimited names.
|
||||
|
||||
Here are some examples:
|
||||
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 04 pm" src="https://user-images.githubusercontent.com/71256/29091703-a6302cdc-7c38-11e7-8304-7c0b3bc600cd.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 38 pm" src="https://user-images.githubusercontent.com/71256/29091700-a62a6888-7c38-11e7-800b-db911291ca2b.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 25 pm" src="https://user-images.githubusercontent.com/71256/29091701-a62ea114-7c38-11e7-826a-2692bedca740.png">
|
||||
|
||||
#### Windows command prompt notes
|
||||
|
||||
##### CMD
|
||||
|
||||
On Windows the environment variable is set using the `set` command.
|
||||
|
||||
```cmd
|
||||
set DEBUG=*,-not_this
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
set DEBUG=* & node app.js
|
||||
```
|
||||
|
||||
##### PowerShell (VS Code default)
|
||||
|
||||
PowerShell uses different syntax to set environment variables.
|
||||
|
||||
```cmd
|
||||
$env:DEBUG = "*,-not_this"
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
$env:DEBUG='app';node app.js
|
||||
```
|
||||
|
||||
Then, run the program to be debugged as usual.
|
||||
|
||||
npm script example:
|
||||
```js
|
||||
"windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js",
|
||||
```
|
||||
|
||||
## Namespace Colors
|
||||
|
||||
Every debug instance has a color generated for it based on its namespace name.
|
||||
This helps when visually parsing the debug output to identify which debug instance
|
||||
a debug line belongs to.
|
||||
|
||||
#### Node.js
|
||||
|
||||
In Node.js, colors are enabled when stderr is a TTY. You also _should_ install
|
||||
the [`supports-color`](https://npmjs.org/supports-color) module alongside debug,
|
||||
otherwise debug will only use a small handful of basic colors.
|
||||
|
||||
<img width="521" src="https://user-images.githubusercontent.com/71256/29092181-47f6a9e6-7c3a-11e7-9a14-1928d8a711cd.png">
|
||||
|
||||
#### Web Browser
|
||||
|
||||
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
|
||||
option. These are WebKit web inspectors, Firefox ([since version
|
||||
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
|
||||
and the Firebug plugin for Firefox (any version).
|
||||
|
||||
<img width="524" src="https://user-images.githubusercontent.com/71256/29092033-b65f9f2e-7c39-11e7-8e32-f6f0d8e865c1.png">
|
||||
|
||||
|
||||
## Millisecond diff
|
||||
|
||||
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091956-6bd78372-7c39-11e7-8c55-c948396d6edd.png">
|
||||
|
||||
|
||||
## Conventions
|
||||
|
||||
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
|
||||
|
||||
## Wildcards
|
||||
|
||||
The `*` character may be used as a wildcard. Suppose for example your library has
|
||||
debuggers named "connect:bodyParser", "connect:compress", "connect:session",
|
||||
instead of listing all three with
|
||||
`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do
|
||||
`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
|
||||
|
||||
You can also exclude specific debuggers by prefixing them with a "-" character.
|
||||
For example, `DEBUG=*,-connect:*` would include all debuggers except those
|
||||
starting with "connect:".
|
||||
|
||||
## Environment Variables
|
||||
|
||||
When running through Node.js, you can set a few environment variables that will
|
||||
change the behavior of the debug logging:
|
||||
|
||||
| Name | Purpose |
|
||||
|-----------|-------------------------------------------------|
|
||||
| `DEBUG` | Enables/disables specific debugging namespaces. |
|
||||
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
|
||||
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
|
||||
| `DEBUG_DEPTH` | Object inspection depth. |
|
||||
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
|
||||
|
||||
|
||||
__Note:__ The environment variables beginning with `DEBUG_` end up being
|
||||
converted into an Options object that gets used with `%o`/`%O` formatters.
|
||||
See the Node.js documentation for
|
||||
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
|
||||
for the complete list.
|
||||
|
||||
## Formatters
|
||||
|
||||
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting.
|
||||
Below are the officially supported formatters:
|
||||
|
||||
| Formatter | Representation |
|
||||
|-----------|----------------|
|
||||
| `%O` | Pretty-print an Object on multiple lines. |
|
||||
| `%o` | Pretty-print an Object all on a single line. |
|
||||
| `%s` | String. |
|
||||
| `%d` | Number (both integer and float). |
|
||||
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
|
||||
| `%%` | Single percent sign ('%'). This does not consume an argument. |
|
||||
|
||||
|
||||
### Custom formatters
|
||||
|
||||
You can add custom formatters by extending the `debug.formatters` object.
|
||||
For example, if you wanted to add support for rendering a Buffer as hex with
|
||||
`%h`, you could do something like:
|
||||
|
||||
```js
|
||||
const createDebug = require('debug')
|
||||
createDebug.formatters.h = (v) => {
|
||||
return v.toString('hex')
|
||||
}
|
||||
|
||||
// …elsewhere
|
||||
const debug = createDebug('foo')
|
||||
debug('this is hex: %h', new Buffer('hello world'))
|
||||
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
|
||||
```
|
||||
|
||||
|
||||
## Browser Support
|
||||
|
||||
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
|
||||
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
|
||||
if you don't want to build it yourself.
|
||||
|
||||
Debug's enable state is currently persisted by `localStorage`.
|
||||
Consider the situation shown below where you have `worker:a` and `worker:b`,
|
||||
and wish to debug both. You can enable this using `localStorage.debug`:
|
||||
|
||||
```js
|
||||
localStorage.debug = 'worker:*'
|
||||
```
|
||||
|
||||
And then refresh the page.
|
||||
|
||||
```js
|
||||
a = debug('worker:a');
|
||||
b = debug('worker:b');
|
||||
|
||||
setInterval(function(){
|
||||
a('doing some work');
|
||||
}, 1000);
|
||||
|
||||
setInterval(function(){
|
||||
b('doing some work');
|
||||
}, 1200);
|
||||
```
|
||||
|
||||
In Chromium-based web browsers (e.g. Brave, Chrome, and Electron), the JavaScript console will—by default—only show messages logged by `debug` if the "Verbose" log level is _enabled_.
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/7143133/152083257-29034707-c42c-4959-8add-3cee850e6fcf.png">
|
||||
|
||||
## Output streams
|
||||
|
||||
By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:
|
||||
|
||||
Example [_stdout.js_](./examples/node/stdout.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug');
|
||||
var error = debug('app:error');
|
||||
|
||||
// by default stderr is used
|
||||
error('goes to stderr!');
|
||||
|
||||
var log = debug('app:log');
|
||||
// set this namespace to log via console.log
|
||||
log.log = console.log.bind(console); // don't forget to bind to console!
|
||||
log('goes to stdout');
|
||||
error('still goes to stderr!');
|
||||
|
||||
// set all output to go via console.info
|
||||
// overrides all per-namespace log settings
|
||||
debug.log = console.info.bind(console);
|
||||
error('now goes to stdout via console.info');
|
||||
log('still goes to stdout, but via console.info now');
|
||||
```
|
||||
|
||||
## Extend
|
||||
You can simply extend debugger
|
||||
```js
|
||||
const log = require('debug')('auth');
|
||||
|
||||
//creates new debug instance with extended namespace
|
||||
const logSign = log.extend('sign');
|
||||
const logLogin = log.extend('login');
|
||||
|
||||
log('hello'); // auth hello
|
||||
logSign('hello'); //auth:sign hello
|
||||
logLogin('hello'); //auth:login hello
|
||||
```
|
||||
|
||||
## Set dynamically
|
||||
|
||||
You can also enable debug dynamically by calling the `enable()` method :
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
|
||||
console.log(1, debug.enabled('test'));
|
||||
|
||||
debug.enable('test');
|
||||
console.log(2, debug.enabled('test'));
|
||||
|
||||
debug.disable();
|
||||
console.log(3, debug.enabled('test'));
|
||||
|
||||
```
|
||||
|
||||
print :
|
||||
```
|
||||
1 false
|
||||
2 true
|
||||
3 false
|
||||
```
|
||||
|
||||
Usage :
|
||||
`enable(namespaces)`
|
||||
`namespaces` can include modes separated by a colon and wildcards.
|
||||
|
||||
Note that calling `enable()` completely overrides previously set DEBUG variable :
|
||||
|
||||
```
|
||||
$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
|
||||
=> false
|
||||
```
|
||||
|
||||
`disable()`
|
||||
|
||||
Will disable all namespaces. The functions returns the namespaces currently
|
||||
enabled (and skipped). This can be useful if you want to disable debugging
|
||||
temporarily without knowing what was enabled to begin with.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
debug.enable('foo:*,-foo:bar');
|
||||
let namespaces = debug.disable();
|
||||
debug.enable(namespaces);
|
||||
```
|
||||
|
||||
Note: There is no guarantee that the string will be identical to the initial
|
||||
enable string, but semantically they will be identical.
|
||||
|
||||
## Checking whether a debug target is enabled
|
||||
|
||||
After you've created a debug instance, you can determine whether or not it is
|
||||
enabled by checking the `enabled` property:
|
||||
|
||||
```javascript
|
||||
const debug = require('debug')('http');
|
||||
|
||||
if (debug.enabled) {
|
||||
// do stuff...
|
||||
}
|
||||
```
|
||||
|
||||
You can also manually toggle this property to force the debug instance to be
|
||||
enabled or disabled.
|
||||
|
||||
## Usage in child processes
|
||||
|
||||
Due to the way `debug` detects if the output is a TTY or not, colors are not shown in child processes when `stderr` is piped. A solution is to pass the `DEBUG_COLORS=1` environment variable to the child process.
|
||||
For example:
|
||||
|
||||
```javascript
|
||||
worker = fork(WORKER_WRAP_PATH, [workerPath], {
|
||||
stdio: [
|
||||
/* stdin: */ 0,
|
||||
/* stdout: */ 'pipe',
|
||||
/* stderr: */ 'pipe',
|
||||
'ipc',
|
||||
],
|
||||
env: Object.assign({}, process.env, {
|
||||
DEBUG_COLORS: 1 // without this settings, colors won't be shown
|
||||
}),
|
||||
});
|
||||
|
||||
worker.stderr.pipe(process.stderr, { end: false });
|
||||
```
|
||||
|
||||
|
||||
## Authors
|
||||
|
||||
- TJ Holowaychuk
|
||||
- Nathan Rajlich
|
||||
- Andrew Rhyne
|
||||
- Josh Junon
|
||||
|
||||
## Backers
|
||||
|
||||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/debug#backer)]
|
||||
|
||||
<a href="https://opencollective.com/debug/backer/0/website" target="_blank"><img src="https://opencollective.com/debug/backer/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/1/website" target="_blank"><img src="https://opencollective.com/debug/backer/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/2/website" target="_blank"><img src="https://opencollective.com/debug/backer/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/3/website" target="_blank"><img src="https://opencollective.com/debug/backer/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/4/website" target="_blank"><img src="https://opencollective.com/debug/backer/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/5/website" target="_blank"><img src="https://opencollective.com/debug/backer/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/6/website" target="_blank"><img src="https://opencollective.com/debug/backer/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/7/website" target="_blank"><img src="https://opencollective.com/debug/backer/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/8/website" target="_blank"><img src="https://opencollective.com/debug/backer/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/9/website" target="_blank"><img src="https://opencollective.com/debug/backer/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/10/website" target="_blank"><img src="https://opencollective.com/debug/backer/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/11/website" target="_blank"><img src="https://opencollective.com/debug/backer/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/12/website" target="_blank"><img src="https://opencollective.com/debug/backer/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/13/website" target="_blank"><img src="https://opencollective.com/debug/backer/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/14/website" target="_blank"><img src="https://opencollective.com/debug/backer/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/15/website" target="_blank"><img src="https://opencollective.com/debug/backer/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/16/website" target="_blank"><img src="https://opencollective.com/debug/backer/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/17/website" target="_blank"><img src="https://opencollective.com/debug/backer/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/18/website" target="_blank"><img src="https://opencollective.com/debug/backer/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/19/website" target="_blank"><img src="https://opencollective.com/debug/backer/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/20/website" target="_blank"><img src="https://opencollective.com/debug/backer/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/21/website" target="_blank"><img src="https://opencollective.com/debug/backer/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/22/website" target="_blank"><img src="https://opencollective.com/debug/backer/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/23/website" target="_blank"><img src="https://opencollective.com/debug/backer/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/24/website" target="_blank"><img src="https://opencollective.com/debug/backer/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/25/website" target="_blank"><img src="https://opencollective.com/debug/backer/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/26/website" target="_blank"><img src="https://opencollective.com/debug/backer/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/27/website" target="_blank"><img src="https://opencollective.com/debug/backer/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/28/website" target="_blank"><img src="https://opencollective.com/debug/backer/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/29/website" target="_blank"><img src="https://opencollective.com/debug/backer/29/avatar.svg"></a>
|
||||
|
||||
|
||||
## Sponsors
|
||||
|
||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/debug#sponsor)]
|
||||
|
||||
<a href="https://opencollective.com/debug/sponsor/0/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/1/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/2/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/3/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/4/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/5/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/6/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/7/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/8/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/9/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/10/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/11/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/12/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/13/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/14/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/15/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/16/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/17/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/18/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/19/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/20/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/21/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/22/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/23/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/24/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/25/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/26/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/27/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/28/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/29/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/29/avatar.svg"></a>
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
||||
Copyright (c) 2018-2021 Josh Junon
|
||||
|
||||
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.
|
||||
64
node_modules/@kwsites/file-exists/node_modules/debug/package.json
generated
vendored
Normal file
64
node_modules/@kwsites/file-exists/node_modules/debug/package.json
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "debug",
|
||||
"version": "4.4.3",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/debug-js/debug.git"
|
||||
},
|
||||
"description": "Lightweight debugging utility for Node.js and the browser",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
"debugger"
|
||||
],
|
||||
"files": [
|
||||
"src",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"author": "Josh Junon (https://github.com/qix-)",
|
||||
"contributors": [
|
||||
"TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"Nathan Rajlich <nathan@tootallnate.net> (http://n8.io)",
|
||||
"Andrew Rhyne <rhyneandrew@gmail.com>"
|
||||
],
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"lint": "xo",
|
||||
"test": "npm run test:node && npm run test:browser && npm run lint",
|
||||
"test:node": "mocha test.js test.node.js",
|
||||
"test:browser": "karma start --single-run",
|
||||
"test:coverage": "cat ./coverage/lcov.info | coveralls"
|
||||
},
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"brfs": "^2.0.1",
|
||||
"browserify": "^16.2.3",
|
||||
"coveralls": "^3.0.2",
|
||||
"karma": "^3.1.4",
|
||||
"karma-browserify": "^6.0.0",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"sinon": "^14.0.0",
|
||||
"xo": "^0.23.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"main": "./src/index.js",
|
||||
"browser": "./src/browser.js",
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"xo": {
|
||||
"rules": {
|
||||
"import/extensions": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
272
node_modules/@kwsites/file-exists/node_modules/debug/src/browser.js
generated
vendored
Normal file
272
node_modules/@kwsites/file-exists/node_modules/debug/src/browser.js
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
exports.destroy = (() => {
|
||||
let warned = false;
|
||||
|
||||
return () => {
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [
|
||||
'#0000CC',
|
||||
'#0000FF',
|
||||
'#0033CC',
|
||||
'#0033FF',
|
||||
'#0066CC',
|
||||
'#0066FF',
|
||||
'#0099CC',
|
||||
'#0099FF',
|
||||
'#00CC00',
|
||||
'#00CC33',
|
||||
'#00CC66',
|
||||
'#00CC99',
|
||||
'#00CCCC',
|
||||
'#00CCFF',
|
||||
'#3300CC',
|
||||
'#3300FF',
|
||||
'#3333CC',
|
||||
'#3333FF',
|
||||
'#3366CC',
|
||||
'#3366FF',
|
||||
'#3399CC',
|
||||
'#3399FF',
|
||||
'#33CC00',
|
||||
'#33CC33',
|
||||
'#33CC66',
|
||||
'#33CC99',
|
||||
'#33CCCC',
|
||||
'#33CCFF',
|
||||
'#6600CC',
|
||||
'#6600FF',
|
||||
'#6633CC',
|
||||
'#6633FF',
|
||||
'#66CC00',
|
||||
'#66CC33',
|
||||
'#9900CC',
|
||||
'#9900FF',
|
||||
'#9933CC',
|
||||
'#9933FF',
|
||||
'#99CC00',
|
||||
'#99CC33',
|
||||
'#CC0000',
|
||||
'#CC0033',
|
||||
'#CC0066',
|
||||
'#CC0099',
|
||||
'#CC00CC',
|
||||
'#CC00FF',
|
||||
'#CC3300',
|
||||
'#CC3333',
|
||||
'#CC3366',
|
||||
'#CC3399',
|
||||
'#CC33CC',
|
||||
'#CC33FF',
|
||||
'#CC6600',
|
||||
'#CC6633',
|
||||
'#CC9900',
|
||||
'#CC9933',
|
||||
'#CCCC00',
|
||||
'#CCCC33',
|
||||
'#FF0000',
|
||||
'#FF0033',
|
||||
'#FF0066',
|
||||
'#FF0099',
|
||||
'#FF00CC',
|
||||
'#FF00FF',
|
||||
'#FF3300',
|
||||
'#FF3333',
|
||||
'#FF3366',
|
||||
'#FF3399',
|
||||
'#FF33CC',
|
||||
'#FF33FF',
|
||||
'#FF6600',
|
||||
'#FF6633',
|
||||
'#FF9900',
|
||||
'#FF9933',
|
||||
'#FFCC00',
|
||||
'#FFCC33'
|
||||
];
|
||||
|
||||
/**
|
||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||||
* and the Firebug extension (any Firefox version) are known
|
||||
* to support "%c" CSS customizations.
|
||||
*
|
||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
function useColors() {
|
||||
// NB: In an Electron preload script, document will be defined but not fully
|
||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
||||
// explicitly
|
||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Internet Explorer and Edge do not support colors.
|
||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let m;
|
||||
|
||||
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
||||
// eslint-disable-next-line no-return-assign
|
||||
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
||||
// Is firebug? http://stackoverflow.com/a/398120/376773
|
||||
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
||||
// Is firefox >= v31?
|
||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
|
||||
// Double check webkit in userAgent just in case we are in a worker
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
||||
}
|
||||
|
||||
/**
|
||||
* Colorize log arguments if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
args[0] = (this.useColors ? '%c' : '') +
|
||||
this.namespace +
|
||||
(this.useColors ? ' %c' : ' ') +
|
||||
args[0] +
|
||||
(this.useColors ? '%c ' : ' ') +
|
||||
'+' + module.exports.humanize(this.diff);
|
||||
|
||||
if (!this.useColors) {
|
||||
return;
|
||||
}
|
||||
|
||||
const c = 'color: ' + this.color;
|
||||
args.splice(1, 0, c, 'color: inherit');
|
||||
|
||||
// The final "%c" is somewhat tricky, because there could be other
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
let index = 0;
|
||||
let lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, match => {
|
||||
if (match === '%%') {
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
if (match === '%c') {
|
||||
// We only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
|
||||
args.splice(lastC, 0, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `console.debug()` when available.
|
||||
* No-op when `console.debug` is not a "function".
|
||||
* If `console.debug` is not available, falls back
|
||||
* to `console.log`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
exports.log = console.debug || console.log || (() => {});
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
try {
|
||||
if (namespaces) {
|
||||
exports.storage.setItem('debug', namespaces);
|
||||
} else {
|
||||
exports.storage.removeItem('debug');
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
function load() {
|
||||
let r;
|
||||
try {
|
||||
r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG') ;
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
|
||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
||||
r = process.env.DEBUG;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Localstorage attempts to return the localstorage.
|
||||
*
|
||||
* This is necessary because safari throws
|
||||
* when a user disables cookies/localstorage
|
||||
* and you attempt to access it.
|
||||
*
|
||||
* @return {LocalStorage}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function localstorage() {
|
||||
try {
|
||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
||||
// The Browser also has localStorage in the global context.
|
||||
return localStorage;
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||||
*/
|
||||
|
||||
formatters.j = function (v) {
|
||||
try {
|
||||
return JSON.stringify(v);
|
||||
} catch (error) {
|
||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
||||
}
|
||||
};
|
||||
292
node_modules/@kwsites/file-exists/node_modules/debug/src/common.js
generated
vendored
Normal file
292
node_modules/@kwsites/file-exists/node_modules/debug/src/common.js
generated
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
|
||||
/**
|
||||
* This is the common logic for both the Node.js and web browser
|
||||
* implementations of `debug()`.
|
||||
*/
|
||||
|
||||
function setup(env) {
|
||||
createDebug.debug = createDebug;
|
||||
createDebug.default = createDebug;
|
||||
createDebug.coerce = coerce;
|
||||
createDebug.disable = disable;
|
||||
createDebug.enable = enable;
|
||||
createDebug.enabled = enabled;
|
||||
createDebug.humanize = require('ms');
|
||||
createDebug.destroy = destroy;
|
||||
|
||||
Object.keys(env).forEach(key => {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
/**
|
||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||||
*
|
||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
||||
*/
|
||||
createDebug.formatters = {};
|
||||
|
||||
/**
|
||||
* Selects a color for a debug namespace
|
||||
* @param {String} namespace The namespace string for the debug instance to be colored
|
||||
* @return {Number|String} An ANSI color code for the given namespace
|
||||
* @api private
|
||||
*/
|
||||
function selectColor(namespace) {
|
||||
let hash = 0;
|
||||
|
||||
for (let i = 0; i < namespace.length; i++) {
|
||||
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
||||
}
|
||||
createDebug.selectColor = selectColor;
|
||||
|
||||
/**
|
||||
* Create a debugger with the given `namespace`.
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
function createDebug(namespace) {
|
||||
let prevTime;
|
||||
let enableOverride = null;
|
||||
let namespacesCache;
|
||||
let enabledCache;
|
||||
|
||||
function debug(...args) {
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = debug;
|
||||
|
||||
// Set `diff` timestamp
|
||||
const curr = Number(new Date());
|
||||
const ms = curr - (prevTime || curr);
|
||||
self.diff = ms;
|
||||
self.prev = prevTime;
|
||||
self.curr = curr;
|
||||
prevTime = curr;
|
||||
|
||||
args[0] = createDebug.coerce(args[0]);
|
||||
|
||||
if (typeof args[0] !== 'string') {
|
||||
// Anything else let's inspect with %O
|
||||
args.unshift('%O');
|
||||
}
|
||||
|
||||
// Apply any `formatters` transformations
|
||||
let index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return '%';
|
||||
}
|
||||
index++;
|
||||
const formatter = createDebug.formatters[format];
|
||||
if (typeof formatter === 'function') {
|
||||
const val = args[index];
|
||||
match = formatter.call(self, val);
|
||||
|
||||
// Now we need to remove `args[index]` since it's inlined in the `format`
|
||||
args.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
// Apply env-specific formatting (colors, etc.)
|
||||
createDebug.formatArgs.call(self, args);
|
||||
|
||||
const logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = createDebug.selectColor(namespace);
|
||||
debug.extend = extend;
|
||||
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
||||
|
||||
Object.defineProperty(debug, 'enabled', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => {
|
||||
if (enableOverride !== null) {
|
||||
return enableOverride;
|
||||
}
|
||||
if (namespacesCache !== createDebug.namespaces) {
|
||||
namespacesCache = createDebug.namespaces;
|
||||
enabledCache = createDebug.enabled(namespace);
|
||||
}
|
||||
|
||||
return enabledCache;
|
||||
},
|
||||
set: v => {
|
||||
enableOverride = v;
|
||||
}
|
||||
});
|
||||
|
||||
// Env-specific initialization logic for debug instances
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
newDebug.log = this.log;
|
||||
return newDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a debug mode by namespaces. This can include modes
|
||||
* separated by a colon and wildcards.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function enable(namespaces) {
|
||||
createDebug.save(namespaces);
|
||||
createDebug.namespaces = namespaces;
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
const split = (typeof namespaces === 'string' ? namespaces : '')
|
||||
.trim()
|
||||
.replace(/\s+/g, ',')
|
||||
.split(',')
|
||||
.filter(Boolean);
|
||||
|
||||
for (const ns of split) {
|
||||
if (ns[0] === '-') {
|
||||
createDebug.skips.push(ns.slice(1));
|
||||
} else {
|
||||
createDebug.names.push(ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given string matches a namespace template, honoring
|
||||
* asterisks as wildcards.
|
||||
*
|
||||
* @param {String} search
|
||||
* @param {String} template
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function matchesTemplate(search, template) {
|
||||
let searchIndex = 0;
|
||||
let templateIndex = 0;
|
||||
let starIndex = -1;
|
||||
let matchIndex = 0;
|
||||
|
||||
while (searchIndex < search.length) {
|
||||
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
|
||||
// Match character or proceed with wildcard
|
||||
if (template[templateIndex] === '*') {
|
||||
starIndex = templateIndex;
|
||||
matchIndex = searchIndex;
|
||||
templateIndex++; // Skip the '*'
|
||||
} else {
|
||||
searchIndex++;
|
||||
templateIndex++;
|
||||
}
|
||||
} else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
|
||||
// Backtrack to the last '*' and try to match more characters
|
||||
templateIndex = starIndex + 1;
|
||||
matchIndex++;
|
||||
searchIndex = matchIndex;
|
||||
} else {
|
||||
return false; // No match
|
||||
}
|
||||
}
|
||||
|
||||
// Handle trailing '*' in template
|
||||
while (templateIndex < template.length && template[templateIndex] === '*') {
|
||||
templateIndex++;
|
||||
}
|
||||
|
||||
return templateIndex === template.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @return {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function disable() {
|
||||
const namespaces = [
|
||||
...createDebug.names,
|
||||
...createDebug.skips.map(namespace => '-' + namespace)
|
||||
].join(',');
|
||||
createDebug.enable('');
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given mode name is enabled, false otherwise.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
function enabled(name) {
|
||||
for (const skip of createDebug.skips) {
|
||||
if (matchesTemplate(name, skip)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const ns of createDebug.names) {
|
||||
if (matchesTemplate(name, ns)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* XXX DO NOT USE. This is a temporary stub function.
|
||||
* XXX It WILL be removed in the next major release.
|
||||
*/
|
||||
function destroy() {
|
||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
10
node_modules/@kwsites/file-exists/node_modules/debug/src/index.js
generated
vendored
Normal file
10
node_modules/@kwsites/file-exists/node_modules/debug/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Detect Electron renderer / nwjs process, which is node, but we should
|
||||
* treat as a browser.
|
||||
*/
|
||||
|
||||
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
||||
module.exports = require('./browser.js');
|
||||
} else {
|
||||
module.exports = require('./node.js');
|
||||
}
|
||||
263
node_modules/@kwsites/file-exists/node_modules/debug/src/node.js
generated
vendored
Normal file
263
node_modules/@kwsites/file-exists/node_modules/debug/src/node.js
generated
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const tty = require('tty');
|
||||
const util = require('util');
|
||||
|
||||
/**
|
||||
* This is the Node.js implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.init = init;
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.destroy = util.deprecate(
|
||||
() => {},
|
||||
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
||||
);
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [6, 2, 3, 4, 5, 1];
|
||||
|
||||
try {
|
||||
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const supportsColor = require('supports-color');
|
||||
|
||||
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
||||
exports.colors = [
|
||||
20,
|
||||
21,
|
||||
26,
|
||||
27,
|
||||
32,
|
||||
33,
|
||||
38,
|
||||
39,
|
||||
40,
|
||||
41,
|
||||
42,
|
||||
43,
|
||||
44,
|
||||
45,
|
||||
56,
|
||||
57,
|
||||
62,
|
||||
63,
|
||||
68,
|
||||
69,
|
||||
74,
|
||||
75,
|
||||
76,
|
||||
77,
|
||||
78,
|
||||
79,
|
||||
80,
|
||||
81,
|
||||
92,
|
||||
93,
|
||||
98,
|
||||
99,
|
||||
112,
|
||||
113,
|
||||
128,
|
||||
129,
|
||||
134,
|
||||
135,
|
||||
148,
|
||||
149,
|
||||
160,
|
||||
161,
|
||||
162,
|
||||
163,
|
||||
164,
|
||||
165,
|
||||
166,
|
||||
167,
|
||||
168,
|
||||
169,
|
||||
170,
|
||||
171,
|
||||
172,
|
||||
173,
|
||||
178,
|
||||
179,
|
||||
184,
|
||||
185,
|
||||
196,
|
||||
197,
|
||||
198,
|
||||
199,
|
||||
200,
|
||||
201,
|
||||
202,
|
||||
203,
|
||||
204,
|
||||
205,
|
||||
206,
|
||||
207,
|
||||
208,
|
||||
209,
|
||||
214,
|
||||
215,
|
||||
220,
|
||||
221
|
||||
];
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
||||
}
|
||||
|
||||
/**
|
||||
* Build up the default `inspectOpts` object from the environment variables.
|
||||
*
|
||||
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
||||
*/
|
||||
|
||||
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
||||
return /^debug_/i.test(key);
|
||||
}).reduce((obj, key) => {
|
||||
// Camel-case
|
||||
const prop = key
|
||||
.substring(6)
|
||||
.toLowerCase()
|
||||
.replace(/_([a-z])/g, (_, k) => {
|
||||
return k.toUpperCase();
|
||||
});
|
||||
|
||||
// Coerce string value into JS value
|
||||
let val = process.env[key];
|
||||
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
||||
val = true;
|
||||
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
||||
val = false;
|
||||
} else if (val === 'null') {
|
||||
val = null;
|
||||
} else {
|
||||
val = Number(val);
|
||||
}
|
||||
|
||||
obj[prop] = val;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
/**
|
||||
* Is stdout a TTY? Colored output is enabled when `true`.
|
||||
*/
|
||||
|
||||
function useColors() {
|
||||
return 'colors' in exports.inspectOpts ?
|
||||
Boolean(exports.inspectOpts.colors) :
|
||||
tty.isatty(process.stderr.fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds ANSI color escape codes if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
const {namespace: name, useColors} = this;
|
||||
|
||||
if (useColors) {
|
||||
const c = this.color;
|
||||
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
||||
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
||||
|
||||
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
||||
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
||||
} else {
|
||||
args[0] = getDate() + name + ' ' + args[0];
|
||||
}
|
||||
}
|
||||
|
||||
function getDate() {
|
||||
if (exports.inspectOpts.hideDate) {
|
||||
return '';
|
||||
}
|
||||
return new Date().toISOString() + ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
|
||||
*/
|
||||
|
||||
function log(...args) {
|
||||
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
if (namespaces) {
|
||||
process.env.DEBUG = namespaces;
|
||||
} else {
|
||||
// If you set a process.env field to null or undefined, it gets cast to the
|
||||
// string 'null' or 'undefined'. Just delete instead.
|
||||
delete process.env.DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function load() {
|
||||
return process.env.DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init logic for `debug` instances.
|
||||
*
|
||||
* Create a new `inspectOpts` object in case `useColors` is set
|
||||
* differently for a particular `debug` instance.
|
||||
*/
|
||||
|
||||
function init(debug) {
|
||||
debug.inspectOpts = {};
|
||||
|
||||
const keys = Object.keys(exports.inspectOpts);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %o to `util.inspect()`, all on a single line.
|
||||
*/
|
||||
|
||||
formatters.o = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts)
|
||||
.split('\n')
|
||||
.map(str => str.trim())
|
||||
.join(' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
||||
*/
|
||||
|
||||
formatters.O = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts);
|
||||
};
|
||||
162
node_modules/@kwsites/file-exists/node_modules/ms/index.js
generated
vendored
Normal file
162
node_modules/@kwsites/file-exists/node_modules/ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function (val, options) {
|
||||
options = options || {};
|
||||
var type = typeof val;
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isFinite(val)) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
throw new Error(
|
||||
'val is not a non-empty string or a valid number. val=' +
|
||||
JSON.stringify(val)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
||||
str
|
||||
);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
return ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
21
node_modules/@kwsites/file-exists/node_modules/ms/license.md
generated
vendored
Normal file
21
node_modules/@kwsites/file-exists/node_modules/ms/license.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Vercel, Inc.
|
||||
|
||||
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.
|
||||
38
node_modules/@kwsites/file-exists/node_modules/ms/package.json
generated
vendored
Normal file
38
node_modules/@kwsites/file-exists/node_modules/ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "ms",
|
||||
"version": "2.1.3",
|
||||
"description": "Tiny millisecond conversion utility",
|
||||
"repository": "vercel/ms",
|
||||
"main": "./index",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"precommit": "lint-staged",
|
||||
"lint": "eslint lib/* bin/*",
|
||||
"test": "mocha tests.js"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"prettier --single-quote --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"eslint": "4.18.2",
|
||||
"expect.js": "0.3.1",
|
||||
"husky": "0.14.3",
|
||||
"lint-staged": "5.0.0",
|
||||
"mocha": "4.0.1",
|
||||
"prettier": "2.0.5"
|
||||
}
|
||||
}
|
||||
59
node_modules/@kwsites/file-exists/node_modules/ms/readme.md
generated
vendored
Normal file
59
node_modules/@kwsites/file-exists/node_modules/ms/readme.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# ms
|
||||
|
||||

|
||||
|
||||
Use this package to easily convert various time formats to milliseconds.
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
ms('10h') // 36000000
|
||||
ms('2.5 hrs') // 9000000
|
||||
ms('2h') // 7200000
|
||||
ms('1m') // 60000
|
||||
ms('5s') // 5000
|
||||
ms('1y') // 31557600000
|
||||
ms('100') // 100
|
||||
ms('-3 days') // -259200000
|
||||
ms('-1h') // -3600000
|
||||
ms('-200') // -200
|
||||
```
|
||||
|
||||
### Convert from Milliseconds
|
||||
|
||||
```js
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(-3 * 60000) // "-3m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
```
|
||||
|
||||
### Time Format Written-Out
|
||||
|
||||
```js
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(-3 * 60000, { long: true }) // "-3 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Works both in [Node.js](https://nodejs.org) and in the browser
|
||||
- If a number is supplied to `ms`, a string with a unit is returned
|
||||
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
|
||||
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
|
||||
|
||||
## Related Packages
|
||||
|
||||
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
|
||||
|
||||
## Caught a Bug?
|
||||
|
||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
|
||||
2. Link the package to the global module directory: `npm link`
|
||||
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
|
||||
|
||||
As always, you can run the tests using: `npm test`
|
||||
42
node_modules/@kwsites/file-exists/package.json
generated
vendored
Normal file
42
node_modules/@kwsites/file-exists/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@kwsites/file-exists",
|
||||
"version": "1.1.1",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
"repository": "git@github.com:kwsites/file-exists.git",
|
||||
"author": "Steve King <steve@mydev.co>",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Steve King",
|
||||
"email": "steve@mydev.co"
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"dist/**/*.*"
|
||||
],
|
||||
"scripts": {
|
||||
"clean": "rimraf ./dist",
|
||||
"build": "yarn run clean && tsc",
|
||||
"preversion": "yarn run clean && yarn run build && yarn test",
|
||||
"postversion": "npm publish --access=public && git push && git push --tags",
|
||||
"test": "jest --coverage",
|
||||
"tsc": "tsc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.1",
|
||||
"@babel/preset-env": "^7.10.1",
|
||||
"@babel/preset-typescript": "^7.10.1",
|
||||
"@types/debug": "^4.1.5",
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/node": "^10.12.0",
|
||||
"babel-jest": "^26.0.1",
|
||||
"jest": "^25.3.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"ts-node": "^8.10.2",
|
||||
"typescript": "^3.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
}
|
||||
41
node_modules/@kwsites/file-exists/readme.md
generated
vendored
Normal file
41
node_modules/@kwsites/file-exists/readme.md
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# @kwsites/file-exists
|
||||
|
||||
Synchronous validation of a path existing either as a file or as a directory.
|
||||
|
||||
```
|
||||
const { exists, FILE, FOLDER, READABLE } = require('@kwsites/file-exists');
|
||||
|
||||
// check for a folder existing
|
||||
assert(exists(__dirname, FOLDER));
|
||||
assert(!exists(__filename, FOLDER));
|
||||
|
||||
// check for a file existing
|
||||
assert(!exists(__filename, FILE));
|
||||
assert(exists(__filename, FILE));
|
||||
|
||||
// when no type is specified, both folders and files are allowed
|
||||
assert(exists(__dirname));
|
||||
assert(exists(__filename));
|
||||
|
||||
// alternatively specify both files and folders
|
||||
assert(exists(__dirname, FILE + FOLDER));
|
||||
|
||||
// or just that the path is readable (can be either a file or folder)
|
||||
assert(exists(__filename, READABLE));
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
This library uses [debug](https://www.npmjs.com/package/debug) to handle logging,
|
||||
to enable logging, use either the environment variable:
|
||||
|
||||
```
|
||||
"DEBUG=@kwsites/file-exists" node ./your-app.js
|
||||
```
|
||||
|
||||
Or explicitly enable logging using the `debug` library itself:
|
||||
|
||||
```javascript
|
||||
require('debug').enable('@kwsites/file-exists');
|
||||
```
|
||||
|
||||
21
node_modules/@kwsites/promise-deferred/LICENSE
generated
vendored
Normal file
21
node_modules/@kwsites/promise-deferred/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 kwsites
|
||||
|
||||
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.
|
||||
49
node_modules/@kwsites/promise-deferred/dist/index.d.ts
generated
vendored
Normal file
49
node_modules/@kwsites/promise-deferred/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* The `DeferredPromise` has a `promise` property in an initially pending state,
|
||||
* that will be resolved when the `done` method is called or rejected when the
|
||||
* `fail` method is called.
|
||||
*/
|
||||
export interface DeferredPromise<RESOLVES, REJECTS extends Error = Error> {
|
||||
done(result: RESOLVES): void;
|
||||
fail(error: REJECTS): void;
|
||||
readonly status: DeferredPromiseStatus;
|
||||
readonly fulfilled: boolean;
|
||||
promise: Promise<RESOLVES>;
|
||||
}
|
||||
/**
|
||||
* The three states the DeferredPromise can be in - initially pending then either
|
||||
* resolved or rejected when it is fulfilled.
|
||||
*
|
||||
* ```typescript
|
||||
import {createDeferred, DeferredPromiseStatus} from '@kwsites/promise-deferred`;
|
||||
|
||||
const pending: DeferredPromiseStatus = 'pending';
|
||||
expect(createDeferred()).toHaveProperty('status', pending);
|
||||
```
|
||||
*/
|
||||
export declare type DeferredPromiseStatus = 'pending' | 'resolved' | 'rejected';
|
||||
/**
|
||||
* Creates a new `DeferredPromise`
|
||||
*
|
||||
* ```typescript
|
||||
import {deferred} from '@kwsites/promise-deferred`;
|
||||
```
|
||||
*/
|
||||
export declare function deferred<T extends any = void, E extends Error = Error>(): DeferredPromise<T, E>;
|
||||
/**
|
||||
* Alias of the exported `deferred` function, to help consumers wanting to use `deferred` as the
|
||||
* local variable name rather than the factory import name, without needing to rename on import.
|
||||
*
|
||||
* ```typescript
|
||||
import {createDeferred} from '@kwsites/promise-deferred`;
|
||||
```
|
||||
*/
|
||||
export declare const createDeferred: typeof deferred;
|
||||
/**
|
||||
* Default export allows use as:
|
||||
*
|
||||
* ```typescript
|
||||
import deferred from '@kwsites/promise-deferred`;
|
||||
```
|
||||
*/
|
||||
export default deferred;
|
||||
59
node_modules/@kwsites/promise-deferred/dist/index.js
generated
vendored
Normal file
59
node_modules/@kwsites/promise-deferred/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createDeferred = exports.deferred = void 0;
|
||||
/**
|
||||
* Creates a new `DeferredPromise`
|
||||
*
|
||||
* ```typescript
|
||||
import {deferred} from '@kwsites/promise-deferred`;
|
||||
```
|
||||
*/
|
||||
function deferred() {
|
||||
let done;
|
||||
let fail;
|
||||
let status = 'pending';
|
||||
const promise = new Promise((_done, _fail) => {
|
||||
done = _done;
|
||||
fail = _fail;
|
||||
});
|
||||
return {
|
||||
promise,
|
||||
done(result) {
|
||||
if (status === 'pending') {
|
||||
status = 'resolved';
|
||||
done(result);
|
||||
}
|
||||
},
|
||||
fail(error) {
|
||||
if (status === 'pending') {
|
||||
status = 'rejected';
|
||||
fail(error);
|
||||
}
|
||||
},
|
||||
get fulfilled() {
|
||||
return status !== 'pending';
|
||||
},
|
||||
get status() {
|
||||
return status;
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.deferred = deferred;
|
||||
/**
|
||||
* Alias of the exported `deferred` function, to help consumers wanting to use `deferred` as the
|
||||
* local variable name rather than the factory import name, without needing to rename on import.
|
||||
*
|
||||
* ```typescript
|
||||
import {createDeferred} from '@kwsites/promise-deferred`;
|
||||
```
|
||||
*/
|
||||
exports.createDeferred = deferred;
|
||||
/**
|
||||
* Default export allows use as:
|
||||
*
|
||||
* ```typescript
|
||||
import deferred from '@kwsites/promise-deferred`;
|
||||
```
|
||||
*/
|
||||
exports.default = deferred;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kwsites/promise-deferred/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@kwsites/promise-deferred/dist/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA0BA;;;;;;GAMG;AACH,SAAgB,QAAQ;IACrB,IAAI,IAAyB,CAAC;IAC9B,IAAI,IAAwB,CAAC;IAC7B,IAAI,MAAM,GAA0B,SAAS,CAAC;IAE9C,MAAM,OAAO,GAAe,IAAI,OAAO,CAAI,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACzD,IAAI,GAAG,KAAK,CAAC;QACb,IAAI,GAAG,KAAK,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,OAAO;QACJ,OAAO;QACP,IAAI,CAAE,MAAM;YACT,IAAI,MAAM,KAAK,SAAS,EAAE;gBACvB,MAAM,GAAG,UAAU,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC,CAAC;aACf;QACJ,CAAC;QACD,IAAI,CAAE,KAAK;YACR,IAAI,MAAM,KAAK,SAAS,EAAE;gBACvB,MAAM,GAAG,UAAU,CAAC;gBACpB,IAAI,CAAC,KAAK,CAAC,CAAC;aACd;QACJ,CAAC;QACD,IAAI,SAAS;YACV,OAAO,MAAM,KAAK,SAAS,CAAC;QAC/B,CAAC;QACD,IAAI,MAAM;YACP,OAAO,MAAM,CAAC;QACjB,CAAC;KACH,CAAC;AACL,CAAC;AA/BD,4BA+BC;AAED;;;;;;;GAOG;AACU,QAAA,cAAc,GAAG,QAAQ,CAAC;AAEvC;;;;;;GAMG;AACH,kBAAe,QAAQ,CAAC"}
|
||||
43
node_modules/@kwsites/promise-deferred/package.json
generated
vendored
Normal file
43
node_modules/@kwsites/promise-deferred/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@kwsites/promise-deferred",
|
||||
"description": "Minimalist creation of promise wrappers, exposing the ability to resolve or reject the inner promise",
|
||||
"version": "1.1.1",
|
||||
"private": false,
|
||||
"author": "Steve King <steve@mydev.co>",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Steve King",
|
||||
"email": "steve@mydev.co"
|
||||
}
|
||||
],
|
||||
"main": "./dist/index",
|
||||
"types": "./dist/index",
|
||||
"license": "MIT",
|
||||
"repository": "git://github.com/kwsites/promise-deferred.git",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.3",
|
||||
"@babel/preset-env": "^7.10.3",
|
||||
"@babel/preset-typescript": "^7.10.1",
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/node": "^14.0.13",
|
||||
"babel-jest": "^26.1.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"jest": "^26.1.0",
|
||||
"ts-node": "^8.10.2",
|
||||
"typescript": "^3.9.5"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"dist/**/*.*"
|
||||
],
|
||||
"scripts": {
|
||||
"clean": "git clean -fxd -e .idea -e node_modules",
|
||||
"clean:modules": "git clean -fxd node_modules",
|
||||
"build": "tsc --build",
|
||||
"build:clean": "yarn run clean && tsc",
|
||||
"preversion": "yarn run build:clean && yarn test",
|
||||
"postversion": "npm publish --access=public && git push && git push --tags",
|
||||
"test": "jest --coverage",
|
||||
"tsc": "tsc"
|
||||
}
|
||||
}
|
||||
21
node_modules/@node-llama-cpp/win-arm64/LICENSE
generated
vendored
Normal file
21
node_modules/@node-llama-cpp/win-arm64/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Gilad S.
|
||||
|
||||
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.
|
||||
4
node_modules/@node-llama-cpp/win-arm64/README.md
generated
vendored
Normal file
4
node_modules/@node-llama-cpp/win-arm64/README.md
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# [`node-llama-cpp`](https://github.com/withcatai/node-llama-cpp)
|
||||
This is a prebuilt binary package for [`node-llama-cpp`](https://github.com/withcatai/node-llama-cpp) for Windows arm64.
|
||||
|
||||
Do not install this package directly.
|
||||
1
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/_nlcBuildMetadata.json
generated
vendored
Normal file
1
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/_nlcBuildMetadata.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"arm64","gpu":false,"llamaCpp":{"repo":"ggml-org/llama.cpp","release":"b7836"}}}
|
||||
BIN
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/ggml-base.dll
generated
vendored
Normal file
BIN
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/ggml-base.dll
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/ggml-cpu.dll
generated
vendored
Normal file
BIN
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/ggml-cpu.dll
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/ggml.b7836.dll
generated
vendored
Normal file
BIN
node_modules/@node-llama-cpp/win-arm64/bins/win-arm64/ggml.b7836.dll
generated
vendored
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user