mirror of
https://github.com/Dvorinka/ClubLogos.git
synced 2026-06-03 19:42:58 +00:00
fff
This commit is contained in:
+16
@@ -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/../nodemon/bin/nodemon.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../nodemon/bin/nodemon.js" "$@"
|
||||
fi
|
||||
+17
@@ -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%\..\nodemon\bin\nodemon.js" %*
|
||||
+28
@@ -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/../nodemon/bin/nodemon.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../nodemon/bin/nodemon.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../nodemon/bin/nodemon.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../nodemon/bin/nodemon.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+16
@@ -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/../touch/bin/nodetouch.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../touch/bin/nodetouch.js" "$@"
|
||||
fi
|
||||
+17
@@ -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%\..\touch\bin\nodetouch.js" %*
|
||||
+28
@@ -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/../touch/bin/nodetouch.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../touch/bin/nodetouch.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../touch/bin/nodetouch.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../touch/bin/nodetouch.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+16
@@ -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/../prebuild-install/bin.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../prebuild-install/bin.js" "$@"
|
||||
fi
|
||||
+17
@@ -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%\..\prebuild-install\bin.js" %*
|
||||
+28
@@ -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/../prebuild-install/bin.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../prebuild-install/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../prebuild-install/bin.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../prebuild-install/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+16
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
+16
@@ -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/../svgo/bin/svgo" "$@"
|
||||
else
|
||||
exec node "$basedir/../svgo/bin/svgo" "$@"
|
||||
fi
|
||||
+17
@@ -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%\..\svgo\bin\svgo" %*
|
||||
+28
@@ -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/../svgo/bin/svgo" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../svgo/bin/svgo" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../svgo/bin/svgo" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../svgo/bin/svgo" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+1333
File diff suppressed because it is too large
Load Diff
+15
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
# svg/sax
|
||||
|
||||
A maintained fork of [sax-js](https://github.com/isaacs/sax-js) sax-style parser for XML and HTML.
|
||||
|
||||
Designed with [node](http://nodejs.org/) in mind, but should work fine in
|
||||
the browser or other CommonJS implementations.
|
||||
|
||||
## What This Is
|
||||
|
||||
* A very simple tool to parse through an XML string.
|
||||
* A stepping stone to a streaming HTML parser.
|
||||
* A handy way to deal with RSS and other mostly-ok-but-kinda-broken XML
|
||||
docs.
|
||||
|
||||
## What This Is (probably) Not
|
||||
|
||||
* An HTML Parser - That's a fine goal, but this isn't it. It's just
|
||||
XML.
|
||||
* A DOM Builder - You can use it to build an object model out of XML,
|
||||
but it doesn't do that out of the box.
|
||||
* XSLT - No DOM = no querying.
|
||||
* 100% Compliant with (some other SAX implementation) - Most SAX
|
||||
implementations are in Java and do a lot more than this does.
|
||||
* An XML Validator - It does a little validation when in strict mode, but
|
||||
not much.
|
||||
* A Schema-Aware XSD Thing - Schemas are an exercise in fetishistic
|
||||
masochism.
|
||||
* A DTD-aware Thing - Fetching DTDs is a much bigger job.
|
||||
|
||||
## Regarding `<!DOCTYPE`s and `<!ENTITY`s
|
||||
|
||||
The parser will handle the basic XML entities in text nodes and attribute
|
||||
values: `& < > ' "`. It's possible to define additional
|
||||
entities in XML by putting them in the DTD. This parser doesn't do anything
|
||||
with that. If you want to listen to the `ondoctype` event, and then fetch
|
||||
the doctypes, and read the entities and add them to `parser.ENTITIES`, then
|
||||
be my guest.
|
||||
|
||||
Unknown entities will fail in strict mode, and in loose mode, will pass
|
||||
through unmolested.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var sax = require("./lib/sax"),
|
||||
strict = true, // set to false for html-mode
|
||||
parser = sax.parser(strict);
|
||||
|
||||
parser.onerror = function (e) {
|
||||
// an error happened.
|
||||
};
|
||||
parser.ontext = function (t) {
|
||||
// got some text. t is the string of text.
|
||||
};
|
||||
parser.onopentag = function (node) {
|
||||
// opened a tag. node has "name" and "attributes"
|
||||
};
|
||||
parser.onattribute = function (attr) {
|
||||
// an attribute. attr has "name" and "value"
|
||||
};
|
||||
parser.onend = function () {
|
||||
// parser stream is done, and ready to have more stuff written to it.
|
||||
};
|
||||
|
||||
parser.write('<xml>Hello, <who name="world">world</who>!</xml>').close();
|
||||
```
|
||||
|
||||
|
||||
## Arguments
|
||||
|
||||
Pass the following arguments to the parser function. All are optional.
|
||||
|
||||
`strict` - Boolean. Whether or not to be a jerk. Default: `false`.
|
||||
|
||||
`opt` - Object bag of settings regarding string formatting. All default to `false`.
|
||||
|
||||
Settings supported:
|
||||
|
||||
* `trim` - Boolean. Whether or not to trim text and comment nodes.
|
||||
* `normalize` - Boolean. If true, then turn any whitespace into a single
|
||||
space.
|
||||
* `lowercase` - Boolean. If true, then lowercase tag names and attribute names
|
||||
in loose mode, rather than uppercasing them.
|
||||
* `xmlns` - Boolean. If true, then namespaces are supported.
|
||||
* `position` - Boolean. If false, then don't track line/col/position.
|
||||
* `strictEntities` - Boolean. If true, only parse [predefined XML
|
||||
entities](http://www.w3.org/TR/REC-xml/#sec-predefined-ent)
|
||||
(`&`, `'`, `>`, `<`, and `"`)
|
||||
|
||||
## Methods
|
||||
|
||||
`write` - Write bytes onto the stream. You don't have to do this all at
|
||||
once. You can keep writing as much as you want.
|
||||
|
||||
`close` - Close the stream. Once closed, no more data may be written until
|
||||
it is done processing the buffer, which is signaled by the `end` event.
|
||||
|
||||
`resume` - To gracefully handle errors, assign a listener to the `error`
|
||||
event. Then, when the error is taken care of, you can call `resume` to
|
||||
continue parsing. Otherwise, the parser will not continue while in an error
|
||||
state.
|
||||
|
||||
## Members
|
||||
|
||||
At all times, the parser object will have the following members:
|
||||
|
||||
`line`, `column`, `position` - Indications of the position in the XML
|
||||
document where the parser currently is looking.
|
||||
|
||||
`startTagPosition` - Indicates the position where the current tag starts.
|
||||
|
||||
`closed` - Boolean indicating whether or not the parser can be written to.
|
||||
If it's `true`, then wait for the `ready` event to write again.
|
||||
|
||||
`strict` - Boolean indicating whether or not the parser is a jerk.
|
||||
|
||||
`opt` - Any options passed into the constructor.
|
||||
|
||||
`tag` - The current tag being dealt with.
|
||||
|
||||
And a bunch of other stuff that you probably shouldn't touch.
|
||||
|
||||
## Events
|
||||
|
||||
All events emit with a single argument. To listen to an event, assign a
|
||||
function to `on<eventname>`. Functions get executed in the this-context of
|
||||
the parser object. The list of supported events are also in the exported
|
||||
`EVENTS` array.
|
||||
|
||||
`error` - Indication that something bad happened. The error will be hanging
|
||||
out on `parser.error`, and must be deleted before parsing can continue. By
|
||||
listening to this event, you can keep an eye on that kind of stuff. Note:
|
||||
this happens *much* more in strict mode. Argument: instance of `Error`.
|
||||
|
||||
`text` - Text node. Argument: string of text.
|
||||
|
||||
`doctype` - The `<!DOCTYPE` declaration. Argument: doctype string.
|
||||
|
||||
`processinginstruction` - Stuff like `<?xml foo="blerg" ?>`. Argument:
|
||||
object with `name` and `body` members. Attributes are not parsed, as
|
||||
processing instructions have implementation dependent semantics.
|
||||
|
||||
`sgmldeclaration` - Random SGML declarations. Stuff like `<!ENTITY p>`
|
||||
would trigger this kind of event. This is a weird thing to support, so it
|
||||
might go away at some point. SAX isn't intended to be used to parse SGML,
|
||||
after all.
|
||||
|
||||
`opentagstart` - Emitted immediately when the tag name is available,
|
||||
but before any attributes are encountered. Argument: object with a
|
||||
`name` field and an empty `attributes` set. Note that this is the
|
||||
same object that will later be emitted in the `opentag` event.
|
||||
|
||||
`opentag` - An opening tag. Argument: object with `name` and `attributes`.
|
||||
In non-strict mode, tag names are uppercased, unless the `lowercase`
|
||||
option is set. If the `xmlns` option is set, then it will contain
|
||||
namespace binding information on the `ns` member, and will have a
|
||||
`local`, `prefix`, and `uri` member.
|
||||
|
||||
`closetag` - A closing tag. In loose mode, tags are auto-closed if their
|
||||
parent closes. In strict mode, well-formedness is enforced. Note that
|
||||
self-closing tags will have `closeTag` emitted immediately after `openTag`.
|
||||
Argument: tag name.
|
||||
|
||||
`attribute` - An attribute node. Argument: object with `name` and `value`.
|
||||
In non-strict mode, attribute names are uppercased, unless the `lowercase`
|
||||
option is set. If the `xmlns` option is set, it will also contains namespace
|
||||
information.
|
||||
|
||||
`comment` - A comment node. Argument: the string of the comment.
|
||||
|
||||
`opencdata` - The opening tag of a `<![CDATA[` block.
|
||||
|
||||
`cdata` - The text of a `<![CDATA[` block. Since `<![CDATA[` blocks can get
|
||||
quite large, this event may fire multiple times for a single block, if it
|
||||
is broken up into multiple `write()`s. Argument: the string of random
|
||||
character data.
|
||||
|
||||
`closecdata` - The closing tag (`]]>`) of a `<![CDATA[` block.
|
||||
|
||||
`opennamespace` - If the `xmlns` option is set, then this event will
|
||||
signal the start of a new namespace binding.
|
||||
|
||||
`closenamespace` - If the `xmlns` option is set, then this event will
|
||||
signal the end of a namespace binding.
|
||||
|
||||
`end` - Indication that the closed stream has ended.
|
||||
|
||||
`ready` - Indication that the stream has reset, and is ready to be written
|
||||
to.
|
||||
|
||||
`noscript` - In non-strict mode, `<script>` tags trigger a `"script"`
|
||||
event, and their contents are not checked for special xml characters.
|
||||
If you pass `noscript: true`, then this behavior is suppressed.
|
||||
|
||||
## Reporting Problems
|
||||
|
||||
It's best to write a failing test if you find an issue. I will always
|
||||
accept pull requests with failing tests if they demonstrate intended
|
||||
behavior, but it is very hard to figure out what issue you're describing
|
||||
without a test. Writing a test is also the best way for you yourself
|
||||
to figure out if you really understand the issue you think you have with
|
||||
sax-js.
|
||||
+1413
File diff suppressed because it is too large
Load Diff
+30
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"name": "@trysound/sax",
|
||||
"description": "An evented streaming XML parser in JavaScript",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"repository": "git://github.com/svg/sax.git",
|
||||
"license": "ISC",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Bogdan Chadkin",
|
||||
"email": "trysound@yandex.ru",
|
||||
"url": "http://github.com/TrySound"
|
||||
}
|
||||
],
|
||||
"main": "lib/sax.js",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js --cov -j4",
|
||||
"lint": "standard -F test/*.js lib/*.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "^8.6.0",
|
||||
"tap": "^10.5.1"
|
||||
}
|
||||
}
|
||||
+345
@@ -0,0 +1,345 @@
|
||||
declare type CSSColor =
|
||||
| 'aliceblue'
|
||||
| 'antiquewhite'
|
||||
| 'aqua'
|
||||
| 'aquamarine'
|
||||
| 'azure'
|
||||
| 'beige'
|
||||
| 'bisque'
|
||||
| 'black'
|
||||
| 'blanchedalmond'
|
||||
| 'blue'
|
||||
| 'blueviolet'
|
||||
| 'brown'
|
||||
| 'burlywood'
|
||||
| 'cadetblue'
|
||||
| 'chartreuse'
|
||||
| 'chocolate'
|
||||
| 'coral'
|
||||
| 'cornflowerblue'
|
||||
| 'cornsilk'
|
||||
| 'crimson'
|
||||
| 'cyan'
|
||||
| 'darkblue'
|
||||
| 'darkcyan'
|
||||
| 'darkgoldenrod'
|
||||
| 'darkgray'
|
||||
| 'darkgreen'
|
||||
| 'darkgrey'
|
||||
| 'darkkhaki'
|
||||
| 'darkmagenta'
|
||||
| 'darkolivegreen'
|
||||
| 'darkorange'
|
||||
| 'darkorchid'
|
||||
| 'darkred'
|
||||
| 'darksalmon'
|
||||
| 'darkseagreen'
|
||||
| 'darkslateblue'
|
||||
| 'darkslategray'
|
||||
| 'darkslategrey'
|
||||
| 'darkturquoise'
|
||||
| 'darkviolet'
|
||||
| 'deeppink'
|
||||
| 'deepskyblue'
|
||||
| 'dimgray'
|
||||
| 'dimgrey'
|
||||
| 'dodgerblue'
|
||||
| 'firebrick'
|
||||
| 'floralwhite'
|
||||
| 'forestgreen'
|
||||
| 'fuchsia'
|
||||
| 'gainsboro'
|
||||
| 'ghostwhite'
|
||||
| 'gold'
|
||||
| 'goldenrod'
|
||||
| 'gray'
|
||||
| 'green'
|
||||
| 'greenyellow'
|
||||
| 'grey'
|
||||
| 'honeydew'
|
||||
| 'hotpink'
|
||||
| 'indianred'
|
||||
| 'indigo'
|
||||
| 'ivory'
|
||||
| 'khaki'
|
||||
| 'lavender'
|
||||
| 'lavenderblush'
|
||||
| 'lawngreen'
|
||||
| 'lemonchiffon'
|
||||
| 'lightblue'
|
||||
| 'lightcoral'
|
||||
| 'lightcyan'
|
||||
| 'lightgoldenrodyellow'
|
||||
| 'lightgray'
|
||||
| 'lightgreen'
|
||||
| 'lightgrey'
|
||||
| 'lightpink'
|
||||
| 'lightsalmon'
|
||||
| 'lightseagreen'
|
||||
| 'lightskyblue'
|
||||
| 'lightslategray'
|
||||
| 'lightslategrey'
|
||||
| 'lightsteelblue'
|
||||
| 'lightyellow'
|
||||
| 'lime'
|
||||
| 'limegreen'
|
||||
| 'linen'
|
||||
| 'magenta'
|
||||
| 'maroon'
|
||||
| 'mediumaquamarine'
|
||||
| 'mediumblue'
|
||||
| 'mediumorchid'
|
||||
| 'mediumpurple'
|
||||
| 'mediumseagreen'
|
||||
| 'mediumslateblue'
|
||||
| 'mediumspringgreen'
|
||||
| 'mediumturquoise'
|
||||
| 'mediumvioletred'
|
||||
| 'midnightblue'
|
||||
| 'mintcream'
|
||||
| 'mistyrose'
|
||||
| 'moccasin'
|
||||
| 'navajowhite'
|
||||
| 'navy'
|
||||
| 'oldlace'
|
||||
| 'olive'
|
||||
| 'olivedrab'
|
||||
| 'orange'
|
||||
| 'orangered'
|
||||
| 'orchid'
|
||||
| 'palegoldenrod'
|
||||
| 'palegreen'
|
||||
| 'paleturquoise'
|
||||
| 'palevioletred'
|
||||
| 'papayawhip'
|
||||
| 'peachpuff'
|
||||
| 'peru'
|
||||
| 'pink'
|
||||
| 'plum'
|
||||
| 'powderblue'
|
||||
| 'purple'
|
||||
| 'rebeccapurple'
|
||||
| 'red'
|
||||
| 'rosybrown'
|
||||
| 'royalblue'
|
||||
| 'saddlebrown'
|
||||
| 'salmon'
|
||||
| 'sandybrown'
|
||||
| 'seagreen'
|
||||
| 'seashell'
|
||||
| 'sienna'
|
||||
| 'silver'
|
||||
| 'skyblue'
|
||||
| 'slateblue'
|
||||
| 'slategray'
|
||||
| 'slategrey'
|
||||
| 'snow'
|
||||
| 'springgreen'
|
||||
| 'steelblue'
|
||||
| 'tan'
|
||||
| 'teal'
|
||||
| 'thistle'
|
||||
| 'tomato'
|
||||
| 'turquoise'
|
||||
| 'violet'
|
||||
| 'wheat'
|
||||
| 'white'
|
||||
| 'whitesmoke'
|
||||
| 'yellow'
|
||||
| 'yellowgreen';
|
||||
|
||||
declare namespace ansiStyles {
|
||||
interface ColorConvert {
|
||||
/**
|
||||
The RGB color space.
|
||||
|
||||
@param red - (`0`-`255`)
|
||||
@param green - (`0`-`255`)
|
||||
@param blue - (`0`-`255`)
|
||||
*/
|
||||
rgb(red: number, green: number, blue: number): string;
|
||||
|
||||
/**
|
||||
The RGB HEX color space.
|
||||
|
||||
@param hex - A hexadecimal string containing RGB data.
|
||||
*/
|
||||
hex(hex: string): string;
|
||||
|
||||
/**
|
||||
@param keyword - A CSS color name.
|
||||
*/
|
||||
keyword(keyword: CSSColor): string;
|
||||
|
||||
/**
|
||||
The HSL color space.
|
||||
|
||||
@param hue - (`0`-`360`)
|
||||
@param saturation - (`0`-`100`)
|
||||
@param lightness - (`0`-`100`)
|
||||
*/
|
||||
hsl(hue: number, saturation: number, lightness: number): string;
|
||||
|
||||
/**
|
||||
The HSV color space.
|
||||
|
||||
@param hue - (`0`-`360`)
|
||||
@param saturation - (`0`-`100`)
|
||||
@param value - (`0`-`100`)
|
||||
*/
|
||||
hsv(hue: number, saturation: number, value: number): string;
|
||||
|
||||
/**
|
||||
The HSV color space.
|
||||
|
||||
@param hue - (`0`-`360`)
|
||||
@param whiteness - (`0`-`100`)
|
||||
@param blackness - (`0`-`100`)
|
||||
*/
|
||||
hwb(hue: number, whiteness: number, blackness: number): string;
|
||||
|
||||
/**
|
||||
Use a [4-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4-bit) to set text color.
|
||||
*/
|
||||
ansi(ansi: number): string;
|
||||
|
||||
/**
|
||||
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
||||
*/
|
||||
ansi256(ansi: number): string;
|
||||
}
|
||||
|
||||
interface CSPair {
|
||||
/**
|
||||
The ANSI terminal control sequence for starting this style.
|
||||
*/
|
||||
readonly open: string;
|
||||
|
||||
/**
|
||||
The ANSI terminal control sequence for ending this style.
|
||||
*/
|
||||
readonly close: string;
|
||||
}
|
||||
|
||||
interface ColorBase {
|
||||
readonly ansi: ColorConvert;
|
||||
readonly ansi256: ColorConvert;
|
||||
readonly ansi16m: ColorConvert;
|
||||
|
||||
/**
|
||||
The ANSI terminal control sequence for ending this color.
|
||||
*/
|
||||
readonly close: string;
|
||||
}
|
||||
|
||||
interface Modifier {
|
||||
/**
|
||||
Resets the current color chain.
|
||||
*/
|
||||
readonly reset: CSPair;
|
||||
|
||||
/**
|
||||
Make text bold.
|
||||
*/
|
||||
readonly bold: CSPair;
|
||||
|
||||
/**
|
||||
Emitting only a small amount of light.
|
||||
*/
|
||||
readonly dim: CSPair;
|
||||
|
||||
/**
|
||||
Make text italic. (Not widely supported)
|
||||
*/
|
||||
readonly italic: CSPair;
|
||||
|
||||
/**
|
||||
Make text underline. (Not widely supported)
|
||||
*/
|
||||
readonly underline: CSPair;
|
||||
|
||||
/**
|
||||
Inverse background and foreground colors.
|
||||
*/
|
||||
readonly inverse: CSPair;
|
||||
|
||||
/**
|
||||
Prints the text, but makes it invisible.
|
||||
*/
|
||||
readonly hidden: CSPair;
|
||||
|
||||
/**
|
||||
Puts a horizontal line through the center of the text. (Not widely supported)
|
||||
*/
|
||||
readonly strikethrough: CSPair;
|
||||
}
|
||||
|
||||
interface ForegroundColor {
|
||||
readonly black: CSPair;
|
||||
readonly red: CSPair;
|
||||
readonly green: CSPair;
|
||||
readonly yellow: CSPair;
|
||||
readonly blue: CSPair;
|
||||
readonly cyan: CSPair;
|
||||
readonly magenta: CSPair;
|
||||
readonly white: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `blackBright`.
|
||||
*/
|
||||
readonly gray: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `blackBright`.
|
||||
*/
|
||||
readonly grey: CSPair;
|
||||
|
||||
readonly blackBright: CSPair;
|
||||
readonly redBright: CSPair;
|
||||
readonly greenBright: CSPair;
|
||||
readonly yellowBright: CSPair;
|
||||
readonly blueBright: CSPair;
|
||||
readonly cyanBright: CSPair;
|
||||
readonly magentaBright: CSPair;
|
||||
readonly whiteBright: CSPair;
|
||||
}
|
||||
|
||||
interface BackgroundColor {
|
||||
readonly bgBlack: CSPair;
|
||||
readonly bgRed: CSPair;
|
||||
readonly bgGreen: CSPair;
|
||||
readonly bgYellow: CSPair;
|
||||
readonly bgBlue: CSPair;
|
||||
readonly bgCyan: CSPair;
|
||||
readonly bgMagenta: CSPair;
|
||||
readonly bgWhite: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `bgBlackBright`.
|
||||
*/
|
||||
readonly bgGray: CSPair;
|
||||
|
||||
/**
|
||||
Alias for `bgBlackBright`.
|
||||
*/
|
||||
readonly bgGrey: CSPair;
|
||||
|
||||
readonly bgBlackBright: CSPair;
|
||||
readonly bgRedBright: CSPair;
|
||||
readonly bgGreenBright: CSPair;
|
||||
readonly bgYellowBright: CSPair;
|
||||
readonly bgBlueBright: CSPair;
|
||||
readonly bgCyanBright: CSPair;
|
||||
readonly bgMagentaBright: CSPair;
|
||||
readonly bgWhiteBright: CSPair;
|
||||
}
|
||||
}
|
||||
|
||||
declare const ansiStyles: {
|
||||
readonly modifier: ansiStyles.Modifier;
|
||||
readonly color: ansiStyles.ForegroundColor & ansiStyles.ColorBase;
|
||||
readonly bgColor: ansiStyles.BackgroundColor & ansiStyles.ColorBase;
|
||||
readonly codes: ReadonlyMap<number, number>;
|
||||
} & ansiStyles.BackgroundColor & ansiStyles.ForegroundColor & ansiStyles.Modifier;
|
||||
|
||||
export = ansiStyles;
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
'use strict';
|
||||
|
||||
const wrapAnsi16 = (fn, offset) => (...args) => {
|
||||
const code = fn(...args);
|
||||
return `\u001B[${code + offset}m`;
|
||||
};
|
||||
|
||||
const wrapAnsi256 = (fn, offset) => (...args) => {
|
||||
const code = fn(...args);
|
||||
return `\u001B[${38 + offset};5;${code}m`;
|
||||
};
|
||||
|
||||
const wrapAnsi16m = (fn, offset) => (...args) => {
|
||||
const rgb = fn(...args);
|
||||
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
||||
};
|
||||
|
||||
const ansi2ansi = n => n;
|
||||
const rgb2rgb = (r, g, b) => [r, g, b];
|
||||
|
||||
const setLazyProperty = (object, property, get) => {
|
||||
Object.defineProperty(object, property, {
|
||||
get: () => {
|
||||
const value = get();
|
||||
|
||||
Object.defineProperty(object, property, {
|
||||
value,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
return value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
};
|
||||
|
||||
/** @type {typeof import('color-convert')} */
|
||||
let colorConvert;
|
||||
const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
||||
if (colorConvert === undefined) {
|
||||
colorConvert = require('color-convert');
|
||||
}
|
||||
|
||||
const offset = isBackground ? 10 : 0;
|
||||
const styles = {};
|
||||
|
||||
for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
|
||||
const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
|
||||
if (sourceSpace === targetSpace) {
|
||||
styles[name] = wrap(identity, offset);
|
||||
} else if (typeof suite === 'object') {
|
||||
styles[name] = wrap(suite[targetSpace], offset);
|
||||
}
|
||||
}
|
||||
|
||||
return styles;
|
||||
};
|
||||
|
||||
function assembleStyles() {
|
||||
const codes = new Map();
|
||||
const styles = {
|
||||
modifier: {
|
||||
reset: [0, 0],
|
||||
// 21 isn't widely supported and 22 does the same thing
|
||||
bold: [1, 22],
|
||||
dim: [2, 22],
|
||||
italic: [3, 23],
|
||||
underline: [4, 24],
|
||||
inverse: [7, 27],
|
||||
hidden: [8, 28],
|
||||
strikethrough: [9, 29]
|
||||
},
|
||||
color: {
|
||||
black: [30, 39],
|
||||
red: [31, 39],
|
||||
green: [32, 39],
|
||||
yellow: [33, 39],
|
||||
blue: [34, 39],
|
||||
magenta: [35, 39],
|
||||
cyan: [36, 39],
|
||||
white: [37, 39],
|
||||
|
||||
// Bright color
|
||||
blackBright: [90, 39],
|
||||
redBright: [91, 39],
|
||||
greenBright: [92, 39],
|
||||
yellowBright: [93, 39],
|
||||
blueBright: [94, 39],
|
||||
magentaBright: [95, 39],
|
||||
cyanBright: [96, 39],
|
||||
whiteBright: [97, 39]
|
||||
},
|
||||
bgColor: {
|
||||
bgBlack: [40, 49],
|
||||
bgRed: [41, 49],
|
||||
bgGreen: [42, 49],
|
||||
bgYellow: [43, 49],
|
||||
bgBlue: [44, 49],
|
||||
bgMagenta: [45, 49],
|
||||
bgCyan: [46, 49],
|
||||
bgWhite: [47, 49],
|
||||
|
||||
// Bright color
|
||||
bgBlackBright: [100, 49],
|
||||
bgRedBright: [101, 49],
|
||||
bgGreenBright: [102, 49],
|
||||
bgYellowBright: [103, 49],
|
||||
bgBlueBright: [104, 49],
|
||||
bgMagentaBright: [105, 49],
|
||||
bgCyanBright: [106, 49],
|
||||
bgWhiteBright: [107, 49]
|
||||
}
|
||||
};
|
||||
|
||||
// Alias bright black as gray (and grey)
|
||||
styles.color.gray = styles.color.blackBright;
|
||||
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
||||
styles.color.grey = styles.color.blackBright;
|
||||
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
||||
|
||||
for (const [groupName, group] of Object.entries(styles)) {
|
||||
for (const [styleName, style] of Object.entries(group)) {
|
||||
styles[styleName] = {
|
||||
open: `\u001B[${style[0]}m`,
|
||||
close: `\u001B[${style[1]}m`
|
||||
};
|
||||
|
||||
group[styleName] = styles[styleName];
|
||||
|
||||
codes.set(style[0], style[1]);
|
||||
}
|
||||
|
||||
Object.defineProperty(styles, groupName, {
|
||||
value: group,
|
||||
enumerable: false
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(styles, 'codes', {
|
||||
value: codes,
|
||||
enumerable: false
|
||||
});
|
||||
|
||||
styles.color.close = '\u001B[39m';
|
||||
styles.bgColor.close = '\u001B[49m';
|
||||
|
||||
setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
|
||||
setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
|
||||
setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
|
||||
setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
|
||||
setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
|
||||
setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
// Make the export immutable
|
||||
Object.defineProperty(module, 'exports', {
|
||||
enumerable: true,
|
||||
get: assembleStyles
|
||||
});
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "ansi-styles",
|
||||
"version": "4.3.0",
|
||||
"description": "ANSI escape codes for styling strings in the terminal",
|
||||
"license": "MIT",
|
||||
"repository": "chalk/ansi-styles",
|
||||
"funding": "https://github.com/chalk/ansi-styles?sponsor=1",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd",
|
||||
"screenshot": "svg-term --command='node screenshot' --out=screenshot.svg --padding=3 --width=55 --height=3 --at=1000 --no-cursor"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"ansi",
|
||||
"styles",
|
||||
"color",
|
||||
"colour",
|
||||
"colors",
|
||||
"terminal",
|
||||
"console",
|
||||
"cli",
|
||||
"string",
|
||||
"tty",
|
||||
"escape",
|
||||
"formatting",
|
||||
"rgb",
|
||||
"256",
|
||||
"shell",
|
||||
"xterm",
|
||||
"log",
|
||||
"logging",
|
||||
"command-line",
|
||||
"text"
|
||||
],
|
||||
"dependencies": {
|
||||
"color-convert": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/color-convert": "^1.9.0",
|
||||
"ava": "^2.3.0",
|
||||
"svg-term-cli": "^2.1.1",
|
||||
"tsd": "^0.11.0",
|
||||
"xo": "^0.25.3"
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
# ansi-styles [](https://travis-ci.org/chalk/ansi-styles)
|
||||
|
||||
> [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal
|
||||
|
||||
You probably want the higher-level [chalk](https://github.com/chalk/chalk) module for styling your strings.
|
||||
|
||||
<img src="screenshot.svg" width="900">
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install ansi-styles
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const style = require('ansi-styles');
|
||||
|
||||
console.log(`${style.green.open}Hello world!${style.green.close}`);
|
||||
|
||||
|
||||
// Color conversion between 16/256/truecolor
|
||||
// NOTE: If conversion goes to 16 colors or 256 colors, the original color
|
||||
// may be degraded to fit that color palette. This means terminals
|
||||
// that do not support 16 million colors will best-match the
|
||||
// original color.
|
||||
console.log(style.bgColor.ansi.hsl(120, 80, 72) + 'Hello world!' + style.bgColor.close);
|
||||
console.log(style.color.ansi256.rgb(199, 20, 250) + 'Hello world!' + style.color.close);
|
||||
console.log(style.color.ansi16m.hex('#abcdef') + 'Hello world!' + style.color.close);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
Each style has an `open` and `close` property.
|
||||
|
||||
## Styles
|
||||
|
||||
### Modifiers
|
||||
|
||||
- `reset`
|
||||
- `bold`
|
||||
- `dim`
|
||||
- `italic` *(Not widely supported)*
|
||||
- `underline`
|
||||
- `inverse`
|
||||
- `hidden`
|
||||
- `strikethrough` *(Not widely supported)*
|
||||
|
||||
### Colors
|
||||
|
||||
- `black`
|
||||
- `red`
|
||||
- `green`
|
||||
- `yellow`
|
||||
- `blue`
|
||||
- `magenta`
|
||||
- `cyan`
|
||||
- `white`
|
||||
- `blackBright` (alias: `gray`, `grey`)
|
||||
- `redBright`
|
||||
- `greenBright`
|
||||
- `yellowBright`
|
||||
- `blueBright`
|
||||
- `magentaBright`
|
||||
- `cyanBright`
|
||||
- `whiteBright`
|
||||
|
||||
### Background colors
|
||||
|
||||
- `bgBlack`
|
||||
- `bgRed`
|
||||
- `bgGreen`
|
||||
- `bgYellow`
|
||||
- `bgBlue`
|
||||
- `bgMagenta`
|
||||
- `bgCyan`
|
||||
- `bgWhite`
|
||||
- `bgBlackBright` (alias: `bgGray`, `bgGrey`)
|
||||
- `bgRedBright`
|
||||
- `bgGreenBright`
|
||||
- `bgYellowBright`
|
||||
- `bgBlueBright`
|
||||
- `bgMagentaBright`
|
||||
- `bgCyanBright`
|
||||
- `bgWhiteBright`
|
||||
|
||||
## Advanced usage
|
||||
|
||||
By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
|
||||
|
||||
- `style.modifier`
|
||||
- `style.color`
|
||||
- `style.bgColor`
|
||||
|
||||
###### Example
|
||||
|
||||
```js
|
||||
console.log(style.color.green.open);
|
||||
```
|
||||
|
||||
Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `style.codes`, which returns a `Map` with the open codes as keys and close codes as values.
|
||||
|
||||
###### Example
|
||||
|
||||
```js
|
||||
console.log(style.codes.get(36));
|
||||
//=> 39
|
||||
```
|
||||
|
||||
## [256 / 16 million (TrueColor) support](https://gist.github.com/XVilka/8346728)
|
||||
|
||||
`ansi-styles` uses the [`color-convert`](https://github.com/Qix-/color-convert) package to allow for converting between various colors and ANSI escapes, with support for 256 and 16 million colors.
|
||||
|
||||
The following color spaces from `color-convert` are supported:
|
||||
|
||||
- `rgb`
|
||||
- `hex`
|
||||
- `keyword`
|
||||
- `hsl`
|
||||
- `hsv`
|
||||
- `hwb`
|
||||
- `ansi`
|
||||
- `ansi256`
|
||||
|
||||
To use these, call the associated conversion function with the intended output, for example:
|
||||
|
||||
```js
|
||||
style.color.ansi.rgb(100, 200, 15); // RGB to 16 color ansi foreground code
|
||||
style.bgColor.ansi.rgb(100, 200, 15); // RGB to 16 color ansi background code
|
||||
|
||||
style.color.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
|
||||
style.bgColor.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
|
||||
|
||||
style.color.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color foreground code
|
||||
style.bgColor.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color background code
|
||||
```
|
||||
|
||||
## Related
|
||||
|
||||
- [ansi-escapes](https://github.com/sindresorhus/ansi-escapes) - ANSI escape codes for manipulating the terminal
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Josh Junon](https://github.com/qix-)
|
||||
|
||||
## For enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of `ansi-styles` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-ansi-styles?utm_source=npm-ansi-styles&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com)
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
anymatch [](https://travis-ci.org/micromatch/anymatch) [](https://coveralls.io/r/micromatch/anymatch?branch=master)
|
||||
======
|
||||
Javascript module to match a string against a regular expression, glob, string,
|
||||
or function that takes the string as an argument and returns a truthy or falsy
|
||||
value. The matcher can also be an array of any or all of these. Useful for
|
||||
allowing a very flexible user-defined config to define things like file paths.
|
||||
|
||||
__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
```sh
|
||||
npm install anymatch
|
||||
```
|
||||
|
||||
#### anymatch(matchers, testString, [returnIndex], [options])
|
||||
* __matchers__: (_Array|String|RegExp|Function_)
|
||||
String to be directly matched, string with glob patterns, regular expression
|
||||
test, function that takes the testString as an argument and returns a truthy
|
||||
value if it should be matched, or an array of any number and mix of these types.
|
||||
* __testString__: (_String|Array_) The string to test against the matchers. If
|
||||
passed as an array, the first element of the array will be used as the
|
||||
`testString` for non-function matchers, while the entire array will be applied
|
||||
as the arguments for function matchers.
|
||||
* __options__: (_Object_ [optional]_) Any of the [picomatch](https://github.com/micromatch/picomatch#options) options.
|
||||
* __returnIndex__: (_Boolean [optional]_) If true, return the array index of
|
||||
the first matcher that that testString matched, or -1 if no match, instead of a
|
||||
boolean result.
|
||||
|
||||
```js
|
||||
const anymatch = require('anymatch');
|
||||
|
||||
const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ;
|
||||
|
||||
anymatch(matchers, 'path/to/file.js'); // true
|
||||
anymatch(matchers, 'path/anyjs/baz.js'); // true
|
||||
anymatch(matchers, 'path/to/foo.js'); // true
|
||||
anymatch(matchers, 'path/to/bar.js'); // true
|
||||
anymatch(matchers, 'bar.js'); // false
|
||||
|
||||
// returnIndex = true
|
||||
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
|
||||
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1
|
||||
|
||||
// any picomatc
|
||||
|
||||
// using globs to match directories and their children
|
||||
anymatch('node_modules', 'node_modules'); // true
|
||||
anymatch('node_modules', 'node_modules/somelib/index.js'); // false
|
||||
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
|
||||
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
|
||||
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
|
||||
|
||||
const matcher = anymatch(matchers);
|
||||
['foo.js', 'bar.js'].filter(matcher); // [ 'foo.js' ]
|
||||
anymatch master* ❯
|
||||
|
||||
```
|
||||
|
||||
#### anymatch(matchers)
|
||||
You can also pass in only your matcher(s) to get a curried function that has
|
||||
already been bound to the provided matching criteria. This can be used as an
|
||||
`Array#filter` callback.
|
||||
|
||||
```js
|
||||
var matcher = anymatch(matchers);
|
||||
|
||||
matcher('path/to/file.js'); // true
|
||||
matcher('path/anyjs/baz.js', true); // 1
|
||||
|
||||
['foo.js', 'bar.js'].filter(matcher); // ['foo.js']
|
||||
```
|
||||
|
||||
Changelog
|
||||
----------
|
||||
[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
|
||||
|
||||
- **v3.0:** Removed `startIndex` and `endIndex` arguments. Node 8.x-only.
|
||||
- **v2.0:** [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
|
||||
- **v1.2:** anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
|
||||
for glob pattern matching. Issues with glob pattern matching should be
|
||||
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
|
||||
|
||||
License
|
||||
-------
|
||||
[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
type AnymatchFn = (testString: string) => boolean;
|
||||
type AnymatchPattern = string|RegExp|AnymatchFn;
|
||||
type AnymatchMatcher = AnymatchPattern|AnymatchPattern[]
|
||||
type AnymatchTester = {
|
||||
(testString: string|any[], returnIndex: true): number;
|
||||
(testString: string|any[]): boolean;
|
||||
}
|
||||
|
||||
type PicomatchOptions = {dot: boolean};
|
||||
|
||||
declare const anymatch: {
|
||||
(matchers: AnymatchMatcher): AnymatchTester;
|
||||
(matchers: AnymatchMatcher, testString: null, returnIndex: true | PicomatchOptions): AnymatchTester;
|
||||
(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number;
|
||||
(matchers: AnymatchMatcher, testString: string|any[]): boolean;
|
||||
}
|
||||
|
||||
export {AnymatchMatcher as Matcher}
|
||||
export {AnymatchTester as Tester}
|
||||
export default anymatch
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
|
||||
const picomatch = require('picomatch');
|
||||
const normalizePath = require('normalize-path');
|
||||
|
||||
/**
|
||||
* @typedef {(testString: string) => boolean} AnymatchFn
|
||||
* @typedef {string|RegExp|AnymatchFn} AnymatchPattern
|
||||
* @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
|
||||
*/
|
||||
const BANG = '!';
|
||||
const DEFAULT_OPTIONS = {returnIndex: false};
|
||||
const arrify = (item) => Array.isArray(item) ? item : [item];
|
||||
|
||||
/**
|
||||
* @param {AnymatchPattern} matcher
|
||||
* @param {object} options
|
||||
* @returns {AnymatchFn}
|
||||
*/
|
||||
const createPattern = (matcher, options) => {
|
||||
if (typeof matcher === 'function') {
|
||||
return matcher;
|
||||
}
|
||||
if (typeof matcher === 'string') {
|
||||
const glob = picomatch(matcher, options);
|
||||
return (string) => matcher === string || glob(string);
|
||||
}
|
||||
if (matcher instanceof RegExp) {
|
||||
return (string) => matcher.test(string);
|
||||
}
|
||||
return (string) => false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array<Function>} patterns
|
||||
* @param {Array<Function>} negPatterns
|
||||
* @param {String|Array} args
|
||||
* @param {Boolean} returnIndex
|
||||
* @returns {boolean|number}
|
||||
*/
|
||||
const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
|
||||
const isList = Array.isArray(args);
|
||||
const _path = isList ? args[0] : args;
|
||||
if (!isList && typeof _path !== 'string') {
|
||||
throw new TypeError('anymatch: second argument must be a string: got ' +
|
||||
Object.prototype.toString.call(_path))
|
||||
}
|
||||
const path = normalizePath(_path, false);
|
||||
|
||||
for (let index = 0; index < negPatterns.length; index++) {
|
||||
const nglob = negPatterns[index];
|
||||
if (nglob(path)) {
|
||||
return returnIndex ? -1 : false;
|
||||
}
|
||||
}
|
||||
|
||||
const applied = isList && [path].concat(args.slice(1));
|
||||
for (let index = 0; index < patterns.length; index++) {
|
||||
const pattern = patterns[index];
|
||||
if (isList ? pattern(...applied) : pattern(path)) {
|
||||
return returnIndex ? index : true;
|
||||
}
|
||||
}
|
||||
|
||||
return returnIndex ? -1 : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AnymatchMatcher} matchers
|
||||
* @param {Array|string} testString
|
||||
* @param {object} options
|
||||
* @returns {boolean|number|Function}
|
||||
*/
|
||||
const anymatch = (matchers, testString, options = DEFAULT_OPTIONS) => {
|
||||
if (matchers == null) {
|
||||
throw new TypeError('anymatch: specify first argument');
|
||||
}
|
||||
const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
|
||||
const returnIndex = opts.returnIndex || false;
|
||||
|
||||
// Early cache for matchers.
|
||||
const mtchers = arrify(matchers);
|
||||
const negatedGlobs = mtchers
|
||||
.filter(item => typeof item === 'string' && item.charAt(0) === BANG)
|
||||
.map(item => item.slice(1))
|
||||
.map(item => picomatch(item, opts));
|
||||
const patterns = mtchers
|
||||
.filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG))
|
||||
.map(matcher => createPattern(matcher, opts));
|
||||
|
||||
if (testString == null) {
|
||||
return (testString, ri = false) => {
|
||||
const returnIndex = typeof ri === 'boolean' ? ri : false;
|
||||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
|
||||
};
|
||||
|
||||
anymatch.default = anymatch;
|
||||
module.exports = anymatch;
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "anymatch",
|
||||
"version": "3.1.3",
|
||||
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"normalize-path": "^3.0.0",
|
||||
"picomatch": "^2.0.4"
|
||||
},
|
||||
"author": {
|
||||
"name": "Elan Shanker",
|
||||
"url": "https://github.com/es128"
|
||||
},
|
||||
"license": "ISC",
|
||||
"homepage": "https://github.com/micromatch/anymatch",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/micromatch/anymatch"
|
||||
},
|
||||
"keywords": [
|
||||
"match",
|
||||
"any",
|
||||
"string",
|
||||
"file",
|
||||
"fs",
|
||||
"list",
|
||||
"glob",
|
||||
"regex",
|
||||
"regexp",
|
||||
"regular",
|
||||
"expression",
|
||||
"function"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "nyc mocha",
|
||||
"mocha": "mocha"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^6.1.3",
|
||||
"nyc": "^14.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
}
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
# Buffer for Array
|
||||
|
||||
Buffer for Array (B4A) provides a set of functions for bridging the gap between the Node.js `Buffer` class and the `Uint8Array` class. A browser compatibility layer is also included, making it possible to use B4A in both Node.js and browsers without having to worry about whether you're dealing with buffers or typed arrays.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm i b4a
|
||||
```
|
||||
|
||||
### React Native
|
||||
|
||||
When imported from React Native `b4a` will make use of `react-native-b4a` for optimised buffer operations when available. All you need to do is install it:
|
||||
|
||||
```sh
|
||||
npm i react-native-b4a
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
#### `b4a.isBuffer(value)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferisbufferobj
|
||||
|
||||
This will also return `true` when passed a `Uint8Array`.
|
||||
|
||||
#### `b4a.isEncoding(encoding)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferisencodingencoding
|
||||
|
||||
#### `b4a.alloc(size[, fill[, encoding]])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferallocsize-fill-encoding
|
||||
|
||||
#### `b4a.allocUnsafe(size)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferallocunsafesize
|
||||
|
||||
#### `b4a.allocUnsafeSlow(size)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferallocunsafeslowsize
|
||||
|
||||
#### `b4a.byteLength(string)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferbytelengthstring-encoding
|
||||
|
||||
#### `b4a.compare(buf1, buf2)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-buffercomparebuf1-buf2
|
||||
|
||||
#### `b4a.concat(buffers[, totalLength])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferconcatlist-totallength
|
||||
|
||||
#### `b4a.copy(source, target[, targetStart[, sourceStart[, sourceEnd]]])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufcopytarget-targetstart-sourcestart-sourceend
|
||||
|
||||
#### `b4a.equals(buf1, buf2)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufequalsotherbuffer
|
||||
|
||||
#### `b4a.fill(buffer, value[, offset[, end]][, encoding])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#buffillvalue-offset-end-encoding
|
||||
|
||||
#### `b4a.from(array)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferfromarray
|
||||
|
||||
#### `b4a.from(arrayBuffer[, byteOffset[, length]])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length
|
||||
|
||||
#### `b4a.from(buffer)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferfrombuffer
|
||||
|
||||
#### `b4a.from(string[, encoding])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#static-method-bufferfromstring-encoding
|
||||
|
||||
#### `b4a.includes(buffer, value[, byteOffset][, encoding])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufincludesvalue-byteoffset-encoding
|
||||
|
||||
#### `b4a.indexOf(buffer, value[, byteOffset][, encoding])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufindexofvalue-byteoffset-encoding
|
||||
|
||||
#### `b4a.lastIndexOf(buffer, value[, byteOffset][, encoding])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#buflastindexofvalue-byteoffset-encoding
|
||||
|
||||
#### `b4a.swap16(buffer)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufswap16
|
||||
|
||||
#### `b4a.swap32(buffer)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufswap32
|
||||
|
||||
#### `b4a.swap64(buffer)`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufswap64
|
||||
|
||||
#### `b4a.toBuffer(buffer)`
|
||||
|
||||
Convert a buffer to its canonical representation. In Node.js, the canonical representation is a `Buffer`. In the browser, the canonical representation is a `Uint8Array`.
|
||||
|
||||
#### `b4a.toString(buffer, [encoding[, start[, end]]])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#buftostringencoding-start-end
|
||||
|
||||
#### `b4a.write(buffer, string[, offset[, length]][, encoding])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufwritestring-offset-length-encoding
|
||||
|
||||
#### `b4a.writeDoubleLE(buffer, value[, offset])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufwritedoublelevalue-offset
|
||||
|
||||
#### `b4a.writeFloatLE(buffer, value[, offset])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufwritefloatlevalue-offset
|
||||
|
||||
#### `b4a.writeUInt32LE(buffer, value[, offset])`
|
||||
|
||||
https://nodejs.org/api/buffer.html#bufwriteuint32levalue-offset
|
||||
|
||||
#### `b4a.writeInt32LE(buffer, value[, offset])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufwriteint32levalue-offset
|
||||
|
||||
#### `b4a.readDoubleLE(buffer[, offset])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufreaddoubleleoffset
|
||||
|
||||
#### `b4a.readFloatLE(buffer[, offset])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufreadfloatleoffset
|
||||
|
||||
#### `b4a.readUInt32LE(buffer[, offset])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufreaduint32leoffset
|
||||
|
||||
#### `b4a.readInt32LE(buffer[, offset])`
|
||||
|
||||
See https://nodejs.org/api/buffer.html#bufreadint32leoffset
|
||||
|
||||
## License
|
||||
|
||||
Apache 2.0
|
||||
+563
@@ -0,0 +1,563 @@
|
||||
const ascii = require('./lib/ascii')
|
||||
const base64 = require('./lib/base64')
|
||||
const hex = require('./lib/hex')
|
||||
const utf8 = require('./lib/utf8')
|
||||
const utf16le = require('./lib/utf16le')
|
||||
|
||||
const LE = new Uint8Array(Uint16Array.of(0xff).buffer)[0] === 0xff
|
||||
|
||||
function codecFor(encoding) {
|
||||
switch (encoding) {
|
||||
case 'ascii':
|
||||
return ascii
|
||||
case 'base64':
|
||||
return base64
|
||||
case 'hex':
|
||||
return hex
|
||||
case 'utf8':
|
||||
case 'utf-8':
|
||||
case undefined:
|
||||
case null:
|
||||
return utf8
|
||||
case 'ucs2':
|
||||
case 'ucs-2':
|
||||
case 'utf16le':
|
||||
case 'utf-16le':
|
||||
return utf16le
|
||||
default:
|
||||
throw new Error(`Unknown encoding '${encoding}'`)
|
||||
}
|
||||
}
|
||||
|
||||
function isBuffer(value) {
|
||||
return value instanceof Uint8Array
|
||||
}
|
||||
|
||||
function isEncoding(encoding) {
|
||||
try {
|
||||
codecFor(encoding)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function alloc(size, fill, encoding) {
|
||||
const buffer = new Uint8Array(size)
|
||||
if (fill !== undefined) {
|
||||
exports.fill(buffer, fill, 0, buffer.byteLength, encoding)
|
||||
}
|
||||
return buffer
|
||||
}
|
||||
|
||||
function allocUnsafe(size) {
|
||||
return new Uint8Array(size)
|
||||
}
|
||||
|
||||
function allocUnsafeSlow(size) {
|
||||
return new Uint8Array(size)
|
||||
}
|
||||
|
||||
function byteLength(string, encoding) {
|
||||
return codecFor(encoding).byteLength(string)
|
||||
}
|
||||
|
||||
function compare(a, b) {
|
||||
if (a === b) return 0
|
||||
|
||||
const len = Math.min(a.byteLength, b.byteLength)
|
||||
|
||||
a = new DataView(a.buffer, a.byteOffset, a.byteLength)
|
||||
b = new DataView(b.buffer, b.byteOffset, b.byteLength)
|
||||
|
||||
let i = 0
|
||||
|
||||
for (let n = len - (len % 4); i < n; i += 4) {
|
||||
const x = a.getUint32(i, LE)
|
||||
const y = b.getUint32(i, LE)
|
||||
if (x !== y) break
|
||||
}
|
||||
|
||||
for (; i < len; i++) {
|
||||
const x = a.getUint8(i)
|
||||
const y = b.getUint8(i)
|
||||
if (x < y) return -1
|
||||
if (x > y) return 1
|
||||
}
|
||||
|
||||
return a.byteLength > b.byteLength ? 1 : a.byteLength < b.byteLength ? -1 : 0
|
||||
}
|
||||
|
||||
function concat(buffers, length) {
|
||||
if (length === undefined) {
|
||||
length = buffers.reduce((len, buffer) => len + buffer.byteLength, 0)
|
||||
}
|
||||
|
||||
const result = new Uint8Array(length)
|
||||
|
||||
let offset = 0
|
||||
|
||||
for (const buffer of buffers) {
|
||||
if (offset + buffer.byteLength > result.byteLength) {
|
||||
result.set(buffer.subarray(0, result.byteLength - offset), offset)
|
||||
return result
|
||||
}
|
||||
|
||||
result.set(buffer, offset)
|
||||
offset += buffer.byteLength
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function copy(
|
||||
source,
|
||||
target,
|
||||
targetStart = 0,
|
||||
sourceStart = 0,
|
||||
sourceEnd = source.byteLength
|
||||
) {
|
||||
if (targetStart < 0) targetStart = 0
|
||||
if (targetStart >= target.byteLength) return 0
|
||||
|
||||
const targetLength = target.byteLength - targetStart
|
||||
|
||||
if (sourceStart < 0) sourceStart = 0
|
||||
if (sourceStart >= source.byteLength) return 0
|
||||
|
||||
if (sourceEnd <= sourceStart) return 0
|
||||
if (sourceEnd > source.byteLength) sourceEnd = source.byteLength
|
||||
|
||||
if (sourceEnd - sourceStart > targetLength) {
|
||||
sourceEnd = sourceStart + targetLength
|
||||
}
|
||||
|
||||
const sourceLength = sourceEnd - sourceStart
|
||||
|
||||
if (source === target) {
|
||||
target.copyWithin(targetStart, sourceStart, sourceEnd)
|
||||
} else {
|
||||
if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
|
||||
source = source.subarray(sourceStart, sourceEnd)
|
||||
}
|
||||
|
||||
target.set(source, targetStart)
|
||||
}
|
||||
|
||||
return sourceLength
|
||||
}
|
||||
|
||||
function equals(a, b) {
|
||||
if (a === b) return true
|
||||
if (a.byteLength !== b.byteLength) return false
|
||||
|
||||
return compare(a, b) === 0
|
||||
}
|
||||
|
||||
function fill(
|
||||
buffer,
|
||||
value,
|
||||
offset = 0,
|
||||
end = buffer.byteLength,
|
||||
encoding = 'utf8'
|
||||
) {
|
||||
if (typeof value === 'string') {
|
||||
if (typeof offset === 'string') {
|
||||
// fill(string, encoding)
|
||||
encoding = offset
|
||||
offset = 0
|
||||
end = buffer.byteLength
|
||||
} else if (typeof end === 'string') {
|
||||
// fill(string, offset, encoding)
|
||||
encoding = end
|
||||
end = buffer.byteLength
|
||||
}
|
||||
} else if (typeof value === 'number') {
|
||||
value = value & 0xff
|
||||
} else if (typeof value === 'boolean') {
|
||||
value = +value
|
||||
}
|
||||
|
||||
if (offset < 0) offset = 0
|
||||
if (offset >= buffer.byteLength) return buffer
|
||||
|
||||
if (end <= offset) return buffer
|
||||
if (end > buffer.byteLength) end = buffer.byteLength
|
||||
|
||||
if (typeof value === 'number') return buffer.fill(value, offset, end)
|
||||
|
||||
if (typeof value === 'string') value = exports.from(value, encoding)
|
||||
|
||||
const len = value.byteLength
|
||||
|
||||
for (let i = 0, n = end - offset; i < n; ++i) {
|
||||
buffer[i + offset] = value[i % len]
|
||||
}
|
||||
|
||||
return buffer
|
||||
}
|
||||
|
||||
function from(value, encodingOrOffset, length) {
|
||||
// from(string, encoding)
|
||||
if (typeof value === 'string') return fromString(value, encodingOrOffset)
|
||||
|
||||
// from(array)
|
||||
if (Array.isArray(value)) return fromArray(value)
|
||||
|
||||
// from(buffer)
|
||||
if (ArrayBuffer.isView(value)) return fromBuffer(value)
|
||||
|
||||
// from(arrayBuffer[, byteOffset[, length]])
|
||||
return fromArrayBuffer(value, encodingOrOffset, length)
|
||||
}
|
||||
|
||||
function fromString(string, encoding) {
|
||||
const codec = codecFor(encoding)
|
||||
const buffer = new Uint8Array(codec.byteLength(string))
|
||||
codec.write(buffer, string)
|
||||
return buffer
|
||||
}
|
||||
|
||||
function fromArray(array) {
|
||||
const buffer = new Uint8Array(array.length)
|
||||
buffer.set(array)
|
||||
return buffer
|
||||
}
|
||||
|
||||
function fromBuffer(buffer) {
|
||||
const copy = new Uint8Array(buffer.byteLength)
|
||||
copy.set(buffer)
|
||||
return copy
|
||||
}
|
||||
|
||||
function fromArrayBuffer(arrayBuffer, byteOffset, length) {
|
||||
return new Uint8Array(arrayBuffer, byteOffset, length)
|
||||
}
|
||||
|
||||
function includes(buffer, value, byteOffset, encoding) {
|
||||
return indexOf(buffer, value, byteOffset, encoding) !== -1
|
||||
}
|
||||
|
||||
function indexOf(buffer, value, byteOffset, encoding) {
|
||||
return bidirectionalIndexOf(
|
||||
buffer,
|
||||
value,
|
||||
byteOffset,
|
||||
encoding,
|
||||
true /* first */
|
||||
)
|
||||
}
|
||||
|
||||
function lastIndexOf(buffer, value, byteOffset, encoding) {
|
||||
return bidirectionalIndexOf(
|
||||
buffer,
|
||||
value,
|
||||
byteOffset,
|
||||
encoding,
|
||||
false /* last */
|
||||
)
|
||||
}
|
||||
|
||||
function bidirectionalIndexOf(buffer, value, byteOffset, encoding, first) {
|
||||
if (buffer.byteLength === 0) return -1
|
||||
|
||||
if (typeof byteOffset === 'string') {
|
||||
encoding = byteOffset
|
||||
byteOffset = 0
|
||||
} else if (byteOffset === undefined) {
|
||||
byteOffset = first ? 0 : buffer.length - 1
|
||||
} else if (byteOffset < 0) {
|
||||
byteOffset += buffer.byteLength
|
||||
}
|
||||
|
||||
if (byteOffset >= buffer.byteLength) {
|
||||
if (first) return -1
|
||||
else byteOffset = buffer.byteLength - 1
|
||||
} else if (byteOffset < 0) {
|
||||
if (first) byteOffset = 0
|
||||
else return -1
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
value = from(value, encoding)
|
||||
} else if (typeof value === 'number') {
|
||||
value = value & 0xff
|
||||
|
||||
if (first) {
|
||||
return buffer.indexOf(value, byteOffset)
|
||||
} else {
|
||||
return buffer.lastIndexOf(value, byteOffset)
|
||||
}
|
||||
}
|
||||
|
||||
if (value.byteLength === 0) return -1
|
||||
|
||||
if (first) {
|
||||
let foundIndex = -1
|
||||
|
||||
for (let i = byteOffset; i < buffer.byteLength; i++) {
|
||||
if (buffer[i] === value[foundIndex === -1 ? 0 : i - foundIndex]) {
|
||||
if (foundIndex === -1) foundIndex = i
|
||||
if (i - foundIndex + 1 === value.byteLength) return foundIndex
|
||||
} else {
|
||||
if (foundIndex !== -1) i -= i - foundIndex
|
||||
foundIndex = -1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (byteOffset + value.byteLength > buffer.byteLength) {
|
||||
byteOffset = buffer.byteLength - value.byteLength
|
||||
}
|
||||
|
||||
for (let i = byteOffset; i >= 0; i--) {
|
||||
let found = true
|
||||
|
||||
for (let j = 0; j < value.byteLength; j++) {
|
||||
if (buffer[i + j] !== value[j]) {
|
||||
found = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (found) return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
function swap(buffer, n, m) {
|
||||
const i = buffer[n]
|
||||
buffer[n] = buffer[m]
|
||||
buffer[m] = i
|
||||
}
|
||||
|
||||
function swap16(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
if (len % 2 !== 0)
|
||||
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
||||
|
||||
for (let i = 0; i < len; i += 2) swap(buffer, i, i + 1)
|
||||
|
||||
return buffer
|
||||
}
|
||||
|
||||
function swap32(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
if (len % 4 !== 0)
|
||||
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
||||
|
||||
for (let i = 0; i < len; i += 4) {
|
||||
swap(buffer, i, i + 3)
|
||||
swap(buffer, i + 1, i + 2)
|
||||
}
|
||||
|
||||
return buffer
|
||||
}
|
||||
|
||||
function swap64(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
if (len % 8 !== 0)
|
||||
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
||||
|
||||
for (let i = 0; i < len; i += 8) {
|
||||
swap(buffer, i, i + 7)
|
||||
swap(buffer, i + 1, i + 6)
|
||||
swap(buffer, i + 2, i + 5)
|
||||
swap(buffer, i + 3, i + 4)
|
||||
}
|
||||
|
||||
return buffer
|
||||
}
|
||||
|
||||
function toBuffer(buffer) {
|
||||
return buffer
|
||||
}
|
||||
|
||||
function toString(
|
||||
buffer,
|
||||
encoding = 'utf8',
|
||||
start = 0,
|
||||
end = buffer.byteLength
|
||||
) {
|
||||
// toString(buffer)
|
||||
if (arguments.length === 1) return utf8.toString(buffer)
|
||||
|
||||
// toString(buffer, encoding)
|
||||
if (arguments.length === 2) return codecFor(encoding).toString(buffer)
|
||||
|
||||
if (start < 0) start = 0
|
||||
if (start >= buffer.byteLength) return ''
|
||||
|
||||
if (end <= start) return ''
|
||||
if (end > buffer.byteLength) end = buffer.byteLength
|
||||
|
||||
if (start !== 0 || end !== buffer.byteLength) {
|
||||
buffer = buffer.subarray(start, end)
|
||||
}
|
||||
|
||||
return codecFor(encoding).toString(buffer)
|
||||
}
|
||||
|
||||
function write(buffer, string, offset, length, encoding) {
|
||||
// write(buffer, string)
|
||||
if (arguments.length === 2) return utf8.write(buffer, string)
|
||||
|
||||
if (typeof offset === 'string') {
|
||||
// write(buffer, string, encoding)
|
||||
encoding = offset
|
||||
offset = 0
|
||||
length = buffer.byteLength
|
||||
} else if (typeof length === 'string') {
|
||||
// write(buffer, string, offset, encoding)
|
||||
encoding = length
|
||||
length = buffer.byteLength - offset
|
||||
}
|
||||
|
||||
length = Math.min(length, exports.byteLength(string, encoding))
|
||||
|
||||
let start = offset
|
||||
if (start < 0) start = 0
|
||||
if (start >= buffer.byteLength) return 0
|
||||
|
||||
let end = offset + length
|
||||
if (end <= start) return 0
|
||||
if (end > buffer.byteLength) end = buffer.byteLength
|
||||
|
||||
if (start !== 0 || end !== buffer.byteLength) {
|
||||
buffer = buffer.subarray(start, end)
|
||||
}
|
||||
|
||||
return codecFor(encoding).write(buffer, string)
|
||||
}
|
||||
|
||||
function readDoubleBE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getFloat64(offset, false)
|
||||
}
|
||||
|
||||
function readDoubleLE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getFloat64(offset, true)
|
||||
}
|
||||
|
||||
function readFloatBE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getFloat32(offset, false)
|
||||
}
|
||||
|
||||
function readFloatLE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getFloat32(offset, true)
|
||||
}
|
||||
|
||||
function readInt32BE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getInt32(offset, false)
|
||||
}
|
||||
|
||||
function readInt32LE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getInt32(offset, true)
|
||||
}
|
||||
|
||||
function readUInt32BE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getUint32(offset, false)
|
||||
}
|
||||
|
||||
function readUInt32LE(buffer, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
return view.getUint32(offset, true)
|
||||
}
|
||||
|
||||
function writeDoubleBE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setFloat64(offset, value, false)
|
||||
return offset + 8
|
||||
}
|
||||
|
||||
function writeDoubleLE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setFloat64(offset, value, true)
|
||||
return offset + 8
|
||||
}
|
||||
|
||||
function writeFloatBE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setFloat32(offset, value, false)
|
||||
return offset + 4
|
||||
}
|
||||
|
||||
function writeFloatLE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setFloat32(offset, value, true)
|
||||
return offset + 4
|
||||
}
|
||||
|
||||
function writeInt32BE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setInt32(offset, value, false)
|
||||
return offset + 4
|
||||
}
|
||||
|
||||
function writeInt32LE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setInt32(offset, value, true)
|
||||
return offset + 4
|
||||
}
|
||||
|
||||
function writeUInt32BE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setUint32(offset, value, false)
|
||||
return offset + 4
|
||||
}
|
||||
|
||||
function writeUInt32LE(buffer, value, offset = 0) {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
view.setUint32(offset, value, true)
|
||||
return offset + 4
|
||||
}
|
||||
|
||||
module.exports = exports = {
|
||||
isBuffer,
|
||||
isEncoding,
|
||||
alloc,
|
||||
allocUnsafe,
|
||||
allocUnsafeSlow,
|
||||
byteLength,
|
||||
compare,
|
||||
concat,
|
||||
copy,
|
||||
equals,
|
||||
fill,
|
||||
from,
|
||||
includes,
|
||||
indexOf,
|
||||
lastIndexOf,
|
||||
swap16,
|
||||
swap32,
|
||||
swap64,
|
||||
toBuffer,
|
||||
toString,
|
||||
write,
|
||||
readDoubleBE,
|
||||
readDoubleLE,
|
||||
readFloatBE,
|
||||
readFloatLE,
|
||||
readInt32BE,
|
||||
readInt32LE,
|
||||
readUInt32BE,
|
||||
readUInt32LE,
|
||||
writeDoubleBE,
|
||||
writeDoubleLE,
|
||||
writeFloatBE,
|
||||
writeFloatLE,
|
||||
writeInt32BE,
|
||||
writeInt32LE,
|
||||
writeUInt32BE,
|
||||
writeUInt32LE
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
function isBuffer(value) {
|
||||
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
||||
}
|
||||
|
||||
function isEncoding(encoding) {
|
||||
return Buffer.isEncoding(encoding)
|
||||
}
|
||||
|
||||
function alloc(size, fill, encoding) {
|
||||
return Buffer.alloc(size, fill, encoding)
|
||||
}
|
||||
|
||||
function allocUnsafe(size) {
|
||||
return Buffer.allocUnsafe(size)
|
||||
}
|
||||
|
||||
function allocUnsafeSlow(size) {
|
||||
return Buffer.allocUnsafeSlow(size)
|
||||
}
|
||||
|
||||
function byteLength(string, encoding) {
|
||||
return Buffer.byteLength(string, encoding)
|
||||
}
|
||||
|
||||
function compare(a, b) {
|
||||
return Buffer.compare(a, b)
|
||||
}
|
||||
|
||||
function concat(buffers, totalLength) {
|
||||
return Buffer.concat(buffers, totalLength)
|
||||
}
|
||||
|
||||
function copy(source, target, targetStart, start, end) {
|
||||
return toBuffer(source).copy(target, targetStart, start, end)
|
||||
}
|
||||
|
||||
function equals(a, b) {
|
||||
return toBuffer(a).equals(b)
|
||||
}
|
||||
|
||||
function fill(buffer, value, offset, end, encoding) {
|
||||
return toBuffer(buffer).fill(value, offset, end, encoding)
|
||||
}
|
||||
|
||||
function from(value, encodingOrOffset, length) {
|
||||
return Buffer.from(value, encodingOrOffset, length)
|
||||
}
|
||||
|
||||
function includes(buffer, value, byteOffset, encoding) {
|
||||
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
||||
}
|
||||
|
||||
function indexOf(buffer, value, byfeOffset, encoding) {
|
||||
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
||||
}
|
||||
|
||||
function lastIndexOf(buffer, value, byteOffset, encoding) {
|
||||
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
||||
}
|
||||
|
||||
function swap16(buffer) {
|
||||
return toBuffer(buffer).swap16()
|
||||
}
|
||||
|
||||
function swap32(buffer) {
|
||||
return toBuffer(buffer).swap32()
|
||||
}
|
||||
|
||||
function swap64(buffer) {
|
||||
return toBuffer(buffer).swap64()
|
||||
}
|
||||
|
||||
function toBuffer(buffer) {
|
||||
if (Buffer.isBuffer(buffer)) return buffer
|
||||
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
||||
}
|
||||
|
||||
function toString(buffer, encoding, start, end) {
|
||||
return toBuffer(buffer).toString(encoding, start, end)
|
||||
}
|
||||
|
||||
function write(buffer, string, offset, length, encoding) {
|
||||
return toBuffer(buffer).write(string, offset, length, encoding)
|
||||
}
|
||||
|
||||
function readDoubleBE(buffer, offset) {
|
||||
return toBuffer(buffer).readDoubleBE(offset)
|
||||
}
|
||||
|
||||
function readDoubleLE(buffer, offset) {
|
||||
return toBuffer(buffer).readDoubleLE(offset)
|
||||
}
|
||||
|
||||
function readFloatBE(buffer, offset) {
|
||||
return toBuffer(buffer).readFloatBE(offset)
|
||||
}
|
||||
|
||||
function readFloatLE(buffer, offset) {
|
||||
return toBuffer(buffer).readFloatLE(offset)
|
||||
}
|
||||
|
||||
function readInt32BE(buffer, offset) {
|
||||
return toBuffer(buffer).readInt32BE(offset)
|
||||
}
|
||||
|
||||
function readInt32LE(buffer, offset) {
|
||||
return toBuffer(buffer).readInt32LE(offset)
|
||||
}
|
||||
|
||||
function readUInt32BE(buffer, offset) {
|
||||
return toBuffer(buffer).readUInt32BE(offset)
|
||||
}
|
||||
|
||||
function readUInt32LE(buffer, offset) {
|
||||
return toBuffer(buffer).readUInt32LE(offset)
|
||||
}
|
||||
|
||||
function writeDoubleBE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeDoubleBE(value, offset)
|
||||
}
|
||||
|
||||
function writeDoubleLE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeDoubleLE(value, offset)
|
||||
}
|
||||
|
||||
function writeFloatBE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeFloatBE(value, offset)
|
||||
}
|
||||
|
||||
function writeFloatLE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeFloatLE(value, offset)
|
||||
}
|
||||
|
||||
function writeInt32BE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeInt32BE(value, offset)
|
||||
}
|
||||
|
||||
function writeInt32LE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeInt32LE(value, offset)
|
||||
}
|
||||
|
||||
function writeUInt32BE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeUInt32BE(value, offset)
|
||||
}
|
||||
|
||||
function writeUInt32LE(buffer, value, offset) {
|
||||
return toBuffer(buffer).writeUInt32LE(value, offset)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isBuffer,
|
||||
isEncoding,
|
||||
alloc,
|
||||
allocUnsafe,
|
||||
allocUnsafeSlow,
|
||||
byteLength,
|
||||
compare,
|
||||
concat,
|
||||
copy,
|
||||
equals,
|
||||
fill,
|
||||
from,
|
||||
includes,
|
||||
indexOf,
|
||||
lastIndexOf,
|
||||
swap16,
|
||||
swap32,
|
||||
swap64,
|
||||
toBuffer,
|
||||
toString,
|
||||
write,
|
||||
readDoubleBE,
|
||||
readDoubleLE,
|
||||
readFloatBE,
|
||||
readFloatLE,
|
||||
readInt32BE,
|
||||
readInt32LE,
|
||||
readUInt32BE,
|
||||
readUInt32LE,
|
||||
writeDoubleBE,
|
||||
writeDoubleLE,
|
||||
writeFloatBE,
|
||||
writeFloatLE,
|
||||
writeInt32BE,
|
||||
writeInt32LE,
|
||||
writeUInt32BE,
|
||||
writeUInt32LE
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
function byteLength(string) {
|
||||
return string.length
|
||||
}
|
||||
|
||||
function toString(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
let result = ''
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
result += String.fromCharCode(buffer[i])
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function write(buffer, string) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
buffer[i] = string.charCodeAt(i)
|
||||
}
|
||||
|
||||
return len
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
byteLength,
|
||||
toString,
|
||||
write
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
const alphabet =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
|
||||
const codes = new Uint8Array(256)
|
||||
|
||||
for (let i = 0; i < alphabet.length; i++) {
|
||||
codes[alphabet.charCodeAt(i)] = i
|
||||
}
|
||||
|
||||
codes[/* - */ 0x2d] = 62
|
||||
codes[/* _ */ 0x5f] = 63
|
||||
|
||||
function byteLength(string) {
|
||||
let len = string.length
|
||||
|
||||
if (string.charCodeAt(len - 1) === 0x3d) len--
|
||||
if (len > 1 && string.charCodeAt(len - 1) === 0x3d) len--
|
||||
|
||||
return (len * 3) >>> 2
|
||||
}
|
||||
|
||||
function toString(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
let result = ''
|
||||
|
||||
for (let i = 0; i < len; i += 3) {
|
||||
result +=
|
||||
alphabet[buffer[i] >> 2] +
|
||||
alphabet[((buffer[i] & 3) << 4) | (buffer[i + 1] >> 4)] +
|
||||
alphabet[((buffer[i + 1] & 15) << 2) | (buffer[i + 2] >> 6)] +
|
||||
alphabet[buffer[i + 2] & 63]
|
||||
}
|
||||
|
||||
if (len % 3 === 2) {
|
||||
result = result.substring(0, result.length - 1) + '='
|
||||
} else if (len % 3 === 1) {
|
||||
result = result.substring(0, result.length - 2) + '=='
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function write(buffer, string) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
for (let i = 0, j = 0; j < len; i += 4) {
|
||||
const a = codes[string.charCodeAt(i)]
|
||||
const b = codes[string.charCodeAt(i + 1)]
|
||||
const c = codes[string.charCodeAt(i + 2)]
|
||||
const d = codes[string.charCodeAt(i + 3)]
|
||||
|
||||
buffer[j++] = (a << 2) | (b >> 4)
|
||||
buffer[j++] = ((b & 15) << 4) | (c >> 2)
|
||||
buffer[j++] = ((c & 3) << 6) | (d & 63)
|
||||
}
|
||||
|
||||
return len
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
byteLength,
|
||||
toString,
|
||||
write
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
function byteLength(string) {
|
||||
return string.length >>> 1
|
||||
}
|
||||
|
||||
function toString(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
buffer = new DataView(buffer.buffer, buffer.byteOffset, len)
|
||||
|
||||
let result = ''
|
||||
let i = 0
|
||||
|
||||
for (let n = len - (len % 4); i < n; i += 4) {
|
||||
result += buffer.getUint32(i).toString(16).padStart(8, '0')
|
||||
}
|
||||
|
||||
for (; i < len; i++) {
|
||||
result += buffer.getUint8(i).toString(16).padStart(2, '0')
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function write(buffer, string) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
const a = hexValue(string.charCodeAt(i * 2))
|
||||
const b = hexValue(string.charCodeAt(i * 2 + 1))
|
||||
|
||||
if (a === undefined || b === undefined) {
|
||||
return buffer.subarray(0, i)
|
||||
}
|
||||
|
||||
buffer[i] = (a << 4) | b
|
||||
}
|
||||
|
||||
return len
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
byteLength,
|
||||
toString,
|
||||
write
|
||||
}
|
||||
|
||||
function hexValue(char) {
|
||||
if (char >= 0x30 && char <= 0x39) return char - 0x30
|
||||
if (char >= 0x41 && char <= 0x46) return char - 0x41 + 10
|
||||
if (char >= 0x61 && char <= 0x66) return char - 0x61 + 10
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
function byteLength(string) {
|
||||
return string.length * 2
|
||||
}
|
||||
|
||||
function toString(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
let result = ''
|
||||
|
||||
for (let i = 0; i < len - 1; i += 2) {
|
||||
result += String.fromCharCode(buffer[i] + buffer[i + 1] * 256)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function write(buffer, string) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
let units = len
|
||||
|
||||
for (let i = 0; i < string.length; ++i) {
|
||||
if ((units -= 2) < 0) break
|
||||
|
||||
const c = string.charCodeAt(i)
|
||||
const hi = c >> 8
|
||||
const lo = c % 256
|
||||
|
||||
buffer[i * 2] = lo
|
||||
buffer[i * 2 + 1] = hi
|
||||
}
|
||||
|
||||
return len
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
byteLength,
|
||||
toString,
|
||||
write
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
function byteLength(string) {
|
||||
let length = 0
|
||||
|
||||
for (let i = 0, n = string.length; i < n; i++) {
|
||||
const code = string.charCodeAt(i)
|
||||
|
||||
if (code >= 0xd800 && code <= 0xdbff && i + 1 < n) {
|
||||
const code = string.charCodeAt(i + 1)
|
||||
|
||||
if (code >= 0xdc00 && code <= 0xdfff) {
|
||||
length += 4
|
||||
i++
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (code <= 0x7f) length += 1
|
||||
else if (code <= 0x7ff) length += 2
|
||||
else length += 3
|
||||
}
|
||||
|
||||
return length
|
||||
}
|
||||
|
||||
let toString
|
||||
|
||||
if (typeof TextDecoder !== 'undefined') {
|
||||
const decoder = new TextDecoder()
|
||||
|
||||
toString = function toString(buffer) {
|
||||
return decoder.decode(buffer)
|
||||
}
|
||||
} else {
|
||||
toString = function toString(buffer) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
let output = ''
|
||||
let i = 0
|
||||
|
||||
while (i < len) {
|
||||
let byte = buffer[i]
|
||||
|
||||
if (byte <= 0x7f) {
|
||||
output += String.fromCharCode(byte)
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
let bytesNeeded = 0
|
||||
let codePoint = 0
|
||||
|
||||
if (byte <= 0xdf) {
|
||||
bytesNeeded = 1
|
||||
codePoint = byte & 0x1f
|
||||
} else if (byte <= 0xef) {
|
||||
bytesNeeded = 2
|
||||
codePoint = byte & 0x0f
|
||||
} else if (byte <= 0xf4) {
|
||||
bytesNeeded = 3
|
||||
codePoint = byte & 0x07
|
||||
}
|
||||
|
||||
if (len - i - bytesNeeded > 0) {
|
||||
let k = 0
|
||||
|
||||
while (k < bytesNeeded) {
|
||||
byte = buffer[i + k + 1]
|
||||
codePoint = (codePoint << 6) | (byte & 0x3f)
|
||||
k += 1
|
||||
}
|
||||
} else {
|
||||
codePoint = 0xfffd
|
||||
bytesNeeded = len - i
|
||||
}
|
||||
|
||||
output += String.fromCodePoint(codePoint)
|
||||
i += bytesNeeded + 1
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
}
|
||||
|
||||
let write
|
||||
|
||||
if (typeof TextEncoder !== 'undefined') {
|
||||
const encoder = new TextEncoder()
|
||||
|
||||
write = function write(buffer, string) {
|
||||
return encoder.encodeInto(string, buffer).written
|
||||
}
|
||||
} else {
|
||||
write = function write(buffer, string) {
|
||||
const len = buffer.byteLength
|
||||
|
||||
let i = 0
|
||||
let j = 0
|
||||
|
||||
while (i < string.length) {
|
||||
const code = string.codePointAt(i)
|
||||
|
||||
if (code <= 0x7f) {
|
||||
buffer[j++] = code
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
let count = 0
|
||||
let bits = 0
|
||||
|
||||
if (code <= 0x7ff) {
|
||||
count = 6
|
||||
bits = 0xc0
|
||||
} else if (code <= 0xffff) {
|
||||
count = 12
|
||||
bits = 0xe0
|
||||
} else if (code <= 0x1fffff) {
|
||||
count = 18
|
||||
bits = 0xf0
|
||||
}
|
||||
|
||||
buffer[j++] = bits | (code >> count)
|
||||
count -= 6
|
||||
|
||||
while (count >= 0) {
|
||||
buffer[j++] = 0x80 | ((code >> count) & 0x3f)
|
||||
count -= 6
|
||||
}
|
||||
|
||||
i += code >= 0x10000 ? 2 : 1
|
||||
}
|
||||
|
||||
return len
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
byteLength,
|
||||
toString,
|
||||
write
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "b4a",
|
||||
"version": "1.7.3",
|
||||
"description": "Bridging the gap between buffers and typed arrays",
|
||||
"exports": {
|
||||
"./package": "./package.json",
|
||||
".": {
|
||||
"react-native": "./react-native.js",
|
||||
"browser": "./browser.js",
|
||||
"default": "./index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"browser.js",
|
||||
"index.js",
|
||||
"react-native.js",
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "npm run lint && npm run test:bare && npm run test:node",
|
||||
"test:bare": "bare test.mjs",
|
||||
"test:node": "node test.mjs",
|
||||
"lint": "prettier . --check"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/holepunchto/b4a.git"
|
||||
},
|
||||
"author": "Holepunch",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/holepunchto/b4a/issues"
|
||||
},
|
||||
"homepage": "https://github.com/holepunchto/b4a#readme",
|
||||
"devDependencies": {
|
||||
"brittle": "^3.5.2",
|
||||
"nanobench": "^3.0.0",
|
||||
"prettier": "^3.6.2",
|
||||
"prettier-config-holepunch": "^1.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react-native-b4a": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react-native-b4a": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
try {
|
||||
module.exports = require('react-native-b4a')
|
||||
} catch {
|
||||
module.exports = require('./browser')
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
tidelift: "npm/balanced-match"
|
||||
patreon: juliangruber
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
(MIT)
|
||||
|
||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
# balanced-match
|
||||
|
||||
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
|
||||
|
||||
[](http://travis-ci.org/juliangruber/balanced-match)
|
||||
[](https://www.npmjs.org/package/balanced-match)
|
||||
|
||||
[](https://ci.testling.com/juliangruber/balanced-match)
|
||||
|
||||
## Example
|
||||
|
||||
Get the first matching pair of braces:
|
||||
|
||||
```js
|
||||
var balanced = require('balanced-match');
|
||||
|
||||
console.log(balanced('{', '}', 'pre{in{nested}}post'));
|
||||
console.log(balanced('{', '}', 'pre{first}between{second}post'));
|
||||
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
|
||||
```
|
||||
|
||||
The matches are:
|
||||
|
||||
```bash
|
||||
$ node example.js
|
||||
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
|
||||
{ start: 3,
|
||||
end: 9,
|
||||
pre: 'pre',
|
||||
body: 'first',
|
||||
post: 'between{second}post' }
|
||||
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### var m = balanced(a, b, str)
|
||||
|
||||
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
||||
object with those keys:
|
||||
|
||||
* **start** the index of the first match of `a`
|
||||
* **end** the index of the matching `b`
|
||||
* **pre** the preamble, `a` and `b` not included
|
||||
* **body** the match, `a` and `b` not included
|
||||
* **post** the postscript, `a` and `b` not included
|
||||
|
||||
If there's no match, `undefined` will be returned.
|
||||
|
||||
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
|
||||
|
||||
### var r = balanced.range(a, b, str)
|
||||
|
||||
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
||||
array with indexes: `[ <a index>, <b index> ]`.
|
||||
|
||||
If there's no match, `undefined` will be returned.
|
||||
|
||||
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
|
||||
|
||||
## Installation
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```bash
|
||||
npm install balanced-match
|
||||
```
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the
|
||||
[Tidelift security contact](https://tidelift.com/security).
|
||||
Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
## License
|
||||
|
||||
(MIT)
|
||||
|
||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
module.exports = balanced;
|
||||
function balanced(a, b, str) {
|
||||
if (a instanceof RegExp) a = maybeMatch(a, str);
|
||||
if (b instanceof RegExp) b = maybeMatch(b, str);
|
||||
|
||||
var r = range(a, b, str);
|
||||
|
||||
return r && {
|
||||
start: r[0],
|
||||
end: r[1],
|
||||
pre: str.slice(0, r[0]),
|
||||
body: str.slice(r[0] + a.length, r[1]),
|
||||
post: str.slice(r[1] + b.length)
|
||||
};
|
||||
}
|
||||
|
||||
function maybeMatch(reg, str) {
|
||||
var m = str.match(reg);
|
||||
return m ? m[0] : null;
|
||||
}
|
||||
|
||||
balanced.range = range;
|
||||
function range(a, b, str) {
|
||||
var begs, beg, left, right, result;
|
||||
var ai = str.indexOf(a);
|
||||
var bi = str.indexOf(b, ai + 1);
|
||||
var i = ai;
|
||||
|
||||
if (ai >= 0 && bi > 0) {
|
||||
if(a===b) {
|
||||
return [ai, bi];
|
||||
}
|
||||
begs = [];
|
||||
left = str.length;
|
||||
|
||||
while (i >= 0 && !result) {
|
||||
if (i == ai) {
|
||||
begs.push(i);
|
||||
ai = str.indexOf(a, i + 1);
|
||||
} else if (begs.length == 1) {
|
||||
result = [ begs.pop(), bi ];
|
||||
} else {
|
||||
beg = begs.pop();
|
||||
if (beg < left) {
|
||||
left = beg;
|
||||
right = bi;
|
||||
}
|
||||
|
||||
bi = str.indexOf(b, i + 1);
|
||||
}
|
||||
|
||||
i = ai < bi && ai >= 0 ? ai : bi;
|
||||
}
|
||||
|
||||
if (begs.length) {
|
||||
result = [ left, right ];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "balanced-match",
|
||||
"description": "Match balanced character pairs, like \"{\" and \"}\"",
|
||||
"version": "1.0.2",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/juliangruber/balanced-match.git"
|
||||
},
|
||||
"homepage": "https://github.com/juliangruber/balanced-match",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "tape test/test.js",
|
||||
"bench": "matcha test/bench.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"matcha": "^0.7.0",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"keywords": [
|
||||
"match",
|
||||
"regexp",
|
||||
"test",
|
||||
"balanced",
|
||||
"parse"
|
||||
],
|
||||
"author": {
|
||||
"name": "Julian Gruber",
|
||||
"email": "mail@juliangruber.com",
|
||||
"url": "http://juliangruber.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": [
|
||||
"ie/8..latest",
|
||||
"firefox/20..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/25..latest",
|
||||
"chrome/canary",
|
||||
"opera/12..latest",
|
||||
"opera/next",
|
||||
"safari/5.1..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2..latest"
|
||||
]
|
||||
}
|
||||
}
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
# bare-events
|
||||
|
||||
Event emitters for JavaScript.
|
||||
|
||||
```
|
||||
npm install bare-events
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const EventEmitter = require('bare-events')
|
||||
|
||||
const e = new EventEmitter()
|
||||
|
||||
e.on('hello', function (data) {
|
||||
console.log(data)
|
||||
})
|
||||
|
||||
e.emit('hello', 'world')
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import * as events from './web'
|
||||
|
||||
type EventConstructor = typeof events.Event
|
||||
type EventTargetConstructor = typeof events.EventTarget
|
||||
|
||||
declare global {
|
||||
type Event = events.Event
|
||||
type EventTarget = events.EventTarget
|
||||
|
||||
const Event: EventConstructor
|
||||
const EventTarget: EventTargetConstructor
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
const events = require('./web')
|
||||
|
||||
global.Event = events.Event
|
||||
global.EventTarget = events.EventTarget
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
interface EventMap {
|
||||
[event: string | symbol]: unknown[]
|
||||
}
|
||||
|
||||
interface EventHandler<in A extends unknown[] = unknown[], out R = unknown> {
|
||||
(...args: A): R
|
||||
}
|
||||
|
||||
declare class EventEmitterError extends Error {
|
||||
static OPERATION_ABORTED(cause: Error, msg?: string): EventEmitterError
|
||||
static UNHANDLED_ERROR(cause: Error, msg?: string): EventEmitterError
|
||||
}
|
||||
|
||||
interface EventEmitter<in out M extends EventMap = EventMap> {
|
||||
addListener<E extends keyof M, R>(name: E, fn: EventHandler<M[E], R>): this
|
||||
|
||||
addOnceListener<E extends keyof M, R>(
|
||||
name: E,
|
||||
fn: EventHandler<M[E], R>
|
||||
): this
|
||||
|
||||
prependListener<E extends keyof M, R>(
|
||||
name: E,
|
||||
fn: EventHandler<M[E], R>
|
||||
): this
|
||||
|
||||
prependOnceListener<E extends keyof M, R>(
|
||||
name: E,
|
||||
fn: EventHandler<M[E], R>
|
||||
): this
|
||||
|
||||
removeListener<E extends keyof M, R>(name: E, fn: EventHandler<M[E], R>): this
|
||||
|
||||
removeAllListeners<E extends keyof M>(name?: E): this
|
||||
|
||||
on<E extends keyof M, R>(name: E, fn: EventHandler<M[E], R>): this
|
||||
|
||||
once<E extends keyof M, R>(name: E, fn: EventHandler<M[E], R>): this
|
||||
|
||||
off<E extends keyof M, R>(name: E, fn: EventHandler<M[E], R>): this
|
||||
|
||||
emit<E extends keyof M>(name: E, ...args: M[E]): boolean
|
||||
|
||||
listeners<E extends keyof M, R>(name: E): EventHandler<M[E], R>
|
||||
|
||||
listenerCount<E extends keyof M>(name: E): number
|
||||
|
||||
getMaxListeners(): number
|
||||
setMaxListeners(n: number): void
|
||||
}
|
||||
|
||||
declare class EventEmitter<in out M extends EventMap = EventMap> {}
|
||||
|
||||
declare namespace EventEmitter {
|
||||
export function on<M extends EventMap, E extends keyof M>(
|
||||
emitter: EventEmitter<M>,
|
||||
name: E,
|
||||
opts?: { signal?: AbortSignal }
|
||||
): AsyncIterableIterator<M[E]>
|
||||
|
||||
export function once<M extends EventMap, E extends keyof M>(
|
||||
emitter: EventEmitter<M>,
|
||||
name: E,
|
||||
opts?: { signal?: AbortSignal }
|
||||
): Promise<M[E]>
|
||||
|
||||
export function forward<
|
||||
F extends EventMap,
|
||||
E extends keyof F,
|
||||
T extends Pick<F, E>
|
||||
>(
|
||||
from: EventEmitter<F>,
|
||||
to: EventEmitter<T>,
|
||||
names: E | E[],
|
||||
opts?: { emit?: (name: E, ...args: T[E]) => void }
|
||||
): void
|
||||
|
||||
export function listenerCount<M extends EventMap, E extends keyof M>(
|
||||
emitter: EventEmitter<M>,
|
||||
name: E
|
||||
): number
|
||||
|
||||
export function getMaxListeners(emitter: EventEmitter): number
|
||||
|
||||
export function setMaxListeners(n: number, ...emitters: EventEmitter[]): void
|
||||
|
||||
export let defaultMaxListeners: number
|
||||
|
||||
export { EventEmitter, EventEmitterError as errors, EventMap, EventHandler }
|
||||
}
|
||||
|
||||
export = EventEmitter
|
||||
+355
@@ -0,0 +1,355 @@
|
||||
const errors = require('./lib/errors')
|
||||
|
||||
class EventListener {
|
||||
constructor() {
|
||||
this.list = []
|
||||
this.count = 0
|
||||
}
|
||||
|
||||
append(ctx, name, fn, once) {
|
||||
this.count++
|
||||
ctx.emit('newListener', name, fn) // Emit BEFORE adding
|
||||
this.list.push([fn, once])
|
||||
}
|
||||
|
||||
prepend(ctx, name, fn, once) {
|
||||
this.count++
|
||||
ctx.emit('newListener', name, fn) // Emit BEFORE adding
|
||||
this.list.unshift([fn, once])
|
||||
}
|
||||
|
||||
remove(ctx, name, fn) {
|
||||
for (let i = 0, n = this.list.length; i < n; i++) {
|
||||
const l = this.list[i]
|
||||
|
||||
if (l[0] === fn) {
|
||||
this.list.splice(i, 1)
|
||||
|
||||
if (this.count === 1) delete ctx._events[name]
|
||||
|
||||
ctx.emit('removeListener', name, fn) // Emit AFTER removing
|
||||
|
||||
this.count--
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removeAll(ctx, name) {
|
||||
const list = [...this.list]
|
||||
this.list = []
|
||||
|
||||
if (this.count === list.length) delete ctx._events[name]
|
||||
|
||||
for (let i = list.length - 1; i >= 0; i--) {
|
||||
ctx.emit('removeListener', name, list[i][0]) // Emit AFTER removing
|
||||
}
|
||||
|
||||
this.count -= list.length
|
||||
}
|
||||
|
||||
emit(ctx, name, ...args) {
|
||||
const list = [...this.list]
|
||||
|
||||
for (let i = 0, n = list.length; i < n; i++) {
|
||||
const l = list[i]
|
||||
|
||||
if (l[1] === true) this.remove(ctx, name, l[0])
|
||||
|
||||
Reflect.apply(l[0], ctx, args)
|
||||
}
|
||||
|
||||
return list.length > 0
|
||||
}
|
||||
}
|
||||
|
||||
function appendListener(ctx, name, fn, once) {
|
||||
const e = ctx._events[name] || (ctx._events[name] = new EventListener())
|
||||
e.append(ctx, name, fn, once)
|
||||
return ctx
|
||||
}
|
||||
|
||||
function prependListener(ctx, name, fn, once) {
|
||||
const e = ctx._events[name] || (ctx._events[name] = new EventListener())
|
||||
e.prepend(ctx, name, fn, once)
|
||||
return ctx
|
||||
}
|
||||
|
||||
function removeListener(ctx, name, fn) {
|
||||
const e = ctx._events[name]
|
||||
if (e !== undefined) e.remove(ctx, name, fn)
|
||||
return ctx
|
||||
}
|
||||
|
||||
function throwUnhandledError(...args) {
|
||||
let err
|
||||
|
||||
if (args.length > 0) err = args[0]
|
||||
|
||||
if (err instanceof Error === false) err = errors.UNHANDLED_ERROR(err)
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(err, exports.prototype.emit)
|
||||
}
|
||||
|
||||
queueMicrotask(() => {
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = exports = class EventEmitter {
|
||||
constructor() {
|
||||
this._events = Object.create(null)
|
||||
}
|
||||
|
||||
addListener(name, fn) {
|
||||
return appendListener(this, name, fn, false)
|
||||
}
|
||||
|
||||
addOnceListener(name, fn) {
|
||||
return appendListener(this, name, fn, true)
|
||||
}
|
||||
|
||||
prependListener(name, fn) {
|
||||
return prependListener(this, name, fn, false)
|
||||
}
|
||||
|
||||
prependOnceListener(name, fn) {
|
||||
return prependListener(this, name, fn, true)
|
||||
}
|
||||
|
||||
removeListener(name, fn) {
|
||||
return removeListener(this, name, fn)
|
||||
}
|
||||
|
||||
on(name, fn) {
|
||||
return appendListener(this, name, fn, false)
|
||||
}
|
||||
|
||||
once(name, fn) {
|
||||
return appendListener(this, name, fn, true)
|
||||
}
|
||||
|
||||
off(name, fn) {
|
||||
return removeListener(this, name, fn)
|
||||
}
|
||||
|
||||
emit(name, ...args) {
|
||||
if (name === 'error' && this._events.error === undefined) {
|
||||
throwUnhandledError(...args)
|
||||
}
|
||||
|
||||
const e = this._events[name]
|
||||
return e === undefined ? false : e.emit(this, name, ...args)
|
||||
}
|
||||
|
||||
listeners(name) {
|
||||
const e = this._events[name]
|
||||
return e === undefined ? [] : [...e.list]
|
||||
}
|
||||
|
||||
listenerCount(name) {
|
||||
const e = this._events[name]
|
||||
return e === undefined ? 0 : e.list.length
|
||||
}
|
||||
|
||||
getMaxListeners() {
|
||||
return EventEmitter.defaultMaxListeners
|
||||
}
|
||||
|
||||
setMaxListeners(n) {}
|
||||
|
||||
removeAllListeners(name) {
|
||||
if (arguments.length === 0) {
|
||||
for (const key of Reflect.ownKeys(this._events)) {
|
||||
if (key === 'removeListener') continue
|
||||
this.removeAllListeners(key)
|
||||
}
|
||||
this.removeAllListeners('removeListener')
|
||||
} else {
|
||||
const e = this._events[name]
|
||||
if (e !== undefined) e.removeAll(this, name)
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
exports.EventEmitter = exports
|
||||
|
||||
exports.errors = errors
|
||||
|
||||
exports.defaultMaxListeners = 10
|
||||
|
||||
exports.on = function on(emitter, name, opts = {}) {
|
||||
const { signal } = opts
|
||||
|
||||
if (signal && signal.aborted) {
|
||||
throw errors.OPERATION_ABORTED(signal.reason)
|
||||
}
|
||||
|
||||
let error = null
|
||||
let done = false
|
||||
|
||||
const events = []
|
||||
const promises = []
|
||||
|
||||
emitter.on(name, onevent)
|
||||
|
||||
if (name !== 'error') emitter.on('error', onerror)
|
||||
|
||||
if (signal) signal.addEventListener('abort', onabort)
|
||||
|
||||
return {
|
||||
next() {
|
||||
if (events.length) {
|
||||
return Promise.resolve({ value: events.shift(), done: false })
|
||||
}
|
||||
|
||||
if (error) {
|
||||
const err = error
|
||||
|
||||
error = null
|
||||
|
||||
return Promise.reject(err)
|
||||
}
|
||||
|
||||
if (done) return onclose()
|
||||
|
||||
return new Promise((resolve, reject) =>
|
||||
promises.push({ resolve, reject })
|
||||
)
|
||||
},
|
||||
|
||||
return() {
|
||||
return onclose()
|
||||
},
|
||||
|
||||
throw(err) {
|
||||
return onerror(err)
|
||||
},
|
||||
|
||||
[Symbol.asyncIterator]() {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
function onevent(...args) {
|
||||
if (promises.length) {
|
||||
promises.shift().resolve({ value: args, done: false })
|
||||
} else {
|
||||
events.push(args)
|
||||
}
|
||||
}
|
||||
|
||||
function onerror(err) {
|
||||
if (promises.length) {
|
||||
promises.shift().reject(err)
|
||||
} else {
|
||||
error = err
|
||||
}
|
||||
|
||||
return Promise.resolve({ done: true })
|
||||
}
|
||||
|
||||
function onabort() {
|
||||
onerror(errors.OPERATION_ABORTED(signal.reason))
|
||||
}
|
||||
|
||||
function onclose() {
|
||||
emitter.off(name, onevent)
|
||||
|
||||
if (name !== 'error') emitter.off('error', onerror)
|
||||
|
||||
if (signal) signal.removeEventListener('abort', onabort)
|
||||
|
||||
done = true
|
||||
|
||||
if (promises.length) promises.shift().resolve({ done: true })
|
||||
|
||||
return Promise.resolve({ done: true })
|
||||
}
|
||||
}
|
||||
|
||||
exports.once = function once(emitter, name, opts = {}) {
|
||||
const { signal } = opts
|
||||
|
||||
if (signal && signal.aborted) {
|
||||
throw errors.OPERATION_ABORTED(signal.reason)
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (name !== 'error') emitter.on('error', onerror)
|
||||
|
||||
if (signal) signal.addEventListener('abort', onabort)
|
||||
|
||||
emitter.once(name, (...args) => {
|
||||
if (name !== 'error') emitter.off('error', onerror)
|
||||
|
||||
if (signal) signal.removeEventListener('abort', onabort)
|
||||
|
||||
resolve(args)
|
||||
})
|
||||
|
||||
function onerror(err) {
|
||||
emitter.off('error', onerror)
|
||||
|
||||
reject(err)
|
||||
}
|
||||
|
||||
function onabort() {
|
||||
signal.removeEventListener('abort', onabort)
|
||||
|
||||
onerror(errors.OPERATION_ABORTED(signal.reason))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
exports.forward = function forward(from, to, names, opts = {}) {
|
||||
if (typeof names === 'string') names = [names]
|
||||
|
||||
const { emit = to.emit.bind(to) } = opts
|
||||
|
||||
const listeners = names.map(
|
||||
(name) =>
|
||||
function onevent(...args) {
|
||||
emit(name, ...args)
|
||||
}
|
||||
)
|
||||
|
||||
to.on('newListener', (name) => {
|
||||
const i = names.indexOf(name)
|
||||
|
||||
if (i !== -1 && to.listenerCount(name) === 0) {
|
||||
from.on(name, listeners[i])
|
||||
}
|
||||
}).on('removeListener', (name) => {
|
||||
const i = names.indexOf(name)
|
||||
|
||||
if (i !== -1 && to.listenerCount(name) === 0) {
|
||||
from.off(name, listeners[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
exports.listenerCount = function listenerCount(emitter, name) {
|
||||
return emitter.listenerCount(name)
|
||||
}
|
||||
|
||||
exports.getMaxListeners = function getMaxListeners(emitter) {
|
||||
if (typeof emitter.getMaxListeners === 'function') {
|
||||
return emitter.getMaxListeners()
|
||||
}
|
||||
|
||||
return exports.defaultMaxListeners
|
||||
}
|
||||
|
||||
exports.setMaxListeners = function setMaxListeners(n, ...emitters) {
|
||||
if (emitters.length === 0) exports.defaultMaxListeners = n
|
||||
else {
|
||||
for (const emitter of emitters) {
|
||||
if (typeof emitter.setMaxListeners === 'function') {
|
||||
emitter.setMaxListeners(n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
module.exports = class EventEmitterError extends Error {
|
||||
constructor(msg, code, fn = EventEmitterError, opts) {
|
||||
super(`${code}: ${msg}`, opts)
|
||||
this.code = code
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, fn)
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'EventEmitterError'
|
||||
}
|
||||
|
||||
static OPERATION_ABORTED(cause, msg = 'Operation aborted') {
|
||||
return new EventEmitterError(
|
||||
msg,
|
||||
'OPERATION_ABORTED',
|
||||
EventEmitterError.OPERATION_ABORTED,
|
||||
{ cause }
|
||||
)
|
||||
}
|
||||
|
||||
static UNHANDLED_ERROR(cause, msg = 'Unhandled error') {
|
||||
return new EventEmitterError(
|
||||
msg,
|
||||
'UNHANDLED_ERROR',
|
||||
EventEmitterError.UNHANDLED_ERROR,
|
||||
{ cause }
|
||||
)
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "bare-events",
|
||||
"version": "2.7.0",
|
||||
"description": "Event emitters for JavaScript",
|
||||
"exports": {
|
||||
"./package": "./package.json",
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./global": {
|
||||
"types": "./global.d.ts",
|
||||
"default": "./global.js"
|
||||
},
|
||||
"./web": {
|
||||
"types": "./web.d.ts",
|
||||
"default": "./web.js"
|
||||
},
|
||||
"./errors": "./lib/errors.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"global.js",
|
||||
"global.d.ts",
|
||||
"web.js",
|
||||
"web.d.ts",
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "npm run lint && npm run test:bare && npm run test:node",
|
||||
"test:bare": "bare test.js",
|
||||
"test:node": "node test.js",
|
||||
"lint": "prettier . --check"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/holepunchto/bare-events.git"
|
||||
},
|
||||
"author": "Holepunch",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/holepunchto/bare-events/issues"
|
||||
},
|
||||
"homepage": "https://github.com/holepunchto/bare-events#readme",
|
||||
"devDependencies": {
|
||||
"brittle": "^3.3.2",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-config-standard": "^7.0.0"
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
interface AbortSignal extends EventTarget {}
|
||||
|
||||
export interface EventOptions {
|
||||
bubbles?: boolean
|
||||
cancelable?: boolean
|
||||
composed?: boolean
|
||||
}
|
||||
|
||||
export interface Event {
|
||||
readonly type: string
|
||||
readonly target: EventTarget | null
|
||||
readonly currentTarget: EventTarget | null
|
||||
readonly bubbles: boolean
|
||||
readonly cancelable: boolean
|
||||
readonly composed: boolean
|
||||
readonly defaultPrevented: boolean
|
||||
readonly isTrusted: boolean
|
||||
|
||||
preventDefault(): void
|
||||
stopPropagation(): void
|
||||
stopImmediatePropagation(): void
|
||||
}
|
||||
|
||||
export class Event {
|
||||
constructor(type: string, options?: EventOptions)
|
||||
}
|
||||
|
||||
export interface AddEventListenerOptions {
|
||||
capture?: boolean
|
||||
passive?: boolean
|
||||
once?: boolean
|
||||
signal?: AbortSignal | null
|
||||
}
|
||||
|
||||
export interface RemoveEventListenerOptions {
|
||||
capture?: boolean
|
||||
}
|
||||
|
||||
export interface EventTarget {
|
||||
addEventListener(
|
||||
type: string,
|
||||
callback: EventListener,
|
||||
options?: AddEventListenerOptions | boolean
|
||||
): void
|
||||
|
||||
removeEventListener(
|
||||
type: string,
|
||||
callback: EventListener,
|
||||
options?: RemoveEventListenerOptions | boolean
|
||||
): void
|
||||
|
||||
dispatchEvent(event: Event): boolean
|
||||
}
|
||||
|
||||
export class EventTarget {
|
||||
constructor()
|
||||
}
|
||||
|
||||
export type EventListener = EventCallback | EventHandler
|
||||
|
||||
export interface EventCallback {
|
||||
(event: Event): void
|
||||
}
|
||||
|
||||
export interface EventHandler {
|
||||
handleEvent(event: Event): void
|
||||
}
|
||||
+329
@@ -0,0 +1,329 @@
|
||||
// Event state
|
||||
const BUBBLES = 0x1
|
||||
const CANCELABLE = 0x2
|
||||
const COMPOSED = 0x4
|
||||
const CANCELED = 0x8
|
||||
const DISPATCH = 0x10
|
||||
const STOP = 0x20
|
||||
|
||||
// EventTarget state
|
||||
const CAPTURE = 0x1
|
||||
const PASSIVE = 0x2
|
||||
const ONCE = 0x4
|
||||
|
||||
// https://dom.spec.whatwg.org/#event
|
||||
exports.Event = class Event {
|
||||
// https://dom.spec.whatwg.org/#dom-event-event
|
||||
constructor(type, options = {}) {
|
||||
const { bubbles = false, cancelable = false, composed = false } = options
|
||||
|
||||
this._type = type
|
||||
this._target = null
|
||||
this._state = 0
|
||||
|
||||
if (bubbles) this._state |= BUBBLES
|
||||
if (cancelable) this._state |= CANCELABLE
|
||||
if (composed) this._state |= COMPOSED
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-type
|
||||
get type() {
|
||||
return this._type
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-target
|
||||
get target() {
|
||||
return this._target
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-currenttarget
|
||||
get currentTarget() {
|
||||
return null
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-bubbles
|
||||
get bubbles() {
|
||||
return (this._state & BUBBLES) !== 0
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-cancelable
|
||||
get cancelable() {
|
||||
return (this._state & CANCELABLE) !== 0
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-composed
|
||||
get composed() {
|
||||
return (this._state & COMPOSED) !== 0
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-defaultprevented
|
||||
get defaultPrevented() {
|
||||
return (this._state & CANCELED) !== 0
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||
get isTrusted() {
|
||||
return false
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-preventdefault
|
||||
preventDefault() {
|
||||
if (this._state & CANCELABLE) this._state |= CANCELED
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-stoppropagation
|
||||
stopPropagation() {}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
|
||||
stopImmediatePropagation() {
|
||||
this._state |= STOP
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
type: this.type,
|
||||
target: this.target,
|
||||
bubbles: this.bubbles,
|
||||
cancelable: this.cancelable,
|
||||
composed: this.composed,
|
||||
defaultPrevented: this.defaultPrevented,
|
||||
isTrusted: this.isTrusted
|
||||
}
|
||||
}
|
||||
|
||||
[Symbol.for('bare.inspect')]() {
|
||||
return {
|
||||
__proto__: { constructor: Event },
|
||||
|
||||
type: this.type,
|
||||
target: this.target,
|
||||
bubbles: this.bubbles,
|
||||
cancelable: this.cancelable,
|
||||
composed: this.composed,
|
||||
defaultPrevented: this.defaultPrevented,
|
||||
isTrusted: this.isTrusted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#eventtarget
|
||||
exports.EventTarget = class EventTarget {
|
||||
// https://dom.spec.whatwg.org/#dom-eventtarget-eventtarget
|
||||
constructor() {
|
||||
this._listeners = new Map()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener
|
||||
addEventListener(type, callback = null, options = {}) {
|
||||
if (typeof options === 'boolean') options = { capture: options }
|
||||
|
||||
const {
|
||||
capture = false,
|
||||
passive = false,
|
||||
once = false,
|
||||
signal = null
|
||||
} = options
|
||||
|
||||
if (signal !== null && signal.aborted) return
|
||||
if (callback === null) return
|
||||
|
||||
const listener = new EventListener(
|
||||
type,
|
||||
callback,
|
||||
capture,
|
||||
passive,
|
||||
once,
|
||||
signal
|
||||
)
|
||||
|
||||
const listeners = this._listeners.get(type)
|
||||
|
||||
if (listeners === undefined) this._listeners.set(type, listener)
|
||||
else {
|
||||
for (const existing of listeners) {
|
||||
if (callback === existing.callback && capture === existing.capture) {
|
||||
return // Duplicate listener
|
||||
}
|
||||
}
|
||||
|
||||
listener.link(listeners)
|
||||
|
||||
if (signal !== null) {
|
||||
signal.addEventListener('abort', onabort)
|
||||
|
||||
function onabort() {
|
||||
listener.unlink()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-eventtarget-removeeventlistener
|
||||
removeEventListener(type, callback = null, options = {}) {
|
||||
if (typeof options === 'boolean') options = { capture: options }
|
||||
|
||||
const { capture = false } = options
|
||||
|
||||
const listeners = this._listeners.get(type)
|
||||
|
||||
if (listeners === undefined) return
|
||||
|
||||
for (const existing of listeners) {
|
||||
if (callback === existing.callback && capture === existing.capture) {
|
||||
const next = existing.unlink()
|
||||
|
||||
if (listeners === existing) this._listeners.set(type, next)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
|
||||
dispatchEvent(event) {
|
||||
event._target = this
|
||||
event._state |= DISPATCH
|
||||
|
||||
const listeners = this._listeners.get(event.type)
|
||||
|
||||
try {
|
||||
if (listeners === undefined) return true
|
||||
|
||||
for (const listener of listeners) {
|
||||
// https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke
|
||||
|
||||
if (listener.once) listener.unlink()
|
||||
|
||||
let callback = listener.callback
|
||||
let context = this
|
||||
|
||||
if (typeof callback === 'object') {
|
||||
context = callback
|
||||
callback = callback.handleEvent
|
||||
}
|
||||
|
||||
Reflect.apply(callback, context, [event])
|
||||
|
||||
if (event._state & STOP) break
|
||||
}
|
||||
|
||||
return (event._state & CANCELED) === 0
|
||||
} finally {
|
||||
event._state &= ~DISPATCH
|
||||
event._state &= ~STOP
|
||||
}
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {}
|
||||
}
|
||||
|
||||
[Symbol.for('bare.inspect')]() {
|
||||
return {
|
||||
__proto__: { constructor: EventTarget }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-event-listener
|
||||
class EventListener {
|
||||
constructor(type, callback, capture, passive, once, signal) {
|
||||
this._type = type
|
||||
this._callback = callback
|
||||
this._signal = signal
|
||||
this._state = 0
|
||||
|
||||
if (capture) this._state |= CAPTURE
|
||||
if (passive) this._state |= PASSIVE
|
||||
if (once) this._state |= ONCE
|
||||
|
||||
this._previous = this
|
||||
this._next = this
|
||||
}
|
||||
|
||||
get type() {
|
||||
return this._type
|
||||
}
|
||||
|
||||
get callback() {
|
||||
return this._callback
|
||||
}
|
||||
|
||||
get capture() {
|
||||
return (this._state & CAPTURE) !== 0
|
||||
}
|
||||
|
||||
get passive() {
|
||||
return (this._state & PASSIVE) !== 0
|
||||
}
|
||||
|
||||
get once() {
|
||||
return (this._state & ONCE) !== 0
|
||||
}
|
||||
|
||||
get removed() {
|
||||
return this._previous === this && this._next === this
|
||||
}
|
||||
|
||||
link(listener) {
|
||||
const next = this._next
|
||||
const previous = listener._previous
|
||||
|
||||
this._next = listener
|
||||
listener._previous = this
|
||||
|
||||
previous._next = next
|
||||
next._previous = previous
|
||||
|
||||
return listener
|
||||
}
|
||||
|
||||
unlink() {
|
||||
if (this.removed) return this
|
||||
|
||||
const next = this._next
|
||||
const previous = this._previous
|
||||
|
||||
this._next = this
|
||||
this._previous = this
|
||||
|
||||
previous._next = next
|
||||
next._previous = previous
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
let current = this
|
||||
|
||||
while (true) {
|
||||
const next = current._next
|
||||
yield current
|
||||
if (next === this) break
|
||||
current = next
|
||||
}
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
type: this.type,
|
||||
capture: this.capture,
|
||||
passive: this.passive,
|
||||
once: this.once,
|
||||
removed: this.removed
|
||||
}
|
||||
}
|
||||
|
||||
[Symbol.for('bare.inspect')]() {
|
||||
return {
|
||||
__proto__: { constructor: EventListener },
|
||||
|
||||
type: this.type,
|
||||
callback: this.callback,
|
||||
capture: this.capture,
|
||||
passive: this.passive,
|
||||
once: this.once,
|
||||
removed: this.removed
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
|
||||
|
||||
project(bare_fs C)
|
||||
|
||||
add_bare_module(bare_fs)
|
||||
|
||||
target_sources(
|
||||
${bare_fs}
|
||||
PRIVATE
|
||||
binding.c
|
||||
)
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
# bare-fs
|
||||
|
||||
Native file system operations for Javascript.
|
||||
|
||||
```
|
||||
npm i bare-fs
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const fs = require('bare-fs')
|
||||
|
||||
const fd = await fs.open('hello.txt')
|
||||
|
||||
const buffer = Buffer.alloc(1024)
|
||||
|
||||
try {
|
||||
const length = await fs.read(fd, buffer)
|
||||
|
||||
console.log('Read', length, 'bytes')
|
||||
} finally {
|
||||
await fs.close(fd)
|
||||
}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
+2238
File diff suppressed because it is too large
Load Diff
+1
@@ -0,0 +1 @@
|
||||
module.exports = require.addon()
|
||||
+1265
File diff suppressed because it is too large
Load Diff
+2332
File diff suppressed because it is too large
Load Diff
+49
@@ -0,0 +1,49 @@
|
||||
declare const constants: {
|
||||
O_RDWR: number
|
||||
O_RDONLY: number
|
||||
O_WRONLY: number
|
||||
O_CREAT: number
|
||||
O_TRUNC: number
|
||||
O_APPEND: number
|
||||
|
||||
F_OK: number
|
||||
R_OK: number
|
||||
W_OK: number
|
||||
X_OK: number
|
||||
|
||||
S_IFMT: number
|
||||
S_IFREG: number
|
||||
S_IFDIR: number
|
||||
S_IFCHR: number
|
||||
S_IFLNK: number
|
||||
S_IFBLK: number
|
||||
S_IFIFO: number
|
||||
S_IFSOCK: number
|
||||
|
||||
S_IRUSR: number
|
||||
S_IWUSR: number
|
||||
S_IXUSR: number
|
||||
S_IRGRP: number
|
||||
S_IWGRP: number
|
||||
S_IXGRP: number
|
||||
S_IROTH: number
|
||||
S_IWOTH: number
|
||||
S_IXOTH: number
|
||||
|
||||
UV_DIRENT_UNKNOWN: number
|
||||
UV_DIRENT_FILE: number
|
||||
UV_DIRENT_DIR: number
|
||||
UV_DIRENT_LINK: number
|
||||
UV_DIRENT_FIFO: number
|
||||
UV_DIRENT_SOCKET: number
|
||||
UV_DIRENT_CHAR: number
|
||||
UV_DIRENT_BLOCK: number
|
||||
|
||||
COPYFILE_EXCL: number
|
||||
COPYFILE_FICLONE: number
|
||||
COPYFILE_FICLONE_FORCE: number
|
||||
UV_FS_SYMLINK_DIR: number
|
||||
UV_FS_SYMLINK_JUNCTION: number
|
||||
}
|
||||
|
||||
export = constants
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
const binding = require('../binding')
|
||||
|
||||
module.exports = {
|
||||
O_RDWR: binding.O_RDWR,
|
||||
O_RDONLY: binding.O_RDONLY,
|
||||
O_WRONLY: binding.O_WRONLY,
|
||||
O_CREAT: binding.O_CREAT,
|
||||
O_TRUNC: binding.O_TRUNC,
|
||||
O_APPEND: binding.O_APPEND,
|
||||
|
||||
F_OK: binding.F_OK || 0,
|
||||
R_OK: binding.R_OK || 0,
|
||||
W_OK: binding.W_OK || 0,
|
||||
X_OK: binding.X_OK || 0,
|
||||
|
||||
S_IFMT: binding.S_IFMT,
|
||||
S_IFREG: binding.S_IFREG,
|
||||
S_IFDIR: binding.S_IFDIR,
|
||||
S_IFCHR: binding.S_IFCHR,
|
||||
S_IFLNK: binding.S_IFLNK,
|
||||
S_IFBLK: binding.S_IFBLK || 0,
|
||||
S_IFIFO: binding.S_IFIFO || 0,
|
||||
S_IFSOCK: binding.S_IFSOCK || 0,
|
||||
|
||||
S_IRUSR: binding.S_IRUSR || 0,
|
||||
S_IWUSR: binding.S_IWUSR || 0,
|
||||
S_IXUSR: binding.S_IXUSR || 0,
|
||||
S_IRGRP: binding.S_IRGRP || 0,
|
||||
S_IWGRP: binding.S_IWGRP || 0,
|
||||
S_IXGRP: binding.S_IXGRP || 0,
|
||||
S_IROTH: binding.S_IROTH || 0,
|
||||
S_IWOTH: binding.S_IWOTH || 0,
|
||||
S_IXOTH: binding.S_IXOTH || 0,
|
||||
|
||||
UV_DIRENT_UNKNOWN: binding.UV_DIRENT_UNKNOWN,
|
||||
UV_DIRENT_FILE: binding.UV_DIRENT_FILE,
|
||||
UV_DIRENT_DIR: binding.UV_DIRENT_DIR,
|
||||
UV_DIRENT_LINK: binding.UV_DIRENT_LINK,
|
||||
UV_DIRENT_FIFO: binding.UV_DIRENT_FIFO,
|
||||
UV_DIRENT_SOCKET: binding.UV_DIRENT_SOCKET,
|
||||
UV_DIRENT_CHAR: binding.UV_DIRENT_CHAR,
|
||||
UV_DIRENT_BLOCK: binding.UV_DIRENT_BLOCK,
|
||||
|
||||
COPYFILE_EXCL: binding.UV_FS_COPYFILE_EXCL,
|
||||
COPYFILE_FICLONE: binding.UV_FS_COPYFILE_FICLONE,
|
||||
COPYFILE_FICLONE_FORCE: binding.UV_FS_COPYFILE_FICLONE_FORCE,
|
||||
UV_FS_SYMLINK_DIR: binding.UV_FS_SYMLINK_DIR,
|
||||
UV_FS_SYMLINK_JUNCTION: binding.UV_FS_SYMLINK_JUNCTION
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
declare class FileError extends Error {
|
||||
private constructor(msg: string)
|
||||
|
||||
readonly code: string
|
||||
readonly operation?: string
|
||||
readonly path?: string
|
||||
readonly destination?: string
|
||||
readonly fd?: number
|
||||
}
|
||||
|
||||
export = FileError
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
const os = require('bare-os')
|
||||
|
||||
module.exports = class FileError extends Error {
|
||||
constructor(msg, opts = {}) {
|
||||
const {
|
||||
code,
|
||||
operation = null,
|
||||
path = null,
|
||||
destination = null,
|
||||
fd = -1
|
||||
} = opts
|
||||
|
||||
if (operation !== null) msg += describe(operation, opts)
|
||||
|
||||
super(`${code}: ${msg}`)
|
||||
|
||||
this.code = code
|
||||
|
||||
if (operation !== null) this.operation = operation
|
||||
if (path !== null) this.path = path
|
||||
if (destination !== null) this.destination = destination
|
||||
if (fd !== -1) this.fd = fd
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'FileError'
|
||||
}
|
||||
|
||||
// For Node.js compatibility
|
||||
get errno() {
|
||||
return os.constants.errnos[this.code]
|
||||
}
|
||||
|
||||
// For Node.js compatibility
|
||||
get syscall() {
|
||||
return this.operation
|
||||
}
|
||||
|
||||
// For Node.js compatibility
|
||||
get dest() {
|
||||
return this.destination
|
||||
}
|
||||
}
|
||||
|
||||
function describe(operation, opts) {
|
||||
const { path = null, destination = null, fd = -1 } = opts
|
||||
|
||||
let result = `, ${operation}`
|
||||
|
||||
if (path !== null) {
|
||||
result += ` ${JSON.stringify(path)}`
|
||||
|
||||
if (destination !== null) {
|
||||
result += ` -> ${JSON.stringify(destination)}`
|
||||
}
|
||||
} else if (fd !== -1) {
|
||||
result += ` ${fd}`
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"name": "bare-fs",
|
||||
"version": "4.4.5",
|
||||
"description": "Native file system operations for Javascript",
|
||||
"exports": {
|
||||
"./package": "./package.json",
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./promises": {
|
||||
"types": "./promises.d.ts",
|
||||
"default": "./promises.js"
|
||||
},
|
||||
"./constants": {
|
||||
"types": "./lib/constants.d.ts",
|
||||
"default": "./lib/constants.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"promises.js",
|
||||
"promises.d.ts",
|
||||
"binding.c",
|
||||
"binding.js",
|
||||
"CMakeLists.txt",
|
||||
"lib",
|
||||
"prebuilds"
|
||||
],
|
||||
"addon": true,
|
||||
"scripts": {
|
||||
"test": "prettier . --check && bare test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/holepunchto/bare-fs.git"
|
||||
},
|
||||
"author": "Holepunch",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/holepunchto/bare-fs/issues"
|
||||
},
|
||||
"homepage": "https://github.com/holepunchto/bare-fs#readme",
|
||||
"engines": {
|
||||
"bare": ">=1.16.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bare-events": "^2.5.4",
|
||||
"bare-path": "^3.0.0",
|
||||
"bare-stream": "^2.6.4",
|
||||
"bare-url": "^2.2.2",
|
||||
"fast-fifo": "^1.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bare-buffer": "^3.0.2",
|
||||
"bare-crypto": "^1.11.2",
|
||||
"brittle": "^3.1.1",
|
||||
"cmake-bare": "^1.1.7",
|
||||
"prettier": "^3.4.1",
|
||||
"prettier-config-standard": "^7.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bare-buffer": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bare-buffer": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+319
@@ -0,0 +1,319 @@
|
||||
import EventEmitter, { EventMap } from 'bare-events'
|
||||
import Buffer, { BufferEncoding } from 'bare-buffer'
|
||||
import {
|
||||
constants,
|
||||
AppendFileOptions,
|
||||
Dir,
|
||||
MkdirOptions,
|
||||
OpendirOptions,
|
||||
Path,
|
||||
ReadFileOptions,
|
||||
ReadStream,
|
||||
ReadStreamOptions,
|
||||
ReaddirOptions,
|
||||
ReadlinkOptions,
|
||||
RealpathOptions,
|
||||
RmOptions,
|
||||
Stats,
|
||||
Watcher,
|
||||
WatcherOptions,
|
||||
WriteFileOptions,
|
||||
WriteStream,
|
||||
WriteStreamOptions
|
||||
} from '.'
|
||||
|
||||
export { constants }
|
||||
|
||||
interface FileHandleEvents extends EventMap {
|
||||
close: []
|
||||
}
|
||||
|
||||
interface FileHandle extends EventEmitter<FileHandleEvents>, AsyncDisposable {
|
||||
close(): Promise<void>
|
||||
|
||||
read(
|
||||
buffer: Buffer | ArrayBufferView,
|
||||
offset?: number,
|
||||
len?: number,
|
||||
pos?: number
|
||||
): Promise<number>
|
||||
|
||||
readv(buffers: ArrayBufferView[], position?: number): Promise<number>
|
||||
|
||||
write(
|
||||
data: Buffer | ArrayBufferView,
|
||||
offset?: number,
|
||||
len?: number,
|
||||
pos?: number
|
||||
): Promise<number>
|
||||
|
||||
write(data: string, pos?: number, encoding?: BufferEncoding): Promise<number>
|
||||
|
||||
stat(): Promise<Stats>
|
||||
|
||||
chmod(mode: string | number): Promise<void>
|
||||
|
||||
createReadStream(opts?: ReadStreamOptions): ReadStream
|
||||
|
||||
createWriteStream(opts?: WriteStreamOptions): WriteStream
|
||||
}
|
||||
|
||||
declare class FileHandle {
|
||||
private constructor(fd: number)
|
||||
}
|
||||
|
||||
export function open(
|
||||
filepath: Path,
|
||||
flags?: Flag | number,
|
||||
mode?: string | number
|
||||
): Promise<FileHandle>
|
||||
|
||||
export function access(filepath: Path, mode?: number): Promise<void>
|
||||
|
||||
export function appendFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
opts?: AppendFileOptions
|
||||
): Promise<void>
|
||||
|
||||
export function appendFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
encoding: BufferEncoding
|
||||
): Promise<void>
|
||||
|
||||
export function chmod(filepath: Path, mode: string | number): Promise<void>
|
||||
|
||||
export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
|
||||
|
||||
export function lstat(filepath: Path): Promise<Stats>
|
||||
|
||||
export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
|
||||
|
||||
export function mkdir(filepath: Path, mode: number): Promise<void>
|
||||
|
||||
export function opendir(
|
||||
filepath: Path,
|
||||
opts: OpendirOptions & { encoding?: BufferEncoding }
|
||||
): Promise<Dir<string>>
|
||||
|
||||
export function opendir(
|
||||
filepath: Path,
|
||||
opts: OpendirOptions & { encoding: 'buffer' }
|
||||
): Promise<Dir<Buffer>>
|
||||
|
||||
export function opendir(filepath: Path, opts: OpendirOptions): Promise<Dir>
|
||||
|
||||
export function opendir(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding
|
||||
): Promise<Dir<string>>
|
||||
|
||||
export function opendir(
|
||||
filepath: Path,
|
||||
encoding: 'buffer'
|
||||
): Promise<Dir<Buffer>>
|
||||
|
||||
export function opendir(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Promise<Dir>
|
||||
|
||||
export function opendir(filepath: Path): Promise<Dir<string>>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
opts: ReadFileOptions & { encoding: BufferEncoding }
|
||||
): Promise<string>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
opts: ReadFileOptions & { encoding?: 'buffer' }
|
||||
): Promise<Buffer>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
opts: ReadFileOptions
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding
|
||||
): Promise<string>
|
||||
|
||||
export function readFile(filepath: Path, encoding: 'buffer'): Promise<Buffer>
|
||||
|
||||
export function readFile(
|
||||
filepath: Path,
|
||||
encoding?: BufferEncoding | 'buffer'
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function readFile(filepath: Path): Promise<Buffer>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding?: BufferEncoding }
|
||||
): Promise<Dir<string>[] | string[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
|
||||
): Promise<Dir<string>[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes?: false }
|
||||
): Promise<string[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding: 'buffer' }
|
||||
): Promise<Dir<Buffer>[] | Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
|
||||
): Promise<Dir<Buffer>[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes?: false }
|
||||
): Promise<Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { withFileTypes: true }
|
||||
): Promise<Dir<string | Buffer>[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions & { withFileTypes?: false }
|
||||
): Promise<string[] | Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
opts: ReaddirOptions
|
||||
): Promise<Dir[] | string[] | Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding
|
||||
): Promise<string[]>
|
||||
|
||||
export function readdir(filepath: Path, encoding: 'buffer'): Promise<Buffer[]>
|
||||
|
||||
export function readdir(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Promise<string[] | Buffer[]>
|
||||
|
||||
export function readdir(filepath: Path): Promise<string[]>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
opts: ReadlinkOptions & { encoding?: BufferEncoding }
|
||||
): Promise<string>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
opts: ReadlinkOptions & { encoding: 'buffer' }
|
||||
): Promise<Buffer>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
opts: ReadlinkOptions
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding
|
||||
): Promise<string>
|
||||
|
||||
export function readlink(filepath: Path, encoding: 'buffer'): Promise<Buffer>
|
||||
|
||||
export function readlink(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function readlink(filepath: Path): Promise<string>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
opts: RealpathOptions & { encoding?: BufferEncoding }
|
||||
): Promise<string>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
opts: RealpathOptions & { encoding: 'buffer' }
|
||||
): Promise<Buffer>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
opts: RealpathOptions
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding
|
||||
): Promise<string>
|
||||
|
||||
export function realpath(filepath: Path, encoding: 'buffer'): Promise<Buffer>
|
||||
|
||||
export function realpath(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Promise<string | Buffer>
|
||||
|
||||
export function realpath(filepath: Path): Promise<string>
|
||||
|
||||
export function rename(src: Path, dst: Path): Promise<void>
|
||||
|
||||
export function rm(filepath: Path, opts?: RmOptions): Promise<void>
|
||||
|
||||
export function rmdir(filepath: Path): Promise<void>
|
||||
|
||||
export function stat(filepath: Path): Promise<Stats>
|
||||
|
||||
export function symlink(
|
||||
target: Path,
|
||||
filepath: Path,
|
||||
type?: string | number
|
||||
): Promise<void>
|
||||
|
||||
export function unlink(filepath: Path): Promise<void>
|
||||
|
||||
export function watch(
|
||||
filepath: Path,
|
||||
opts: WatcherOptions & { encoding?: BufferEncoding }
|
||||
): Watcher<string>
|
||||
|
||||
export function watch(
|
||||
filepath: Path,
|
||||
opts: WatcherOptions & { encoding: 'buffer' }
|
||||
): Watcher<Buffer>
|
||||
|
||||
export function watch(filepath: Path, opts: WatcherOptions): Watcher
|
||||
|
||||
export function watch(filepath: Path, encoding: BufferEncoding): Watcher<string>
|
||||
|
||||
export function watch(filepath: Path, encoding: 'buffer'): Watcher<Buffer>
|
||||
|
||||
export function watch(
|
||||
filepath: Path,
|
||||
encoding: BufferEncoding | 'buffer'
|
||||
): Watcher
|
||||
|
||||
export function watch(filepath: Path): Watcher<string>
|
||||
|
||||
export function writeFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
opts?: WriteFileOptions
|
||||
): Promise<void>
|
||||
|
||||
export function writeFile(
|
||||
filepath: Path,
|
||||
data: string | Buffer | ArrayBufferView,
|
||||
encoding: BufferEncoding
|
||||
): Promise<void>
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
const EventEmitter = require('bare-events')
|
||||
const fs = require('.')
|
||||
|
||||
class FileHandle extends EventEmitter {
|
||||
constructor(fd) {
|
||||
this.fd = fd
|
||||
}
|
||||
|
||||
async close() {
|
||||
await fs.close(fd)
|
||||
|
||||
this.fd = -1
|
||||
this.emit('close')
|
||||
}
|
||||
|
||||
async read(buffer, ...args) {
|
||||
return {
|
||||
bytesRead: await fs.read(this.fd, buffer, ...args),
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
async readv(buffers, ...args) {
|
||||
return {
|
||||
bytesRead: await fs.readv(this.fd, buffers, ...args),
|
||||
buffers
|
||||
}
|
||||
}
|
||||
|
||||
async write(buffer, ...args) {
|
||||
return {
|
||||
bytesWritten: await fs.write(this.fd, buffer, ...args),
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
async writev(buffers, ...args) {
|
||||
return {
|
||||
bytesWritten: await fs.writev(this.fd, buffers, ...args),
|
||||
buffers
|
||||
}
|
||||
}
|
||||
|
||||
async stat() {
|
||||
return fs.fstat(this.fd)
|
||||
}
|
||||
|
||||
async chmod(mode) {
|
||||
await fs.fchmod(this.fd, mode)
|
||||
}
|
||||
|
||||
createReadStream(opts) {
|
||||
return fs.createReadStream(null, { ...opts, fd: this.fd })
|
||||
}
|
||||
|
||||
createWriteStream(opts) {
|
||||
return fs.createWriteStream(null, { ...opts, fd: this.fd })
|
||||
}
|
||||
|
||||
async [Symbol.asyncDispose]() {
|
||||
await this.close()
|
||||
}
|
||||
}
|
||||
|
||||
exports.open = async function open(filepath, flags, mode) {
|
||||
return new FileHandle(await fs.open(filepath, flags, mode))
|
||||
}
|
||||
|
||||
exports.access = fs.access
|
||||
exports.appendFile = fs.appendFile
|
||||
exports.chmod = fs.chmod
|
||||
exports.constants = fs.constants
|
||||
exports.copyFile = fs.copyFile
|
||||
exports.lstat = fs.lstat
|
||||
exports.mkdir = fs.mkdir
|
||||
exports.opendir = fs.opendir
|
||||
exports.readFile = fs.readFile
|
||||
exports.readdir = fs.readdir
|
||||
exports.readlink = fs.readlink
|
||||
exports.realpath = fs.realpath
|
||||
exports.rename = fs.rename
|
||||
exports.rm = fs.rm
|
||||
exports.rmdir = fs.rmdir
|
||||
exports.stat = fs.stat
|
||||
exports.symlink = fs.symlink
|
||||
exports.unlink = fs.unlink
|
||||
exports.utimes = fs.utimes
|
||||
exports.watch = fs.watch
|
||||
exports.writeFile = fs.writeFile
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
|
||||
find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
|
||||
|
||||
project(bare_os C)
|
||||
|
||||
add_bare_module(bare_os)
|
||||
|
||||
target_sources(
|
||||
${bare_os}
|
||||
PRIVATE
|
||||
binding.c
|
||||
)
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
# bare-os
|
||||
|
||||
Operating system utilities for Javascript.
|
||||
|
||||
```
|
||||
npm i bare-os
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
+1119
File diff suppressed because it is too large
Load Diff
+1
@@ -0,0 +1 @@
|
||||
module.exports = require.addon()
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
export const constants: {
|
||||
signals: Record<string, number>
|
||||
errnos: Record<string, number>
|
||||
}
|
||||
|
||||
export const EOL: '\r\n' | '\n'
|
||||
|
||||
export function platform(): 'android' | 'darwin' | 'ios' | 'linux' | 'win32'
|
||||
|
||||
export function arch(): 'arm' | 'arm64' | 'ia32' | 'x64'
|
||||
|
||||
export function type(): string
|
||||
|
||||
export function version(): string
|
||||
|
||||
export function release(): string
|
||||
|
||||
export function machine(): string
|
||||
|
||||
export function execPath(): string
|
||||
|
||||
export function pid(): number
|
||||
|
||||
export function ppid(): number
|
||||
|
||||
export function cwd(): string
|
||||
|
||||
export function chdir(dir: string): string
|
||||
|
||||
export function tmpdir(): string
|
||||
|
||||
export function homedir(): string
|
||||
|
||||
export function hostname(): string
|
||||
|
||||
export function kill(pid: number, signal?: string | number): void
|
||||
|
||||
export function endianness(): 'LE' | 'BE'
|
||||
|
||||
export function availableParallelism(): number
|
||||
|
||||
export interface CpuUsage {
|
||||
user: number
|
||||
system: number
|
||||
}
|
||||
|
||||
export function cpuUsage(previous?: CpuUsage): CpuUsage
|
||||
|
||||
export function threadCpuUsage(previous?: CpuUsage): CpuUsage
|
||||
|
||||
export function resourceUsage(): {
|
||||
userCPUTime: number
|
||||
systemCPUTime: number
|
||||
maxRSS: number
|
||||
sharedMemorySize: number
|
||||
unsharedDataSize: number
|
||||
unsharedStackSize: number
|
||||
minorPageFault: number
|
||||
majorPageFault: number
|
||||
swappedOut: number
|
||||
fsRead: number
|
||||
fsWrite: number
|
||||
ipcSent: number
|
||||
ipcReceived: number
|
||||
signalsCount: number
|
||||
voluntaryContextSwitches: number
|
||||
involuntaryContextSwitches: number
|
||||
}
|
||||
|
||||
export function memoryUsage(): {
|
||||
rss: number
|
||||
heapTotal: number
|
||||
heapUsed: number
|
||||
external: number
|
||||
}
|
||||
|
||||
export function freemem(): number
|
||||
|
||||
export function totalmem(): number
|
||||
|
||||
export function uptime(): number
|
||||
|
||||
export function loadavg(): ArrayLike<number>
|
||||
|
||||
export function cpus(): {
|
||||
model: string
|
||||
speed: number
|
||||
times: {
|
||||
user: number
|
||||
nice: number
|
||||
sys: number
|
||||
idle: number
|
||||
irq: number
|
||||
}
|
||||
}[]
|
||||
|
||||
export function getProcessTitle(): string
|
||||
|
||||
export function setProcessTitle(title: unknown): void
|
||||
|
||||
export function getEnvKeys(): string[]
|
||||
|
||||
export function getEnv(name: string): string | undefined
|
||||
|
||||
export function hasEnv(name: string): boolean
|
||||
|
||||
export function setEnv(name: string, value: string): void
|
||||
|
||||
export function unsetEnv(name: string): void
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
const binding = require('./binding')
|
||||
const errors = require('./lib/errors')
|
||||
const constants = require('./lib/constants')
|
||||
|
||||
exports.constants = constants
|
||||
|
||||
exports.EOL = binding.platform === 'win32' ? '\r\n' : '\n'
|
||||
|
||||
exports.platform = function platform() {
|
||||
return binding.platform
|
||||
}
|
||||
|
||||
exports.arch = function arch() {
|
||||
return binding.arch
|
||||
}
|
||||
|
||||
exports.type = binding.type
|
||||
exports.version = binding.version
|
||||
exports.release = binding.release
|
||||
exports.machine = binding.machine
|
||||
exports.execPath = binding.execPath
|
||||
exports.pid = binding.pid
|
||||
exports.ppid = binding.ppid
|
||||
exports.cwd = binding.cwd
|
||||
exports.chdir = binding.chdir
|
||||
exports.tmpdir = binding.tmpdir
|
||||
exports.homedir = binding.homedir
|
||||
exports.hostname = binding.hostname
|
||||
exports.userInfo = binding.userInfo
|
||||
|
||||
exports.kill = function kill(pid, signal = constants.signals.SIGTERM) {
|
||||
if (typeof signal === 'string') {
|
||||
if (signal in constants.signals === false) {
|
||||
throw errors.UNKNOWN_SIGNAL('Unknown signal: ' + signal)
|
||||
}
|
||||
|
||||
signal = constants.signals[signal]
|
||||
}
|
||||
|
||||
binding.kill(pid, signal)
|
||||
}
|
||||
|
||||
exports.endianness = function endianness() {
|
||||
return binding.isLittleEndian ? 'LE' : 'BE'
|
||||
}
|
||||
|
||||
exports.availableParallelism = binding.availableParallelism
|
||||
|
||||
exports.cpuUsage = function cpuUsage(previous) {
|
||||
const current = binding.cpuUsage()
|
||||
|
||||
if (previous) {
|
||||
return {
|
||||
user: current.user - previous.user,
|
||||
system: current.system - previous.system
|
||||
}
|
||||
}
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
exports.threadCpuUsage = function threadCpuUsage(previous) {
|
||||
const current = binding.threadCpuUsage()
|
||||
|
||||
if (previous) {
|
||||
return {
|
||||
user: current.user - previous.user,
|
||||
system: current.system - previous.system
|
||||
}
|
||||
}
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
exports.resourceUsage = binding.resourceUsage
|
||||
exports.memoryUsage = binding.memoryUsage
|
||||
exports.freemem = binding.freemem
|
||||
exports.totalmem = binding.totalmem
|
||||
exports.uptime = binding.uptime
|
||||
exports.loadavg = binding.loadavg
|
||||
exports.cpus = binding.cpus
|
||||
|
||||
exports.getProcessTitle = binding.getProcessTitle
|
||||
|
||||
exports.setProcessTitle = function setProcessTitle(title) {
|
||||
if (typeof title !== 'string') title = title.toString()
|
||||
|
||||
if (title.length >= 256) {
|
||||
throw errors.TITLE_OVERFLOW('Process title is too long')
|
||||
}
|
||||
|
||||
binding.setProcessTitle(title)
|
||||
}
|
||||
|
||||
exports.getEnvKeys = binding.getEnvKeys
|
||||
exports.getEnv = binding.getEnv
|
||||
exports.hasEnv = binding.hasEnv
|
||||
exports.setEnv = binding.setEnv
|
||||
exports.unsetEnv = binding.unsetEnv
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
const binding = require('../binding')
|
||||
|
||||
module.exports = {
|
||||
signals: binding.signals,
|
||||
errnos: binding.errnos
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
module.exports = class OSError extends Error {
|
||||
constructor(msg, code, fn = OSError) {
|
||||
super(`${code}: ${msg}`)
|
||||
this.code = code
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, fn)
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'OSError'
|
||||
}
|
||||
|
||||
static UNKNOWN_SIGNAL(msg) {
|
||||
return new OSError(msg, 'UNKNOWN_SIGNAL', OSError.UNKNOWN_SIGNAL)
|
||||
}
|
||||
|
||||
static TITLE_OVERFLOW(msg) {
|
||||
return new OSError(msg, 'TITLE_OVERFLOW', OSError.TITLE_OVERFLOW)
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "bare-os",
|
||||
"version": "3.6.2",
|
||||
"description": "Operating system utilities for Javascript",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./package": "./package.json",
|
||||
"./constants": "./lib/constants.js",
|
||||
"./errors": "./lib/errors.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"binding.c",
|
||||
"binding.js",
|
||||
"CMakeLists.txt",
|
||||
"lib",
|
||||
"prebuilds"
|
||||
],
|
||||
"addon": true,
|
||||
"scripts": {
|
||||
"test": "prettier . --check && bare test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/holepunchto/bare-os.git"
|
||||
},
|
||||
"author": "Holepunch",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/holepunchto/bare-os/issues"
|
||||
},
|
||||
"homepage": "https://github.com/holepunchto/bare-os#readme",
|
||||
"engines": {
|
||||
"bare": ">=1.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"brittle": "^3.1.1",
|
||||
"cmake-bare": "^1.1.6",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-config-standard": "^7.0.0"
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
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