Initial commit
This commit is contained in:
commit
21e364ee38
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/../../../../:\IntellijProjects\woam-antispam-bot\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
12
.idea/dataSources.xml
generated
Normal file
12
.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="c1woam_bot@localhost" uuid="112d4e6b-18c0-47f6-af79-cbfa6a945483">
|
||||
<driver-ref>mariadb</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mariadb://localhost:3306/c1woam_bot</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
1101
.idea/dataSources/112d4e6b-18c0-47f6-af79-cbfa6a945483.xml
generated
Normal file
1101
.idea/dataSources/112d4e6b-18c0-47f6-af79-cbfa6a945483.xml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,2 @@
|
||||
#n:information_schema
|
||||
!<md> [null, 0, null, null, -2147483648, -2147483648]
|
6
.idea/discord.xml
generated
Normal file
6
.idea/discord.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
</component>
|
||||
</project>
|
6
.idea/jsLibraryMappings.xml
generated
Normal file
6
.idea/jsLibraryMappings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<includedPredefinedLibrary name="Node.js Core" />
|
||||
</component>
|
||||
</project>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/woam-antispam-bot.iml" filepath="$PROJECT_DIR$/woam-antispam-bot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
8
config.json
Normal file
8
config.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"prefix": ".w ",
|
||||
"TOKEN": "ODE5NTM0OTU2ODA3MzIzNjY5.YEoBZw.AENVYEFA-QCQt8XapCfjLfPThJY",
|
||||
"mysqlHost": "localhost",
|
||||
"mysqlUsername": "c1woam_bot",
|
||||
"mysqlDatabase": "c1woam_bot",
|
||||
"mysqlPassword": "siodzmHFEX#M2"
|
||||
}
|
265
index.js
Normal file
265
index.js
Normal file
@ -0,0 +1,265 @@
|
||||
// Required Things
|
||||
const Discord = require ( "discord.js" );
|
||||
const config = require ( "./config.json" );
|
||||
const AntiSpam = require ( "discord-anti-spam" );
|
||||
const mySQL = require( "mysql" );
|
||||
|
||||
|
||||
// new Discord Client
|
||||
const client = new Discord.Client ( {partials: [ 'MESSAGE', 'CHANNEL' ], disableMentions: "none"} );
|
||||
|
||||
const antiSpam = new AntiSpam ( {
|
||||
warnThreshold: 4, // Amount of messages sent in a row that will cause a warning.
|
||||
muteThreshold: 6, // Amount of messages sent in a row that will cause a mute
|
||||
kickThreshold: 10, // Amount of messages sent in a row that will cause a kick.
|
||||
banThreshold: 15, // Amount of messages sent in a row that will cause a ban.
|
||||
maxInterval: 2300, // Amount of time (in milliseconds) in which messages are considered spam.
|
||||
warnMessage: '{@user}, du hast eine Verwarnung für Spaming erhalten.', // Message that will be sent in chat upon warning a user.
|
||||
kickMessage: '**{user_tag}** wurde wegen Spaming von unserem Server gekickt.', // Message that will be sent in chat upon kicking a user.
|
||||
muteMessage: '**{user_tag}** wurde wegen Spaming temporär stumm geschaltet.',// Message that will be sent in chat upon muting a user.
|
||||
banMessage: '**{user_tag}** wurde wegen Spaming von unserer Community ausgeschlossen.', // Message that will be sent in chat upon banning a user.
|
||||
maxDuplicatesWarning: 5, // Amount of duplicate messages that trigger a warning.
|
||||
maxDuplicatesKick: 10, // Amount of duplicate messages that trigger a warning.
|
||||
maxDuplicatesBan: 15, // Amount of duplicate messages that trigger a warning.
|
||||
exemptPermissions: [ 'ADMINISTRATOR' ], // Bypass users with any of these permissions.
|
||||
ignoreBots: true, // Ignore bot messages.
|
||||
verbose: true, // Extended Logs from module.
|
||||
ignoredUsers: [], // Array of User IDs that get ignored.
|
||||
muteRoleName: "Muted", // Name of the role that will be given to muted users!
|
||||
removeMessages: true // If the bot should remove all the spam messages when taking action on a user!
|
||||
// And many more options... See the documentation.
|
||||
} );
|
||||
|
||||
const con = mySQL.createConnection ( {
|
||||
host: config.mysqlHost,
|
||||
user: config.mysqlUsername,
|
||||
password: config.mysqlPassword
|
||||
} );
|
||||
|
||||
let badWords = {"0":{}};
|
||||
|
||||
con.connect(function(err) {
|
||||
if (err) {
|
||||
console.log ( "[ERROR] Cannot connect to database! Critical error" );
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
console.log("[INFO] Connected to mySQL Server!");
|
||||
});
|
||||
|
||||
client.on ( "ready", () =>
|
||||
{
|
||||
console.log ( "[INFO] Bot is now ready" );
|
||||
client.user.setPresence ( {
|
||||
activity:
|
||||
{
|
||||
name: "Reading your lovely messages",
|
||||
type: 'PLAYING'
|
||||
}
|
||||
} ).then ( r =>
|
||||
{
|
||||
console.log ( "[INFO] Presence set" );
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
client.on ( "message", async ( message ) =>
|
||||
{
|
||||
if ( message.author.bot ) return;
|
||||
|
||||
// Beleidigungsfilter?
|
||||
if ( !message.content.startsWith ( config.prefix ) )
|
||||
{
|
||||
// Check if the user has Admin permissions, so skip him
|
||||
if ( message.member.hasPermission ( "ADMINISTRATOR" ) ) return;
|
||||
|
||||
// Filter goes here
|
||||
|
||||
if ( checkMessage ( message.content ) )
|
||||
{
|
||||
await message.delete ();
|
||||
let notifyChannelID = getNotifyChannel ( message.guild.id );
|
||||
if ( notifyChannelID.length === 0 || notifyChannelID === 0 )
|
||||
{
|
||||
// NotifyChannel not send, so we gonna send the msg here
|
||||
const notify = new Discord.MessageEmbed ()
|
||||
.setColor ( "#b30202" )
|
||||
.setTitle ( "Nachricht gelöscht" )
|
||||
.setDescription ( `Es wurde eine Nachricht von ${ message.author.toString () } entfernt, da ein dort enthaltenes Wort auf der Blacklist steht.` )
|
||||
.addField ( 'Warnung', `Mir wurde noch nicht gesagt, wo ich Nachricht wie diese hinschreiben soll.\nDu kannst dies als Administrator mit ".w setNotify" in einem beliebigen Channel setzen.` );
|
||||
message.channel.send ( notify ).then ( () =>
|
||||
{
|
||||
} ).catch ( () =>
|
||||
{
|
||||
console.log ( "[ERROR] Cannot send a message on guild " + message.guild.id + " in channel " + message.channel.id );
|
||||
} );
|
||||
} else
|
||||
{
|
||||
const notifyChannel = message.member.guild.channels.cache.find ( ch => ch.id === notifyChannelID );
|
||||
const notify = new Discord.MessageEmbed ()
|
||||
.setColor ( "#b30202" )
|
||||
.setTitle ( "Nachricht gelöscht" )
|
||||
.setDescription ( `Es wurde eine Nachricht von ${ message.author.toString () } entfernt, da ein dort enthaltenes Wort auf der Blacklist steht.` );
|
||||
notifyChannel.send ( notify ).then ( () =>
|
||||
{
|
||||
} ).catch ( () =>
|
||||
{
|
||||
console.log ( "[ERROR] Cannot send a message on guild " + message.guild.id + " in channel " + message.channel.id );
|
||||
} );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Commands here
|
||||
|
||||
if ( !message.member.hasPermission ( "ADMINISTRATOR" ) )
|
||||
{
|
||||
await message.reply ( "mir wurde beigebracht, dass ich mit fremden Leuten nicht reden darf :c" );
|
||||
return;
|
||||
}
|
||||
|
||||
const commandBody = message.content.slice ( config.prefix.length );
|
||||
const args = commandBody.split ( ' ' );
|
||||
const command = args.shift ().toLowerCase ();
|
||||
|
||||
|
||||
if ( command === "ping" )
|
||||
{
|
||||
const timeTaken = Date.now () - message.createdTimestamp;
|
||||
message.reply ( `Der Ping von mir liegt bei ${ timeTaken }ms.` ).then ( () => {} );
|
||||
}
|
||||
|
||||
if ( command === "list" )
|
||||
{
|
||||
// Listet alle Wörter des Servers mit indexen auf
|
||||
let words = listWords( message.guild.id );
|
||||
let output = "";
|
||||
|
||||
for ( let wordsKey in words )
|
||||
{
|
||||
output += `${words[wordsKey]["id"]} | ${words[wordsKey]["word"]}\n`;
|
||||
}
|
||||
|
||||
await message.channel.send ( `Folgende Wörter & Sätze stehen auf der Schwarzen Liste:\nIndex\tWort\n` + output );
|
||||
}
|
||||
|
||||
if ( command === "remove" )
|
||||
{
|
||||
if ( args.length >= 2 )
|
||||
{
|
||||
const index = Number.parseInt ( args[1] );
|
||||
if ( !isNaN ( index ) )
|
||||
{
|
||||
|
||||
} else
|
||||
{
|
||||
await message.reply ( `bitte gebe einen Index mit an. ${ config.prefix }delete <index>` )
|
||||
}
|
||||
} else
|
||||
{
|
||||
await message.reply ( `bitte gebe einen Index mit an. ${ config.prefix }delete <index>` )
|
||||
}
|
||||
}
|
||||
|
||||
if ( command === "add" )
|
||||
{
|
||||
if ( args.length >= 2 )
|
||||
{
|
||||
addWord ( message.guild.id, args[1] );
|
||||
|
||||
} else
|
||||
{
|
||||
await message.reply ( `bitte gebe ein Wort/Satz mit an. ${ config.prefix }add <Wort/Satz>` );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} );
|
||||
|
||||
client.on ( "guildCreate", ( guild ) =>
|
||||
{
|
||||
console.log ( `[INFO] Joined a new guild named "${ guild.name }" with ID ${ guild.id }` );
|
||||
createServerEntry ( guild.id, guild.name );
|
||||
|
||||
} );
|
||||
|
||||
function createServerEntry( a_ServerID, a_ServerName )
|
||||
{
|
||||
console.log ( `[INFO] Creating server entry...` );
|
||||
let query = "INSERT INTO guilds ( guild_id, server_name ) VALUES ( ?, ? )";
|
||||
con.query( query, [ a_ServerID, a_ServerName ], function( error, results, fields )
|
||||
{
|
||||
if( error )
|
||||
{
|
||||
console.log ( `[ERROR] An error occurred while creating a new guild in database` );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function checkMessage( a_Message )
|
||||
{
|
||||
/*let query = "SELECT word FROM words WHERE word LIKE ?";
|
||||
con.query( query, ['%' + a_Message + '%'], function( error, results, fields ) {
|
||||
if( error )
|
||||
{
|
||||
console.log ( `[ERROR] An error occurred while fetching th` )
|
||||
}
|
||||
} );*/
|
||||
return false;
|
||||
}
|
||||
|
||||
function getNotifyChannel( a_ServerID )
|
||||
{
|
||||
let query = "SELECT notify_channel FROM guilds WHERE guilds.guild_id = ?";
|
||||
con.query( query, [ a_ServerID ], function( error, results, fields ) {
|
||||
if( error )
|
||||
{
|
||||
console.log ( `[ERROR] An error occurred while fetching the notify channel` )
|
||||
}
|
||||
return results.notify_channel;
|
||||
} );
|
||||
return 0;
|
||||
}
|
||||
|
||||
function deleteWord( a_Index )
|
||||
{
|
||||
// Delete the word out of the database
|
||||
}
|
||||
|
||||
function addWord( a_ServerID, a_Word )
|
||||
{
|
||||
// Add the word to the database
|
||||
let query = "INSERT INTO words ( word, guildID ) VALUES ( ?, ? )";
|
||||
con.query( query, [ a_Word, a_ServerID ], function( error, results, fields ) {
|
||||
if( error )
|
||||
{
|
||||
console.log ( `[ERROR] An error occurred while inserting a new filter entry` );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} );
|
||||
return false;
|
||||
}
|
||||
|
||||
function listWords( a_ServerID )
|
||||
{
|
||||
|
||||
return {0:{id:1,word:"huan"},1:{id:2,word:"sinnex"}};
|
||||
}
|
||||
|
||||
|
||||
// Discord Login
|
||||
|
||||
client.login ( config.TOKEN ).then ( r =>
|
||||
{
|
||||
console.log ( "[INFO] Logged in as Woam" )
|
||||
} );
|
||||
|
190
node_modules/@discordjs/collection/LICENSE
generated
vendored
Normal file
190
node_modules/@discordjs/collection/LICENSE
generated
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
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
|
||||
|
||||
Copyright 2015 - 2020 Amish Shah
|
||||
|
||||
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.
|
3
node_modules/@discordjs/collection/README.md
generated
vendored
Normal file
3
node_modules/@discordjs/collection/README.md
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Collection
|
||||
|
||||
Utility data structure used in Discord.js.
|
319
node_modules/@discordjs/collection/dist/index.d.ts
generated
vendored
Normal file
319
node_modules/@discordjs/collection/dist/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,319 @@
|
||||
export interface CollectionConstructor {
|
||||
new (): Collection<unknown, unknown>;
|
||||
new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;
|
||||
new <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;
|
||||
readonly prototype: Collection<unknown, unknown>;
|
||||
readonly [Symbol.species]: CollectionConstructor;
|
||||
}
|
||||
/**
|
||||
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
||||
* an ID, for significantly improved performance and ease-of-use.
|
||||
* @extends {Map}
|
||||
* @property {number} size - The amount of elements in this collection.
|
||||
*/
|
||||
declare class Collection<K, V> extends Map<K, V> {
|
||||
private _array;
|
||||
private _keyArray;
|
||||
static readonly default: typeof Collection;
|
||||
['constructor']: typeof Collection;
|
||||
constructor(entries?: ReadonlyArray<readonly [K, V]> | null);
|
||||
/**
|
||||
* Identical to [Map.get()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get).
|
||||
* Gets an element with the specified key, and returns its value, or `undefined` if the element does not exist.
|
||||
* @param {*} key - The key to get from this collection
|
||||
* @returns {* | undefined}
|
||||
*/
|
||||
get(key: K): V | undefined;
|
||||
/**
|
||||
* Identical to [Map.set()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set).
|
||||
* Sets a new element in the collection with the specified key and value.
|
||||
* @param {*} key - The key of the element to add
|
||||
* @param {*} value - The value of the element to add
|
||||
* @returns {Collection}
|
||||
*/
|
||||
set(key: K, value: V): this;
|
||||
/**
|
||||
* Identical to [Map.has()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has).
|
||||
* Checks if an element exists in the collection.
|
||||
* @param {*} key - The key of the element to check for
|
||||
* @returns {boolean} `true` if the element exists, `false` if it does not exist.
|
||||
*/
|
||||
has(key: K): boolean;
|
||||
/**
|
||||
* Identical to [Map.delete()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete).
|
||||
* Deletes an element from the collection.
|
||||
* @param {*} key - The key to delete from the collection
|
||||
* @returns {boolean} `true` if the element was removed, `false` if the element does not exist.
|
||||
*/
|
||||
delete(key: K): boolean;
|
||||
/**
|
||||
* Identical to [Map.clear()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear).
|
||||
* Removes all elements from the collection.
|
||||
* @returns {undefined}
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Creates an ordered array of the values of this collection, and caches it internally. The array will only be
|
||||
* reconstructed if an item is added to or removed from the collection, or if you change the length of the array
|
||||
* itself. If you don't want this caching behavior, use `[...collection.values()]` or
|
||||
* `Array.from(collection.values())` instead.
|
||||
* @returns {Array}
|
||||
*/
|
||||
array(): V[];
|
||||
/**
|
||||
* Creates an ordered array of the keys of this collection, and caches it internally. The array will only be
|
||||
* reconstructed if an item is added to or removed from the collection, or if you change the length of the array
|
||||
* itself. If you don't want this caching behavior, use `[...collection.keys()]` or
|
||||
* `Array.from(collection.keys())` instead.
|
||||
* @returns {Array}
|
||||
*/
|
||||
keyArray(): K[];
|
||||
/**
|
||||
* Obtains the first value(s) in this collection.
|
||||
* @param {number} [amount] Amount of values to obtain from the beginning
|
||||
* @returns {*|Array<*>} A single value if no amount is provided or an array of values, starting from the end if
|
||||
* amount is negative
|
||||
*/
|
||||
first(): V | undefined;
|
||||
first(amount: number): V[];
|
||||
/**
|
||||
* Obtains the first key(s) in this collection.
|
||||
* @param {number} [amount] Amount of keys to obtain from the beginning
|
||||
* @returns {*|Array<*>} A single key if no amount is provided or an array of keys, starting from the end if
|
||||
* amount is negative
|
||||
*/
|
||||
firstKey(): K | undefined;
|
||||
firstKey(amount: number): K[];
|
||||
/**
|
||||
* Obtains the last value(s) in this collection. This relies on {@link Collection#array}, and thus the caching
|
||||
* mechanism applies here as well.
|
||||
* @param {number} [amount] Amount of values to obtain from the end
|
||||
* @returns {*|Array<*>} A single value if no amount is provided or an array of values, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
last(): V | undefined;
|
||||
last(amount: number): V[];
|
||||
/**
|
||||
* Obtains the last key(s) in this collection. This relies on {@link Collection#keyArray}, and thus the caching
|
||||
* mechanism applies here as well.
|
||||
* @param {number} [amount] Amount of keys to obtain from the end
|
||||
* @returns {*|Array<*>} A single key if no amount is provided or an array of keys, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
lastKey(): K | undefined;
|
||||
lastKey(amount: number): K[];
|
||||
/**
|
||||
* Obtains unique random value(s) from this collection. This relies on {@link Collection#array}, and thus the caching
|
||||
* mechanism applies here as well.
|
||||
* @param {number} [amount] Amount of values to obtain randomly
|
||||
* @returns {*|Array<*>} A single value if no amount is provided or an array of values
|
||||
*/
|
||||
random(): V;
|
||||
random(amount: number): V[];
|
||||
/**
|
||||
* Obtains unique random key(s) from this collection. This relies on {@link Collection#keyArray}, and thus the caching
|
||||
* mechanism applies here as well.
|
||||
* @param {number} [amount] Amount of keys to obtain randomly
|
||||
* @returns {*|Array<*>} A single key if no amount is provided or an array
|
||||
*/
|
||||
randomKey(): K;
|
||||
randomKey(amount: number): K[];
|
||||
/**
|
||||
* Searches for a single item where the given function returns a truthy value. This behaves like
|
||||
* [Array.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
|
||||
* <warn>All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you
|
||||
* should use the `get` method. See
|
||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.</warn>
|
||||
* @param {Function} fn The function to test with (should return boolean)
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {*}
|
||||
* @example collection.find(user => user.username === 'Bob');
|
||||
*/
|
||||
find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;
|
||||
find<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): V | undefined;
|
||||
/**
|
||||
* Searches for the key of a single item where the given function returns a truthy value. This behaves like
|
||||
* [Array.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex),
|
||||
* but returns the key rather than the positional index.
|
||||
* @param {Function} fn The function to test with (should return boolean)
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {*}
|
||||
* @example collection.findKey(user => user.username === 'Bob');
|
||||
*/
|
||||
findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;
|
||||
findKey<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): K | undefined;
|
||||
/**
|
||||
* Removes items that satisfy the provided filter function.
|
||||
* @param {Function} fn Function used to test (should return a boolean)
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {number} The number of removed entries
|
||||
*/
|
||||
sweep(fn: (value: V, key: K, collection: this) => boolean): number;
|
||||
sweep<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): number;
|
||||
/**
|
||||
* Identical to
|
||||
* [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),
|
||||
* but returns a Collection instead of an Array.
|
||||
* @param {Function} fn The function to test with (should return boolean)
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Collection}
|
||||
* @example collection.filter(user => user.username === 'Bob');
|
||||
*/
|
||||
filter(fn: (value: V, key: K, collection: this) => boolean): this;
|
||||
filter<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): this;
|
||||
/**
|
||||
* Partitions the collection into two collections where the first collection
|
||||
* contains the items that passed and the second contains the items that failed.
|
||||
* @param {Function} fn Function used to test (should return a boolean)
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Collection[]}
|
||||
* @example const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
||||
*/
|
||||
partition(fn: (value: V, key: K, collection: this) => boolean): [this, this];
|
||||
partition<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): [this, this];
|
||||
/**
|
||||
* Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to
|
||||
* [Array.flatMap()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap).
|
||||
* @param {Function} fn Function that produces a new Collection
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Collection}
|
||||
* @example collection.flatMap(guild => guild.members.cache);
|
||||
*/
|
||||
flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;
|
||||
flatMap<T, This>(fn: (this: This, value: V, key: K, collection: this) => Collection<K, T>, thisArg: This): Collection<K, T>;
|
||||
/**
|
||||
* Maps each item to another value into an array. Identical in behavior to
|
||||
* [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
|
||||
* @param {Function} fn Function that produces an element of the new array, taking three arguments
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Array}
|
||||
* @example collection.map(user => user.tag);
|
||||
*/
|
||||
map<T>(fn: (value: V, key: K, collection: this) => T): T[];
|
||||
map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];
|
||||
/**
|
||||
* Maps each item to another value into a collection. Identical in behavior to
|
||||
* [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
|
||||
* @param {Function} fn Function that produces an element of the new collection, taking three arguments
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Collection}
|
||||
* @example collection.mapValues(user => user.tag);
|
||||
*/
|
||||
mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;
|
||||
mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;
|
||||
/**
|
||||
* Checks if there exists an item that passes a test. Identical in behavior to
|
||||
* [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).
|
||||
* @param {Function} fn Function used to test (should return a boolean)
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {boolean}
|
||||
* @example collection.some(user => user.discriminator === '0000');
|
||||
*/
|
||||
some(fn: (value: V, key: K, collection: this) => boolean): boolean;
|
||||
some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;
|
||||
/**
|
||||
* Checks if all items passes a test. Identical in behavior to
|
||||
* [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).
|
||||
* @param {Function} fn Function used to test (should return a boolean)
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {boolean}
|
||||
* @example collection.every(user => !user.bot);
|
||||
*/
|
||||
every(fn: (value: V, key: K, collection: this) => boolean): boolean;
|
||||
every<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;
|
||||
/**
|
||||
* Applies a function to produce a single value. Identical in behavior to
|
||||
* [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
|
||||
* @param {Function} fn Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
|
||||
* and `collection`
|
||||
* @param {*} [initialValue] Starting value for the accumulator
|
||||
* @returns {*}
|
||||
* @example collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||
*/
|
||||
reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T;
|
||||
/**
|
||||
* Identical to
|
||||
* [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),
|
||||
* but returns the collection instead of undefined.
|
||||
* @param {Function} fn Function to execute for each element
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Collection}
|
||||
* @example
|
||||
* collection
|
||||
* .each(user => console.log(user.username))
|
||||
* .filter(user => user.bot)
|
||||
* .each(user => console.log(user.username));
|
||||
*/
|
||||
each(fn: (value: V, key: K, collection: this) => void): this;
|
||||
each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
|
||||
/**
|
||||
* Runs a function on the collection and returns the collection.
|
||||
* @param {Function} fn Function to execute
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Collection}
|
||||
* @example
|
||||
* collection
|
||||
* .tap(coll => console.log(coll.size))
|
||||
* .filter(user => user.bot)
|
||||
* .tap(coll => console.log(coll.size))
|
||||
*/
|
||||
tap(fn: (collection: this) => void): this;
|
||||
tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;
|
||||
/**
|
||||
* Creates an identical shallow copy of this collection.
|
||||
* @returns {Collection}
|
||||
* @example const newColl = someColl.clone();
|
||||
*/
|
||||
clone(): this;
|
||||
/**
|
||||
* Combines this collection with others into a new collection. None of the source collections are modified.
|
||||
* @param {...Collection} collections Collections to merge
|
||||
* @returns {Collection}
|
||||
* @example const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
||||
*/
|
||||
concat(...collections: Collection<K, V>[]): this;
|
||||
/**
|
||||
* Checks if this collection shares identical items with another.
|
||||
* This is different to checking for equality using equal-signs, because
|
||||
* the collections may be different objects, but contain the same data.
|
||||
* @param {Collection} collection Collection to compare with
|
||||
* @returns {boolean} Whether the collections have identical contents
|
||||
*/
|
||||
equals(collection: Collection<K, V>): boolean;
|
||||
/**
|
||||
* The sort method sorts the items of a collection in place and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
* @param {Function} [compareFunction] Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
||||
* according to the string conversion of each element.
|
||||
* @returns {Collection}
|
||||
* @example collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
*/
|
||||
sort(compareFunction?: (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number): this;
|
||||
/**
|
||||
* The intersect method returns a new structure containing items where the keys are present in both original structures.
|
||||
* @param {Collection} other The other Collection to filter against
|
||||
* @returns {Collection}
|
||||
*/
|
||||
intersect(other: Collection<K, V>): Collection<K, V>;
|
||||
/**
|
||||
* The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
|
||||
* @param {Collection} other The other Collection to filter against
|
||||
* @returns {Collection}
|
||||
*/
|
||||
difference(other: Collection<K, V>): Collection<K, V>;
|
||||
/**
|
||||
* The sorted method sorts the items of a collection and returns it.
|
||||
* The sort is not necessarily stable in Node 10 or older.
|
||||
* The default sort order is according to string Unicode code points.
|
||||
* @param {Function} [compareFunction] Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
||||
* according to the string conversion of each element.
|
||||
* @returns {Collection}
|
||||
* @example collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
*/
|
||||
sorted(compareFunction?: (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number): this;
|
||||
}
|
||||
export { Collection };
|
||||
export default Collection;
|
392
node_modules/@discordjs/collection/dist/index.js
generated
vendored
Normal file
392
node_modules/@discordjs/collection/dist/index.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
78
node_modules/@discordjs/collection/package.json
generated
vendored
Normal file
78
node_modules/@discordjs/collection/package.json
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
{
|
||||
"_from": "@discordjs/collection@^0.1.6",
|
||||
"_id": "@discordjs/collection@0.1.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==",
|
||||
"_location": "/@discordjs/collection",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "@discordjs/collection@^0.1.6",
|
||||
"name": "@discordjs/collection",
|
||||
"escapedName": "@discordjs%2fcollection",
|
||||
"scope": "@discordjs",
|
||||
"rawSpec": "^0.1.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.1.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/discord.js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
|
||||
"_shasum": "9e9a7637f4e4e0688fd8b2b5c63133c91607682c",
|
||||
"_spec": "@discordjs/collection@^0.1.6",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\discord.js",
|
||||
"author": {
|
||||
"name": "Amish Shah",
|
||||
"email": "amishshah.2k@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/collection/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Utility data structure used in Discord.js",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.8.4",
|
||||
"@babel/core": "^7.8.4",
|
||||
"@babel/preset-env": "^7.8.4",
|
||||
"@babel/preset-typescript": "^7.8.3",
|
||||
"@types/node": "^13.7.4",
|
||||
"@typescript-eslint/eslint-plugin": "^2.21.0",
|
||||
"@typescript-eslint/parser": "^2.21.0",
|
||||
"discord.js-docgen": "github:discordjs/docgen#ts-patch",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-marine": "^6.0.0",
|
||||
"jsdoc-babel": "^0.5.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.2"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "marine/node"
|
||||
},
|
||||
"homepage": "https://github.com/discordjs/collection#readme",
|
||||
"keywords": [
|
||||
"map",
|
||||
"collection",
|
||||
"utility"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"main": "dist/index.js",
|
||||
"name": "@discordjs/collection",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/discordjs/collection.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist/ && tsc",
|
||||
"docs": "docgen --jsdoc jsdoc.json --source src/*.ts src/**/*.ts --custom docs/index.yml --output docs/docs.json",
|
||||
"docs:test": "docgen --jsdoc jsdoc.json --source src/*.ts src/**/*.ts --custom docs/index.yml",
|
||||
"lint": "eslint src --ext .ts",
|
||||
"prebuild": "npm run lint",
|
||||
"pretest": "npm run build",
|
||||
"test": "node test/index.js"
|
||||
},
|
||||
"types": "dist/index.d.ts",
|
||||
"version": "0.1.6"
|
||||
}
|
19
node_modules/@discordjs/form-data/License
generated
vendored
Normal file
19
node_modules/@discordjs/form-data/License
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
|
||||
|
||||
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.
|
353
node_modules/@discordjs/form-data/Readme.md
generated
vendored
Normal file
353
node_modules/@discordjs/form-data/Readme.md
generated
vendored
Normal file
@ -0,0 +1,353 @@
|
||||
# Form-Data [](https://www.npmjs.com/package/form-data) [](https://gitter.im/form-data/form-data)
|
||||
|
||||
A library to create readable ```"multipart/form-data"``` streams. Can be used to submit forms and file uploads to other web applications.
|
||||
|
||||
The API of this library is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd].
|
||||
|
||||
[xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface
|
||||
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
|
||||
[](https://coveralls.io/github/form-data/form-data?branch=master)
|
||||
[](https://david-dm.org/form-data/form-data)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install --save form-data
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
In this example we are constructing a form with 3 fields that contain a string,
|
||||
a buffer and a file stream.
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var fs = require('fs');
|
||||
|
||||
var form = new FormData();
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
||||
```
|
||||
|
||||
Also you can use http-response stream:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var http = require('http');
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
http.request('http://nodejs.org/images/logo.png', function(response) {
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_logo', response);
|
||||
});
|
||||
```
|
||||
|
||||
Or @mikeal's [request](https://github.com/request/request) stream:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var request = require('request');
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_logo', request('http://nodejs.org/images/logo.png'));
|
||||
```
|
||||
|
||||
In order to submit this form to a web application, call ```submit(url, [callback])``` method:
|
||||
|
||||
``` javascript
|
||||
form.submit('http://example.org/', function(err, res) {
|
||||
// res – response object (http.IncomingMessage) //
|
||||
res.resume();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
For more advanced request manipulations ```submit()``` method returns ```http.ClientRequest``` object, or you can choose from one of the alternative submission methods.
|
||||
|
||||
### Custom options
|
||||
|
||||
You can provide custom options, such as `maxDataSize`:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
|
||||
var form = new FormData({ maxDataSize: 20971520 });
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', /* something big */);
|
||||
```
|
||||
|
||||
List of available options could be found in [combined-stream](https://github.com/felixge/node-combined-stream/blob/master/lib/combined_stream.js#L7-L15)
|
||||
|
||||
### Alternative submission methods
|
||||
|
||||
You can use node's http client interface:
|
||||
|
||||
``` javascript
|
||||
var http = require('http');
|
||||
|
||||
var request = http.request({
|
||||
method: 'post',
|
||||
host: 'example.org',
|
||||
path: '/upload',
|
||||
headers: form.getHeaders()
|
||||
});
|
||||
|
||||
form.pipe(request);
|
||||
|
||||
request.on('response', function(res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
Or if you would prefer the `'Content-Length'` header to be set for you:
|
||||
|
||||
``` javascript
|
||||
form.submit('example.org/upload', function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
To use custom headers and pre-known length in parts:
|
||||
|
||||
``` javascript
|
||||
var CRLF = '\r\n';
|
||||
var form = new FormData();
|
||||
|
||||
var options = {
|
||||
header: CRLF + '--' + form.getBoundary() + CRLF + 'X-Custom-Header: 123' + CRLF + CRLF,
|
||||
knownLength: 1
|
||||
};
|
||||
|
||||
form.append('my_buffer', buffer, options);
|
||||
|
||||
form.submit('http://example.com/', function(err, res) {
|
||||
if (err) throw err;
|
||||
console.log('Done');
|
||||
});
|
||||
```
|
||||
|
||||
Form-Data can recognize and fetch all the required information from common types of streams (```fs.readStream```, ```http.response``` and ```mikeal's request```), for some other types of streams you'd need to provide "file"-related information manually:
|
||||
|
||||
``` javascript
|
||||
someModule.stream(function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
form.append('file', stdout, {
|
||||
filename: 'unicycle.jpg', // ... or:
|
||||
filepath: 'photos/toys/unicycle.jpg',
|
||||
contentType: 'image/jpeg',
|
||||
knownLength: 19806
|
||||
});
|
||||
|
||||
form.submit('http://example.com/', function(err, res) {
|
||||
if (err) throw err;
|
||||
console.log('Done');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The `filepath` property overrides `filename` and may contain a relative path. This is typically used when uploading [multiple files from a directory](https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory).
|
||||
|
||||
For edge cases, like POST request to URL with query string or to pass HTTP auth credentials, object can be passed to `form.submit()` as first parameter:
|
||||
|
||||
``` javascript
|
||||
form.submit({
|
||||
host: 'example.com',
|
||||
path: '/probably.php?extra=params',
|
||||
auth: 'username:password'
|
||||
}, function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
In case you need to also send custom HTTP headers with the POST request, you can use the `headers` key in first parameter of `form.submit()`:
|
||||
|
||||
``` javascript
|
||||
form.submit({
|
||||
host: 'example.com',
|
||||
path: '/surelynot.php',
|
||||
headers: {'x-test-header': 'test-header-value'}
|
||||
}, function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
### Methods
|
||||
|
||||
- [_Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )](https://github.com/form-data/form-data#void-append-string-field-mixed-value--mixed-options-).
|
||||
- [_Headers_ getHeaders( [**Headers** _userHeaders_] )](https://github.com/form-data/form-data#array-getheaders-array-userheaders-)
|
||||
- [_String_ getBoundary()](https://github.com/form-data/form-data#string-getboundary)
|
||||
- [_Buffer_ getBuffer()](https://github.com/form-data/form-data#buffer-getbuffer)
|
||||
- [_Integer_ getLengthSync()](https://github.com/form-data/form-data#integer-getlengthsync)
|
||||
- [_Integer_ getLength( **function** _callback_ )](https://github.com/form-data/form-data#integer-getlength-function-callback-)
|
||||
- [_Boolean_ hasKnownLength()](https://github.com/form-data/form-data#boolean-hasknownlength)
|
||||
- [_Request_ submit( _params_, **function** _callback_ )](https://github.com/form-data/form-data#request-submit-params-function-callback-)
|
||||
- [_String_ toString()](https://github.com/form-data/form-data#string-tostring)
|
||||
|
||||
#### _Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )
|
||||
Append data to the form. You can submit about any format (string, integer, boolean, buffer, etc.). However, Arrays are not supported and need to be turned into strings by the user.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_string', 'my value' );
|
||||
form.append( 'my_integer', 1 );
|
||||
form.append( 'my_boolean', true );
|
||||
form.append( 'my_buffer', new Buffer(10) );
|
||||
form.append( 'my_array_as_json', JSON.stringify( ['bird','cute'] ) )
|
||||
```
|
||||
|
||||
You may provide a string for options, or an object.
|
||||
```javascript
|
||||
// Set filename by providing a string for options
|
||||
form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), 'bar.jpg' );
|
||||
|
||||
// provide an object.
|
||||
form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), {filename: 'bar.jpg', contentType: 'image/jpeg', knownLength: 19806} );
|
||||
```
|
||||
|
||||
#### _Headers_ getHeaders( [**Headers** _userHeaders_] )
|
||||
This method adds the correct `content-type` header to the provided array of `userHeaders`.
|
||||
|
||||
#### _String_ getBoundary()
|
||||
Return the boundary of the formData. A boundary consists of 26 `-` followed by 24 numbers
|
||||
for example:
|
||||
```javascript
|
||||
--------------------------515890814546601021194782
|
||||
```
|
||||
_Note: The boundary must be unique and may not appear in the data._
|
||||
|
||||
#### _Buffer_ getBuffer()
|
||||
Return the full formdata request package, as a Buffer. You can insert this Buffer in e.g. Axios to send multipart data.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_buffer', Buffer.from([0x4a,0x42,0x20,0x52,0x6f,0x63,0x6b,0x73]) );
|
||||
form.append( 'my_file', fs.readFileSync('/foo/bar.jpg') );
|
||||
|
||||
axios.post( 'https://example.com/path/to/api',
|
||||
form.getBuffer(),
|
||||
form.getHeaders()
|
||||
)
|
||||
```
|
||||
**Note:** Because the output is of type Buffer, you can only append types that are accepted by Buffer: *string, Buffer, ArrayBuffer, Array, or Array-like Object*. A ReadStream for example will result in an error.
|
||||
|
||||
#### _Integer_ getLengthSync()
|
||||
Same as `getLength` but synchronous.
|
||||
|
||||
_Note: getLengthSync __doesn't__ calculate streams length._
|
||||
|
||||
#### _Integer_ getLength( **function** _callback_ )
|
||||
Returns the `Content-Length` async. The callback is used to handle errors and continue once the length has been calculated
|
||||
```javascript
|
||||
this.getLength(function(err, length) {
|
||||
if (err) {
|
||||
this._error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// add content length
|
||||
request.setHeader('Content-Length', length);
|
||||
|
||||
...
|
||||
}.bind(this));
|
||||
```
|
||||
|
||||
#### _Boolean_ hasKnownLength()
|
||||
Checks if the length of added values is known.
|
||||
|
||||
#### _Request_ submit( _params_, **function** _callback_ )
|
||||
Submit the form to a web application.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_string', 'Hello World' );
|
||||
|
||||
form.submit( 'http://example.com/', function(err, res) {
|
||||
// res – response object (http.IncomingMessage) //
|
||||
res.resume();
|
||||
} );
|
||||
```
|
||||
|
||||
#### _String_ toString()
|
||||
Returns the form data as a string. Don't use this if you are sending files or buffers, use `getBuffer()` instead.
|
||||
|
||||
### Integration with other libraries
|
||||
|
||||
#### Request
|
||||
|
||||
Form submission using [request](https://github.com/request/request):
|
||||
|
||||
```javascript
|
||||
var formData = {
|
||||
my_field: 'my_value',
|
||||
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
|
||||
};
|
||||
|
||||
request.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) {
|
||||
if (err) {
|
||||
return console.error('upload failed:', err);
|
||||
}
|
||||
console.log('Upload successful! Server responded with:', body);
|
||||
});
|
||||
```
|
||||
|
||||
For more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads).
|
||||
|
||||
#### node-fetch
|
||||
|
||||
You can also submit a form using [node-fetch](https://github.com/bitinn/node-fetch):
|
||||
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
|
||||
form.append('a', 1);
|
||||
|
||||
fetch('http://example.com', { method: 'POST', body: form })
|
||||
.then(function(res) {
|
||||
return res.json();
|
||||
}).then(function(json) {
|
||||
console.log(json);
|
||||
});
|
||||
```
|
||||
|
||||
#### axios
|
||||
|
||||
In Node.js you can post a file using [axios](https://github.com/axios/axios):
|
||||
```javascript
|
||||
const form = new FormData();
|
||||
const stream = fs.createReadStream(PATH_TO_FILE);
|
||||
|
||||
form.append('image', stream);
|
||||
|
||||
// In Node.js environment you need to set boundary in the header field 'Content-Type' by calling method `getHeaders`
|
||||
const formHeaders = form.getHeaders();
|
||||
|
||||
axios.post('http://example.com', form, {
|
||||
headers: {
|
||||
...formHeaders,
|
||||
},
|
||||
})
|
||||
.then(response => response)
|
||||
.catch(error => error)
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround.
|
||||
- ```getLength(cb)``` will send an error as first parameter of callback if stream length cannot be calculated (e.g. send in custom streams w/o using ```knownLength```).
|
||||
- ```sbumit``` will not add `content-length` if form length is unknown or not calculable.
|
||||
- Starting version `2.x` FormData has dropped support for `node@0.10.x`.
|
||||
- Starting version `3.x` FormData has dropped support for `node@4.x`.
|
||||
|
||||
## License
|
||||
|
||||
Form-Data is released under the [MIT](License) license.
|
61
node_modules/@discordjs/form-data/index.d.ts
generated
vendored
Normal file
61
node_modules/@discordjs/form-data/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>
|
||||
// Leon Yu <https://github.com/leonyu>
|
||||
// BendingBender <https://github.com/BendingBender>
|
||||
// Maple Miao <https://github.com/mapleeit>
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as stream from 'stream';
|
||||
import * as http from 'http';
|
||||
|
||||
export = FormData;
|
||||
|
||||
// Extracted because @types/node doesn't export interfaces.
|
||||
interface ReadableOptions {
|
||||
highWaterMark?: number;
|
||||
encoding?: string;
|
||||
objectMode?: boolean;
|
||||
read?(this: stream.Readable, size: number): void;
|
||||
destroy?(this: stream.Readable, error: Error | null, callback: (error: Error | null) => void): void;
|
||||
autoDestroy?: boolean;
|
||||
}
|
||||
|
||||
interface Options extends ReadableOptions {
|
||||
writable?: boolean;
|
||||
readable?: boolean;
|
||||
dataSize?: number;
|
||||
maxDataSize?: number;
|
||||
pauseStreams?: boolean;
|
||||
}
|
||||
|
||||
declare class FormData extends stream.Readable {
|
||||
constructor(options?: Options);
|
||||
append(key: string, value: any, options?: FormData.AppendOptions | string): void;
|
||||
getHeaders(userHeaders?: FormData.Headers): FormData.Headers;
|
||||
submit(
|
||||
params: string | FormData.SubmitOptions,
|
||||
callback?: (error: Error | null, response: http.IncomingMessage) => void
|
||||
): http.ClientRequest;
|
||||
getBuffer(): Buffer;
|
||||
getBoundary(): string;
|
||||
getLength(callback: (err: Error | null, length: number) => void): void;
|
||||
getLengthSync(): number;
|
||||
hasKnownLength(): boolean;
|
||||
}
|
||||
|
||||
declare namespace FormData {
|
||||
interface Headers {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface AppendOptions {
|
||||
header?: string | Headers;
|
||||
knownLength?: number;
|
||||
filename?: string;
|
||||
filepath?: string;
|
||||
contentType?: string;
|
||||
}
|
||||
|
||||
interface SubmitOptions extends http.RequestOptions {
|
||||
protocol?: 'https:' | 'http:';
|
||||
}
|
||||
}
|
2
node_modules/@discordjs/form-data/lib/browser.js
generated
vendored
Normal file
2
node_modules/@discordjs/form-data/lib/browser.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/* eslint-env browser */
|
||||
module.exports = typeof self == 'object' ? self.FormData : window.FormData;
|
497
node_modules/@discordjs/form-data/lib/form_data.js
generated
vendored
Normal file
497
node_modules/@discordjs/form-data/lib/form_data.js
generated
vendored
Normal file
@ -0,0 +1,497 @@
|
||||
var CombinedStream = require('combined-stream');
|
||||
var util = require('util');
|
||||
var path = require('path');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var parseUrl = require('url').parse;
|
||||
var fs = require('fs');
|
||||
var Stream = require('stream').Stream;
|
||||
var mime = require('mime-types');
|
||||
var asynckit = require('asynckit');
|
||||
var populate = require('./populate.js');
|
||||
|
||||
// Public API
|
||||
module.exports = FormData;
|
||||
|
||||
// make it a Stream
|
||||
util.inherits(FormData, CombinedStream);
|
||||
|
||||
/**
|
||||
* Create readable "multipart/form-data" streams.
|
||||
* Can be used to submit forms
|
||||
* and file uploads to other web applications.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
|
||||
*/
|
||||
function FormData(options) {
|
||||
if (!(this instanceof FormData)) {
|
||||
return new FormData(options);
|
||||
}
|
||||
|
||||
this._overheadLength = 0;
|
||||
this._valueLength = 0;
|
||||
this._valuesToMeasure = [];
|
||||
|
||||
CombinedStream.call(this);
|
||||
|
||||
options = options || {};
|
||||
for (var option in options) {
|
||||
this[option] = options[option];
|
||||
}
|
||||
}
|
||||
|
||||
FormData.LINE_BREAK = '\r\n';
|
||||
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
||||
|
||||
FormData.prototype.append = function(field, value, options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
// allow filename as single option
|
||||
if (typeof options == 'string') {
|
||||
options = {filename: options};
|
||||
}
|
||||
|
||||
var append = CombinedStream.prototype.append.bind(this);
|
||||
|
||||
// all that streamy business can't handle numbers
|
||||
if (typeof value == 'number') {
|
||||
value = '' + value;
|
||||
}
|
||||
|
||||
// https://github.com/felixge/node-form-data/issues/38
|
||||
if (util.isArray(value)) {
|
||||
// Please convert your array into string
|
||||
// the way web server expects it
|
||||
this._error(new Error('Arrays are not supported.'));
|
||||
return;
|
||||
}
|
||||
|
||||
var header = this._multiPartHeader(field, value, options);
|
||||
var footer = this._multiPartFooter();
|
||||
|
||||
append(header);
|
||||
append(value);
|
||||
append(footer);
|
||||
|
||||
// pass along options.knownLength
|
||||
this._trackLength(header, value, options);
|
||||
};
|
||||
|
||||
FormData.prototype._trackLength = function(header, value, options) {
|
||||
var valueLength = 0;
|
||||
|
||||
// used w/ getLengthSync(), when length is known.
|
||||
// e.g. for streaming directly from a remote server,
|
||||
// w/ a known file a size, and not wanting to wait for
|
||||
// incoming file to finish to get its size.
|
||||
if (options.knownLength != null) {
|
||||
valueLength += +options.knownLength;
|
||||
} else if (Buffer.isBuffer(value)) {
|
||||
valueLength = value.length;
|
||||
} else if (typeof value === 'string') {
|
||||
valueLength = Buffer.byteLength(value);
|
||||
}
|
||||
|
||||
this._valueLength += valueLength;
|
||||
|
||||
// @check why add CRLF? does this account for custom/multiple CRLFs?
|
||||
this._overheadLength +=
|
||||
Buffer.byteLength(header) +
|
||||
FormData.LINE_BREAK.length;
|
||||
|
||||
// empty or either doesn't have path or not an http response or not a stream
|
||||
if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// no need to bother with the length
|
||||
if (!options.knownLength) {
|
||||
this._valuesToMeasure.push(value);
|
||||
}
|
||||
};
|
||||
|
||||
FormData.prototype._lengthRetriever = function(value, callback) {
|
||||
|
||||
if (value.hasOwnProperty('fd')) {
|
||||
|
||||
// take read range into a account
|
||||
// `end` = Infinity –> read file till the end
|
||||
//
|
||||
// TODO: Looks like there is bug in Node fs.createReadStream
|
||||
// it doesn't respect `end` options without `start` options
|
||||
// Fix it when node fixes it.
|
||||
// https://github.com/joyent/node/issues/7819
|
||||
if (value.end != undefined && value.end != Infinity && value.start != undefined) {
|
||||
|
||||
// when end specified
|
||||
// no need to calculate range
|
||||
// inclusive, starts with 0
|
||||
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
||||
|
||||
// not that fast snoopy
|
||||
} else {
|
||||
// still need to fetch file size from fs
|
||||
fs.stat(value.path, function(err, stat) {
|
||||
|
||||
var fileSize;
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// update final size based on the range options
|
||||
fileSize = stat.size - (value.start ? value.start : 0);
|
||||
callback(null, fileSize);
|
||||
});
|
||||
}
|
||||
|
||||
// or http response
|
||||
} else if (value.hasOwnProperty('httpVersion')) {
|
||||
callback(null, +value.headers['content-length']);
|
||||
|
||||
// or request stream http://github.com/mikeal/request
|
||||
} else if (value.hasOwnProperty('httpModule')) {
|
||||
// wait till response come back
|
||||
value.on('response', function(response) {
|
||||
value.pause();
|
||||
callback(null, +response.headers['content-length']);
|
||||
});
|
||||
value.resume();
|
||||
|
||||
// something else
|
||||
} else {
|
||||
callback('Unknown stream');
|
||||
}
|
||||
};
|
||||
|
||||
FormData.prototype._multiPartHeader = function(field, value, options) {
|
||||
// custom header specified (as string)?
|
||||
// it becomes responsible for boundary
|
||||
// (e.g. to handle extra CRLFs on .NET servers)
|
||||
if (typeof options.header == 'string') {
|
||||
return options.header;
|
||||
}
|
||||
|
||||
var contentDisposition = this._getContentDisposition(value, options);
|
||||
var contentType = this._getContentType(value, options);
|
||||
|
||||
var contents = '';
|
||||
var headers = {
|
||||
// add custom disposition as third element or keep it two elements if not
|
||||
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
|
||||
// if no content type. allow it to be empty array
|
||||
'Content-Type': [].concat(contentType || [])
|
||||
};
|
||||
|
||||
// allow custom headers.
|
||||
if (typeof options.header == 'object') {
|
||||
populate(headers, options.header);
|
||||
}
|
||||
|
||||
var header;
|
||||
for (var prop in headers) {
|
||||
if (!headers.hasOwnProperty(prop)) continue;
|
||||
header = headers[prop];
|
||||
|
||||
// skip nullish headers.
|
||||
if (header == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// convert all headers to arrays.
|
||||
if (!Array.isArray(header)) {
|
||||
header = [header];
|
||||
}
|
||||
|
||||
// add non-empty headers.
|
||||
if (header.length) {
|
||||
contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
|
||||
};
|
||||
|
||||
FormData.prototype._getContentDisposition = function(value, options) {
|
||||
|
||||
var filename
|
||||
, contentDisposition
|
||||
;
|
||||
|
||||
if (typeof options.filepath === 'string') {
|
||||
// custom filepath for relative paths
|
||||
filename = path.normalize(options.filepath).replace(/\\/g, '/');
|
||||
} else if (options.filename || value.name || value.path) {
|
||||
// custom filename take precedence
|
||||
// formidable and the browser add a name property
|
||||
// fs- and request- streams have path property
|
||||
filename = path.basename(options.filename || value.name || value.path);
|
||||
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
|
||||
// or try http response
|
||||
filename = path.basename(value.client._httpMessage.path || '');
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
contentDisposition = 'filename="' + filename + '"';
|
||||
}
|
||||
|
||||
return contentDisposition;
|
||||
};
|
||||
|
||||
FormData.prototype._getContentType = function(value, options) {
|
||||
|
||||
// use custom content-type above all
|
||||
var contentType = options.contentType;
|
||||
|
||||
// or try `name` from formidable, browser
|
||||
if (!contentType && value.name) {
|
||||
contentType = mime.lookup(value.name);
|
||||
}
|
||||
|
||||
// or try `path` from fs-, request- streams
|
||||
if (!contentType && value.path) {
|
||||
contentType = mime.lookup(value.path);
|
||||
}
|
||||
|
||||
// or if it's http-reponse
|
||||
if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) {
|
||||
contentType = value.headers['content-type'];
|
||||
}
|
||||
|
||||
// or guess it from the filepath or filename
|
||||
if (!contentType && (options.filepath || options.filename)) {
|
||||
contentType = mime.lookup(options.filepath || options.filename);
|
||||
}
|
||||
|
||||
// fallback to the default content type if `value` is not simple value
|
||||
if (!contentType && typeof value == 'object') {
|
||||
contentType = FormData.DEFAULT_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
return contentType;
|
||||
};
|
||||
|
||||
FormData.prototype._multiPartFooter = function() {
|
||||
return function(next) {
|
||||
var footer = FormData.LINE_BREAK;
|
||||
|
||||
var lastPart = (this._streams.length === 0);
|
||||
if (lastPart) {
|
||||
footer += this._lastBoundary();
|
||||
}
|
||||
|
||||
next(footer);
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
FormData.prototype._lastBoundary = function() {
|
||||
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
|
||||
};
|
||||
|
||||
FormData.prototype.getHeaders = function(userHeaders) {
|
||||
var header;
|
||||
var formHeaders = {
|
||||
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
|
||||
};
|
||||
|
||||
for (header in userHeaders) {
|
||||
if (userHeaders.hasOwnProperty(header)) {
|
||||
formHeaders[header.toLowerCase()] = userHeaders[header];
|
||||
}
|
||||
}
|
||||
|
||||
return formHeaders;
|
||||
};
|
||||
|
||||
FormData.prototype.getBoundary = function() {
|
||||
if (!this._boundary) {
|
||||
this._generateBoundary();
|
||||
}
|
||||
|
||||
return this._boundary;
|
||||
};
|
||||
|
||||
FormData.prototype.getBuffer = function() {
|
||||
var dataBuffer = new Buffer.alloc( 0 );
|
||||
var boundary = this.getBoundary();
|
||||
|
||||
// Create the form content. Add Line breaks to the end of data.
|
||||
for (var i = 0, len = this._streams.length; i < len; i++) {
|
||||
if (typeof this._streams[i] !== 'function') {
|
||||
|
||||
// Add content to the buffer.
|
||||
if(Buffer.isBuffer(this._streams[i])) {
|
||||
dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
|
||||
}else {
|
||||
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
|
||||
}
|
||||
|
||||
// Add break after content.
|
||||
if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
|
||||
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the footer and return the Buffer object.
|
||||
return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
|
||||
};
|
||||
|
||||
FormData.prototype._generateBoundary = function() {
|
||||
// This generates a 50 character boundary similar to those used by Firefox.
|
||||
// They are optimized for boyer-moore parsing.
|
||||
var boundary = '--------------------------';
|
||||
for (var i = 0; i < 24; i++) {
|
||||
boundary += Math.floor(Math.random() * 10).toString(16);
|
||||
}
|
||||
|
||||
this._boundary = boundary;
|
||||
};
|
||||
|
||||
// Note: getLengthSync DOESN'T calculate streams length
|
||||
// As workaround one can calculate file size manually
|
||||
// and add it as knownLength option
|
||||
FormData.prototype.getLengthSync = function() {
|
||||
var knownLength = this._overheadLength + this._valueLength;
|
||||
|
||||
// Don't get confused, there are 3 "internal" streams for each keyval pair
|
||||
// so it basically checks if there is any value added to the form
|
||||
if (this._streams.length) {
|
||||
knownLength += this._lastBoundary().length;
|
||||
}
|
||||
|
||||
// https://github.com/form-data/form-data/issues/40
|
||||
if (!this.hasKnownLength()) {
|
||||
// Some async length retrievers are present
|
||||
// therefore synchronous length calculation is false.
|
||||
// Please use getLength(callback) to get proper length
|
||||
this._error(new Error('Cannot calculate proper length in synchronous way.'));
|
||||
}
|
||||
|
||||
return knownLength;
|
||||
};
|
||||
|
||||
// Public API to check if length of added values is known
|
||||
// https://github.com/form-data/form-data/issues/196
|
||||
// https://github.com/form-data/form-data/issues/262
|
||||
FormData.prototype.hasKnownLength = function() {
|
||||
var hasKnownLength = true;
|
||||
|
||||
if (this._valuesToMeasure.length) {
|
||||
hasKnownLength = false;
|
||||
}
|
||||
|
||||
return hasKnownLength;
|
||||
};
|
||||
|
||||
FormData.prototype.getLength = function(cb) {
|
||||
var knownLength = this._overheadLength + this._valueLength;
|
||||
|
||||
if (this._streams.length) {
|
||||
knownLength += this._lastBoundary().length;
|
||||
}
|
||||
|
||||
if (!this._valuesToMeasure.length) {
|
||||
process.nextTick(cb.bind(this, null, knownLength));
|
||||
return;
|
||||
}
|
||||
|
||||
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
values.forEach(function(length) {
|
||||
knownLength += length;
|
||||
});
|
||||
|
||||
cb(null, knownLength);
|
||||
});
|
||||
};
|
||||
|
||||
FormData.prototype.submit = function(params, cb) {
|
||||
var request
|
||||
, options
|
||||
, defaults = {method: 'post'}
|
||||
;
|
||||
|
||||
// parse provided url if it's string
|
||||
// or treat it as options object
|
||||
if (typeof params == 'string') {
|
||||
|
||||
params = parseUrl(params);
|
||||
options = populate({
|
||||
port: params.port,
|
||||
path: params.pathname,
|
||||
host: params.hostname,
|
||||
protocol: params.protocol
|
||||
}, defaults);
|
||||
|
||||
// use custom params
|
||||
} else {
|
||||
|
||||
options = populate(params, defaults);
|
||||
// if no port provided use default one
|
||||
if (!options.port) {
|
||||
options.port = options.protocol == 'https:' ? 443 : 80;
|
||||
}
|
||||
}
|
||||
|
||||
// put that good code in getHeaders to some use
|
||||
options.headers = this.getHeaders(params.headers);
|
||||
|
||||
// https if specified, fallback to http in any other case
|
||||
if (options.protocol == 'https:') {
|
||||
request = https.request(options);
|
||||
} else {
|
||||
request = http.request(options);
|
||||
}
|
||||
|
||||
// get content length and fire away
|
||||
this.getLength(function(err, length) {
|
||||
if (err && err !== 'Unknown stream') {
|
||||
this._error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// add content length
|
||||
if (length) {
|
||||
request.setHeader('Content-Length', length);
|
||||
}
|
||||
|
||||
this.pipe(request);
|
||||
if (cb) {
|
||||
var onResponse;
|
||||
|
||||
var callback = function (error, responce) {
|
||||
request.removeListener('error', callback);
|
||||
request.removeListener('response', onResponse);
|
||||
|
||||
return cb.call(this, error, responce);
|
||||
};
|
||||
|
||||
onResponse = callback.bind(this, null);
|
||||
|
||||
request.on('error', callback);
|
||||
request.on('response', onResponse);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
return request;
|
||||
};
|
||||
|
||||
FormData.prototype._error = function(err) {
|
||||
if (!this.error) {
|
||||
this.error = err;
|
||||
this.pause();
|
||||
this.emit('error', err);
|
||||
}
|
||||
};
|
||||
|
||||
FormData.prototype.toString = function () {
|
||||
return '[object FormData]';
|
||||
};
|
10
node_modules/@discordjs/form-data/lib/populate.js
generated
vendored
Normal file
10
node_modules/@discordjs/form-data/lib/populate.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// populates missing values
|
||||
module.exports = function(dst, src) {
|
||||
|
||||
Object.keys(src).forEach(function(prop)
|
||||
{
|
||||
dst[prop] = dst[prop] || src[prop];
|
||||
});
|
||||
|
||||
return dst;
|
||||
};
|
98
node_modules/@discordjs/form-data/package.json
generated
vendored
Normal file
98
node_modules/@discordjs/form-data/package.json
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"_from": "@discordjs/form-data@^3.0.1",
|
||||
"_id": "@discordjs/form-data@3.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
|
||||
"_location": "/@discordjs/form-data",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "@discordjs/form-data@^3.0.1",
|
||||
"name": "@discordjs/form-data",
|
||||
"escapedName": "@discordjs%2fform-data",
|
||||
"scope": "@discordjs",
|
||||
"rawSpec": "^3.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/discord.js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
|
||||
"_shasum": "5c9e6be992e2e57d0dfa0e39979a850225fb4697",
|
||||
"_spec": "@discordjs/form-data@^3.0.1",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\discord.js",
|
||||
"author": {
|
||||
"name": "Felix Geisendörfer",
|
||||
"email": "felix@debuggable.com",
|
||||
"url": "http://debuggable.com/"
|
||||
},
|
||||
"browser": "./lib/browser",
|
||||
"bugs": {
|
||||
"url": "https://github.com/form-data/form-data/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.",
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.0.10",
|
||||
"browserify": "^13.1.1",
|
||||
"browserify-istanbul": "^2.0.0",
|
||||
"coveralls": "^3.0.4",
|
||||
"cross-spawn": "^6.0.5",
|
||||
"eslint": "^6.0.1",
|
||||
"fake": "^0.2.2",
|
||||
"far": "^0.0.7",
|
||||
"formidable": "^1.0.17",
|
||||
"in-publish": "^2.0.0",
|
||||
"is-node-modern": "^1.0.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"obake": "^0.1.2",
|
||||
"pkgfiles": "^2.3.0",
|
||||
"pre-commit": "^1.1.3",
|
||||
"puppeteer": "^1.19.0",
|
||||
"request": "^2.88.0",
|
||||
"rimraf": "^2.7.1",
|
||||
"tape": "^4.6.2",
|
||||
"typescript": "^3.5.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
},
|
||||
"homepage": "https://github.com/form-data/form-data#readme",
|
||||
"license": "MIT",
|
||||
"main": "./lib/form_data",
|
||||
"name": "@discordjs/form-data",
|
||||
"pre-commit": [
|
||||
"lint",
|
||||
"ci-test",
|
||||
"check"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/form-data/form-data.git"
|
||||
},
|
||||
"scripts": {
|
||||
"browser": "browserify -t browserify-istanbul test/run-browser.js | obake --coverage",
|
||||
"check": "istanbul check-coverage coverage/coverage*.json",
|
||||
"ci-lint": "is-node-modern 8 && npm run lint || is-node-not-modern 8",
|
||||
"ci-test": "npm run test && npm run browser && npm run report",
|
||||
"debug": "verbose=1 ./test/run.js",
|
||||
"files": "pkgfiles --sort=name",
|
||||
"get-version": "node -e \"console.log(require('./package.json').version)\"",
|
||||
"lint": "eslint lib/*.js test/*.js test/integration/*.js",
|
||||
"posttest": "istanbul report lcov text",
|
||||
"predebug": "rimraf coverage test/tmp",
|
||||
"pretest": "rimraf coverage test/tmp",
|
||||
"report": "istanbul report lcov text",
|
||||
"test": "istanbul cover test/run.js"
|
||||
},
|
||||
"typings": "./index.d.ts",
|
||||
"version": "3.0.1"
|
||||
}
|
21
node_modules/abort-controller/LICENSE
generated
vendored
Normal file
21
node_modules/abort-controller/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Toru Nagashima
|
||||
|
||||
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.
|
98
node_modules/abort-controller/README.md
generated
vendored
Normal file
98
node_modules/abort-controller/README.md
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
# abort-controller
|
||||
|
||||
[](https://www.npmjs.com/package/abort-controller)
|
||||
[](http://www.npmtrends.com/abort-controller)
|
||||
[](https://travis-ci.org/mysticatea/abort-controller)
|
||||
[](https://codecov.io/gh/mysticatea/abort-controller)
|
||||
[](https://david-dm.org/mysticatea/abort-controller)
|
||||
|
||||
An implementation of [WHATWG AbortController interface](https://dom.spec.whatwg.org/#interface-abortcontroller).
|
||||
|
||||
```js
|
||||
import AbortController from "abort-controller"
|
||||
|
||||
const controller = new AbortController()
|
||||
const signal = controller.signal
|
||||
|
||||
signal.addEventListener("abort", () => {
|
||||
console.log("aborted!")
|
||||
})
|
||||
|
||||
controller.abort()
|
||||
```
|
||||
|
||||
> https://jsfiddle.net/1r2994qp/1/
|
||||
|
||||
## 💿 Installation
|
||||
|
||||
Use [npm](https://www.npmjs.com/) to install then use a bundler.
|
||||
|
||||
```
|
||||
npm install abort-controller
|
||||
```
|
||||
|
||||
Or download from [`dist` directory](./dist).
|
||||
|
||||
- [dist/abort-controller.mjs](dist/abort-controller.mjs) ... ES modules version.
|
||||
- [dist/abort-controller.js](dist/abort-controller.js) ... Common JS version.
|
||||
- [dist/abort-controller.umd.js](dist/abort-controller.umd.js) ... UMD (Universal Module Definition) version. This is transpiled by [Babel](https://babeljs.io/) for IE 11.
|
||||
|
||||
## 📖 Usage
|
||||
|
||||
### Basic
|
||||
|
||||
```js
|
||||
import AbortController from "abort-controller"
|
||||
// or
|
||||
const AbortController = require("abort-controller")
|
||||
|
||||
// or UMD version defines a global variable:
|
||||
const AbortController = window.AbortControllerShim
|
||||
```
|
||||
|
||||
If your bundler recognizes `browser` field of `package.json`, the imported `AbortController` is the native one and it doesn't contain shim (even if the native implementation was nothing).
|
||||
If you wanted to polyfill `AbortController` for IE, use `abort-controller/polyfill`.
|
||||
|
||||
### Polyfilling
|
||||
|
||||
Importing `abort-controller/polyfill` assigns the `AbortController` shim to the `AbortController` global variable if the native implementation was nothing.
|
||||
|
||||
```js
|
||||
import "abort-controller/polyfill"
|
||||
// or
|
||||
require("abort-controller/polyfill")
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
#### AbortController
|
||||
|
||||
> https://dom.spec.whatwg.org/#interface-abortcontroller
|
||||
|
||||
##### controller.signal
|
||||
|
||||
The [AbortSignal](https://dom.spec.whatwg.org/#interface-AbortSignal) object which is associated to this controller.
|
||||
|
||||
##### controller.abort()
|
||||
|
||||
Notify `abort` event to listeners that the `signal` has.
|
||||
|
||||
## 📰 Changelog
|
||||
|
||||
- See [GitHub releases](https://github.com/mysticatea/abort-controller/releases).
|
||||
|
||||
## 🍻 Contributing
|
||||
|
||||
Contributing is welcome ❤️
|
||||
|
||||
Please use GitHub issues/PRs.
|
||||
|
||||
### Development tools
|
||||
|
||||
- `npm install` installs dependencies for development.
|
||||
- `npm test` runs tests and measures code coverage.
|
||||
- `npm run clean` removes temporary files of tests.
|
||||
- `npm run coverage` opens code coverage of the previous test with your default browser.
|
||||
- `npm run lint` runs ESLint.
|
||||
- `npm run build` generates `dist` codes.
|
||||
- `npm run watch` runs tests on each file change.
|
13
node_modules/abort-controller/browser.js
generated
vendored
Normal file
13
node_modules/abort-controller/browser.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/*globals self, window */
|
||||
"use strict"
|
||||
|
||||
/*eslint-disable @mysticatea/prettier */
|
||||
const { AbortController, AbortSignal } =
|
||||
typeof self !== "undefined" ? self :
|
||||
typeof window !== "undefined" ? window :
|
||||
/* otherwise */ undefined
|
||||
/*eslint-enable @mysticatea/prettier */
|
||||
|
||||
module.exports = AbortController
|
||||
module.exports.AbortSignal = AbortSignal
|
||||
module.exports.default = AbortController
|
11
node_modules/abort-controller/browser.mjs
generated
vendored
Normal file
11
node_modules/abort-controller/browser.mjs
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/*globals self, window */
|
||||
|
||||
/*eslint-disable @mysticatea/prettier */
|
||||
const { AbortController, AbortSignal } =
|
||||
typeof self !== "undefined" ? self :
|
||||
typeof window !== "undefined" ? window :
|
||||
/* otherwise */ undefined
|
||||
/*eslint-enable @mysticatea/prettier */
|
||||
|
||||
export default AbortController
|
||||
export { AbortController, AbortSignal }
|
43
node_modules/abort-controller/dist/abort-controller.d.ts
generated
vendored
Normal file
43
node_modules/abort-controller/dist/abort-controller.d.ts
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
import { EventTarget } from "event-target-shim"
|
||||
|
||||
type Events = {
|
||||
abort: any
|
||||
}
|
||||
type EventAttributes = {
|
||||
onabort: any
|
||||
}
|
||||
/**
|
||||
* The signal class.
|
||||
* @see https://dom.spec.whatwg.org/#abortsignal
|
||||
*/
|
||||
declare class AbortSignal extends EventTarget<Events, EventAttributes> {
|
||||
/**
|
||||
* AbortSignal cannot be constructed directly.
|
||||
*/
|
||||
constructor()
|
||||
/**
|
||||
* Returns `true` if this `AbortSignal`"s `AbortController` has signaled to abort, and `false` otherwise.
|
||||
*/
|
||||
readonly aborted: boolean
|
||||
}
|
||||
/**
|
||||
* The AbortController.
|
||||
* @see https://dom.spec.whatwg.org/#abortcontroller
|
||||
*/
|
||||
declare class AbortController {
|
||||
/**
|
||||
* Initialize this controller.
|
||||
*/
|
||||
constructor()
|
||||
/**
|
||||
* Returns the `AbortSignal` object associated with this object.
|
||||
*/
|
||||
readonly signal: AbortSignal
|
||||
/**
|
||||
* Abort and signal to any observers that the associated activity is to be aborted.
|
||||
*/
|
||||
abort(): void
|
||||
}
|
||||
|
||||
export default AbortController
|
||||
export { AbortController, AbortSignal }
|
127
node_modules/abort-controller/dist/abort-controller.js
generated
vendored
Normal file
127
node_modules/abort-controller/dist/abort-controller.js
generated
vendored
Normal file
@ -0,0 +1,127 @@
|
||||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var eventTargetShim = require('event-target-shim');
|
||||
|
||||
/**
|
||||
* The signal class.
|
||||
* @see https://dom.spec.whatwg.org/#abortsignal
|
||||
*/
|
||||
class AbortSignal extends eventTargetShim.EventTarget {
|
||||
/**
|
||||
* AbortSignal cannot be constructed directly.
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
throw new TypeError("AbortSignal cannot be constructed directly");
|
||||
}
|
||||
/**
|
||||
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
|
||||
*/
|
||||
get aborted() {
|
||||
const aborted = abortedFlags.get(this);
|
||||
if (typeof aborted !== "boolean") {
|
||||
throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
|
||||
}
|
||||
return aborted;
|
||||
}
|
||||
}
|
||||
eventTargetShim.defineEventAttribute(AbortSignal.prototype, "abort");
|
||||
/**
|
||||
* Create an AbortSignal object.
|
||||
*/
|
||||
function createAbortSignal() {
|
||||
const signal = Object.create(AbortSignal.prototype);
|
||||
eventTargetShim.EventTarget.call(signal);
|
||||
abortedFlags.set(signal, false);
|
||||
return signal;
|
||||
}
|
||||
/**
|
||||
* Abort a given signal.
|
||||
*/
|
||||
function abortSignal(signal) {
|
||||
if (abortedFlags.get(signal) !== false) {
|
||||
return;
|
||||
}
|
||||
abortedFlags.set(signal, true);
|
||||
signal.dispatchEvent({ type: "abort" });
|
||||
}
|
||||
/**
|
||||
* Aborted flag for each instances.
|
||||
*/
|
||||
const abortedFlags = new WeakMap();
|
||||
// Properties should be enumerable.
|
||||
Object.defineProperties(AbortSignal.prototype, {
|
||||
aborted: { enumerable: true },
|
||||
});
|
||||
// `toString()` should return `"[object AbortSignal]"`
|
||||
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
||||
Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
|
||||
configurable: true,
|
||||
value: "AbortSignal",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The AbortController.
|
||||
* @see https://dom.spec.whatwg.org/#abortcontroller
|
||||
*/
|
||||
class AbortController {
|
||||
/**
|
||||
* Initialize this controller.
|
||||
*/
|
||||
constructor() {
|
||||
signals.set(this, createAbortSignal());
|
||||
}
|
||||
/**
|
||||
* Returns the `AbortSignal` object associated with this object.
|
||||
*/
|
||||
get signal() {
|
||||
return getSignal(this);
|
||||
}
|
||||
/**
|
||||
* Abort and signal to any observers that the associated activity is to be aborted.
|
||||
*/
|
||||
abort() {
|
||||
abortSignal(getSignal(this));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Associated signals.
|
||||
*/
|
||||
const signals = new WeakMap();
|
||||
/**
|
||||
* Get the associated signal of a given controller.
|
||||
*/
|
||||
function getSignal(controller) {
|
||||
const signal = signals.get(controller);
|
||||
if (signal == null) {
|
||||
throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
|
||||
}
|
||||
return signal;
|
||||
}
|
||||
// Properties should be enumerable.
|
||||
Object.defineProperties(AbortController.prototype, {
|
||||
signal: { enumerable: true },
|
||||
abort: { enumerable: true },
|
||||
});
|
||||
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
||||
Object.defineProperty(AbortController.prototype, Symbol.toStringTag, {
|
||||
configurable: true,
|
||||
value: "AbortController",
|
||||
});
|
||||
}
|
||||
|
||||
exports.AbortController = AbortController;
|
||||
exports.AbortSignal = AbortSignal;
|
||||
exports.default = AbortController;
|
||||
|
||||
module.exports = AbortController
|
||||
module.exports.AbortController = module.exports["default"] = AbortController
|
||||
module.exports.AbortSignal = AbortSignal
|
||||
//# sourceMappingURL=abort-controller.js.map
|
1
node_modules/abort-controller/dist/abort-controller.js.map
generated
vendored
Normal file
1
node_modules/abort-controller/dist/abort-controller.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
118
node_modules/abort-controller/dist/abort-controller.mjs
generated
vendored
Normal file
118
node_modules/abort-controller/dist/abort-controller.mjs
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
import { EventTarget, defineEventAttribute } from 'event-target-shim';
|
||||
|
||||
/**
|
||||
* The signal class.
|
||||
* @see https://dom.spec.whatwg.org/#abortsignal
|
||||
*/
|
||||
class AbortSignal extends EventTarget {
|
||||
/**
|
||||
* AbortSignal cannot be constructed directly.
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
throw new TypeError("AbortSignal cannot be constructed directly");
|
||||
}
|
||||
/**
|
||||
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
|
||||
*/
|
||||
get aborted() {
|
||||
const aborted = abortedFlags.get(this);
|
||||
if (typeof aborted !== "boolean") {
|
||||
throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
|
||||
}
|
||||
return aborted;
|
||||
}
|
||||
}
|
||||
defineEventAttribute(AbortSignal.prototype, "abort");
|
||||
/**
|
||||
* Create an AbortSignal object.
|
||||
*/
|
||||
function createAbortSignal() {
|
||||
const signal = Object.create(AbortSignal.prototype);
|
||||
EventTarget.call(signal);
|
||||
abortedFlags.set(signal, false);
|
||||
return signal;
|
||||
}
|
||||
/**
|
||||
* Abort a given signal.
|
||||
*/
|
||||
function abortSignal(signal) {
|
||||
if (abortedFlags.get(signal) !== false) {
|
||||
return;
|
||||
}
|
||||
abortedFlags.set(signal, true);
|
||||
signal.dispatchEvent({ type: "abort" });
|
||||
}
|
||||
/**
|
||||
* Aborted flag for each instances.
|
||||
*/
|
||||
const abortedFlags = new WeakMap();
|
||||
// Properties should be enumerable.
|
||||
Object.defineProperties(AbortSignal.prototype, {
|
||||
aborted: { enumerable: true },
|
||||
});
|
||||
// `toString()` should return `"[object AbortSignal]"`
|
||||
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
||||
Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
|
||||
configurable: true,
|
||||
value: "AbortSignal",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The AbortController.
|
||||
* @see https://dom.spec.whatwg.org/#abortcontroller
|
||||
*/
|
||||
class AbortController {
|
||||
/**
|
||||
* Initialize this controller.
|
||||
*/
|
||||
constructor() {
|
||||
signals.set(this, createAbortSignal());
|
||||
}
|
||||
/**
|
||||
* Returns the `AbortSignal` object associated with this object.
|
||||
*/
|
||||
get signal() {
|
||||
return getSignal(this);
|
||||
}
|
||||
/**
|
||||
* Abort and signal to any observers that the associated activity is to be aborted.
|
||||
*/
|
||||
abort() {
|
||||
abortSignal(getSignal(this));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Associated signals.
|
||||
*/
|
||||
const signals = new WeakMap();
|
||||
/**
|
||||
* Get the associated signal of a given controller.
|
||||
*/
|
||||
function getSignal(controller) {
|
||||
const signal = signals.get(controller);
|
||||
if (signal == null) {
|
||||
throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
|
||||
}
|
||||
return signal;
|
||||
}
|
||||
// Properties should be enumerable.
|
||||
Object.defineProperties(AbortController.prototype, {
|
||||
signal: { enumerable: true },
|
||||
abort: { enumerable: true },
|
||||
});
|
||||
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
||||
Object.defineProperty(AbortController.prototype, Symbol.toStringTag, {
|
||||
configurable: true,
|
||||
value: "AbortController",
|
||||
});
|
||||
}
|
||||
|
||||
export default AbortController;
|
||||
export { AbortController, AbortSignal };
|
||||
//# sourceMappingURL=abort-controller.mjs.map
|
1
node_modules/abort-controller/dist/abort-controller.mjs.map
generated
vendored
Normal file
1
node_modules/abort-controller/dist/abort-controller.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
5
node_modules/abort-controller/dist/abort-controller.umd.js
generated
vendored
Normal file
5
node_modules/abort-controller/dist/abort-controller.umd.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/abort-controller/dist/abort-controller.umd.js.map
generated
vendored
Normal file
1
node_modules/abort-controller/dist/abort-controller.umd.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
125
node_modules/abort-controller/package.json
generated
vendored
Normal file
125
node_modules/abort-controller/package.json
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
{
|
||||
"_from": "abort-controller@^3.0.0",
|
||||
"_id": "abort-controller@3.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"_location": "/abort-controller",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "abort-controller@^3.0.0",
|
||||
"name": "abort-controller",
|
||||
"escapedName": "abort-controller",
|
||||
"rawSpec": "^3.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/discord.js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"_shasum": "eaf54d53b62bae4138e809ca225c8439a6efb392",
|
||||
"_spec": "abort-controller@^3.0.0",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\discord.js",
|
||||
"author": {
|
||||
"name": "Toru Nagashima",
|
||||
"url": "https://github.com/mysticatea"
|
||||
},
|
||||
"browser": "./browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mysticatea/abort-controller/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "An implementation of WHATWG AbortController interface.",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.2.2",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
|
||||
"@babel/preset-env": "^7.3.0",
|
||||
"@babel/register": "^7.0.0",
|
||||
"@mysticatea/eslint-plugin": "^8.0.1",
|
||||
"@mysticatea/spy": "^0.1.2",
|
||||
"@types/mocha": "^5.2.5",
|
||||
"@types/node": "^10.12.18",
|
||||
"assert": "^1.4.1",
|
||||
"codecov": "^3.1.0",
|
||||
"dts-bundle-generator": "^2.0.0",
|
||||
"eslint": "^5.12.1",
|
||||
"karma": "^3.1.4",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-coverage": "^1.1.2",
|
||||
"karma-firefox-launcher": "^1.1.0",
|
||||
"karma-growl-reporter": "^1.0.0",
|
||||
"karma-ie-launcher": "^1.0.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-rollup-preprocessor": "^7.0.0-rc.2",
|
||||
"mocha": "^5.2.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^13.1.0",
|
||||
"opener": "^1.5.1",
|
||||
"rimraf": "^2.6.3",
|
||||
"rollup": "^1.1.2",
|
||||
"rollup-plugin-babel": "^4.3.2",
|
||||
"rollup-plugin-babel-minify": "^7.0.0",
|
||||
"rollup-plugin-commonjs": "^9.2.0",
|
||||
"rollup-plugin-node-resolve": "^4.0.0",
|
||||
"rollup-plugin-sourcemaps": "^0.4.2",
|
||||
"rollup-plugin-typescript": "^1.0.0",
|
||||
"rollup-watch": "^4.3.1",
|
||||
"ts-node": "^8.0.1",
|
||||
"type-tester": "^1.0.0",
|
||||
"typescript": "^3.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.5"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"polyfill.*",
|
||||
"browser.*"
|
||||
],
|
||||
"homepage": "https://github.com/mysticatea/abort-controller#readme",
|
||||
"keywords": [
|
||||
"w3c",
|
||||
"whatwg",
|
||||
"event",
|
||||
"events",
|
||||
"abort",
|
||||
"cancel",
|
||||
"abortcontroller",
|
||||
"abortsignal",
|
||||
"controller",
|
||||
"signal",
|
||||
"shim"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/abort-controller",
|
||||
"name": "abort-controller",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mysticatea/abort-controller.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "run-s -s build:*",
|
||||
"build:dts": "dts-bundle-generator -o dist/abort-controller.d.ts src/abort-controller.ts && ts-node scripts/fix-dts",
|
||||
"build:rollup": "rollup -c",
|
||||
"clean": "rimraf .nyc_output coverage",
|
||||
"codecov": "codecov",
|
||||
"coverage": "opener coverage/lcov-report/index.html",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"postversion": "git push && git push --tags",
|
||||
"preversion": "npm test",
|
||||
"test": "run-s -s lint test:*",
|
||||
"test:karma": "karma start --single-run",
|
||||
"test:mocha": "nyc mocha test/*.ts",
|
||||
"version": "npm run -s build && git add dist/*",
|
||||
"watch": "run-p -s watch:*",
|
||||
"watch:karma": "karma start --watch",
|
||||
"watch:mocha": "mocha test/*.ts --require ts-node/register --watch-extensions ts --watch --growl"
|
||||
},
|
||||
"version": "3.0.0"
|
||||
}
|
21
node_modules/abort-controller/polyfill.js
generated
vendored
Normal file
21
node_modules/abort-controller/polyfill.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
/*globals require, self, window */
|
||||
"use strict"
|
||||
|
||||
const ac = require("./dist/abort-controller")
|
||||
|
||||
/*eslint-disable @mysticatea/prettier */
|
||||
const g =
|
||||
typeof self !== "undefined" ? self :
|
||||
typeof window !== "undefined" ? window :
|
||||
typeof global !== "undefined" ? global :
|
||||
/* otherwise */ undefined
|
||||
/*eslint-enable @mysticatea/prettier */
|
||||
|
||||
if (g) {
|
||||
if (typeof g.AbortController === "undefined") {
|
||||
g.AbortController = ac.AbortController
|
||||
}
|
||||
if (typeof g.AbortSignal === "undefined") {
|
||||
g.AbortSignal = ac.AbortSignal
|
||||
}
|
||||
}
|
19
node_modules/abort-controller/polyfill.mjs
generated
vendored
Normal file
19
node_modules/abort-controller/polyfill.mjs
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*globals self, window */
|
||||
import * as ac from "./dist/abort-controller"
|
||||
|
||||
/*eslint-disable @mysticatea/prettier */
|
||||
const g =
|
||||
typeof self !== "undefined" ? self :
|
||||
typeof window !== "undefined" ? window :
|
||||
typeof global !== "undefined" ? global :
|
||||
/* otherwise */ undefined
|
||||
/*eslint-enable @mysticatea/prettier */
|
||||
|
||||
if (g) {
|
||||
if (typeof g.AbortController === "undefined") {
|
||||
g.AbortController = ac.AbortController
|
||||
}
|
||||
if (typeof g.AbortSignal === "undefined") {
|
||||
g.AbortSignal = ac.AbortSignal
|
||||
}
|
||||
}
|
21
node_modules/asynckit/LICENSE
generated
vendored
Normal file
21
node_modules/asynckit/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Alex Indigo
|
||||
|
||||
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.
|
233
node_modules/asynckit/README.md
generated
vendored
Normal file
233
node_modules/asynckit/README.md
generated
vendored
Normal file
@ -0,0 +1,233 @@
|
||||
# asynckit [](https://www.npmjs.com/package/asynckit)
|
||||
|
||||
Minimal async jobs utility library, with streams support.
|
||||
|
||||
[](https://travis-ci.org/alexindigo/asynckit)
|
||||
[](https://travis-ci.org/alexindigo/asynckit)
|
||||
[](https://ci.appveyor.com/project/alexindigo/asynckit)
|
||||
|
||||
[](https://coveralls.io/github/alexindigo/asynckit?branch=master)
|
||||
[](https://david-dm.org/alexindigo/asynckit)
|
||||
[](https://www.bithound.io/github/alexindigo/asynckit)
|
||||
|
||||
<!-- [](https://www.npmjs.com/package/reamde) -->
|
||||
|
||||
AsyncKit provides harness for `parallel` and `serial` iterators over list of items represented by arrays or objects.
|
||||
Optionally it accepts abort function (should be synchronously return by iterator for each item), and terminates left over jobs upon an error event. For specific iteration order built-in (`ascending` and `descending`) and custom sort helpers also supported, via `asynckit.serialOrdered` method.
|
||||
|
||||
It ensures async operations to keep behavior more stable and prevent `Maximum call stack size exceeded` errors, from sync iterators.
|
||||
|
||||
| compression | size |
|
||||
| :----------------- | -------: |
|
||||
| asynckit.js | 12.34 kB |
|
||||
| asynckit.min.js | 4.11 kB |
|
||||
| asynckit.min.js.gz | 1.47 kB |
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install --save asynckit
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Parallel Jobs
|
||||
|
||||
Runs iterator over provided array in parallel. Stores output in the `result` array,
|
||||
on the matching positions. In unlikely event of an error from one of the jobs,
|
||||
will terminate rest of the active jobs (if abort function is provided)
|
||||
and return error along with salvaged data to the main callback function.
|
||||
|
||||
#### Input Array
|
||||
|
||||
```javascript
|
||||
var parallel = require('asynckit').parallel
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
parallel(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// async job accepts one element from the array
|
||||
// and a callback function
|
||||
function asyncJob(item, cb)
|
||||
{
|
||||
// different delays (in ms) per item
|
||||
var delay = item * 25;
|
||||
|
||||
// pretend different jobs take different time to finish
|
||||
// and not in consequential order
|
||||
var timeoutId = setTimeout(function() {
|
||||
target.push(item);
|
||||
cb(null, item * 2);
|
||||
}, delay);
|
||||
|
||||
// allow to cancel "leftover" jobs upon error
|
||||
// return function, invoking of which will abort this job
|
||||
return clearTimeout.bind(null, timeoutId);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-parallel-array.js](test/test-parallel-array.js).
|
||||
|
||||
#### Input Object
|
||||
|
||||
Also it supports named jobs, listed via object.
|
||||
|
||||
```javascript
|
||||
var parallel = require('asynckit/parallel')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
|
||||
, expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
|
||||
, expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
|
||||
, expectedKeys = [ 'first', 'one', 'two', 'four', 'eight', 'sixteen', 'thirtyTwo', 'sixtyFour' ]
|
||||
, target = []
|
||||
, keys = []
|
||||
;
|
||||
|
||||
parallel(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
assert.deepEqual(keys, expectedKeys);
|
||||
});
|
||||
|
||||
// supports full value, key, callback (shortcut) interface
|
||||
function asyncJob(item, key, cb)
|
||||
{
|
||||
// different delays (in ms) per item
|
||||
var delay = item * 25;
|
||||
|
||||
// pretend different jobs take different time to finish
|
||||
// and not in consequential order
|
||||
var timeoutId = setTimeout(function() {
|
||||
keys.push(key);
|
||||
target.push(item);
|
||||
cb(null, item * 2);
|
||||
}, delay);
|
||||
|
||||
// allow to cancel "leftover" jobs upon error
|
||||
// return function, invoking of which will abort this job
|
||||
return clearTimeout.bind(null, timeoutId);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-parallel-object.js](test/test-parallel-object.js).
|
||||
|
||||
### Serial Jobs
|
||||
|
||||
Runs iterator over provided array sequentially. Stores output in the `result` array,
|
||||
on the matching positions. In unlikely event of an error from one of the jobs,
|
||||
will not proceed to the rest of the items in the list
|
||||
and return error along with salvaged data to the main callback function.
|
||||
|
||||
#### Input Array
|
||||
|
||||
```javascript
|
||||
var serial = require('asynckit/serial')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
serial(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// extended interface (item, key, callback)
|
||||
// also supported for arrays
|
||||
function asyncJob(item, key, cb)
|
||||
{
|
||||
target.push(key);
|
||||
|
||||
// it will be automatically made async
|
||||
// even it iterator "returns" in the same event loop
|
||||
cb(null, item * 2);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-serial-array.js](test/test-serial-array.js).
|
||||
|
||||
#### Input Object
|
||||
|
||||
Also it supports named jobs, listed via object.
|
||||
|
||||
```javascript
|
||||
var serial = require('asynckit').serial
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
|
||||
, expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
|
||||
, expectedTarget = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
|
||||
serial(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// shortcut interface (item, callback)
|
||||
// works for object as well as for the arrays
|
||||
function asyncJob(item, cb)
|
||||
{
|
||||
target.push(item);
|
||||
|
||||
// it will be automatically made async
|
||||
// even it iterator "returns" in the same event loop
|
||||
cb(null, item * 2);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-serial-object.js](test/test-serial-object.js).
|
||||
|
||||
_Note: Since _object_ is an _unordered_ collection of properties,
|
||||
it may produce unexpected results with sequential iterations.
|
||||
Whenever order of the jobs' execution is important please use `serialOrdered` method._
|
||||
|
||||
### Ordered Serial Iterations
|
||||
|
||||
TBD
|
||||
|
||||
For example [compare-property](compare-property) package.
|
||||
|
||||
### Streaming interface
|
||||
|
||||
TBD
|
||||
|
||||
## Want to Know More?
|
||||
|
||||
More examples can be found in [test folder](test/).
|
||||
|
||||
Or open an [issue](https://github.com/alexindigo/asynckit/issues) with questions and/or suggestions.
|
||||
|
||||
## License
|
||||
|
||||
AsyncKit is licensed under the MIT license.
|
76
node_modules/asynckit/bench.js
generated
vendored
Normal file
76
node_modules/asynckit/bench.js
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
/* eslint no-console: "off" */
|
||||
|
||||
var asynckit = require('./')
|
||||
, async = require('async')
|
||||
, assert = require('assert')
|
||||
, expected = 0
|
||||
;
|
||||
|
||||
var Benchmark = require('benchmark');
|
||||
var suite = new Benchmark.Suite;
|
||||
|
||||
var source = [];
|
||||
for (var z = 1; z < 100; z++)
|
||||
{
|
||||
source.push(z);
|
||||
expected += z;
|
||||
}
|
||||
|
||||
suite
|
||||
// add tests
|
||||
|
||||
.add('async.map', function(deferred)
|
||||
{
|
||||
var total = 0;
|
||||
|
||||
async.map(source,
|
||||
function(i, cb)
|
||||
{
|
||||
setImmediate(function()
|
||||
{
|
||||
total += i;
|
||||
cb(null, total);
|
||||
});
|
||||
},
|
||||
function(err, result)
|
||||
{
|
||||
assert.ifError(err);
|
||||
assert.equal(result[result.length - 1], expected);
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {'defer': true})
|
||||
|
||||
|
||||
.add('asynckit.parallel', function(deferred)
|
||||
{
|
||||
var total = 0;
|
||||
|
||||
asynckit.parallel(source,
|
||||
function(i, cb)
|
||||
{
|
||||
setImmediate(function()
|
||||
{
|
||||
total += i;
|
||||
cb(null, total);
|
||||
});
|
||||
},
|
||||
function(err, result)
|
||||
{
|
||||
assert.ifError(err);
|
||||
assert.equal(result[result.length - 1], expected);
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {'defer': true})
|
||||
|
||||
|
||||
// add listeners
|
||||
.on('cycle', function(ev)
|
||||
{
|
||||
console.log(String(ev.target));
|
||||
})
|
||||
.on('complete', function()
|
||||
{
|
||||
console.log('Fastest is ' + this.filter('fastest').map('name'));
|
||||
})
|
||||
// run async
|
||||
.run({ 'async': true });
|
6
node_modules/asynckit/index.js
generated
vendored
Normal file
6
node_modules/asynckit/index.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports =
|
||||
{
|
||||
parallel : require('./parallel.js'),
|
||||
serial : require('./serial.js'),
|
||||
serialOrdered : require('./serialOrdered.js')
|
||||
};
|
29
node_modules/asynckit/lib/abort.js
generated
vendored
Normal file
29
node_modules/asynckit/lib/abort.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// API
|
||||
module.exports = abort;
|
||||
|
||||
/**
|
||||
* Aborts leftover active jobs
|
||||
*
|
||||
* @param {object} state - current state object
|
||||
*/
|
||||
function abort(state)
|
||||
{
|
||||
Object.keys(state.jobs).forEach(clean.bind(state));
|
||||
|
||||
// reset leftover jobs
|
||||
state.jobs = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up leftover job by invoking abort function for the provided job id
|
||||
*
|
||||
* @this state
|
||||
* @param {string|number} key - job id to abort
|
||||
*/
|
||||
function clean(key)
|
||||
{
|
||||
if (typeof this.jobs[key] == 'function')
|
||||
{
|
||||
this.jobs[key]();
|
||||
}
|
||||
}
|
34
node_modules/asynckit/lib/async.js
generated
vendored
Normal file
34
node_modules/asynckit/lib/async.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
var defer = require('./defer.js');
|
||||
|
||||
// API
|
||||
module.exports = async;
|
||||
|
||||
/**
|
||||
* Runs provided callback asynchronously
|
||||
* even if callback itself is not
|
||||
*
|
||||
* @param {function} callback - callback to invoke
|
||||
* @returns {function} - augmented callback
|
||||
*/
|
||||
function async(callback)
|
||||
{
|
||||
var isAsync = false;
|
||||
|
||||
// check if async happened
|
||||
defer(function() { isAsync = true; });
|
||||
|
||||
return function async_callback(err, result)
|
||||
{
|
||||
if (isAsync)
|
||||
{
|
||||
callback(err, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
defer(function nextTick_callback()
|
||||
{
|
||||
callback(err, result);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
26
node_modules/asynckit/lib/defer.js
generated
vendored
Normal file
26
node_modules/asynckit/lib/defer.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
module.exports = defer;
|
||||
|
||||
/**
|
||||
* Runs provided function on next iteration of the event loop
|
||||
*
|
||||
* @param {function} fn - function to run
|
||||
*/
|
||||
function defer(fn)
|
||||
{
|
||||
var nextTick = typeof setImmediate == 'function'
|
||||
? setImmediate
|
||||
: (
|
||||
typeof process == 'object' && typeof process.nextTick == 'function'
|
||||
? process.nextTick
|
||||
: null
|
||||
);
|
||||
|
||||
if (nextTick)
|
||||
{
|
||||
nextTick(fn);
|
||||
}
|
||||
else
|
||||
{
|
||||
setTimeout(fn, 0);
|
||||
}
|
||||
}
|
75
node_modules/asynckit/lib/iterate.js
generated
vendored
Normal file
75
node_modules/asynckit/lib/iterate.js
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
var async = require('./async.js')
|
||||
, abort = require('./abort.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports = iterate;
|
||||
|
||||
/**
|
||||
* Iterates over each job object
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {object} state - current job status
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
*/
|
||||
function iterate(list, iterator, state, callback)
|
||||
{
|
||||
// store current index
|
||||
var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
|
||||
|
||||
state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
|
||||
{
|
||||
// don't repeat yourself
|
||||
// skip secondary callbacks
|
||||
if (!(key in state.jobs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// clean up jobs
|
||||
delete state.jobs[key];
|
||||
|
||||
if (error)
|
||||
{
|
||||
// don't process rest of the results
|
||||
// stop still active jobs
|
||||
// and reset the list
|
||||
abort(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.results[key] = output;
|
||||
}
|
||||
|
||||
// return salvaged results
|
||||
callback(error, state.results);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs iterator over provided job element
|
||||
*
|
||||
* @param {function} iterator - iterator to invoke
|
||||
* @param {string|number} key - key/index of the element in the list of jobs
|
||||
* @param {mixed} item - job description
|
||||
* @param {function} callback - invoked after iterator is done with the job
|
||||
* @returns {function|mixed} - job abort function or something else
|
||||
*/
|
||||
function runJob(iterator, key, item, callback)
|
||||
{
|
||||
var aborter;
|
||||
|
||||
// allow shortcut if iterator expects only two arguments
|
||||
if (iterator.length == 2)
|
||||
{
|
||||
aborter = iterator(item, async(callback));
|
||||
}
|
||||
// otherwise go with full three arguments
|
||||
else
|
||||
{
|
||||
aborter = iterator(item, key, async(callback));
|
||||
}
|
||||
|
||||
return aborter;
|
||||
}
|
91
node_modules/asynckit/lib/readable_asynckit.js
generated
vendored
Normal file
91
node_modules/asynckit/lib/readable_asynckit.js
generated
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
var streamify = require('./streamify.js')
|
||||
, defer = require('./defer.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports = ReadableAsyncKit;
|
||||
|
||||
/**
|
||||
* Base constructor for all streams
|
||||
* used to hold properties/methods
|
||||
*/
|
||||
function ReadableAsyncKit()
|
||||
{
|
||||
ReadableAsyncKit.super_.apply(this, arguments);
|
||||
|
||||
// list of active jobs
|
||||
this.jobs = {};
|
||||
|
||||
// add stream methods
|
||||
this.destroy = destroy;
|
||||
this._start = _start;
|
||||
this._read = _read;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys readable stream,
|
||||
* by aborting outstanding jobs
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function destroy()
|
||||
{
|
||||
if (this.destroyed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.destroyed = true;
|
||||
|
||||
if (typeof this.terminator == 'function')
|
||||
{
|
||||
this.terminator();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts provided jobs in async manner
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _start()
|
||||
{
|
||||
// first argument – runner function
|
||||
var runner = arguments[0]
|
||||
// take away first argument
|
||||
, args = Array.prototype.slice.call(arguments, 1)
|
||||
// second argument - input data
|
||||
, input = args[0]
|
||||
// last argument - result callback
|
||||
, endCb = streamify.callback.call(this, args[args.length - 1])
|
||||
;
|
||||
|
||||
args[args.length - 1] = endCb;
|
||||
// third argument - iterator
|
||||
args[1] = streamify.iterator.call(this, args[1]);
|
||||
|
||||
// allow time for proper setup
|
||||
defer(function()
|
||||
{
|
||||
if (!this.destroyed)
|
||||
{
|
||||
this.terminator = runner.apply(null, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
endCb(null, Array.isArray(input) ? [] : {});
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implement _read to comply with Readable streams
|
||||
* Doesn't really make sense for flowing object mode
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _read()
|
||||
{
|
||||
|
||||
}
|
25
node_modules/asynckit/lib/readable_parallel.js
generated
vendored
Normal file
25
node_modules/asynckit/lib/readable_parallel.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
var parallel = require('../parallel.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableParallel;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.parallel`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableParallel(list, iterator, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableParallel))
|
||||
{
|
||||
return new ReadableParallel(list, iterator, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableParallel.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(parallel, list, iterator, callback);
|
||||
}
|
25
node_modules/asynckit/lib/readable_serial.js
generated
vendored
Normal file
25
node_modules/asynckit/lib/readable_serial.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
var serial = require('../serial.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableSerial;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.serial`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableSerial(list, iterator, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableSerial))
|
||||
{
|
||||
return new ReadableSerial(list, iterator, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableSerial.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(serial, list, iterator, callback);
|
||||
}
|
29
node_modules/asynckit/lib/readable_serial_ordered.js
generated
vendored
Normal file
29
node_modules/asynckit/lib/readable_serial_ordered.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
var serialOrdered = require('../serialOrdered.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableSerialOrdered;
|
||||
// expose sort helpers
|
||||
module.exports.ascending = serialOrdered.ascending;
|
||||
module.exports.descending = serialOrdered.descending;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.serialOrdered`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} sortMethod - custom sort function
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableSerialOrdered(list, iterator, sortMethod, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableSerialOrdered))
|
||||
{
|
||||
return new ReadableSerialOrdered(list, iterator, sortMethod, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableSerialOrdered.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(serialOrdered, list, iterator, sortMethod, callback);
|
||||
}
|
37
node_modules/asynckit/lib/state.js
generated
vendored
Normal file
37
node_modules/asynckit/lib/state.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// API
|
||||
module.exports = state;
|
||||
|
||||
/**
|
||||
* Creates initial state object
|
||||
* for iteration over list
|
||||
*
|
||||
* @param {array|object} list - list to iterate over
|
||||
* @param {function|null} sortMethod - function to use for keys sort,
|
||||
* or `null` to keep them as is
|
||||
* @returns {object} - initial state object
|
||||
*/
|
||||
function state(list, sortMethod)
|
||||
{
|
||||
var isNamedList = !Array.isArray(list)
|
||||
, initState =
|
||||
{
|
||||
index : 0,
|
||||
keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
|
||||
jobs : {},
|
||||
results : isNamedList ? {} : [],
|
||||
size : isNamedList ? Object.keys(list).length : list.length
|
||||
}
|
||||
;
|
||||
|
||||
if (sortMethod)
|
||||
{
|
||||
// sort array keys based on it's values
|
||||
// sort object's keys just on own merit
|
||||
initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
|
||||
{
|
||||
return sortMethod(list[a], list[b]);
|
||||
});
|
||||
}
|
||||
|
||||
return initState;
|
||||
}
|
141
node_modules/asynckit/lib/streamify.js
generated
vendored
Normal file
141
node_modules/asynckit/lib/streamify.js
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
var async = require('./async.js');
|
||||
|
||||
// API
|
||||
module.exports = {
|
||||
iterator: wrapIterator,
|
||||
callback: wrapCallback
|
||||
};
|
||||
|
||||
/**
|
||||
* Wraps iterators with long signature
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {function} iterator - function to wrap
|
||||
* @returns {function} - wrapped function
|
||||
*/
|
||||
function wrapIterator(iterator)
|
||||
{
|
||||
var stream = this;
|
||||
|
||||
return function(item, key, cb)
|
||||
{
|
||||
var aborter
|
||||
, wrappedCb = async(wrapIteratorCallback.call(stream, cb, key))
|
||||
;
|
||||
|
||||
stream.jobs[key] = wrappedCb;
|
||||
|
||||
// it's either shortcut (item, cb)
|
||||
if (iterator.length == 2)
|
||||
{
|
||||
aborter = iterator(item, wrappedCb);
|
||||
}
|
||||
// or long format (item, key, cb)
|
||||
else
|
||||
{
|
||||
aborter = iterator(item, key, wrappedCb);
|
||||
}
|
||||
|
||||
return aborter;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps provided callback function
|
||||
* allowing to execute snitch function before
|
||||
* real callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {function} callback - function to wrap
|
||||
* @returns {function} - wrapped function
|
||||
*/
|
||||
function wrapCallback(callback)
|
||||
{
|
||||
var stream = this;
|
||||
|
||||
var wrapped = function(error, result)
|
||||
{
|
||||
return finisher.call(stream, error, result, callback);
|
||||
};
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps provided iterator callback function
|
||||
* makes sure snitch only called once,
|
||||
* but passes secondary calls to the original callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {function} callback - callback to wrap
|
||||
* @param {number|string} key - iteration key
|
||||
* @returns {function} wrapped callback
|
||||
*/
|
||||
function wrapIteratorCallback(callback, key)
|
||||
{
|
||||
var stream = this;
|
||||
|
||||
return function(error, output)
|
||||
{
|
||||
// don't repeat yourself
|
||||
if (!(key in stream.jobs))
|
||||
{
|
||||
callback(error, output);
|
||||
return;
|
||||
}
|
||||
|
||||
// clean up jobs
|
||||
delete stream.jobs[key];
|
||||
|
||||
return streamer.call(stream, error, {key: key, value: output}, callback);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream wrapper for iterator callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {mixed} error - error response
|
||||
* @param {mixed} output - iterator output
|
||||
* @param {function} callback - callback that expects iterator results
|
||||
*/
|
||||
function streamer(error, output, callback)
|
||||
{
|
||||
if (error && !this.error)
|
||||
{
|
||||
this.error = error;
|
||||
this.pause();
|
||||
this.emit('error', error);
|
||||
// send back value only, as expected
|
||||
callback(error, output && output.value);
|
||||
return;
|
||||
}
|
||||
|
||||
// stream stuff
|
||||
this.push(output);
|
||||
|
||||
// back to original track
|
||||
// send back value only, as expected
|
||||
callback(error, output && output.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream wrapper for finishing callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {mixed} error - error response
|
||||
* @param {mixed} output - iterator output
|
||||
* @param {function} callback - callback that expects final results
|
||||
*/
|
||||
function finisher(error, output, callback)
|
||||
{
|
||||
// signal end of the stream
|
||||
// only for successfully finished streams
|
||||
if (!error)
|
||||
{
|
||||
this.push(null);
|
||||
}
|
||||
|
||||
// back to original track
|
||||
callback(error, output);
|
||||
}
|
29
node_modules/asynckit/lib/terminator.js
generated
vendored
Normal file
29
node_modules/asynckit/lib/terminator.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
var abort = require('./abort.js')
|
||||
, async = require('./async.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports = terminator;
|
||||
|
||||
/**
|
||||
* Terminates jobs in the attached state context
|
||||
*
|
||||
* @this AsyncKitState#
|
||||
* @param {function} callback - final callback to invoke after termination
|
||||
*/
|
||||
function terminator(callback)
|
||||
{
|
||||
if (!Object.keys(this.jobs).length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// fast forward iteration index
|
||||
this.index = this.size;
|
||||
|
||||
// abort jobs
|
||||
abort(this);
|
||||
|
||||
// send back results we have so far
|
||||
async(callback)(null, this.results);
|
||||
}
|
91
node_modules/asynckit/package.json
generated
vendored
Normal file
91
node_modules/asynckit/package.json
generated
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
{
|
||||
"_from": "asynckit@^0.4.0",
|
||||
"_id": "asynckit@0.4.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
|
||||
"_location": "/asynckit",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "asynckit@^0.4.0",
|
||||
"name": "asynckit",
|
||||
"escapedName": "asynckit",
|
||||
"rawSpec": "^0.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@discordjs/form-data"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"_shasum": "c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79",
|
||||
"_spec": "asynckit@^0.4.0",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\@discordjs\\form-data",
|
||||
"author": {
|
||||
"name": "Alex Indigo",
|
||||
"email": "iam@alexindigo.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/alexindigo/asynckit/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Minimal async jobs utility library, with streams support",
|
||||
"devDependencies": {
|
||||
"browserify": "^13.0.0",
|
||||
"browserify-istanbul": "^2.0.0",
|
||||
"coveralls": "^2.11.9",
|
||||
"eslint": "^2.9.0",
|
||||
"istanbul": "^0.4.3",
|
||||
"obake": "^0.1.2",
|
||||
"phantomjs-prebuilt": "^2.1.7",
|
||||
"pre-commit": "^1.1.3",
|
||||
"reamde": "^1.1.0",
|
||||
"rimraf": "^2.5.2",
|
||||
"size-table": "^0.2.0",
|
||||
"tap-spec": "^4.1.1",
|
||||
"tape": "^4.5.1"
|
||||
},
|
||||
"homepage": "https://github.com/alexindigo/asynckit#readme",
|
||||
"keywords": [
|
||||
"async",
|
||||
"jobs",
|
||||
"parallel",
|
||||
"serial",
|
||||
"iterator",
|
||||
"array",
|
||||
"object",
|
||||
"stream",
|
||||
"destroy",
|
||||
"terminate",
|
||||
"abort"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "asynckit",
|
||||
"pre-commit": [
|
||||
"clean",
|
||||
"lint",
|
||||
"test",
|
||||
"browser",
|
||||
"report",
|
||||
"size"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/alexindigo/asynckit.git"
|
||||
},
|
||||
"scripts": {
|
||||
"browser": "browserify -t browserify-istanbul test/lib/browserify_adjustment.js test/test-*.js | obake --coverage | tap-spec",
|
||||
"clean": "rimraf coverage",
|
||||
"debug": "tape test/test-*.js",
|
||||
"lint": "eslint *.js lib/*.js test/*.js",
|
||||
"report": "istanbul report",
|
||||
"size": "browserify index.js | size-table asynckit",
|
||||
"test": "istanbul cover --reporter=json tape -- 'test/test-*.js' | tap-spec",
|
||||
"win-test": "tape test/test-*.js"
|
||||
},
|
||||
"version": "0.4.0"
|
||||
}
|
43
node_modules/asynckit/parallel.js
generated
vendored
Normal file
43
node_modules/asynckit/parallel.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
var iterate = require('./lib/iterate.js')
|
||||
, initState = require('./lib/state.js')
|
||||
, terminator = require('./lib/terminator.js')
|
||||
;
|
||||
|
||||
// Public API
|
||||
module.exports = parallel;
|
||||
|
||||
/**
|
||||
* Runs iterator over provided array elements in parallel
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {function} - jobs terminator
|
||||
*/
|
||||
function parallel(list, iterator, callback)
|
||||
{
|
||||
var state = initState(list);
|
||||
|
||||
while (state.index < (state['keyedList'] || list).length)
|
||||
{
|
||||
iterate(list, iterator, state, function(error, result)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
callback(error, result);
|
||||
return;
|
||||
}
|
||||
|
||||
// looks like it's the last one
|
||||
if (Object.keys(state.jobs).length === 0)
|
||||
{
|
||||
callback(null, state.results);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
state.index++;
|
||||
}
|
||||
|
||||
return terminator.bind(state, callback);
|
||||
}
|
17
node_modules/asynckit/serial.js
generated
vendored
Normal file
17
node_modules/asynckit/serial.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
var serialOrdered = require('./serialOrdered.js');
|
||||
|
||||
// Public API
|
||||
module.exports = serial;
|
||||
|
||||
/**
|
||||
* Runs iterator over provided array elements in series
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {function} - jobs terminator
|
||||
*/
|
||||
function serial(list, iterator, callback)
|
||||
{
|
||||
return serialOrdered(list, iterator, null, callback);
|
||||
}
|
75
node_modules/asynckit/serialOrdered.js
generated
vendored
Normal file
75
node_modules/asynckit/serialOrdered.js
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
var iterate = require('./lib/iterate.js')
|
||||
, initState = require('./lib/state.js')
|
||||
, terminator = require('./lib/terminator.js')
|
||||
;
|
||||
|
||||
// Public API
|
||||
module.exports = serialOrdered;
|
||||
// sorting helpers
|
||||
module.exports.ascending = ascending;
|
||||
module.exports.descending = descending;
|
||||
|
||||
/**
|
||||
* Runs iterator over provided sorted array elements in series
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} sortMethod - custom sort function
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {function} - jobs terminator
|
||||
*/
|
||||
function serialOrdered(list, iterator, sortMethod, callback)
|
||||
{
|
||||
var state = initState(list, sortMethod);
|
||||
|
||||
iterate(list, iterator, state, function iteratorHandler(error, result)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
callback(error, result);
|
||||
return;
|
||||
}
|
||||
|
||||
state.index++;
|
||||
|
||||
// are we there yet?
|
||||
if (state.index < (state['keyedList'] || list).length)
|
||||
{
|
||||
iterate(list, iterator, state, iteratorHandler);
|
||||
return;
|
||||
}
|
||||
|
||||
// done here
|
||||
callback(null, state.results);
|
||||
});
|
||||
|
||||
return terminator.bind(state, callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* -- Sort methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* sort helper to sort array elements in ascending order
|
||||
*
|
||||
* @param {mixed} a - an item to compare
|
||||
* @param {mixed} b - an item to compare
|
||||
* @returns {number} - comparison result
|
||||
*/
|
||||
function ascending(a, b)
|
||||
{
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* sort helper to sort array elements in descending order
|
||||
*
|
||||
* @param {mixed} a - an item to compare
|
||||
* @param {mixed} b - an item to compare
|
||||
* @returns {number} - comparison result
|
||||
*/
|
||||
function descending(a, b)
|
||||
{
|
||||
return -1 * ascending(a, b);
|
||||
}
|
21
node_modules/asynckit/stream.js
generated
vendored
Normal file
21
node_modules/asynckit/stream.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
var inherits = require('util').inherits
|
||||
, Readable = require('stream').Readable
|
||||
, ReadableAsyncKit = require('./lib/readable_asynckit.js')
|
||||
, ReadableParallel = require('./lib/readable_parallel.js')
|
||||
, ReadableSerial = require('./lib/readable_serial.js')
|
||||
, ReadableSerialOrdered = require('./lib/readable_serial_ordered.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports =
|
||||
{
|
||||
parallel : ReadableParallel,
|
||||
serial : ReadableSerial,
|
||||
serialOrdered : ReadableSerialOrdered,
|
||||
};
|
||||
|
||||
inherits(ReadableAsyncKit, Readable);
|
||||
|
||||
inherits(ReadableParallel, ReadableAsyncKit);
|
||||
inherits(ReadableSerial, ReadableAsyncKit);
|
||||
inherits(ReadableSerialOrdered, ReadableAsyncKit);
|
3
node_modules/better-js-class/.npmignore
generated
vendored
Normal file
3
node_modules/better-js-class/.npmignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea
|
||||
*.iml
|
||||
npm-debug.log
|
19
node_modules/better-js-class/LICENSE
generated
vendored
Normal file
19
node_modules/better-js-class/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013 Chiyan Chen
|
||||
|
||||
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.
|
44
node_modules/better-js-class/README.md
generated
vendored
Normal file
44
node_modules/better-js-class/README.md
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
# class
|
||||
|
||||
A convenient way to emulated class and inheritance in Javascript.
|
||||
|
||||
Why is this "better"? In the inheritance case, the super function can be called without explicitly referring to the parent class. One can just write:
|
||||
|
||||
```javascript
|
||||
this.parent.methodName.call(this, args);
|
||||
```
|
||||
|
||||
__Example__
|
||||
|
||||
```javascript
|
||||
var Class = require('better-js-class');
|
||||
|
||||
var A = Class({
|
||||
_init: function() {
|
||||
this._bar = 'bar';
|
||||
},
|
||||
|
||||
foo: function() {
|
||||
console.log('foo ' + this._bar);
|
||||
}
|
||||
});
|
||||
|
||||
var B = Class(A, {
|
||||
_init: function() {
|
||||
this.parent._init.call(this);
|
||||
},
|
||||
|
||||
kaz: function() {
|
||||
console.log('kaz ' + this._bar);
|
||||
}
|
||||
});
|
||||
|
||||
var a = new B();
|
||||
a.foo();
|
||||
a.kaz();
|
||||
```
|
||||
|
||||
## Note
|
||||
|
||||
The constructor function's name is conventioned to be "_init".
|
||||
|
58
node_modules/better-js-class/lib/class.js
generated
vendored
Normal file
58
node_modules/better-js-class/lib/class.js
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
module.exports = function() {
|
||||
var Class = function () {
|
||||
var extend = function (subclass, superclass, overrides) {
|
||||
var magic = function(fn) {
|
||||
return function() {
|
||||
var tmp = this.parent;
|
||||
this.parent = superclass.prototype;
|
||||
var res = fn.apply(this, arguments);
|
||||
this.parent = tmp;
|
||||
return res;
|
||||
};
|
||||
};
|
||||
|
||||
var k,
|
||||
TempClass = function () {};
|
||||
|
||||
TempClass.prototype = superclass.prototype;
|
||||
subclass.prototype = new TempClass();
|
||||
|
||||
for (k in overrides) {
|
||||
subclass.prototype[k] = magic(overrides[k]);
|
||||
}
|
||||
|
||||
return superclass.prototype;
|
||||
};
|
||||
|
||||
var Class = function () {
|
||||
var superclass, methods;
|
||||
|
||||
if (arguments.length === 1) {
|
||||
methods = arguments[0];
|
||||
} else {
|
||||
superclass = arguments[0];
|
||||
methods = arguments[1];
|
||||
}
|
||||
|
||||
var cls = function () {
|
||||
this._init.apply(this, arguments);
|
||||
}
|
||||
|
||||
if (superclass) {
|
||||
extend(cls, superclass, methods);
|
||||
} else {
|
||||
if (methods._init == null) {
|
||||
methods._init = function() {};
|
||||
}
|
||||
cls.prototype = methods;
|
||||
}
|
||||
|
||||
return cls;
|
||||
};
|
||||
|
||||
return Class;
|
||||
}();
|
||||
|
||||
return Class;
|
||||
}();
|
56
node_modules/better-js-class/package.json
generated
vendored
Normal file
56
node_modules/better-js-class/package.json
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"_from": "better-js-class@*",
|
||||
"_id": "better-js-class@0.1.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-dY3RdGKzcZ4c+gDMZHoM+ZS6b5Q=",
|
||||
"_location": "/better-js-class",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "better-js-class@*",
|
||||
"name": "better-js-class",
|
||||
"escapedName": "better-js-class",
|
||||
"rawSpec": "*",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "*"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-mysql"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/better-js-class/-/better-js-class-0.1.3.tgz",
|
||||
"_shasum": "758dd17462b3719e1cfa00cc647a0cf994ba6f94",
|
||||
"_spec": "better-js-class@*",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\node-mysql",
|
||||
"author": {
|
||||
"name": "Chiyan Chen"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/redblaze/class/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A convenient way to emulated class and inheritance in Javascript.",
|
||||
"homepage": "https://github.com/redblaze/class#readme",
|
||||
"jam": {
|
||||
"main": "lib/class.js",
|
||||
"include": [
|
||||
"lib/class.js",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
]
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/redblaze/class/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "./lib/class",
|
||||
"name": "better-js-class",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/redblaze/class.git"
|
||||
},
|
||||
"version": "0.1.3"
|
||||
}
|
266
node_modules/bignumber.js/CHANGELOG.md
generated
vendored
Normal file
266
node_modules/bignumber.js/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,266 @@
|
||||
#### 9.0.0
|
||||
* 27/05/2019
|
||||
* For compatibility with legacy browsers, remove `Symbol` references.
|
||||
|
||||
#### 8.1.1
|
||||
* 24/02/2019
|
||||
* [BUGFIX] #222 Restore missing `var` to `export BigNumber`.
|
||||
* Allow any key in BigNumber.Instance in *bignumber.d.ts*.
|
||||
|
||||
#### 8.1.0
|
||||
* 23/02/2019
|
||||
* [NEW FEATURE] #220 Create a BigNumber using `{s, e, c}`.
|
||||
* [NEW FEATURE] `isBigNumber`: if `BigNumber.DEBUG` is `true`, also check that the BigNumber instance is well-formed.
|
||||
* Remove `instanceof` checks; just use `_isBigNumber` to identify a BigNumber instance.
|
||||
* Add `_isBigNumber` to prototype in *bignumber.mjs*.
|
||||
* Add tests for BigNumber creation from object.
|
||||
* Update *API.html*.
|
||||
|
||||
#### 8.0.2
|
||||
* 13/01/2019
|
||||
* #209 `toPrecision` without argument should follow `toString`.
|
||||
* Improve *Use* section of *README*.
|
||||
* Optimise `toString(10)`.
|
||||
* Add verson number to API doc.
|
||||
|
||||
#### 8.0.1
|
||||
* 01/11/2018
|
||||
* Rest parameter must be array type in *bignumber.d.ts*.
|
||||
|
||||
#### 8.0.0
|
||||
* 01/11/2018
|
||||
* [NEW FEATURE] Add `BigNumber.sum` method.
|
||||
* [NEW FEATURE]`toFormat`: add `prefix` and `suffix` options.
|
||||
* [NEW FEATURE] #178 Pass custom formatting to `toFormat`.
|
||||
* [BREAKING CHANGE] #184 `toFraction`: return array of BigNumbers not strings.
|
||||
* [NEW FEATURE] #185 Enable overwrite of `valueOf` to prevent accidental addition to string.
|
||||
* #183 Add Node.js `crypto` requirement to documentation.
|
||||
* [BREAKING CHANGE] #198 Disallow signs and whitespace in custom alphabet.
|
||||
* [NEW FEATURE] #188 Implement `util.inspect.custom` for Node.js REPL.
|
||||
* #170 Make `isBigNumber` a type guard in *bignumber.d.ts*.
|
||||
* [BREAKING CHANGE] `BigNumber.min` and `BigNumber.max`: don't accept an array.
|
||||
* Update *.travis.yml*.
|
||||
* Remove *bower.json*.
|
||||
|
||||
#### 7.2.1
|
||||
* 24/05/2018
|
||||
* Add `browser` field to *package.json*.
|
||||
|
||||
#### 7.2.0
|
||||
* 22/05/2018
|
||||
* #166 Correct *.mjs* file. Remove extension from `main` field in *package.json*.
|
||||
|
||||
#### 7.1.0
|
||||
* 18/05/2018
|
||||
* Add `module` field to *package.json* for *bignumber.mjs*.
|
||||
|
||||
#### 7.0.2
|
||||
* 17/05/2018
|
||||
* #165 Bugfix: upper-case letters for bases 11-36 in a custom alphabet.
|
||||
* Add note to *README* regarding creating BigNumbers from Number values.
|
||||
|
||||
#### 7.0.1
|
||||
* 26/04/2018
|
||||
* #158 Fix global object variable name typo.
|
||||
|
||||
#### 7.0.0
|
||||
* 26/04/2018
|
||||
* #143 Remove global BigNumber from typings.
|
||||
* #144 Enable compatibility with `Object.freeze(Object.prototype)`.
|
||||
* #148 #123 #11 Only throw on a number primitive with more than 15 significant digits if `BigNumber.DEBUG` is `true`.
|
||||
* Only throw on an invalid BigNumber value if `BigNumber.DEBUG` is `true`. Return BigNumber `NaN` instead.
|
||||
* #154 `exponentiatedBy`: allow BigNumber exponent.
|
||||
* #156 Prevent Content Security Policy *unsafe-eval* issue.
|
||||
* `toFraction`: allow `Infinity` maximum denominator.
|
||||
* Comment-out some excess tests to reduce test time.
|
||||
* Amend indentation and other spacing.
|
||||
|
||||
#### 6.0.0
|
||||
* 26/01/2018
|
||||
* #137 Implement `APLHABET` configuration option.
|
||||
* Remove `ERRORS` configuration option.
|
||||
* Remove `toDigits` method; extend `precision` method accordingly.
|
||||
* Remove s`round` method; extend `decimalPlaces` method accordingly.
|
||||
* Remove methods: `ceil`, `floor`, and `truncated`.
|
||||
* Remove method aliases: `add`, `cmp`, `isInt`, `isNeg`, `trunc`, `mul`, `neg` and `sub`.
|
||||
* Rename methods: `shift` to `shiftedBy`, `another` to `clone`, `toPower` to `exponentiatedBy`, and `equals` to `isEqualTo`.
|
||||
* Rename methods: add `is` prefix to `greaterThan`, `greaterThanOrEqualTo`, `lessThan` and `lessThanOrEqualTo`.
|
||||
* Add methods: `multipliedBy`, `isBigNumber`, `isPositive`, `integerValue`, `maximum` and `minimum`.
|
||||
* Refactor test suite.
|
||||
* Add *CHANGELOG.md*.
|
||||
* Rewrite *bignumber.d.ts*.
|
||||
* Redo API image.
|
||||
|
||||
#### 5.0.0
|
||||
* 27/11/2017
|
||||
* #81 Don't throw on constructor call without `new`.
|
||||
|
||||
#### 4.1.0
|
||||
* 26/09/2017
|
||||
* Remove node 0.6 from *.travis.yml*.
|
||||
* Add *bignumber.mjs*.
|
||||
|
||||
#### 4.0.4
|
||||
* 03/09/2017
|
||||
* Add missing aliases to *bignumber.d.ts*.
|
||||
|
||||
#### 4.0.3
|
||||
* 30/08/2017
|
||||
* Add types: *bignumber.d.ts*.
|
||||
|
||||
#### 4.0.2
|
||||
* 03/05/2017
|
||||
* #120 Workaround Safari/Webkit bug.
|
||||
|
||||
#### 4.0.1
|
||||
* 05/04/2017
|
||||
* #121 BigNumber.default to BigNumber['default'].
|
||||
|
||||
#### 4.0.0
|
||||
* 09/01/2017
|
||||
* Replace BigNumber.isBigNumber method with isBigNumber prototype property.
|
||||
|
||||
#### 3.1.2
|
||||
* 08/01/2017
|
||||
* Minor documentation edit.
|
||||
|
||||
#### 3.1.1
|
||||
* 08/01/2017
|
||||
* Uncomment `isBigNumber` tests.
|
||||
* Ignore dot files.
|
||||
|
||||
#### 3.1.0
|
||||
* 08/01/2017
|
||||
* Add `isBigNumber` method.
|
||||
|
||||
#### 3.0.2
|
||||
* 08/01/2017
|
||||
* Bugfix: Possible incorrect value of `ERRORS` after a `BigNumber.another` call (due to `parseNumeric` declaration in outer scope).
|
||||
|
||||
#### 3.0.1
|
||||
* 23/11/2016
|
||||
* Apply fix for old ipads with `%` issue, see #57 and #102.
|
||||
* Correct error message.
|
||||
|
||||
#### 3.0.0
|
||||
* 09/11/2016
|
||||
* Remove `require('crypto')` - leave it to the user.
|
||||
* Add `BigNumber.set` as `BigNumber.config` alias.
|
||||
* Default `POW_PRECISION` to `0`.
|
||||
|
||||
#### 2.4.0
|
||||
* 14/07/2016
|
||||
* #97 Add exports to support ES6 imports.
|
||||
|
||||
#### 2.3.0
|
||||
* 07/03/2016
|
||||
* #86 Add modulus parameter to `toPower`.
|
||||
|
||||
#### 2.2.0
|
||||
* 03/03/2016
|
||||
* #91 Permit larger JS integers.
|
||||
|
||||
#### 2.1.4
|
||||
* 15/12/2015
|
||||
* Correct UMD.
|
||||
|
||||
#### 2.1.3
|
||||
* 13/12/2015
|
||||
* Refactor re global object and crypto availability when bundling.
|
||||
|
||||
#### 2.1.2
|
||||
* 10/12/2015
|
||||
* Bugfix: `window.crypto` not assigned to `crypto`.
|
||||
|
||||
#### 2.1.1
|
||||
* 09/12/2015
|
||||
* Prevent code bundler from adding `crypto` shim.
|
||||
|
||||
#### 2.1.0
|
||||
* 26/10/2015
|
||||
* For `valueOf` and `toJSON`, include the minus sign with negative zero.
|
||||
|
||||
#### 2.0.8
|
||||
* 2/10/2015
|
||||
* Internal round function bugfix.
|
||||
|
||||
#### 2.0.6
|
||||
* 31/03/2015
|
||||
* Add bower.json. Tweak division after in-depth review.
|
||||
|
||||
#### 2.0.5
|
||||
* 25/03/2015
|
||||
* Amend README. Remove bitcoin address.
|
||||
|
||||
#### 2.0.4
|
||||
* 25/03/2015
|
||||
* Critical bugfix #58: division.
|
||||
|
||||
#### 2.0.3
|
||||
* 18/02/2015
|
||||
* Amend README. Add source map.
|
||||
|
||||
#### 2.0.2
|
||||
* 18/02/2015
|
||||
* Correct links.
|
||||
|
||||
#### 2.0.1
|
||||
* 18/02/2015
|
||||
* Add `max`, `min`, `precision`, `random`, `shiftedBy`, `toDigits` and `truncated` methods.
|
||||
* Add the short-forms: `add`, `mul`, `sd`, `sub` and `trunc`.
|
||||
* Add an `another` method to enable multiple independent constructors to be created.
|
||||
* Add support for the base 2, 8 and 16 prefixes `0b`, `0o` and `0x`.
|
||||
* Enable a rounding mode to be specified as a second parameter to `toExponential`, `toFixed`, `toFormat` and `toPrecision`.
|
||||
* Add a `CRYPTO` configuration property so cryptographically-secure pseudo-random number generation can be specified.
|
||||
* Add a `MODULO_MODE` configuration property to enable the rounding mode used by the `modulo` operation to be specified.
|
||||
* Add a `POW_PRECISION` configuration property to enable the number of significant digits calculated by the power operation to be limited.
|
||||
* Improve code quality.
|
||||
* Improve documentation.
|
||||
|
||||
#### 2.0.0
|
||||
* 29/12/2014
|
||||
* Add `dividedToIntegerBy`, `isInteger` and `toFormat` methods.
|
||||
* Remove the following short-forms: `isF`, `isZ`, `toE`, `toF`, `toFr`, `toN`, `toP`, `toS`.
|
||||
* Store a BigNumber's coefficient in base 1e14, rather than base 10.
|
||||
* Add fast path for integers to BigNumber constructor.
|
||||
* Incorporate the library into the online documentation.
|
||||
|
||||
#### 1.5.0
|
||||
* 13/11/2014
|
||||
* Add `toJSON` and `decimalPlaces` methods.
|
||||
|
||||
#### 1.4.1
|
||||
* 08/06/2014
|
||||
* Amend README.
|
||||
|
||||
#### 1.4.0
|
||||
* 08/05/2014
|
||||
* Add `toNumber`.
|
||||
|
||||
#### 1.3.0
|
||||
* 08/11/2013
|
||||
* Ensure correct rounding of `sqrt` in all, rather than almost all, cases.
|
||||
* Maximum radix to 64.
|
||||
|
||||
#### 1.2.1
|
||||
* 17/10/2013
|
||||
* Sign of zero when x < 0 and x + (-x) = 0.
|
||||
|
||||
#### 1.2.0
|
||||
* 19/9/2013
|
||||
* Throw Error objects for stack.
|
||||
|
||||
#### 1.1.1
|
||||
* 22/8/2013
|
||||
* Show original value in constructor error message.
|
||||
|
||||
#### 1.1.0
|
||||
* 1/8/2013
|
||||
* Allow numbers with trailing radix point.
|
||||
|
||||
#### 1.0.1
|
||||
* Bugfix: error messages with incorrect method name
|
||||
|
||||
#### 1.0.0
|
||||
* 8/11/2012
|
||||
* Initial release
|
23
node_modules/bignumber.js/LICENCE
generated
vendored
Normal file
23
node_modules/bignumber.js/LICENCE
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
The MIT Licence.
|
||||
|
||||
Copyright (c) 2019 Michael Mclaughlin
|
||||
|
||||
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.
|
||||
|
268
node_modules/bignumber.js/README.md
generated
vendored
Normal file
268
node_modules/bignumber.js/README.md
generated
vendored
Normal file
@ -0,0 +1,268 @@
|
||||

|
||||
|
||||
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.
|
||||
|
||||
[](https://travis-ci.org/MikeMcl/bignumber.js)
|
||||
|
||||
<br />
|
||||
|
||||
## Features
|
||||
|
||||
- Integers and decimals
|
||||
- Simple API but full-featured
|
||||
- Faster, smaller, and perhaps easier to use than JavaScript versions of Java's BigDecimal
|
||||
- 8 KB minified and gzipped
|
||||
- Replicates the `toExponential`, `toFixed`, `toPrecision` and `toString` methods of JavaScript's Number type
|
||||
- Includes a `toFraction` and a correctly-rounded `squareRoot` method
|
||||
- Supports cryptographically-secure pseudo-random number generation
|
||||
- No dependencies
|
||||
- Wide platform compatibility: uses JavaScript 1.5 (ECMAScript 3) features only
|
||||
- Comprehensive [documentation](http://mikemcl.github.io/bignumber.js/) and test set
|
||||
|
||||

|
||||
|
||||
If a smaller and simpler library is required see [big.js](https://github.com/MikeMcl/big.js/).
|
||||
It's less than half the size but only works with decimal numbers and only has half the methods.
|
||||
It also does not allow `NaN` or `Infinity`, or have the configuration options of this library.
|
||||
|
||||
See also [decimal.js](https://github.com/MikeMcl/decimal.js/), which among other things adds support for non-integer powers, and performs all operations to a specified number of significant digits.
|
||||
|
||||
## Load
|
||||
|
||||
The library is the single JavaScript file *bignumber.js* (or minified, *bignumber.min.js*).
|
||||
|
||||
Browser:
|
||||
|
||||
```html
|
||||
<script src='path/to/bignumber.js'></script>
|
||||
```
|
||||
|
||||
[Node.js](http://nodejs.org):
|
||||
|
||||
```bash
|
||||
$ npm install bignumber.js
|
||||
```
|
||||
|
||||
```javascript
|
||||
const BigNumber = require('bignumber.js');
|
||||
```
|
||||
|
||||
ES6 module:
|
||||
|
||||
```javascript
|
||||
import BigNumber from "./bignumber.mjs"
|
||||
```
|
||||
|
||||
AMD loader libraries such as [requireJS](http://requirejs.org/):
|
||||
|
||||
```javascript
|
||||
require(['bignumber'], function(BigNumber) {
|
||||
// Use BigNumber here in local scope. No global BigNumber.
|
||||
});
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
The library exports a single constructor function, [`BigNumber`](http://mikemcl.github.io/bignumber.js/#bignumber), which accepts a value of type Number, String or BigNumber,
|
||||
|
||||
```javascript
|
||||
let x = new BigNumber(123.4567);
|
||||
let y = BigNumber('123456.7e-3');
|
||||
let z = new BigNumber(x);
|
||||
x.isEqualTo(y) && y.isEqualTo(z) && x.isEqualTo(z); // true
|
||||
```
|
||||
|
||||
To get the string value of a BigNumber use [`toString()`](http://mikemcl.github.io/bignumber.js/#toS) or [`toFixed()`](http://mikemcl.github.io/bignumber.js/#toFix). Using `toFixed()` prevents exponential notation being returned, no matter how large or small the value.
|
||||
|
||||
```javascript
|
||||
let x = new BigNumber('1111222233334444555566');
|
||||
x.toString(); // "1.111222233334444555566e+21"
|
||||
x.toFixed(); // "1111222233334444555566"
|
||||
```
|
||||
|
||||
If the limited precision of Number values is not well understood, it is recommended to create BigNumbers from String values rather than Number values to avoid a potential loss of precision.
|
||||
|
||||
*In all further examples below, `let`, semicolons and `toString` calls are not shown. If a commented-out value is in quotes it means `toString` has been called on the preceding expression.*
|
||||
|
||||
```javascript
|
||||
// Precision loss from using numeric literals with more than 15 significant digits.
|
||||
new BigNumber(1.0000000000000001) // '1'
|
||||
new BigNumber(88259496234518.57) // '88259496234518.56'
|
||||
new BigNumber(99999999999999999999) // '100000000000000000000'
|
||||
|
||||
// Precision loss from using numeric literals outside the range of Number values.
|
||||
new BigNumber(2e+308) // 'Infinity'
|
||||
new BigNumber(1e-324) // '0'
|
||||
|
||||
// Precision loss from the unexpected result of arithmetic with Number values.
|
||||
new BigNumber(0.7 + 0.1) // '0.7999999999999999'
|
||||
```
|
||||
|
||||
When creating a BigNumber from a Number, note that a BigNumber is created from a Number's decimal `toString()` value not from its underlying binary value. If the latter is required, then pass the Number's `toString(2)` value and specify base 2.
|
||||
|
||||
```javascript
|
||||
new BigNumber(Number.MAX_VALUE.toString(2), 2)
|
||||
```
|
||||
|
||||
BigNumbers can be created from values in bases from 2 to 36. See [`ALPHABET`](http://mikemcl.github.io/bignumber.js/#alphabet) to extend this range.
|
||||
|
||||
```javascript
|
||||
a = new BigNumber(1011, 2) // "11"
|
||||
b = new BigNumber('zz.9', 36) // "1295.25"
|
||||
c = a.plus(b) // "1306.25"
|
||||
```
|
||||
|
||||
Performance is better if base 10 is NOT specified for decimal values. Only specify base 10 when it is desired that the number of decimal places of the input value be limited to the current [`DECIMAL_PLACES`](http://mikemcl.github.io/bignumber.js/#decimal-places) setting.
|
||||
|
||||
A BigNumber is immutable in the sense that it is not changed by its methods.
|
||||
|
||||
```javascript
|
||||
0.3 - 0.1 // 0.19999999999999998
|
||||
x = new BigNumber(0.3)
|
||||
x.minus(0.1) // "0.2"
|
||||
x // "0.3"
|
||||
```
|
||||
|
||||
The methods that return a BigNumber can be chained.
|
||||
|
||||
```javascript
|
||||
x.dividedBy(y).plus(z).times(9)
|
||||
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').integerValue()
|
||||
```
|
||||
|
||||
Some of the longer method names have a shorter alias.
|
||||
|
||||
```javascript
|
||||
x.squareRoot().dividedBy(y).exponentiatedBy(3).isEqualTo(x.sqrt().div(y).pow(3)) // true
|
||||
x.modulo(y).multipliedBy(z).eq(x.mod(y).times(z)) // true
|
||||
```
|
||||
|
||||
As with JavaScript's Number type, there are [`toExponential`](http://mikemcl.github.io/bignumber.js/#toE), [`toFixed`](http://mikemcl.github.io/bignumber.js/#toFix) and [`toPrecision`](http://mikemcl.github.io/bignumber.js/#toP) methods.
|
||||
|
||||
```javascript
|
||||
x = new BigNumber(255.5)
|
||||
x.toExponential(5) // "2.55500e+2"
|
||||
x.toFixed(5) // "255.50000"
|
||||
x.toPrecision(5) // "255.50"
|
||||
x.toNumber() // 255.5
|
||||
```
|
||||
|
||||
A base can be specified for [`toString`](http://mikemcl.github.io/bignumber.js/#toS). Performance is better if base 10 is NOT specified, i.e. use `toString()` not `toString(10)`. Only specify base 10 when it is desired that the number of decimal places be limited to the current [`DECIMAL_PLACES`](http://mikemcl.github.io/bignumber.js/#decimal-places) setting.
|
||||
|
||||
```javascript
|
||||
x.toString(16) // "ff.8"
|
||||
```
|
||||
|
||||
There is a [`toFormat`](http://mikemcl.github.io/bignumber.js/#toFor) method which may be useful for internationalisation.
|
||||
|
||||
```javascript
|
||||
y = new BigNumber('1234567.898765')
|
||||
y.toFormat(2) // "1,234,567.90"
|
||||
```
|
||||
|
||||
The maximum number of decimal places of the result of an operation involving division (i.e. a division, square root, base conversion or negative power operation) is set using the `set` or `config` method of the `BigNumber` constructor.
|
||||
|
||||
The other arithmetic operations always give the exact result.
|
||||
|
||||
```javascript
|
||||
BigNumber.set({ DECIMAL_PLACES: 10, ROUNDING_MODE: 4 })
|
||||
|
||||
x = new BigNumber(2)
|
||||
y = new BigNumber(3)
|
||||
z = x.dividedBy(y) // "0.6666666667"
|
||||
z.squareRoot() // "0.8164965809"
|
||||
z.exponentiatedBy(-3) // "3.3749999995"
|
||||
z.toString(2) // "0.1010101011"
|
||||
z.multipliedBy(z) // "0.44444444448888888889"
|
||||
z.multipliedBy(z).decimalPlaces(10) // "0.4444444445"
|
||||
```
|
||||
|
||||
There is a [`toFraction`](http://mikemcl.github.io/bignumber.js/#toFr) method with an optional *maximum denominator* argument
|
||||
|
||||
```javascript
|
||||
y = new BigNumber(355)
|
||||
pi = y.dividedBy(113) // "3.1415929204"
|
||||
pi.toFraction() // [ "7853982301", "2500000000" ]
|
||||
pi.toFraction(1000) // [ "355", "113" ]
|
||||
```
|
||||
|
||||
and [`isNaN`](http://mikemcl.github.io/bignumber.js/#isNaN) and [`isFinite`](http://mikemcl.github.io/bignumber.js/#isF) methods, as `NaN` and `Infinity` are valid `BigNumber` values.
|
||||
|
||||
```javascript
|
||||
x = new BigNumber(NaN) // "NaN"
|
||||
y = new BigNumber(Infinity) // "Infinity"
|
||||
x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true
|
||||
```
|
||||
|
||||
The value of a BigNumber is stored in a decimal floating point format in terms of a coefficient, exponent and sign.
|
||||
|
||||
```javascript
|
||||
x = new BigNumber(-123.456);
|
||||
x.c // [ 123, 45600000000000 ] coefficient (i.e. significand)
|
||||
x.e // 2 exponent
|
||||
x.s // -1 sign
|
||||
```
|
||||
|
||||
For advanced usage, multiple BigNumber constructors can be created, each with their own independent configuration.
|
||||
|
||||
```javascript
|
||||
// Set DECIMAL_PLACES for the original BigNumber constructor
|
||||
BigNumber.set({ DECIMAL_PLACES: 10 })
|
||||
|
||||
// Create another BigNumber constructor, optionally passing in a configuration object
|
||||
BN = BigNumber.clone({ DECIMAL_PLACES: 5 })
|
||||
|
||||
x = new BigNumber(1)
|
||||
y = new BN(1)
|
||||
|
||||
x.div(3) // '0.3333333333'
|
||||
y.div(3) // '0.33333'
|
||||
```
|
||||
|
||||
For further information see the [API](http://mikemcl.github.io/bignumber.js/) reference in the *doc* directory.
|
||||
|
||||
## Test
|
||||
|
||||
The *test/modules* directory contains the test scripts for each method.
|
||||
|
||||
The tests can be run with Node.js or a browser. For Node.js use
|
||||
|
||||
$ npm test
|
||||
|
||||
or
|
||||
|
||||
$ node test/test
|
||||
|
||||
To test a single method, use, for example
|
||||
|
||||
$ node test/methods/toFraction
|
||||
|
||||
For the browser, open *test/test.html*.
|
||||
|
||||
## Build
|
||||
|
||||
For Node, if [uglify-js](https://github.com/mishoo/UglifyJS2) is installed
|
||||
|
||||
npm install uglify-js -g
|
||||
|
||||
then
|
||||
|
||||
npm run build
|
||||
|
||||
will create *bignumber.min.js*.
|
||||
|
||||
A source map will also be created in the root directory.
|
||||
|
||||
## Feedback
|
||||
|
||||
Open an issue, or email
|
||||
|
||||
Michael
|
||||
|
||||
<a href="mailto:M8ch88l@gmail.com">M8ch88l@gmail.com</a>
|
||||
|
||||
## Licence
|
||||
|
||||
The MIT Licence.
|
||||
|
||||
See [LICENCE](https://github.com/MikeMcl/bignumber.js/blob/master/LICENCE).
|
1829
node_modules/bignumber.js/bignumber.d.ts
generated
vendored
Normal file
1829
node_modules/bignumber.js/bignumber.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2902
node_modules/bignumber.js/bignumber.js
generated
vendored
Normal file
2902
node_modules/bignumber.js/bignumber.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/bignumber.js/bignumber.min.js
generated
vendored
Normal file
1
node_modules/bignumber.js/bignumber.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/bignumber.js/bignumber.min.js.map
generated
vendored
Normal file
1
node_modules/bignumber.js/bignumber.min.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2888
node_modules/bignumber.js/bignumber.mjs
generated
vendored
Normal file
2888
node_modules/bignumber.js/bignumber.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2237
node_modules/bignumber.js/doc/API.html
generated
vendored
Normal file
2237
node_modules/bignumber.js/doc/API.html
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
69
node_modules/bignumber.js/package.json
generated
vendored
Normal file
69
node_modules/bignumber.js/package.json
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"_from": "bignumber.js@9.0.0",
|
||||
"_id": "bignumber.js@9.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==",
|
||||
"_location": "/bignumber.js",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "bignumber.js@9.0.0",
|
||||
"name": "bignumber.js",
|
||||
"escapedName": "bignumber.js",
|
||||
"rawSpec": "9.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "9.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mysql"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
|
||||
"_shasum": "805880f84a329b5eac6e7cb6f8274b6d82bdf075",
|
||||
"_spec": "bignumber.js@9.0.0",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\mysql",
|
||||
"author": {
|
||||
"name": "Michael Mclaughlin",
|
||||
"email": "M8ch88l@gmail.com"
|
||||
},
|
||||
"browser": "bignumber.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/MikeMcl/bignumber.js/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "A library for arbitrary-precision decimal and non-decimal arithmetic",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://github.com/MikeMcl/bignumber.js#readme",
|
||||
"keywords": [
|
||||
"arbitrary",
|
||||
"precision",
|
||||
"arithmetic",
|
||||
"big",
|
||||
"number",
|
||||
"decimal",
|
||||
"float",
|
||||
"biginteger",
|
||||
"bigdecimal",
|
||||
"bignumber",
|
||||
"bigint",
|
||||
"bignum"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "bignumber",
|
||||
"module": "bignumber.mjs",
|
||||
"name": "bignumber.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/MikeMcl/bignumber.js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "uglifyjs bignumber.js --source-map -c -m -o bignumber.min.js",
|
||||
"test": "node test/test"
|
||||
},
|
||||
"types": "bignumber.d.ts",
|
||||
"version": "9.0.0"
|
||||
}
|
19
node_modules/combined-stream/License
generated
vendored
Normal file
19
node_modules/combined-stream/License
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2011 Debuggable Limited <felix@debuggable.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.
|
138
node_modules/combined-stream/Readme.md
generated
vendored
Normal file
138
node_modules/combined-stream/Readme.md
generated
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
# combined-stream
|
||||
|
||||
A stream that emits multiple other streams one after another.
|
||||
|
||||
**NB** Currently `combined-stream` works with streams version 1 only. There is ongoing effort to switch this library to streams version 2. Any help is welcome. :) Meanwhile you can explore other libraries that provide streams2 support with more or less compatibility with `combined-stream`.
|
||||
|
||||
- [combined-stream2](https://www.npmjs.com/package/combined-stream2): A drop-in streams2-compatible replacement for the combined-stream module.
|
||||
|
||||
- [multistream](https://www.npmjs.com/package/multistream): A stream that emits multiple other streams one after another.
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
npm install combined-stream
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Here is a simple example that shows how you can use combined-stream to combine
|
||||
two files into one:
|
||||
|
||||
``` javascript
|
||||
var CombinedStream = require('combined-stream');
|
||||
var fs = require('fs');
|
||||
|
||||
var combinedStream = CombinedStream.create();
|
||||
combinedStream.append(fs.createReadStream('file1.txt'));
|
||||
combinedStream.append(fs.createReadStream('file2.txt'));
|
||||
|
||||
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
||||
```
|
||||
|
||||
While the example above works great, it will pause all source streams until
|
||||
they are needed. If you don't want that to happen, you can set `pauseStreams`
|
||||
to `false`:
|
||||
|
||||
``` javascript
|
||||
var CombinedStream = require('combined-stream');
|
||||
var fs = require('fs');
|
||||
|
||||
var combinedStream = CombinedStream.create({pauseStreams: false});
|
||||
combinedStream.append(fs.createReadStream('file1.txt'));
|
||||
combinedStream.append(fs.createReadStream('file2.txt'));
|
||||
|
||||
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
||||
```
|
||||
|
||||
However, what if you don't have all the source streams yet, or you don't want
|
||||
to allocate the resources (file descriptors, memory, etc.) for them right away?
|
||||
Well, in that case you can simply provide a callback that supplies the stream
|
||||
by calling a `next()` function:
|
||||
|
||||
``` javascript
|
||||
var CombinedStream = require('combined-stream');
|
||||
var fs = require('fs');
|
||||
|
||||
var combinedStream = CombinedStream.create();
|
||||
combinedStream.append(function(next) {
|
||||
next(fs.createReadStream('file1.txt'));
|
||||
});
|
||||
combinedStream.append(function(next) {
|
||||
next(fs.createReadStream('file2.txt'));
|
||||
});
|
||||
|
||||
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### CombinedStream.create([options])
|
||||
|
||||
Returns a new combined stream object. Available options are:
|
||||
|
||||
* `maxDataSize`
|
||||
* `pauseStreams`
|
||||
|
||||
The effect of those options is described below.
|
||||
|
||||
### combinedStream.pauseStreams = `true`
|
||||
|
||||
Whether to apply back pressure to the underlaying streams. If set to `false`,
|
||||
the underlaying streams will never be paused. If set to `true`, the
|
||||
underlaying streams will be paused right after being appended, as well as when
|
||||
`delayedStream.pipe()` wants to throttle.
|
||||
|
||||
### combinedStream.maxDataSize = `2 * 1024 * 1024`
|
||||
|
||||
The maximum amount of bytes (or characters) to buffer for all source streams.
|
||||
If this value is exceeded, `combinedStream` emits an `'error'` event.
|
||||
|
||||
### combinedStream.dataSize = `0`
|
||||
|
||||
The amount of bytes (or characters) currently buffered by `combinedStream`.
|
||||
|
||||
### combinedStream.append(stream)
|
||||
|
||||
Appends the given `stream` to the combinedStream object. If `pauseStreams` is
|
||||
set to `true, this stream will also be paused right away.
|
||||
|
||||
`streams` can also be a function that takes one parameter called `next`. `next`
|
||||
is a function that must be invoked in order to provide the `next` stream, see
|
||||
example above.
|
||||
|
||||
Regardless of how the `stream` is appended, combined-stream always attaches an
|
||||
`'error'` listener to it, so you don't have to do that manually.
|
||||
|
||||
Special case: `stream` can also be a String or Buffer.
|
||||
|
||||
### combinedStream.write(data)
|
||||
|
||||
You should not call this, `combinedStream` takes care of piping the appended
|
||||
streams into itself for you.
|
||||
|
||||
### combinedStream.resume()
|
||||
|
||||
Causes `combinedStream` to start drain the streams it manages. The function is
|
||||
idempotent, and also emits a `'resume'` event each time which usually goes to
|
||||
the stream that is currently being drained.
|
||||
|
||||
### combinedStream.pause();
|
||||
|
||||
If `combinedStream.pauseStreams` is set to `false`, this does nothing.
|
||||
Otherwise a `'pause'` event is emitted, this goes to the stream that is
|
||||
currently being drained, so you can use it to apply back pressure.
|
||||
|
||||
### combinedStream.end();
|
||||
|
||||
Sets `combinedStream.writable` to false, emits an `'end'` event, and removes
|
||||
all streams from the queue.
|
||||
|
||||
### combinedStream.destroy();
|
||||
|
||||
Same as `combinedStream.end()`, except it emits a `'close'` event instead of
|
||||
`'end'`.
|
||||
|
||||
## License
|
||||
|
||||
combined-stream is licensed under the MIT license.
|
208
node_modules/combined-stream/lib/combined_stream.js
generated
vendored
Normal file
208
node_modules/combined-stream/lib/combined_stream.js
generated
vendored
Normal file
@ -0,0 +1,208 @@
|
||||
var util = require('util');
|
||||
var Stream = require('stream').Stream;
|
||||
var DelayedStream = require('delayed-stream');
|
||||
|
||||
module.exports = CombinedStream;
|
||||
function CombinedStream() {
|
||||
this.writable = false;
|
||||
this.readable = true;
|
||||
this.dataSize = 0;
|
||||
this.maxDataSize = 2 * 1024 * 1024;
|
||||
this.pauseStreams = true;
|
||||
|
||||
this._released = false;
|
||||
this._streams = [];
|
||||
this._currentStream = null;
|
||||
this._insideLoop = false;
|
||||
this._pendingNext = false;
|
||||
}
|
||||
util.inherits(CombinedStream, Stream);
|
||||
|
||||
CombinedStream.create = function(options) {
|
||||
var combinedStream = new this();
|
||||
|
||||
options = options || {};
|
||||
for (var option in options) {
|
||||
combinedStream[option] = options[option];
|
||||
}
|
||||
|
||||
return combinedStream;
|
||||
};
|
||||
|
||||
CombinedStream.isStreamLike = function(stream) {
|
||||
return (typeof stream !== 'function')
|
||||
&& (typeof stream !== 'string')
|
||||
&& (typeof stream !== 'boolean')
|
||||
&& (typeof stream !== 'number')
|
||||
&& (!Buffer.isBuffer(stream));
|
||||
};
|
||||
|
||||
CombinedStream.prototype.append = function(stream) {
|
||||
var isStreamLike = CombinedStream.isStreamLike(stream);
|
||||
|
||||
if (isStreamLike) {
|
||||
if (!(stream instanceof DelayedStream)) {
|
||||
var newStream = DelayedStream.create(stream, {
|
||||
maxDataSize: Infinity,
|
||||
pauseStream: this.pauseStreams,
|
||||
});
|
||||
stream.on('data', this._checkDataSize.bind(this));
|
||||
stream = newStream;
|
||||
}
|
||||
|
||||
this._handleErrors(stream);
|
||||
|
||||
if (this.pauseStreams) {
|
||||
stream.pause();
|
||||
}
|
||||
}
|
||||
|
||||
this._streams.push(stream);
|
||||
return this;
|
||||
};
|
||||
|
||||
CombinedStream.prototype.pipe = function(dest, options) {
|
||||
Stream.prototype.pipe.call(this, dest, options);
|
||||
this.resume();
|
||||
return dest;
|
||||
};
|
||||
|
||||
CombinedStream.prototype._getNext = function() {
|
||||
this._currentStream = null;
|
||||
|
||||
if (this._insideLoop) {
|
||||
this._pendingNext = true;
|
||||
return; // defer call
|
||||
}
|
||||
|
||||
this._insideLoop = true;
|
||||
try {
|
||||
do {
|
||||
this._pendingNext = false;
|
||||
this._realGetNext();
|
||||
} while (this._pendingNext);
|
||||
} finally {
|
||||
this._insideLoop = false;
|
||||
}
|
||||
};
|
||||
|
||||
CombinedStream.prototype._realGetNext = function() {
|
||||
var stream = this._streams.shift();
|
||||
|
||||
|
||||
if (typeof stream == 'undefined') {
|
||||
this.end();
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof stream !== 'function') {
|
||||
this._pipeNext(stream);
|
||||
return;
|
||||
}
|
||||
|
||||
var getStream = stream;
|
||||
getStream(function(stream) {
|
||||
var isStreamLike = CombinedStream.isStreamLike(stream);
|
||||
if (isStreamLike) {
|
||||
stream.on('data', this._checkDataSize.bind(this));
|
||||
this._handleErrors(stream);
|
||||
}
|
||||
|
||||
this._pipeNext(stream);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
CombinedStream.prototype._pipeNext = function(stream) {
|
||||
this._currentStream = stream;
|
||||
|
||||
var isStreamLike = CombinedStream.isStreamLike(stream);
|
||||
if (isStreamLike) {
|
||||
stream.on('end', this._getNext.bind(this));
|
||||
stream.pipe(this, {end: false});
|
||||
return;
|
||||
}
|
||||
|
||||
var value = stream;
|
||||
this.write(value);
|
||||
this._getNext();
|
||||
};
|
||||
|
||||
CombinedStream.prototype._handleErrors = function(stream) {
|
||||
var self = this;
|
||||
stream.on('error', function(err) {
|
||||
self._emitError(err);
|
||||
});
|
||||
};
|
||||
|
||||
CombinedStream.prototype.write = function(data) {
|
||||
this.emit('data', data);
|
||||
};
|
||||
|
||||
CombinedStream.prototype.pause = function() {
|
||||
if (!this.pauseStreams) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
|
||||
this.emit('pause');
|
||||
};
|
||||
|
||||
CombinedStream.prototype.resume = function() {
|
||||
if (!this._released) {
|
||||
this._released = true;
|
||||
this.writable = true;
|
||||
this._getNext();
|
||||
}
|
||||
|
||||
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
|
||||
this.emit('resume');
|
||||
};
|
||||
|
||||
CombinedStream.prototype.end = function() {
|
||||
this._reset();
|
||||
this.emit('end');
|
||||
};
|
||||
|
||||
CombinedStream.prototype.destroy = function() {
|
||||
this._reset();
|
||||
this.emit('close');
|
||||
};
|
||||
|
||||
CombinedStream.prototype._reset = function() {
|
||||
this.writable = false;
|
||||
this._streams = [];
|
||||
this._currentStream = null;
|
||||
};
|
||||
|
||||
CombinedStream.prototype._checkDataSize = function() {
|
||||
this._updateDataSize();
|
||||
if (this.dataSize <= this.maxDataSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
var message =
|
||||
'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
|
||||
this._emitError(new Error(message));
|
||||
};
|
||||
|
||||
CombinedStream.prototype._updateDataSize = function() {
|
||||
this.dataSize = 0;
|
||||
|
||||
var self = this;
|
||||
this._streams.forEach(function(stream) {
|
||||
if (!stream.dataSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.dataSize += stream.dataSize;
|
||||
});
|
||||
|
||||
if (this._currentStream && this._currentStream.dataSize) {
|
||||
this.dataSize += this._currentStream.dataSize;
|
||||
}
|
||||
};
|
||||
|
||||
CombinedStream.prototype._emitError = function(err) {
|
||||
this._reset();
|
||||
this.emit('error', err);
|
||||
};
|
57
node_modules/combined-stream/package.json
generated
vendored
Normal file
57
node_modules/combined-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"_from": "combined-stream@^1.0.8",
|
||||
"_id": "combined-stream@1.0.8",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"_location": "/combined-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "combined-stream@^1.0.8",
|
||||
"name": "combined-stream",
|
||||
"escapedName": "combined-stream",
|
||||
"rawSpec": "^1.0.8",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.8"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@discordjs/form-data"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"_shasum": "c3d45a8b34fd730631a110a8a2520682b31d5a7f",
|
||||
"_spec": "combined-stream@^1.0.8",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\@discordjs\\form-data",
|
||||
"author": {
|
||||
"name": "Felix Geisendörfer",
|
||||
"email": "felix@debuggable.com",
|
||||
"url": "http://debuggable.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/felixge/node-combined-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A stream that emits multiple other streams one after another.",
|
||||
"devDependencies": {
|
||||
"far": "~0.0.7"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
},
|
||||
"homepage": "https://github.com/felixge/node-combined-stream",
|
||||
"license": "MIT",
|
||||
"main": "./lib/combined_stream",
|
||||
"name": "combined-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/felixge/node-combined-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/run.js"
|
||||
},
|
||||
"version": "1.0.8"
|
||||
}
|
17
node_modules/combined-stream/yarn.lock
generated
vendored
Normal file
17
node_modules/combined-stream/yarn.lock
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
||||
|
||||
far@~0.0.7:
|
||||
version "0.0.7"
|
||||
resolved "https://registry.yarnpkg.com/far/-/far-0.0.7.tgz#01c1fd362bcd26ce9cf161af3938aa34619f79a7"
|
||||
dependencies:
|
||||
oop "0.0.3"
|
||||
|
||||
oop@0.0.3:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/oop/-/oop-0.0.3.tgz#70fa405a5650891a194fdc82ca68dad6dabf4401"
|
19
node_modules/core-util-is/LICENSE
generated
vendored
Normal file
19
node_modules/core-util-is/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright Node.js contributors. All rights reserved.
|
||||
|
||||
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.
|
3
node_modules/core-util-is/README.md
generated
vendored
Normal file
3
node_modules/core-util-is/README.md
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# core-util-is
|
||||
|
||||
The `util.is*` functions introduced in Node v0.12.
|
604
node_modules/core-util-is/float.patch
generated
vendored
Normal file
604
node_modules/core-util-is/float.patch
generated
vendored
Normal file
@ -0,0 +1,604 @@
|
||||
diff --git a/lib/util.js b/lib/util.js
|
||||
index a03e874..9074e8e 100644
|
||||
--- a/lib/util.js
|
||||
+++ b/lib/util.js
|
||||
@@ -19,430 +19,6 @@
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
-var formatRegExp = /%[sdj%]/g;
|
||||
-exports.format = function(f) {
|
||||
- if (!isString(f)) {
|
||||
- var objects = [];
|
||||
- for (var i = 0; i < arguments.length; i++) {
|
||||
- objects.push(inspect(arguments[i]));
|
||||
- }
|
||||
- return objects.join(' ');
|
||||
- }
|
||||
-
|
||||
- var i = 1;
|
||||
- var args = arguments;
|
||||
- var len = args.length;
|
||||
- var str = String(f).replace(formatRegExp, function(x) {
|
||||
- if (x === '%%') return '%';
|
||||
- if (i >= len) return x;
|
||||
- switch (x) {
|
||||
- case '%s': return String(args[i++]);
|
||||
- case '%d': return Number(args[i++]);
|
||||
- case '%j':
|
||||
- try {
|
||||
- return JSON.stringify(args[i++]);
|
||||
- } catch (_) {
|
||||
- return '[Circular]';
|
||||
- }
|
||||
- default:
|
||||
- return x;
|
||||
- }
|
||||
- });
|
||||
- for (var x = args[i]; i < len; x = args[++i]) {
|
||||
- if (isNull(x) || !isObject(x)) {
|
||||
- str += ' ' + x;
|
||||
- } else {
|
||||
- str += ' ' + inspect(x);
|
||||
- }
|
||||
- }
|
||||
- return str;
|
||||
-};
|
||||
-
|
||||
-
|
||||
-// Mark that a method should not be used.
|
||||
-// Returns a modified function which warns once by default.
|
||||
-// If --no-deprecation is set, then it is a no-op.
|
||||
-exports.deprecate = function(fn, msg) {
|
||||
- // Allow for deprecating things in the process of starting up.
|
||||
- if (isUndefined(global.process)) {
|
||||
- return function() {
|
||||
- return exports.deprecate(fn, msg).apply(this, arguments);
|
||||
- };
|
||||
- }
|
||||
-
|
||||
- if (process.noDeprecation === true) {
|
||||
- return fn;
|
||||
- }
|
||||
-
|
||||
- var warned = false;
|
||||
- function deprecated() {
|
||||
- if (!warned) {
|
||||
- if (process.throwDeprecation) {
|
||||
- throw new Error(msg);
|
||||
- } else if (process.traceDeprecation) {
|
||||
- console.trace(msg);
|
||||
- } else {
|
||||
- console.error(msg);
|
||||
- }
|
||||
- warned = true;
|
||||
- }
|
||||
- return fn.apply(this, arguments);
|
||||
- }
|
||||
-
|
||||
- return deprecated;
|
||||
-};
|
||||
-
|
||||
-
|
||||
-var debugs = {};
|
||||
-var debugEnviron;
|
||||
-exports.debuglog = function(set) {
|
||||
- if (isUndefined(debugEnviron))
|
||||
- debugEnviron = process.env.NODE_DEBUG || '';
|
||||
- set = set.toUpperCase();
|
||||
- if (!debugs[set]) {
|
||||
- if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
||||
- var pid = process.pid;
|
||||
- debugs[set] = function() {
|
||||
- var msg = exports.format.apply(exports, arguments);
|
||||
- console.error('%s %d: %s', set, pid, msg);
|
||||
- };
|
||||
- } else {
|
||||
- debugs[set] = function() {};
|
||||
- }
|
||||
- }
|
||||
- return debugs[set];
|
||||
-};
|
||||
-
|
||||
-
|
||||
-/**
|
||||
- * Echos the value of a value. Trys to print the value out
|
||||
- * in the best way possible given the different types.
|
||||
- *
|
||||
- * @param {Object} obj The object to print out.
|
||||
- * @param {Object} opts Optional options object that alters the output.
|
||||
- */
|
||||
-/* legacy: obj, showHidden, depth, colors*/
|
||||
-function inspect(obj, opts) {
|
||||
- // default options
|
||||
- var ctx = {
|
||||
- seen: [],
|
||||
- stylize: stylizeNoColor
|
||||
- };
|
||||
- // legacy...
|
||||
- if (arguments.length >= 3) ctx.depth = arguments[2];
|
||||
- if (arguments.length >= 4) ctx.colors = arguments[3];
|
||||
- if (isBoolean(opts)) {
|
||||
- // legacy...
|
||||
- ctx.showHidden = opts;
|
||||
- } else if (opts) {
|
||||
- // got an "options" object
|
||||
- exports._extend(ctx, opts);
|
||||
- }
|
||||
- // set default options
|
||||
- if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
||||
- if (isUndefined(ctx.depth)) ctx.depth = 2;
|
||||
- if (isUndefined(ctx.colors)) ctx.colors = false;
|
||||
- if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
||||
- if (ctx.colors) ctx.stylize = stylizeWithColor;
|
||||
- return formatValue(ctx, obj, ctx.depth);
|
||||
-}
|
||||
-exports.inspect = inspect;
|
||||
-
|
||||
-
|
||||
-// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
||||
-inspect.colors = {
|
||||
- 'bold' : [1, 22],
|
||||
- 'italic' : [3, 23],
|
||||
- 'underline' : [4, 24],
|
||||
- 'inverse' : [7, 27],
|
||||
- 'white' : [37, 39],
|
||||
- 'grey' : [90, 39],
|
||||
- 'black' : [30, 39],
|
||||
- 'blue' : [34, 39],
|
||||
- 'cyan' : [36, 39],
|
||||
- 'green' : [32, 39],
|
||||
- 'magenta' : [35, 39],
|
||||
- 'red' : [31, 39],
|
||||
- 'yellow' : [33, 39]
|
||||
-};
|
||||
-
|
||||
-// Don't use 'blue' not visible on cmd.exe
|
||||
-inspect.styles = {
|
||||
- 'special': 'cyan',
|
||||
- 'number': 'yellow',
|
||||
- 'boolean': 'yellow',
|
||||
- 'undefined': 'grey',
|
||||
- 'null': 'bold',
|
||||
- 'string': 'green',
|
||||
- 'date': 'magenta',
|
||||
- // "name": intentionally not styling
|
||||
- 'regexp': 'red'
|
||||
-};
|
||||
-
|
||||
-
|
||||
-function stylizeWithColor(str, styleType) {
|
||||
- var style = inspect.styles[styleType];
|
||||
-
|
||||
- if (style) {
|
||||
- return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
||||
- '\u001b[' + inspect.colors[style][1] + 'm';
|
||||
- } else {
|
||||
- return str;
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function stylizeNoColor(str, styleType) {
|
||||
- return str;
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function arrayToHash(array) {
|
||||
- var hash = {};
|
||||
-
|
||||
- array.forEach(function(val, idx) {
|
||||
- hash[val] = true;
|
||||
- });
|
||||
-
|
||||
- return hash;
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function formatValue(ctx, value, recurseTimes) {
|
||||
- // Provide a hook for user-specified inspect functions.
|
||||
- // Check that value is an object with an inspect function on it
|
||||
- if (ctx.customInspect &&
|
||||
- value &&
|
||||
- isFunction(value.inspect) &&
|
||||
- // Filter out the util module, it's inspect function is special
|
||||
- value.inspect !== exports.inspect &&
|
||||
- // Also filter out any prototype objects using the circular check.
|
||||
- !(value.constructor && value.constructor.prototype === value)) {
|
||||
- var ret = value.inspect(recurseTimes, ctx);
|
||||
- if (!isString(ret)) {
|
||||
- ret = formatValue(ctx, ret, recurseTimes);
|
||||
- }
|
||||
- return ret;
|
||||
- }
|
||||
-
|
||||
- // Primitive types cannot have properties
|
||||
- var primitive = formatPrimitive(ctx, value);
|
||||
- if (primitive) {
|
||||
- return primitive;
|
||||
- }
|
||||
-
|
||||
- // Look up the keys of the object.
|
||||
- var keys = Object.keys(value);
|
||||
- var visibleKeys = arrayToHash(keys);
|
||||
-
|
||||
- if (ctx.showHidden) {
|
||||
- keys = Object.getOwnPropertyNames(value);
|
||||
- }
|
||||
-
|
||||
- // Some type of object without properties can be shortcutted.
|
||||
- if (keys.length === 0) {
|
||||
- if (isFunction(value)) {
|
||||
- var name = value.name ? ': ' + value.name : '';
|
||||
- return ctx.stylize('[Function' + name + ']', 'special');
|
||||
- }
|
||||
- if (isRegExp(value)) {
|
||||
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
||||
- }
|
||||
- if (isDate(value)) {
|
||||
- return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
||||
- }
|
||||
- if (isError(value)) {
|
||||
- return formatError(value);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- var base = '', array = false, braces = ['{', '}'];
|
||||
-
|
||||
- // Make Array say that they are Array
|
||||
- if (isArray(value)) {
|
||||
- array = true;
|
||||
- braces = ['[', ']'];
|
||||
- }
|
||||
-
|
||||
- // Make functions say that they are functions
|
||||
- if (isFunction(value)) {
|
||||
- var n = value.name ? ': ' + value.name : '';
|
||||
- base = ' [Function' + n + ']';
|
||||
- }
|
||||
-
|
||||
- // Make RegExps say that they are RegExps
|
||||
- if (isRegExp(value)) {
|
||||
- base = ' ' + RegExp.prototype.toString.call(value);
|
||||
- }
|
||||
-
|
||||
- // Make dates with properties first say the date
|
||||
- if (isDate(value)) {
|
||||
- base = ' ' + Date.prototype.toUTCString.call(value);
|
||||
- }
|
||||
-
|
||||
- // Make error with message first say the error
|
||||
- if (isError(value)) {
|
||||
- base = ' ' + formatError(value);
|
||||
- }
|
||||
-
|
||||
- if (keys.length === 0 && (!array || value.length == 0)) {
|
||||
- return braces[0] + base + braces[1];
|
||||
- }
|
||||
-
|
||||
- if (recurseTimes < 0) {
|
||||
- if (isRegExp(value)) {
|
||||
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
||||
- } else {
|
||||
- return ctx.stylize('[Object]', 'special');
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- ctx.seen.push(value);
|
||||
-
|
||||
- var output;
|
||||
- if (array) {
|
||||
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
||||
- } else {
|
||||
- output = keys.map(function(key) {
|
||||
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
||||
- });
|
||||
- }
|
||||
-
|
||||
- ctx.seen.pop();
|
||||
-
|
||||
- return reduceToSingleString(output, base, braces);
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function formatPrimitive(ctx, value) {
|
||||
- if (isUndefined(value))
|
||||
- return ctx.stylize('undefined', 'undefined');
|
||||
- if (isString(value)) {
|
||||
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
||||
- .replace(/'/g, "\\'")
|
||||
- .replace(/\\"/g, '"') + '\'';
|
||||
- return ctx.stylize(simple, 'string');
|
||||
- }
|
||||
- if (isNumber(value)) {
|
||||
- // Format -0 as '-0'. Strict equality won't distinguish 0 from -0,
|
||||
- // so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 .
|
||||
- if (value === 0 && 1 / value < 0)
|
||||
- return ctx.stylize('-0', 'number');
|
||||
- return ctx.stylize('' + value, 'number');
|
||||
- }
|
||||
- if (isBoolean(value))
|
||||
- return ctx.stylize('' + value, 'boolean');
|
||||
- // For some reason typeof null is "object", so special case here.
|
||||
- if (isNull(value))
|
||||
- return ctx.stylize('null', 'null');
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function formatError(value) {
|
||||
- return '[' + Error.prototype.toString.call(value) + ']';
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
||||
- var output = [];
|
||||
- for (var i = 0, l = value.length; i < l; ++i) {
|
||||
- if (hasOwnProperty(value, String(i))) {
|
||||
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
||||
- String(i), true));
|
||||
- } else {
|
||||
- output.push('');
|
||||
- }
|
||||
- }
|
||||
- keys.forEach(function(key) {
|
||||
- if (!key.match(/^\d+$/)) {
|
||||
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
||||
- key, true));
|
||||
- }
|
||||
- });
|
||||
- return output;
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
||||
- var name, str, desc;
|
||||
- desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
||||
- if (desc.get) {
|
||||
- if (desc.set) {
|
||||
- str = ctx.stylize('[Getter/Setter]', 'special');
|
||||
- } else {
|
||||
- str = ctx.stylize('[Getter]', 'special');
|
||||
- }
|
||||
- } else {
|
||||
- if (desc.set) {
|
||||
- str = ctx.stylize('[Setter]', 'special');
|
||||
- }
|
||||
- }
|
||||
- if (!hasOwnProperty(visibleKeys, key)) {
|
||||
- name = '[' + key + ']';
|
||||
- }
|
||||
- if (!str) {
|
||||
- if (ctx.seen.indexOf(desc.value) < 0) {
|
||||
- if (isNull(recurseTimes)) {
|
||||
- str = formatValue(ctx, desc.value, null);
|
||||
- } else {
|
||||
- str = formatValue(ctx, desc.value, recurseTimes - 1);
|
||||
- }
|
||||
- if (str.indexOf('\n') > -1) {
|
||||
- if (array) {
|
||||
- str = str.split('\n').map(function(line) {
|
||||
- return ' ' + line;
|
||||
- }).join('\n').substr(2);
|
||||
- } else {
|
||||
- str = '\n' + str.split('\n').map(function(line) {
|
||||
- return ' ' + line;
|
||||
- }).join('\n');
|
||||
- }
|
||||
- }
|
||||
- } else {
|
||||
- str = ctx.stylize('[Circular]', 'special');
|
||||
- }
|
||||
- }
|
||||
- if (isUndefined(name)) {
|
||||
- if (array && key.match(/^\d+$/)) {
|
||||
- return str;
|
||||
- }
|
||||
- name = JSON.stringify('' + key);
|
||||
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
||||
- name = name.substr(1, name.length - 2);
|
||||
- name = ctx.stylize(name, 'name');
|
||||
- } else {
|
||||
- name = name.replace(/'/g, "\\'")
|
||||
- .replace(/\\"/g, '"')
|
||||
- .replace(/(^"|"$)/g, "'");
|
||||
- name = ctx.stylize(name, 'string');
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- return name + ': ' + str;
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function reduceToSingleString(output, base, braces) {
|
||||
- var numLinesEst = 0;
|
||||
- var length = output.reduce(function(prev, cur) {
|
||||
- numLinesEst++;
|
||||
- if (cur.indexOf('\n') >= 0) numLinesEst++;
|
||||
- return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
||||
- }, 0);
|
||||
-
|
||||
- if (length > 60) {
|
||||
- return braces[0] +
|
||||
- (base === '' ? '' : base + '\n ') +
|
||||
- ' ' +
|
||||
- output.join(',\n ') +
|
||||
- ' ' +
|
||||
- braces[1];
|
||||
- }
|
||||
-
|
||||
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
||||
-}
|
||||
-
|
||||
-
|
||||
// NOTE: These type checking functions intentionally don't use `instanceof`
|
||||
// because it is fragile and can be easily faked with `Object.create()`.
|
||||
function isArray(ar) {
|
||||
@@ -522,166 +98,10 @@ function isPrimitive(arg) {
|
||||
exports.isPrimitive = isPrimitive;
|
||||
|
||||
function isBuffer(arg) {
|
||||
- return arg instanceof Buffer;
|
||||
+ return Buffer.isBuffer(arg);
|
||||
}
|
||||
exports.isBuffer = isBuffer;
|
||||
|
||||
function objectToString(o) {
|
||||
return Object.prototype.toString.call(o);
|
||||
-}
|
||||
-
|
||||
-
|
||||
-function pad(n) {
|
||||
- return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
-}
|
||||
-
|
||||
-
|
||||
-var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
||||
- 'Oct', 'Nov', 'Dec'];
|
||||
-
|
||||
-// 26 Feb 16:19:34
|
||||
-function timestamp() {
|
||||
- var d = new Date();
|
||||
- var time = [pad(d.getHours()),
|
||||
- pad(d.getMinutes()),
|
||||
- pad(d.getSeconds())].join(':');
|
||||
- return [d.getDate(), months[d.getMonth()], time].join(' ');
|
||||
-}
|
||||
-
|
||||
-
|
||||
-// log is just a thin wrapper to console.log that prepends a timestamp
|
||||
-exports.log = function() {
|
||||
- console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
||||
-};
|
||||
-
|
||||
-
|
||||
-/**
|
||||
- * Inherit the prototype methods from one constructor into another.
|
||||
- *
|
||||
- * The Function.prototype.inherits from lang.js rewritten as a standalone
|
||||
- * function (not on Function.prototype). NOTE: If this file is to be loaded
|
||||
- * during bootstrapping this function needs to be rewritten using some native
|
||||
- * functions as prototype setup using normal JavaScript does not work as
|
||||
- * expected during bootstrapping (see mirror.js in r114903).
|
||||
- *
|
||||
- * @param {function} ctor Constructor function which needs to inherit the
|
||||
- * prototype.
|
||||
- * @param {function} superCtor Constructor function to inherit prototype from.
|
||||
- */
|
||||
-exports.inherits = function(ctor, superCtor) {
|
||||
- ctor.super_ = superCtor;
|
||||
- ctor.prototype = Object.create(superCtor.prototype, {
|
||||
- constructor: {
|
||||
- value: ctor,
|
||||
- enumerable: false,
|
||||
- writable: true,
|
||||
- configurable: true
|
||||
- }
|
||||
- });
|
||||
-};
|
||||
-
|
||||
-exports._extend = function(origin, add) {
|
||||
- // Don't do anything if add isn't an object
|
||||
- if (!add || !isObject(add)) return origin;
|
||||
-
|
||||
- var keys = Object.keys(add);
|
||||
- var i = keys.length;
|
||||
- while (i--) {
|
||||
- origin[keys[i]] = add[keys[i]];
|
||||
- }
|
||||
- return origin;
|
||||
-};
|
||||
-
|
||||
-function hasOwnProperty(obj, prop) {
|
||||
- return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||
-}
|
||||
-
|
||||
-
|
||||
-// Deprecated old stuff.
|
||||
-
|
||||
-exports.p = exports.deprecate(function() {
|
||||
- for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
- console.error(exports.inspect(arguments[i]));
|
||||
- }
|
||||
-}, 'util.p: Use console.error() instead');
|
||||
-
|
||||
-
|
||||
-exports.exec = exports.deprecate(function() {
|
||||
- return require('child_process').exec.apply(this, arguments);
|
||||
-}, 'util.exec is now called `child_process.exec`.');
|
||||
-
|
||||
-
|
||||
-exports.print = exports.deprecate(function() {
|
||||
- for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
- process.stdout.write(String(arguments[i]));
|
||||
- }
|
||||
-}, 'util.print: Use console.log instead');
|
||||
-
|
||||
-
|
||||
-exports.puts = exports.deprecate(function() {
|
||||
- for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
- process.stdout.write(arguments[i] + '\n');
|
||||
- }
|
||||
-}, 'util.puts: Use console.log instead');
|
||||
-
|
||||
-
|
||||
-exports.debug = exports.deprecate(function(x) {
|
||||
- process.stderr.write('DEBUG: ' + x + '\n');
|
||||
-}, 'util.debug: Use console.error instead');
|
||||
-
|
||||
-
|
||||
-exports.error = exports.deprecate(function(x) {
|
||||
- for (var i = 0, len = arguments.length; i < len; ++i) {
|
||||
- process.stderr.write(arguments[i] + '\n');
|
||||
- }
|
||||
-}, 'util.error: Use console.error instead');
|
||||
-
|
||||
-
|
||||
-exports.pump = exports.deprecate(function(readStream, writeStream, callback) {
|
||||
- var callbackCalled = false;
|
||||
-
|
||||
- function call(a, b, c) {
|
||||
- if (callback && !callbackCalled) {
|
||||
- callback(a, b, c);
|
||||
- callbackCalled = true;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- readStream.addListener('data', function(chunk) {
|
||||
- if (writeStream.write(chunk) === false) readStream.pause();
|
||||
- });
|
||||
-
|
||||
- writeStream.addListener('drain', function() {
|
||||
- readStream.resume();
|
||||
- });
|
||||
-
|
||||
- readStream.addListener('end', function() {
|
||||
- writeStream.end();
|
||||
- });
|
||||
-
|
||||
- readStream.addListener('close', function() {
|
||||
- call();
|
||||
- });
|
||||
-
|
||||
- readStream.addListener('error', function(err) {
|
||||
- writeStream.end();
|
||||
- call(err);
|
||||
- });
|
||||
-
|
||||
- writeStream.addListener('error', function(err) {
|
||||
- readStream.destroy();
|
||||
- call(err);
|
||||
- });
|
||||
-}, 'util.pump(): Use readableStream.pipe() instead');
|
||||
-
|
||||
-
|
||||
-var uv;
|
||||
-exports._errnoException = function(err, syscall) {
|
||||
- if (isUndefined(uv)) uv = process.binding('uv');
|
||||
- var errname = uv.errname(err);
|
||||
- var e = new Error(syscall + ' ' + errname);
|
||||
- e.code = errname;
|
||||
- e.errno = errname;
|
||||
- e.syscall = syscall;
|
||||
- return e;
|
||||
-};
|
||||
+}
|
107
node_modules/core-util-is/lib/util.js
generated
vendored
Normal file
107
node_modules/core-util-is/lib/util.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// NOTE: These type checking functions intentionally don't use `instanceof`
|
||||
// because it is fragile and can be easily faked with `Object.create()`.
|
||||
|
||||
function isArray(arg) {
|
||||
if (Array.isArray) {
|
||||
return Array.isArray(arg);
|
||||
}
|
||||
return objectToString(arg) === '[object Array]';
|
||||
}
|
||||
exports.isArray = isArray;
|
||||
|
||||
function isBoolean(arg) {
|
||||
return typeof arg === 'boolean';
|
||||
}
|
||||
exports.isBoolean = isBoolean;
|
||||
|
||||
function isNull(arg) {
|
||||
return arg === null;
|
||||
}
|
||||
exports.isNull = isNull;
|
||||
|
||||
function isNullOrUndefined(arg) {
|
||||
return arg == null;
|
||||
}
|
||||
exports.isNullOrUndefined = isNullOrUndefined;
|
||||
|
||||
function isNumber(arg) {
|
||||
return typeof arg === 'number';
|
||||
}
|
||||
exports.isNumber = isNumber;
|
||||
|
||||
function isString(arg) {
|
||||
return typeof arg === 'string';
|
||||
}
|
||||
exports.isString = isString;
|
||||
|
||||
function isSymbol(arg) {
|
||||
return typeof arg === 'symbol';
|
||||
}
|
||||
exports.isSymbol = isSymbol;
|
||||
|
||||
function isUndefined(arg) {
|
||||
return arg === void 0;
|
||||
}
|
||||
exports.isUndefined = isUndefined;
|
||||
|
||||
function isRegExp(re) {
|
||||
return objectToString(re) === '[object RegExp]';
|
||||
}
|
||||
exports.isRegExp = isRegExp;
|
||||
|
||||
function isObject(arg) {
|
||||
return typeof arg === 'object' && arg !== null;
|
||||
}
|
||||
exports.isObject = isObject;
|
||||
|
||||
function isDate(d) {
|
||||
return objectToString(d) === '[object Date]';
|
||||
}
|
||||
exports.isDate = isDate;
|
||||
|
||||
function isError(e) {
|
||||
return (objectToString(e) === '[object Error]' || e instanceof Error);
|
||||
}
|
||||
exports.isError = isError;
|
||||
|
||||
function isFunction(arg) {
|
||||
return typeof arg === 'function';
|
||||
}
|
||||
exports.isFunction = isFunction;
|
||||
|
||||
function isPrimitive(arg) {
|
||||
return arg === null ||
|
||||
typeof arg === 'boolean' ||
|
||||
typeof arg === 'number' ||
|
||||
typeof arg === 'string' ||
|
||||
typeof arg === 'symbol' || // ES6 symbol
|
||||
typeof arg === 'undefined';
|
||||
}
|
||||
exports.isPrimitive = isPrimitive;
|
||||
|
||||
exports.isBuffer = Buffer.isBuffer;
|
||||
|
||||
function objectToString(o) {
|
||||
return Object.prototype.toString.call(o);
|
||||
}
|
62
node_modules/core-util-is/package.json
generated
vendored
Normal file
62
node_modules/core-util-is/package.json
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"_from": "core-util-is@~1.0.0",
|
||||
"_id": "core-util-is@1.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
|
||||
"_location": "/core-util-is",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "core-util-is@~1.0.0",
|
||||
"name": "core-util-is",
|
||||
"escapedName": "core-util-is",
|
||||
"rawSpec": "~1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/readable-stream"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||
"_shasum": "b5fd54220aa2bc5ab57aab7140c940754503c1a7",
|
||||
"_spec": "core-util-is@~1.0.0",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\readable-stream",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/core-util-is/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "The `util.is*` functions introduced in Node v0.12.",
|
||||
"devDependencies": {
|
||||
"tap": "^2.3.0"
|
||||
},
|
||||
"homepage": "https://github.com/isaacs/core-util-is#readme",
|
||||
"keywords": [
|
||||
"util",
|
||||
"isBuffer",
|
||||
"isArray",
|
||||
"isNumber",
|
||||
"isString",
|
||||
"isRegExp",
|
||||
"isThis",
|
||||
"isThat",
|
||||
"polyfill"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/util.js",
|
||||
"name": "core-util-is",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/core-util-is.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test.js"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
68
node_modules/core-util-is/test.js
generated
vendored
Normal file
68
node_modules/core-util-is/test.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
var assert = require('tap');
|
||||
|
||||
var t = require('./lib/util');
|
||||
|
||||
assert.equal(t.isArray([]), true);
|
||||
assert.equal(t.isArray({}), false);
|
||||
|
||||
assert.equal(t.isBoolean(null), false);
|
||||
assert.equal(t.isBoolean(true), true);
|
||||
assert.equal(t.isBoolean(false), true);
|
||||
|
||||
assert.equal(t.isNull(null), true);
|
||||
assert.equal(t.isNull(undefined), false);
|
||||
assert.equal(t.isNull(false), false);
|
||||
assert.equal(t.isNull(), false);
|
||||
|
||||
assert.equal(t.isNullOrUndefined(null), true);
|
||||
assert.equal(t.isNullOrUndefined(undefined), true);
|
||||
assert.equal(t.isNullOrUndefined(false), false);
|
||||
assert.equal(t.isNullOrUndefined(), true);
|
||||
|
||||
assert.equal(t.isNumber(null), false);
|
||||
assert.equal(t.isNumber('1'), false);
|
||||
assert.equal(t.isNumber(1), true);
|
||||
|
||||
assert.equal(t.isString(null), false);
|
||||
assert.equal(t.isString('1'), true);
|
||||
assert.equal(t.isString(1), false);
|
||||
|
||||
assert.equal(t.isSymbol(null), false);
|
||||
assert.equal(t.isSymbol('1'), false);
|
||||
assert.equal(t.isSymbol(1), false);
|
||||
assert.equal(t.isSymbol(Symbol()), true);
|
||||
|
||||
assert.equal(t.isUndefined(null), false);
|
||||
assert.equal(t.isUndefined(undefined), true);
|
||||
assert.equal(t.isUndefined(false), false);
|
||||
assert.equal(t.isUndefined(), true);
|
||||
|
||||
assert.equal(t.isRegExp(null), false);
|
||||
assert.equal(t.isRegExp('1'), false);
|
||||
assert.equal(t.isRegExp(new RegExp()), true);
|
||||
|
||||
assert.equal(t.isObject({}), true);
|
||||
assert.equal(t.isObject([]), true);
|
||||
assert.equal(t.isObject(new RegExp()), true);
|
||||
assert.equal(t.isObject(new Date()), true);
|
||||
|
||||
assert.equal(t.isDate(null), false);
|
||||
assert.equal(t.isDate('1'), false);
|
||||
assert.equal(t.isDate(new Date()), true);
|
||||
|
||||
assert.equal(t.isError(null), false);
|
||||
assert.equal(t.isError({ err: true }), false);
|
||||
assert.equal(t.isError(new Error()), true);
|
||||
|
||||
assert.equal(t.isFunction(null), false);
|
||||
assert.equal(t.isFunction({ }), false);
|
||||
assert.equal(t.isFunction(function() {}), true);
|
||||
|
||||
assert.equal(t.isPrimitive(null), true);
|
||||
assert.equal(t.isPrimitive(''), true);
|
||||
assert.equal(t.isPrimitive(0), true);
|
||||
assert.equal(t.isPrimitive(new Date()), false);
|
||||
|
||||
assert.equal(t.isBuffer(null), false);
|
||||
assert.equal(t.isBuffer({}), false);
|
||||
assert.equal(t.isBuffer(new Buffer(0)), true);
|
3
node_modules/cps/.npmignore
generated
vendored
Normal file
3
node_modules/cps/.npmignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea
|
||||
cps.iml
|
||||
npm-debug.log
|
19
node_modules/cps/LICENSE
generated
vendored
Normal file
19
node_modules/cps/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013 Chiyan Chen
|
||||
|
||||
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.
|
348
node_modules/cps/README.md
generated
vendored
Normal file
348
node_modules/cps/README.md
generated
vendored
Normal file
@ -0,0 +1,348 @@
|
||||
|
||||
# cps
|
||||
|
||||
A CPS (Continuation Passing Style) library to ease the
|
||||
event-driven/asynchronized coding style in node.js. There seems to be
|
||||
enough node.js libs (e.g. async) doing the same thing, why yet
|
||||
another? This lib is notably different from other libs in
|
||||
exception handling. Using cps:
|
||||
|
||||
* Any "throw" statements in the procedures will be transformed to an
|
||||
application of the callback onto the error object.
|
||||
* A "rescue" function is provided, which can be used to catch such
|
||||
exceptions pass through the callbacks.
|
||||
|
||||
This consistently recovers the try/catch functionality in continuation
|
||||
passing style programming.
|
||||
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```text
|
||||
npm install cps
|
||||
```
|
||||
|
||||
## Terminologies
|
||||
|
||||
### Callback
|
||||
|
||||
We call a function of the following form a callback:
|
||||
|
||||
```javascript
|
||||
function(err, res) {
|
||||
// process the err and res
|
||||
}
|
||||
```
|
||||
|
||||
A callback is a function that takes two arguments, "err" and "res".
|
||||
Semantically, a non-null "err" corresponds to a program exception;
|
||||
while a null "err" corresponds to normal return without any
|
||||
exceptions.
|
||||
|
||||
### Procedure
|
||||
|
||||
We call a function of the following form a procedure:
|
||||
|
||||
```javascript
|
||||
function(arg1, arg2, ..., callback) {
|
||||
// do some work with the arguments and then invoke the callback to continue
|
||||
}
|
||||
```
|
||||
|
||||
A procedure is a function that takes a callback as the last argument.
|
||||
Semantically, a procedure does some work with the input arguments and
|
||||
at some point, call the callback to continue. Note that a call to the
|
||||
"callback" argument MUST always be a tail call. In particular, the
|
||||
following is a procedure:
|
||||
|
||||
```javascript
|
||||
function(callback) {
|
||||
// do some work and then invoke the callback to continue
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## API Document
|
||||
|
||||
* [seq](#seq)
|
||||
* [pwhile](#pwhile)
|
||||
* [peach](#peach)
|
||||
* [pmap](#pmap)
|
||||
* [pfor](#pfor)
|
||||
* [rescue](#rescue)
|
||||
* [parallel](#parallel)
|
||||
|
||||
<a name="seq"/>
|
||||
### seq(array_of_procedures, callback)
|
||||
|
||||
Sequence a list of procedures. Note that the result of each procedure
|
||||
is fed into the next procedure in the listed order.
|
||||
|
||||
__Example__
|
||||
|
||||
```javascript
|
||||
var concatFile = function(f1, f2, resFile, cb) {
|
||||
var contentOfA, contentOfB;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
fs.readFile(f1, cb);
|
||||
},
|
||||
function(res, cb) {
|
||||
contentOfA = res;
|
||||
fs.readFile(f2, cb);
|
||||
},
|
||||
function(res, cb) {
|
||||
contentOfB = res;
|
||||
fs.writeFile(resFile, contentA + contentB, cb);
|
||||
}
|
||||
], cb);
|
||||
};
|
||||
```
|
||||
|
||||
<a name="pwhile">
|
||||
### pwhile(bool_procedure, repeat_body_procedure, cb)
|
||||
|
||||
An asynchronized version of while loop.
|
||||
|
||||
__Example__
|
||||
|
||||
Consider a world in which arithmatic operations do not exists and must
|
||||
be accomplished through alien technology. Then the Fibonacci function
|
||||
needs to be written in the following way:
|
||||
|
||||
```javascript
|
||||
var alienAdd = function(a, b, cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, a + b);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
var asyncFib = function(n, cb) {
|
||||
if (n < 0) {
|
||||
throw new Error('fib input error');
|
||||
}
|
||||
if (n == 0) {return cb(null, 1);}
|
||||
if (n == 1) {return cb(null, 1);}
|
||||
|
||||
var a = 1,
|
||||
b = 1,
|
||||
i = 2;
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.pwhile(
|
||||
function(cb) {
|
||||
cb(null, i <= n);
|
||||
},
|
||||
function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
alienAdd(a, b, cb);
|
||||
},
|
||||
function(res, cb) {
|
||||
a = b;
|
||||
b = res;
|
||||
alienAdd(i, 1, cb);
|
||||
},
|
||||
function(res, cb) {
|
||||
i = res;
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
},
|
||||
cb
|
||||
);
|
||||
},
|
||||
function(_, cb) {
|
||||
cb(null, b);
|
||||
}
|
||||
], cb);
|
||||
};
|
||||
```
|
||||
|
||||
<a name="peach"/>
|
||||
### peach(arr, procedure_for_each_element, callback)
|
||||
|
||||
Apply a procedure on an array sequentially.
|
||||
|
||||
__Example__
|
||||
|
||||
Then in the same "arithmetic-less" world, print out the first 10 Fibonacci numbers.
|
||||
|
||||
```javascript
|
||||
cps.peach(
|
||||
[1,2,3,4,5,6,7,8,9,10],
|
||||
function(el, cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
asyncFib(el, cb);
|
||||
},
|
||||
function(res, cb) {
|
||||
console.log(res);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
|
||||
},
|
||||
cb
|
||||
);
|
||||
```
|
||||
|
||||
<a name="pmap" />
|
||||
### pmap(arr, procedure_for_each_element, callback)
|
||||
|
||||
Apply a procedure on an array sequentially, and record the results in another array, which is pass to the callback.
|
||||
|
||||
__Example__
|
||||
|
||||
You can also map it out first and then log the result list.
|
||||
|
||||
```javascript
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.pmap(
|
||||
[1,2,3,4,5,6,7,8,9,10],
|
||||
function(el, cb) {
|
||||
asyncFib(el, cb);
|
||||
},
|
||||
cb
|
||||
);
|
||||
},
|
||||
function(res, cb) {
|
||||
console.log(res);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
```
|
||||
|
||||
<a name="pfor" />
|
||||
### pfor(number_of_iterations, procedure_for_each_index, callback)
|
||||
|
||||
Apply a procedure on a sequence of consecutive indices, starting of 0.
|
||||
|
||||
__Example__
|
||||
|
||||
|
||||
```javascript
|
||||
var sum = 0;
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
console.log('here');
|
||||
cps.pfor(10, function(i, cb) {
|
||||
setTimeout(function() {
|
||||
sum += i;
|
||||
console.log(sum);
|
||||
cb();
|
||||
}, 1000);
|
||||
}, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
console.log(sum);
|
||||
cb(null, 'ok');
|
||||
}
|
||||
], cb);
|
||||
```
|
||||
|
||||
<a name="rescue"/>
|
||||
### rescue(try_clause_procedure, catch_clause_procedure, callback)
|
||||
|
||||
An asyned version of try/catch. It take two procedures as arguments. If the first one fails, the second is executed to rescue.
|
||||
|
||||
__Example__
|
||||
|
||||
What if there's some invalid input? Let's catch it without disturbing the overall flow.
|
||||
|
||||
```javascript
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.pmap(
|
||||
[1,2,3,4,5,6,7,8,9,10, -1],
|
||||
function(el, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) { // try clause
|
||||
asyncFib(el, cb);
|
||||
},
|
||||
'catch': function(err, cb) { // catch clause
|
||||
console.log(err);
|
||||
cb(null, -1);
|
||||
},
|
||||
'finally': function(cb) { // finally
|
||||
console.log("always print this whether it's good or bad.");
|
||||
cb();
|
||||
}
|
||||
}, cb);
|
||||
},
|
||||
cb
|
||||
);
|
||||
},
|
||||
function(res, cb) {
|
||||
console.log(res);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
```
|
||||
|
||||
<a name="parallel"/>
|
||||
### parallel(array_of_procedures, callback)
|
||||
|
||||
Parallel a list of procedures. The top level callback is only called
|
||||
after each parallel procedure finishes, regardless the procedure
|
||||
succeeds or fails. The callback will never take a non-null error
|
||||
parameter; the result parameter is an array of the following form:
|
||||
|
||||
```js
|
||||
[
|
||||
{"status": "ok", "data": res}, /* in case the procedure in the
|
||||
corresponding position succeeds
|
||||
with result res
|
||||
*/
|
||||
{"status": "error", "error": err} /* in case the procedure in the
|
||||
corresponding position fails
|
||||
with error err
|
||||
*/
|
||||
// ...
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
__Example__
|
||||
|
||||
See "thread b" being printed out before "thread a":
|
||||
|
||||
```javascript
|
||||
var parallelTest = function(cb) {
|
||||
cps.parallel([
|
||||
function(cb) {
|
||||
setTimeout(function() {
|
||||
console.log('3');
|
||||
cb(new Error('kaz'));
|
||||
}, 3000);
|
||||
},
|
||||
function(cb) {
|
||||
setTimeout(function() {
|
||||
console.log('1');
|
||||
cb(null, 'ok');
|
||||
}, 2000);
|
||||
},
|
||||
function(cb) {
|
||||
setTimeout(function() {
|
||||
console.log('2');
|
||||
cb(new Error('foobar'));
|
||||
}, 1000);
|
||||
}
|
||||
], cb);
|
||||
};
|
||||
```
|
||||
|
||||
Running this procedure will yield the following output:
|
||||
|
||||
```text
|
||||
2
|
||||
1
|
||||
3
|
||||
[ { status: 'error', error: [Error: kaz] },
|
||||
{ status: 'ok', data: 'ok' },
|
||||
{ status: 'error', error: [Error: foobar] } ]
|
||||
```
|
||||
|
412
node_modules/cps/lib/cps.js
generated
vendored
Normal file
412
node_modules/cps/lib/cps.js
generated
vendored
Normal file
@ -0,0 +1,412 @@
|
||||
|
||||
var Tail = require('./tail');
|
||||
|
||||
module.exports = function() {
|
||||
var procedure = function(fn) {
|
||||
return function() {
|
||||
var cb = arguments[arguments.length - 1];
|
||||
|
||||
try {
|
||||
fn.apply(this, arguments);
|
||||
} catch(e) {
|
||||
handleError(e, cb);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var handleError = function(e, cb) {
|
||||
cb(e);
|
||||
};
|
||||
|
||||
var callback = function(cb, fn) {
|
||||
var called = false;
|
||||
|
||||
return function(err) {
|
||||
if (called) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
if (err.stack) {
|
||||
console.log(err.stack);
|
||||
}
|
||||
}
|
||||
throw new Error('Continuation is being called more than once!');
|
||||
}
|
||||
called = true;
|
||||
try {
|
||||
if (err) {
|
||||
handleError(err, cb);
|
||||
} else {
|
||||
fn.apply(this, arguments);
|
||||
}
|
||||
} catch(e) {
|
||||
handleError(e, cb);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _seq = procedure(function(procs, i, res, cb) {
|
||||
if (i >= procs.length) {
|
||||
return cb(null, res);
|
||||
}
|
||||
var proc = procs[i];
|
||||
proc(res, callback(cb, function(err, res) {
|
||||
// return _seq(procs, i+1, res, cb);
|
||||
return Tail.run(function() {
|
||||
_seq(procs, i+1, res, cb);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
var seq = function(procs, cb) {
|
||||
return _seq(procs, 0, null, cb);
|
||||
};
|
||||
|
||||
var rescue = procedure(function(procBundle, cb) {
|
||||
var tryProc = procBundle['try'];
|
||||
var catchProc = procBundle['catch'] || function(err, cb) {cb(err);};
|
||||
var finallyProc = procBundle['finally'] || function(cb) {cb();};
|
||||
|
||||
var applyTry = procedure(function(cb) {
|
||||
tryProc(cb);
|
||||
});
|
||||
|
||||
var applyCatch = procedure(function(err, cb) {
|
||||
catchProc(err, cb);
|
||||
});
|
||||
|
||||
var applyFinallyOk = procedure(function(res0, cb) {
|
||||
finallyProc(callback(cb, function(err, res) {
|
||||
cb(null, res0);
|
||||
}));
|
||||
});
|
||||
|
||||
var applyFinallyError = procedure(function(err0, cb) {
|
||||
finallyProc(callback(cb, function(err, res) {
|
||||
cb(err0);
|
||||
}));
|
||||
});
|
||||
|
||||
applyTry(function(err, res) {
|
||||
if (err) {
|
||||
applyCatch(err, function(err, res) {
|
||||
if (err) {
|
||||
applyFinallyError(err, cb);
|
||||
} else {
|
||||
applyFinallyOk(res, cb);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
applyFinallyOk(res, cb);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var pwhile = procedure(function(procBool, procBody, cb) {
|
||||
seq([
|
||||
function(_, cb) {
|
||||
procBool(cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
if (_) {
|
||||
seq([
|
||||
function(_, cb) {
|
||||
procBody(cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
pwhile(procBool, procBody, cb);
|
||||
}
|
||||
], cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
|
||||
var peach = procedure(function(arr, proc, cb) {
|
||||
var i = 0;
|
||||
|
||||
pwhile(
|
||||
function(cb) {
|
||||
cb(null, i < arr.length);
|
||||
},
|
||||
function(cb) {
|
||||
seq([
|
||||
function(_, cb) {
|
||||
proc(arr[i], cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
i++;
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
},
|
||||
cb
|
||||
)
|
||||
});
|
||||
|
||||
var pfor = procedure(function(n, proc, cb) {
|
||||
var i = 0;
|
||||
|
||||
pwhile(
|
||||
function(cb) {
|
||||
cb(null, i < n);
|
||||
},
|
||||
function(cb) {
|
||||
seq([
|
||||
function(_, cb) {
|
||||
proc(i, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
i++;
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
},
|
||||
cb
|
||||
);
|
||||
});
|
||||
|
||||
var pmap = procedure(function(arr, proc, cb) {
|
||||
var l = [];
|
||||
|
||||
seq([
|
||||
function(_, cb) {
|
||||
peach(arr, function(e, cb) {
|
||||
seq([
|
||||
function(_, cb) {
|
||||
proc(e, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
l.push(_);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
}, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
cb(null, l);
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
|
||||
var _parallel2 = procedure(function(proc1, proc2, cb) {
|
||||
var state1 = 'start';
|
||||
var state2 = 'start';
|
||||
var res1;
|
||||
var res2;
|
||||
var err1;
|
||||
var err2;
|
||||
|
||||
var applyProc1 = procedure(function(cb) {
|
||||
proc1(cb);
|
||||
});
|
||||
|
||||
var applyProc2 = procedure(function(cb) {
|
||||
proc2(cb);
|
||||
});
|
||||
|
||||
applyProc1(function(err, res) {Tail.run(function() {
|
||||
if (err) {
|
||||
state1 = 'error';
|
||||
err1 = err;
|
||||
switch(state2) {
|
||||
case 'start':
|
||||
break;
|
||||
case 'done':
|
||||
cb(null, [
|
||||
{status: 'error', error: err1},
|
||||
{status: 'ok', data: res2}
|
||||
]);
|
||||
break;
|
||||
case 'error':
|
||||
cb(null, [
|
||||
{status: 'error', error: err1},
|
||||
{status: 'error', error: err2}
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
state1 = 'done';
|
||||
res1 = res;
|
||||
switch(state2) {
|
||||
case 'start':
|
||||
break;
|
||||
case 'done':
|
||||
cb(null, [
|
||||
{status: 'ok', data: res1},
|
||||
{status: 'ok', data: res2}
|
||||
]);
|
||||
break;
|
||||
case 'error':
|
||||
cb(null, [
|
||||
{status: 'ok', data: res1},
|
||||
{status: 'error', error: err2}
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
})});
|
||||
|
||||
applyProc2(function(err, res) {Tail.run(function() {
|
||||
if (err) {
|
||||
state2 = 'error';
|
||||
err2 = err;
|
||||
switch(state1) {
|
||||
case 'start':
|
||||
break;
|
||||
case 'done':
|
||||
cb(null, [
|
||||
{status: 'ok', data: res1},
|
||||
{status: 'error', error: err2}
|
||||
]);
|
||||
break;
|
||||
case 'error':
|
||||
cb(null, [
|
||||
{status: 'error', error: err1},
|
||||
{status: 'error', error: err2}
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
state2 = 'done';
|
||||
res2 = res;
|
||||
switch(state1) {
|
||||
case 'start':
|
||||
break;
|
||||
case 'done':
|
||||
cb(null, [
|
||||
{status: 'ok', data: res1},
|
||||
{status: 'ok', data: res2}
|
||||
]);
|
||||
break;
|
||||
case 'error':
|
||||
cb(null, [
|
||||
{status: 'error', error: err1},
|
||||
{status: 'ok', data: res2}
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
})});
|
||||
});
|
||||
|
||||
var _parallel = procedure(function(procs, i, cb) {
|
||||
if (procs.length == 0) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
if (i == procs.length - 1) {
|
||||
return procs[i](function(err, res) {
|
||||
if (err) {
|
||||
cb(null, [{status: 'error', error: err}]);
|
||||
} else {
|
||||
cb(null, [{status: 'ok', data: res}]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (i < procs.length) {
|
||||
_parallel2(
|
||||
procs[i],
|
||||
function(cb) {
|
||||
_parallel(procs, i+1, cb);
|
||||
},
|
||||
callback(cb, function(err, res) {
|
||||
cb(null, [res[0]].concat(res[1].data));
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var parallel = procedure(function(procs, cb) {
|
||||
_parallel(procs, 0, cb);
|
||||
});
|
||||
|
||||
var noFail = function() {
|
||||
var proc, handler, cb;
|
||||
|
||||
proc = arguments[0];
|
||||
cb = arguments[arguments.length - 1];
|
||||
|
||||
if (arguments.length == 2) {
|
||||
handler = function(err) {
|
||||
console.log('ERROR caught by cps.noFail: ', err);
|
||||
if (err.stack) {
|
||||
console.log(err.stack);
|
||||
}
|
||||
};
|
||||
} else if (arguments.length == 3) {
|
||||
handler = arguments[1];
|
||||
} else {
|
||||
handleError(new Error('Incorrect number of arguments in calling cps.noFail.'), cb);
|
||||
}
|
||||
|
||||
rescue({
|
||||
'try': function(cb) {
|
||||
proc(cb);
|
||||
},
|
||||
'catch': function(err, cb) {
|
||||
handler(err);
|
||||
cb();
|
||||
}
|
||||
}, cb);
|
||||
};
|
||||
|
||||
var run = function(proc, cfg) {
|
||||
cfg = cfg || {};
|
||||
|
||||
var cb = function(err, res) {
|
||||
try {
|
||||
if (err) {
|
||||
if (cfg['error']) {
|
||||
cfg['error'](err);
|
||||
} else {
|
||||
console.log('cps.run ERROR: ', err);
|
||||
if (err.stack) {
|
||||
console.log(err.stack);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (cfg['ok']) {
|
||||
cfg['ok'](res);
|
||||
} else {
|
||||
console.log('cps.run OK: ', res);
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
if (cfg['topLevelError']) {
|
||||
cfg['topLevelError'](e);
|
||||
} else {
|
||||
console.log('cps.run TOP_LEVEL_ERROR: ', e);
|
||||
}
|
||||
} finally {
|
||||
if (cfg['finally']) {
|
||||
try {
|
||||
cfg['finally']();
|
||||
} catch(e) {
|
||||
console.log('cps.run FINALLY_ERROR: ', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proc(cb);
|
||||
};
|
||||
|
||||
return {
|
||||
seq: seq,
|
||||
peach: peach,
|
||||
pwhile: pwhile,
|
||||
pmap: pmap,
|
||||
pfor: pfor,
|
||||
rescue: rescue,
|
||||
parallel: parallel,
|
||||
noFail: noFail,
|
||||
run: run
|
||||
};
|
||||
}();
|
30
node_modules/cps/lib/tail.js
generated
vendored
Normal file
30
node_modules/cps/lib/tail.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
var Tail = function() {
|
||||
this._q = [];
|
||||
this._running = false;
|
||||
};
|
||||
|
||||
Tail.prototype = {
|
||||
run: function(fn) {
|
||||
this._q.push(fn);
|
||||
if (!this._running) {
|
||||
this._run();
|
||||
}
|
||||
},
|
||||
|
||||
_run: function() {
|
||||
while(true) {
|
||||
var fn = this._q.shift();
|
||||
if (fn) {
|
||||
this._running = true;
|
||||
fn();
|
||||
} else {
|
||||
this._running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = new Tail();
|
||||
|
56
node_modules/cps/package.json
generated
vendored
Normal file
56
node_modules/cps/package.json
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"_from": "cps@*",
|
||||
"_id": "cps@1.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-LNCyXYDxCQljfghWrZumNM4E/x0=",
|
||||
"_location": "/cps",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "cps@*",
|
||||
"name": "cps",
|
||||
"escapedName": "cps",
|
||||
"rawSpec": "*",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "*"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-mysql"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cps/-/cps-1.0.2.tgz",
|
||||
"_shasum": "2cd0b25d80f10909637e0856ad9ba634ce04ff1d",
|
||||
"_spec": "cps@*",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\node-mysql",
|
||||
"author": {
|
||||
"name": "Chiyan Chen"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/redblaze/cps/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A continuation passing style library to help the coding of asynced programs in Javascript/Node.js.",
|
||||
"homepage": "https://github.com/redblaze/cps#readme",
|
||||
"jam": {
|
||||
"main": "lib/cps.js",
|
||||
"include": [
|
||||
"lib/cps.js",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
]
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/redblaze/cps/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "./lib/cps",
|
||||
"name": "cps",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/redblaze/cps.git"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
51
node_modules/cps/test/fib.js
generated
vendored
Normal file
51
node_modules/cps/test/fib.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
var cps = require('../lib/cps.js');
|
||||
|
||||
var alienAdd = function(a, b, cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, a + b);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
var asyncFib = function(n, cb) {
|
||||
if (n < 0) {
|
||||
throw new Error('fib input error');
|
||||
// return cb(new Error('fib input error'));
|
||||
}
|
||||
if (n == 0) {return cb(null, 1);}
|
||||
if (n == 1) {return cb(null, 1);}
|
||||
|
||||
var a = 1,
|
||||
b = 1,
|
||||
i = 2;
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.pwhile(
|
||||
function(cb) {
|
||||
cb(null, i <= n);
|
||||
},
|
||||
function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
alienAdd(a, b, cb);
|
||||
},
|
||||
function(res, cb) {
|
||||
a = b;
|
||||
b = res;
|
||||
alienAdd(i, 1, cb);
|
||||
},
|
||||
function(res, cb) {
|
||||
i = res;
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
},
|
||||
cb
|
||||
);
|
||||
},
|
||||
function(_, cb) {
|
||||
cb(null, b);
|
||||
}
|
||||
], cb);
|
||||
};
|
||||
|
||||
module.exports = asyncFib;
|
417
node_modules/cps/test/test.js
generated
vendored
Normal file
417
node_modules/cps/test/test.js
generated
vendored
Normal file
@ -0,0 +1,417 @@
|
||||
|
||||
var cps = require('../lib/cps.js');
|
||||
var fib = require('./fib');
|
||||
var assert = require("assert");
|
||||
|
||||
describe('cps', function() {
|
||||
describe('seq', function() {
|
||||
it('should return 3 for 1+2', function(cb) {
|
||||
var a, b;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, 1);
|
||||
}, 0);
|
||||
},
|
||||
function(_, cb) {
|
||||
a = _;
|
||||
setTimeout(function() {
|
||||
cb(null, 2);
|
||||
}, 0);
|
||||
},
|
||||
function(_, cb) {
|
||||
b = _;
|
||||
cb(null, a + b);
|
||||
},
|
||||
function(_, cb) {
|
||||
assert.equal(_, 3);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pwhile', function() {
|
||||
it('should return 2 for fib(2)', function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
fib(5, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
assert.equal(_, 8);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
|
||||
it('should not fail for huge loops', function(cb) {
|
||||
this.timeout(0);
|
||||
var i;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
i = 0;
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
cps.pwhile(
|
||||
function(cb) {
|
||||
cb(null, i < 10000);
|
||||
},
|
||||
function(cb) {
|
||||
i++;
|
||||
cb();
|
||||
},
|
||||
cb
|
||||
)
|
||||
},
|
||||
'catch': function(e, cb) {
|
||||
console.log('ERROR: ', e);
|
||||
throw e;
|
||||
}
|
||||
}, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
console.log('i is: ', i);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pfor', function() {
|
||||
it('should return 45 for the sum of 0 through 9', function(cb) {
|
||||
var sum = 0;
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.pfor(10, function(i, cb) {
|
||||
setTimeout(function() {
|
||||
sum += i;
|
||||
cb();
|
||||
}, 0);
|
||||
}, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
assert.equal(sum, 45);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('peach', function() {
|
||||
it('should return 55 for the sum of 1 through 10', function(cb) {
|
||||
var sum = 0;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.peach(
|
||||
[1,2,3,4,5,6,7,8,9,10],
|
||||
function(el, cb) {
|
||||
sum += el;
|
||||
cb();
|
||||
},
|
||||
cb
|
||||
);
|
||||
},
|
||||
function(_, cb) {
|
||||
assert.equal(sum, 55);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pmap', function() {
|
||||
it('should return the list of squares of [1..10]', function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.pmap(
|
||||
[1,2,3,4,5,6,7,8,9,10],
|
||||
function(el, cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, el*el);
|
||||
}, 0);
|
||||
},
|
||||
cb
|
||||
);
|
||||
},
|
||||
function(_, cb) {
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
assert.equal(_[i-1], i*i);
|
||||
}
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parallel', function() {
|
||||
it('should work for 3 parallel threads', function(cb) {
|
||||
this.timeout(0);
|
||||
|
||||
var output = [];
|
||||
var start, end;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
start = new Date();
|
||||
|
||||
cps.parallel([
|
||||
function(cb) {
|
||||
setTimeout(function() {
|
||||
output.push(3);
|
||||
cb(new Error('kaz'));
|
||||
}, 3000);
|
||||
},
|
||||
function(cb) {
|
||||
setTimeout(function() {
|
||||
output.push(2);
|
||||
cb(null, 'ok');
|
||||
}, 2000);
|
||||
},
|
||||
function(cb) {
|
||||
setTimeout(function() {
|
||||
output.push(1);
|
||||
cb(new Error('foobar'));
|
||||
}, 1000);
|
||||
}
|
||||
], cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
end = new Date();
|
||||
|
||||
assert(end-start < 3100, 'parallel is taking too long to run');
|
||||
|
||||
for (var i = 1; i <= 3; i++) {
|
||||
assert.equal(output[i-1], i);
|
||||
}
|
||||
|
||||
assert.equal(_[0].status, 'error');
|
||||
assert.equal(_[0].error.message, 'kaz');
|
||||
|
||||
assert.equal(_[1].status, 'ok');
|
||||
assert.equal(_[1].data, 'ok');
|
||||
|
||||
assert.equal(_[2].status, 'error');
|
||||
assert.equal(_[2].error.message, 'foobar');
|
||||
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('noFail', function() {
|
||||
it('should not fail on success', function(cb) {
|
||||
cps.noFail(function(cb) {
|
||||
cb(null, 1);
|
||||
}, cb);
|
||||
});
|
||||
|
||||
it('should not fail on failure', function(cb) {
|
||||
cps.noFail(function(cb) {
|
||||
cb(new Error('foobar'));
|
||||
}, cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rescue', function() {
|
||||
it('should catch errors', function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(new Error('foobar'));
|
||||
}, 0);
|
||||
},
|
||||
'catch': function(err, cb) {
|
||||
cb(null, 'ok');
|
||||
}
|
||||
}, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
assert.equal(_, 'ok');
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
|
||||
it('should be able to throw errors', function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(new Error('foobar'));
|
||||
}, 0);
|
||||
}
|
||||
}, cb);
|
||||
}
|
||||
], function(err, res) {
|
||||
try {
|
||||
assert.equal(err.message, 'foobar');
|
||||
cb();
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to rethrow errors', function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(new Error('foobar'));
|
||||
}, 0);
|
||||
},
|
||||
'catch': function(err, cb) {
|
||||
throw new Error('kaz');
|
||||
}
|
||||
}, cb);
|
||||
}
|
||||
], function(err, res) {
|
||||
try {
|
||||
assert.equal(err.message, 'kaz');
|
||||
cb();
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should execute finally clause on success', function(cb) {
|
||||
var finallyDone = false;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, 'ok');
|
||||
}, 0);
|
||||
},
|
||||
'finally': function(cb) {
|
||||
finallyDone = true;
|
||||
cb();
|
||||
}
|
||||
}, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
assert.equal(_, 'ok');
|
||||
assert(finallyDone);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
|
||||
it('should execute finally clause on exception being caught', function(cb) {
|
||||
var finallyDone = false;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(new Error('foobar'));
|
||||
}, 0);
|
||||
},
|
||||
'catch': function(err, cb) {
|
||||
cb(null, 'exception caught');
|
||||
},
|
||||
'finally': function(cb) {
|
||||
finallyDone = true;
|
||||
cb();
|
||||
}
|
||||
}, cb);
|
||||
},
|
||||
function(_, cb) {
|
||||
assert.equal(_, 'exception caught');
|
||||
assert(finallyDone);
|
||||
cb();
|
||||
}
|
||||
], cb);
|
||||
});
|
||||
|
||||
it('should execute finally clause on exception', function(cb) {
|
||||
var finallyDone = false;
|
||||
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(new Error('foobar'));
|
||||
}, 0);
|
||||
},
|
||||
'finally': function(cb) {
|
||||
finallyDone = true;
|
||||
cb();
|
||||
}
|
||||
}, cb);
|
||||
}
|
||||
], function(err, res) {
|
||||
try{
|
||||
assert.equal(err.message, 'foobar');
|
||||
assert(finallyDone);
|
||||
cb();
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw exception in finally clause on success', function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, 'ok');
|
||||
}, 0);
|
||||
},
|
||||
'finally': function(cb) {
|
||||
throw new Error('error in finally');
|
||||
cb();
|
||||
}
|
||||
}, cb);
|
||||
}
|
||||
], function(err, res) {
|
||||
try{
|
||||
assert.equal(err.message, 'error in finally');
|
||||
cb();
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw exception in finally clause on exception', function(cb) {
|
||||
cps.seq([
|
||||
function(_, cb) {
|
||||
cps.rescue({
|
||||
'try': function(cb) {
|
||||
setTimeout(function() {
|
||||
cb(new Error('foobar'));
|
||||
}, 0);
|
||||
},
|
||||
'finally': function(cb) {
|
||||
throw new Error('error in finally');
|
||||
cb();
|
||||
}
|
||||
}, cb);
|
||||
}
|
||||
], function(err, res) {
|
||||
try{
|
||||
assert.equal(err.message, 'error in finally');
|
||||
cb();
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
1
node_modules/delayed-stream/.npmignore
generated
vendored
Normal file
1
node_modules/delayed-stream/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
test
|
19
node_modules/delayed-stream/License
generated
vendored
Normal file
19
node_modules/delayed-stream/License
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2011 Debuggable Limited <felix@debuggable.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.
|
7
node_modules/delayed-stream/Makefile
generated
vendored
Normal file
7
node_modules/delayed-stream/Makefile
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
SHELL := /bin/bash
|
||||
|
||||
test:
|
||||
@./test/run.js
|
||||
|
||||
.PHONY: test
|
||||
|
141
node_modules/delayed-stream/Readme.md
generated
vendored
Normal file
141
node_modules/delayed-stream/Readme.md
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
# delayed-stream
|
||||
|
||||
Buffers events from a stream until you are ready to handle them.
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
npm install delayed-stream
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The following example shows how to write a http echo server that delays its
|
||||
response by 1000 ms.
|
||||
|
||||
``` javascript
|
||||
var DelayedStream = require('delayed-stream');
|
||||
var http = require('http');
|
||||
|
||||
http.createServer(function(req, res) {
|
||||
var delayed = DelayedStream.create(req);
|
||||
|
||||
setTimeout(function() {
|
||||
res.writeHead(200);
|
||||
delayed.pipe(res);
|
||||
}, 1000);
|
||||
});
|
||||
```
|
||||
|
||||
If you are not using `Stream#pipe`, you can also manually release the buffered
|
||||
events by calling `delayedStream.resume()`:
|
||||
|
||||
``` javascript
|
||||
var delayed = DelayedStream.create(req);
|
||||
|
||||
setTimeout(function() {
|
||||
// Emit all buffered events and resume underlaying source
|
||||
delayed.resume();
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
## Implementation
|
||||
|
||||
In order to use this meta stream properly, here are a few things you should
|
||||
know about the implementation.
|
||||
|
||||
### Event Buffering / Proxying
|
||||
|
||||
All events of the `source` stream are hijacked by overwriting the `source.emit`
|
||||
method. Until node implements a catch-all event listener, this is the only way.
|
||||
|
||||
However, delayed-stream still continues to emit all events it captures on the
|
||||
`source`, regardless of whether you have released the delayed stream yet or
|
||||
not.
|
||||
|
||||
Upon creation, delayed-stream captures all `source` events and stores them in
|
||||
an internal event buffer. Once `delayedStream.release()` is called, all
|
||||
buffered events are emitted on the `delayedStream`, and the event buffer is
|
||||
cleared. After that, delayed-stream merely acts as a proxy for the underlaying
|
||||
source.
|
||||
|
||||
### Error handling
|
||||
|
||||
Error events on `source` are buffered / proxied just like any other events.
|
||||
However, `delayedStream.create` attaches a no-op `'error'` listener to the
|
||||
`source`. This way you only have to handle errors on the `delayedStream`
|
||||
object, rather than in two places.
|
||||
|
||||
### Buffer limits
|
||||
|
||||
delayed-stream provides a `maxDataSize` property that can be used to limit
|
||||
the amount of data being buffered. In order to protect you from bad `source`
|
||||
streams that don't react to `source.pause()`, this feature is enabled by
|
||||
default.
|
||||
|
||||
## API
|
||||
|
||||
### DelayedStream.create(source, [options])
|
||||
|
||||
Returns a new `delayedStream`. Available options are:
|
||||
|
||||
* `pauseStream`
|
||||
* `maxDataSize`
|
||||
|
||||
The description for those properties can be found below.
|
||||
|
||||
### delayedStream.source
|
||||
|
||||
The `source` stream managed by this object. This is useful if you are
|
||||
passing your `delayedStream` around, and you still want to access properties
|
||||
on the `source` object.
|
||||
|
||||
### delayedStream.pauseStream = true
|
||||
|
||||
Whether to pause the underlaying `source` when calling
|
||||
`DelayedStream.create()`. Modifying this property afterwards has no effect.
|
||||
|
||||
### delayedStream.maxDataSize = 1024 * 1024
|
||||
|
||||
The amount of data to buffer before emitting an `error`.
|
||||
|
||||
If the underlaying source is emitting `Buffer` objects, the `maxDataSize`
|
||||
refers to bytes.
|
||||
|
||||
If the underlaying source is emitting JavaScript strings, the size refers to
|
||||
characters.
|
||||
|
||||
If you know what you are doing, you can set this property to `Infinity` to
|
||||
disable this feature. You can also modify this property during runtime.
|
||||
|
||||
### delayedStream.dataSize = 0
|
||||
|
||||
The amount of data buffered so far.
|
||||
|
||||
### delayedStream.readable
|
||||
|
||||
An ECMA5 getter that returns the value of `source.readable`.
|
||||
|
||||
### delayedStream.resume()
|
||||
|
||||
If the `delayedStream` has not been released so far, `delayedStream.release()`
|
||||
is called.
|
||||
|
||||
In either case, `source.resume()` is called.
|
||||
|
||||
### delayedStream.pause()
|
||||
|
||||
Calls `source.pause()`.
|
||||
|
||||
### delayedStream.pipe(dest)
|
||||
|
||||
Calls `delayedStream.resume()` and then proxies the arguments to `source.pipe`.
|
||||
|
||||
### delayedStream.release()
|
||||
|
||||
Emits and clears all events that have been buffered up so far. This does not
|
||||
resume the underlaying source, use `delayedStream.resume()` instead.
|
||||
|
||||
## License
|
||||
|
||||
delayed-stream is licensed under the MIT license.
|
107
node_modules/delayed-stream/lib/delayed_stream.js
generated
vendored
Normal file
107
node_modules/delayed-stream/lib/delayed_stream.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
var Stream = require('stream').Stream;
|
||||
var util = require('util');
|
||||
|
||||
module.exports = DelayedStream;
|
||||
function DelayedStream() {
|
||||
this.source = null;
|
||||
this.dataSize = 0;
|
||||
this.maxDataSize = 1024 * 1024;
|
||||
this.pauseStream = true;
|
||||
|
||||
this._maxDataSizeExceeded = false;
|
||||
this._released = false;
|
||||
this._bufferedEvents = [];
|
||||
}
|
||||
util.inherits(DelayedStream, Stream);
|
||||
|
||||
DelayedStream.create = function(source, options) {
|
||||
var delayedStream = new this();
|
||||
|
||||
options = options || {};
|
||||
for (var option in options) {
|
||||
delayedStream[option] = options[option];
|
||||
}
|
||||
|
||||
delayedStream.source = source;
|
||||
|
||||
var realEmit = source.emit;
|
||||
source.emit = function() {
|
||||
delayedStream._handleEmit(arguments);
|
||||
return realEmit.apply(source, arguments);
|
||||
};
|
||||
|
||||
source.on('error', function() {});
|
||||
if (delayedStream.pauseStream) {
|
||||
source.pause();
|
||||
}
|
||||
|
||||
return delayedStream;
|
||||
};
|
||||
|
||||
Object.defineProperty(DelayedStream.prototype, 'readable', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return this.source.readable;
|
||||
}
|
||||
});
|
||||
|
||||
DelayedStream.prototype.setEncoding = function() {
|
||||
return this.source.setEncoding.apply(this.source, arguments);
|
||||
};
|
||||
|
||||
DelayedStream.prototype.resume = function() {
|
||||
if (!this._released) {
|
||||
this.release();
|
||||
}
|
||||
|
||||
this.source.resume();
|
||||
};
|
||||
|
||||
DelayedStream.prototype.pause = function() {
|
||||
this.source.pause();
|
||||
};
|
||||
|
||||
DelayedStream.prototype.release = function() {
|
||||
this._released = true;
|
||||
|
||||
this._bufferedEvents.forEach(function(args) {
|
||||
this.emit.apply(this, args);
|
||||
}.bind(this));
|
||||
this._bufferedEvents = [];
|
||||
};
|
||||
|
||||
DelayedStream.prototype.pipe = function() {
|
||||
var r = Stream.prototype.pipe.apply(this, arguments);
|
||||
this.resume();
|
||||
return r;
|
||||
};
|
||||
|
||||
DelayedStream.prototype._handleEmit = function(args) {
|
||||
if (this._released) {
|
||||
this.emit.apply(this, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0] === 'data') {
|
||||
this.dataSize += args[1].length;
|
||||
this._checkIfMaxDataSizeExceeded();
|
||||
}
|
||||
|
||||
this._bufferedEvents.push(args);
|
||||
};
|
||||
|
||||
DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
|
||||
if (this._maxDataSizeExceeded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.dataSize <= this.maxDataSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._maxDataSizeExceeded = true;
|
||||
var message =
|
||||
'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.'
|
||||
this.emit('error', new Error(message));
|
||||
};
|
62
node_modules/delayed-stream/package.json
generated
vendored
Normal file
62
node_modules/delayed-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"_from": "delayed-stream@~1.0.0",
|
||||
"_id": "delayed-stream@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
|
||||
"_location": "/delayed-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "delayed-stream@~1.0.0",
|
||||
"name": "delayed-stream",
|
||||
"escapedName": "delayed-stream",
|
||||
"rawSpec": "~1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/combined-stream"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"_shasum": "df3ae199acadfb7d440aaae0b29e2272b24ec619",
|
||||
"_spec": "delayed-stream@~1.0.0",
|
||||
"_where": "E:\\IntellijProjects\\woam-antispam-bot\\node_modules\\combined-stream",
|
||||
"author": {
|
||||
"name": "Felix Geisendörfer",
|
||||
"email": "felix@debuggable.com",
|
||||
"url": "http://debuggable.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/felixge/node-delayed-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Mike Atkins",
|
||||
"email": "apeherder@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Buffers events from a stream until you are ready to handle them.",
|
||||
"devDependencies": {
|
||||
"fake": "0.2.0",
|
||||
"far": "0.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
},
|
||||
"homepage": "https://github.com/felixge/node-delayed-stream",
|
||||
"license": "MIT",
|
||||
"main": "./lib/delayed_stream",
|
||||
"name": "delayed-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/felixge/node-delayed-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
32
node_modules/discord-anti-spam/.jsdoc.json
generated
vendored
Normal file
32
node_modules/discord-anti-spam/.jsdoc.json
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"tags": {
|
||||
"allowUnknownTags": true,
|
||||
"dictionaries": ["jsdoc"]
|
||||
},
|
||||
"source": {
|
||||
"include": ["index.js", "package.json", "README.md"],
|
||||
"includePattern": ".js$",
|
||||
"excludePattern": "(node_modules/|docs)"
|
||||
},
|
||||
"plugins": [
|
||||
"plugins/markdown"
|
||||
],
|
||||
"templates": {
|
||||
"cleverLinks": false,
|
||||
"monospaceLinks": true,
|
||||
"useLongnameInNav": false,
|
||||
"showInheritedInNav": true,
|
||||
"default": {
|
||||
"outputSourceFiles": false,
|
||||
"includeDate": false
|
||||
}
|
||||
},
|
||||
"opts": {
|
||||
"destination": "./docs/",
|
||||
"encoding": "utf8",
|
||||
"private": true,
|
||||
"recurse": true,
|
||||
"template": "./node_modules/minami",
|
||||
"sort": false
|
||||
}
|
||||
}
|
19
node_modules/discord-anti-spam/LICENSE
generated
vendored
Normal file
19
node_modules/discord-anti-spam/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Michael Scofield <michaelscofield4554@gmail.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.
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user