Updated Ace Editor, Started rewrite of collaborative plugin, added ability to disable and enable editors, Started adding some php variables to javascript.

This commit is contained in:
xevidos 2018-08-08 10:12:29 -04:00
parent 2894a7a694
commit 2f4727aad3
340 changed files with 55273 additions and 1465 deletions

View file

@ -61,6 +61,10 @@
define('SESSIONS_PATH', BASE_PATH . '/data/sessions');
}
if( ! defined( 'SITE_ID' ) ) {
define( 'SITE_ID', $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI] );
}
if(!defined('THEMES')){
define("THEMES", BASE_PATH . "/themes");
}

0
components/editor/ace-editor/ext-options.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-asl.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-csound_document.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-csound_orchestra.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-csound_score.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-csp.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-edifact.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-graphqlschema.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-jssm.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-mixal.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-pig.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-red.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-redshift.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-sparql.js Normal file → Executable file
View file

0
components/editor/ace-editor/mode-turtle.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/asl.js Normal file → Executable file
View file

View file

View file

0
components/editor/ace-editor/snippets/csound_score.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/csp.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/edifact.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/graphqlschema.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/jssm.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/mixal.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/pig.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/red.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/redshift.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/sparql.js Normal file → Executable file
View file

0
components/editor/ace-editor/snippets/turtle.js Normal file → Executable file
View file

0
components/editor/ace-editor/theme-dracula.js Normal file → Executable file
View file

0
components/editor/ace-editor/theme-gob.js Normal file → Executable file
View file

0
components/editor/ace-editor/theme-gruvbox.js Normal file → Executable file
View file

View file

@ -1506,7 +1506,37 @@
break;
}
}
},
//////////////////////////////////////////////////////////////////
//
// Enable editor
//
// Parameters:
// i - {Editor} (Defaults to active editor)
//
//////////////////////////////////////////////////////////////////
enableEditing: function(i) {
i = i || this.getActive();
if (! i) return;
i.textInput.setReadOnly( false );
},
//////////////////////////////////////////////////////////////////
//
// Disable editor
//
// Parameters:
// i - {Editor} (Defaults to active editor)
//
//////////////////////////////////////////////////////////////////
disableEditing: function(i) {
i = i || this.getActive();
if (! i) return;
i.textInput.setReadOnly( true );
},
};

View file

@ -38,6 +38,7 @@ if( defined( "SITE_NAME" ) && ! ( SITE_NAME === "" || SITE_NAME === null ) ) {
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo htmlentities( $site_name ); ?></title>
<script>console.log( '<?php echo $site_name;?>' )</script>
<script src="./js/socket.io.js"></script>
<?php
// Load System CSS Files
$stylesheets = array("jquery.toastmessage.css","reset.css","fonts.css","screen.css");
@ -412,6 +413,13 @@ if( defined( "SITE_NAME" ) && ! ( SITE_NAME === "" || SITE_NAME === null ) ) {
<!-- ACE -->
<script src="components/editor/ace-editor/ace.js"></script>
<!-- Codiad System Variables -->
<script>
codiad.system = {};
codiad.system.site_id = `<?php echo SITE_ID;?>`;
codiad.system.session_id = `<?php echo SESSION_ID;?>`;
</script>
<!-- COMPONENTS -->
<?php
@ -435,6 +443,5 @@ if( defined( "SITE_NAME" ) && ! ( SITE_NAME === "" || SITE_NAME === null ) ) {
}
?>
</body>
</html>

8
js/socket.io.js Executable file

File diff suppressed because one or more lines are too long

View file

@ -4,4 +4,7 @@ This plugin adds collaborative functionallity to Codiad
# Installation
- Install Node.JS
- Install Socket.io
- Forward a port you are comfortable with and change the default port in the config.json
- Download the zip file and extract it to your plugins folder

View file

@ -1,28 +1,12 @@
<?php
/*
* Copyright (c) Codiad (codiad.com) & Florent Galland & Luc Verdier,
* Copyright (c) Codiad (codiad.com) & Isaac Brown (telaaedifex.com),
* distributed as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
/*
* Suppose a user wants to register as a collaborator of file '/test/test.js'.
* He registers to a specific file by creating a marker file
* 'data/_test_test.js%%filename%%username%%registered', and he can
* unregister by deleting this file. Then his current selection will be in
* file 'data/_test_test.js%%username%%selection'.
* The collaborative editing algorithm is based on the differential synchronization
* algorithm by Neil Fraser. The text shadow and server text are stored
* respectively in 'data/_test_test.js%%filename%%username%%shadow' and
* 'data/_test_test.js%%filename%%text'.
* At regular time intervals, the user send an heartbeat which is stored in
* 'data/_test_test.js%%username%%heartbeat' .
*/
require_once('../../common.php');
require_once('../../lib/diff_match_patch.php');
require_once('file_db.php');
//////////////////////////////////////////////////////////////////
// Verify Session or Key
@ -30,481 +14,6 @@
checkSession();
//////////////////////////////////////////////////////////////////
// Initialize Data Base
//////////////////////////////////////////////////////////////////
$collaborativeDataBase = new file_db(BASE_PATH . '/data/collaborative');
function &getDB() {
global $collaborativeDataBase;
return $collaborativeDataBase;
}
//////////////////////////////////////////////////////////////////
// Get Action
//////////////////////////////////////////////////////////////////
if(!isset($_POST['action']) || empty($_POST['action'])) {
exit(formatJSEND('error', 'No action specified'));
}
switch ($_POST['action']) {
case 'registerToFile':
/* Register as a collaborator for the given filename. */
if(!isset($_POST['filename']) || empty($_POST['filename'])) {
exit(formatJSEND('error', 'No filename specified in register'));
}
$isRegistered = registerToFile($_SESSION['user'], $_POST['filename']);
if ($isRegistered) {
echo formatJSEND('success');
} else {
// Should only be enabled when testing
//echo formatJSEND('success', 'Not registered as collaborator for ' . $_POST['filename']);
}
break;
case 'unregisterFromFile':
/* Unregister as a collaborator for the given filename. */
if(!isset($_POST['filename']) || empty($_POST['filename'])) {
exit(formatJSEND('error', 'No filename specified in unregister'));
}
$query = array('user' => $_SESSION['user'], 'filename' => $_POST['filename']);
$entry = getDB()->select($query, 'registered');
if ($entry != null) {
$entry->remove();
echo formatJSEND('success');
} else {
// Should only be enabled when testing
//echo formatJSEND('success', 'Not registered as collaborator for ' . $_POST['filename']);
echo formatJSEND('success');
}
break;
case 'unregisterFromAllFiles':
/* Find all the files for which the current user is registered as
* collaborator and unregister him. */
unregisterFromAllFiles($_SESSION['user']);
echo formatJSEND('success');
break;
case 'removeSelectionAndChangesForAllFiles':
$query = array('user' => $_SESSION['user'], 'filename' => '*');
$entries = getDB()->select($query, 'selection');
foreach($entries as $entry) {
$entry->remove();
}
$entries = getDB()->select($query, 'change');
foreach($entries as $entry) {
$entry->remove();
}
echo formatJSEND('success');
break;
case 'removeServerTextForAllFiles':
$entries = getDB()->select_group('text');
foreach($entries as $entry) $entry->remove();
echo formatJSEND('success');
break;
case 'sendSelectionChange':
/* Push the current selection to the server. */
if(!isset($_POST['filename']) || empty($_POST['filename'])) {
exit(formatJSEND('error', 'No Filename Specified in sendSelectionChange'));
}
if(!isset($_POST['selection']) || empty($_POST['selection'])) {
exit(formatJSEND('error', 'No selection specified in sendSelectionChange'));
}
/* If user is not already registerd for the given file, register him. */
if (!isUserRegisteredForFile($_POST['filename'], $_SESSION['user'])) {
$isRegistered = registerToFile($_POST['filename'], $_SESSION['user']);
if (!$isRegistered) {
// Should only be enabled when testing
//echo formatJSEND('success', 'Not registered as collaborator for ' . $_POST['filename']);
exit;
}
}
$selection = json_decode($_POST['selection']);
$query = array('user' => $_SESSION['user'], 'filename' => $_POST['filename']);
$entry = getDB()->create($query, 'selection');
$entry->put_value($selection);
echo formatJSEND('success');
break;
case 'getUsersAndSelectionsForFile':
/* Get an object containing all the users registered to the given file
* and their associated selections. The data corresponding to the
* current user is omitted. */
if(!isset($_POST['filename']) || empty($_POST['filename'])) {
exit(formatJSEND('error', 'No filename specified in getUsersAndSelectionsForFile'));
}
$filename = $_POST['filename'];
$usersAndSelections = array();
$users = getRegisteredUsersForFile($filename);
foreach ($users as $user) {
if ($user !== $_SESSION['user']) {
$selection = getSelection($filename, $user);
if (!empty($selection)) {
$data = array(
"selection" => $selection,
"color" => getColorForUser($user)
);
$usersAndSelections[$user] = $data;
}
}
}
echo formatJSEND('success', $usersAndSelections);
break;
case 'sendShadow':
if(!isset($_POST['filename']) || empty($_POST['filename'])) {
exit(formatJSEND('error', 'No filename specified in sendShadow'));
}
if(!isset($_POST['shadow'])) {
exit(formatJSEND('error', 'No shadow specified in sendShadow'));
}
$filename = $_POST['filename'];
$clientShadow = $_POST['shadow'];
setShadow($filename, $_SESSION['user'], $clientShadow);
/* If there is no server text for $filename or if there is still no or
* only one user registered for $filename, set the server text equal
* to the shadow. */
$registeredUsersForFileCount = count(getRegisteredUsersForFile($filename));
if (!existsServerText($filename) || $registeredUsersForFileCount == 0) {
setServerText($filename, $clientShadow);
}
echo formatJSEND('success');
break;
case 'synchronizeText':
if(!isset($_POST['filename']) || empty($_POST['filename'])) {
exit(formatJSEND('error', 'No filename specified in synchronizeText'));
}
if(!isset($_POST['patch'])) {
exit(formatJSEND('error', 'No patch specified in synchronizeText'));
}
$query = array('filename' => $_POST['filename']);
$serverTextEntry = getDB()->select($query, 'text');
if ($serverTextEntry == null) {
exit(formatJSEND('error', 'Inconsistent sever text filename in synchronizeText: ' . $serverTextEntry));
}
$query = array('user' => $_SESSION['user'], 'filename' => $_POST['filename']);
$shadowTextEntry = getDB()->select($query, 'shadow');
if ($shadowTextEntry == null) {
exit(formatJSEND('error', 'Inconsistent sever text filename in synchronizeText: ' . $shadowTextEntry));
}
/* First acquire a lock or wait until a lock can be acquired for server
* text and shadow. */
$serverTextEntry->lock();
$shadowTextEntry->lock();
$serverText = $serverTextEntry->get_value();
$shadowText = $shadowTextEntry->get_value();
$patchFromClient = $_POST['patch'];
/* Patch the shadow and server texts with the edits from the client. */
$dmp = new diff_match_patch();
$patchedServerText = $dmp->patch_apply($dmp->patch_fromText($patchFromClient), $serverText);
$serverTextEntry->put_value($patchedServerText[0]);
$patchedShadowText = $dmp->patch_apply($dmp->patch_fromText($patchFromClient), $shadowText);
/* Make a diff between server text and shadow to get the edits to send
* back to the client. */
$patchFromServer = $dmp->patch_toText($dmp->patch_make($patchedShadowText[0], $patchedServerText[0]));
/* Apply it to the shadow. */
$patchedShadowText = $dmp->patch_apply($dmp->patch_fromText($patchFromServer), $patchedShadowText[0]);
$shadowTextEntry->put_value($patchedShadowText[0]);
/* Release locks. */
$serverTextEntry->unlock();
$shadowTextEntry->unlock();
echo formatJSEND('success', $patchFromServer);
break;
case 'sendHeartbeat':
/* Hard coded heartbeat time interval. Beware to keep this value here
* twice the value on client side. */
$maxHeartbeatInterval = 5;
$currentTime = time();
/* Check if the user is a new user, or if it is just an update of
* his heartbeat. */
$isUserNewlyConnected = true;
$query = array('user' => $_SESSION['user']);
$entry = getDB()->select($query, 'heartbeat');
if($entry != null) {
$heartbeatTime = $entry->get_value();
$heartbeatInterval = $currentTime - $heartbeatTime;
$isUserNewlyConnected = ($heartbeatInterval > 1.5*$maxHeartbeatInterval);
/* If the user is newly connected and if the heartbeat file
* exits, that mean that the user was the latest in the previous
* collaborative session. We need to call the disconnect method
* to clear the data relatives to the user before calling the
* connect method. */
if($isUserNewlyConnected) {
onCollaboratorDisconnect($_SESSION['user']);
}
}
updateHeartbeatMarker($_SESSION['user']);
/* If the user is newly connected, we fire the
* corresponding method. */
if($isUserNewlyConnected) {
onCollaboratorConnect($_SESSION['user']);
}
$usersAndHeartbeatTime = getUsersAndHeartbeatTime();
foreach ($usersAndHeartbeatTime as $user => $heartbeatTime) {
if (($currentTime - $heartbeatTime) > $maxHeartbeatInterval) {
/* The $user heartbeat time is too old, consider him dead and
* remove his 'registered' and 'heartbeat' marker files. */
unregisterFromAllFiles($user);
removeHeartbeatMarker($user);
onCollaboratorDisconnect($user);
}
}
/* Return the number of connected collaborators. */
$collaboratorCount = count(getUsersAndHeartbeatTime());
$data = array();
$data['collaboratorCount'] = $collaboratorCount;
echo formatJSEND('success', $data);
break;
default:
exit(formatJSEND('error', 'Unknown Action ' . $_POST['action']));
}
// --------------------
/* $filename must contain only the basename of the file. */
function isUserRegisteredForFile($filename, $user) {
$query = array('user' => $user, 'filename' => $filename);
$entry = getDB()->select($query, 'registered');
return ($entry != null);
}
/* Unregister the given user from all the files by removing his
* 'registered' marker file. */
function unregisterFromAllFiles($user) {
$query = array('user' => $user, 'filename' => '*');
$entries = getDB()->select($query, 'registered');
foreach($entries as $entry) {
$entry->remove();
}
}
/* Register as a collaborator for the given filename. Return false if
* failed. */
function registerToFile($user, $filename) {
$query = array('user' => $user, 'filename' => $filename);
$entry = getDB()->select($query, 'registered');
if ($entry != null) {
debug('Warning: already registered as collaborator for ' . $filename);
return true;
} else {
$entry = getDB()->create($query, 'registered');
if ($entry != null) {
return true;
} else {
debug('Error: unable to register as collaborator for ' . $filename);
return false;
}
}
}
/* Touch the heartbeat marker file for the given user. Return true on
* success, false on failure. */
function updateHeartbeatMarker($user) {
$query = array('user' => $user);
$entry = getDB()->create($query, 'heartbeat');
if($entry == null) return false;
$entry->put_value(time());
return true;
}
function removeHeartbeatMarker($user) {
$query = array('user' => $user);
$entry = getDB()->select($query, 'heartbeat');
if($entry != null) $entry->remove();
}
/* Return an array containing the user as key and his last heartbeat time
* as value. */
function &getUsersAndHeartbeatTime() {
$usersAndHeartbeatTime = array();
$query = array('user' => '*');
$entries = getDB()->select($query, 'heartbeat');
foreach($entries as $entry) {
$user = $entry->get_field('user');
$usersAndHeartbeatTime[$user] = $entry->get_value();
}
return $usersAndHeartbeatTime;
}
/* $filename must contain only the basename of the file. */
function &getRegisteredUsersForFile($filename) {
$usernames = array();
$query = array('user' => '*', 'filename' => $filename);
$entries = getDB()->select($query, 'registered');
foreach($entries as $entry) {
$user = $entry->get_field('user');
$usernames[] = $user;
}
return $usernames;
}
/* Return the selection object, if any, for the given filename and user.
* $filename must contain only the basename of the file. */
function getSelection($filename, $user) {
$query = array('user' => $user, 'filename' => $filename);
$entry = getDB()->select($query, 'selection');
if($entry == null) return null;
return $entry->get_value();
}
/* Return the list of changes, if any, for the given filename, user and
* from the given revision number.
* $filename must contain only the basename of the file. */
function getChanges($filename, $user, $fromRevision) {
$query = array('user' => $user, 'filename' => $filename);
$entry = getDB()->select($query, 'change');
if($entry == null) return null;
return array_slice($entry->get_value(), $fromRevision, NULL, true);
}
/* Set the server shadow acquiring an exclusive lock on the file. $shadow
* is a string. */
function setShadow($filename, $user, $shadow) {
$query = array('user' => $user, 'filename' => $filename);
$entry = getDB()->create($query, 'shadow');
if($entry == null) return null;
$entry->put_value($shadow);
}
/* Return the shadow for the given filename as a string or an empty string
* if no shadow exists. */
function getShadow($filename, $user) {
$query = array('user' => $user, 'filename' => $filename);
$entry = getDB()->select($query, 'shadow');
if($entry == null) return null;
return $entry->get_value();
}
function existsServerText($filename) {
$query = array('filename' => $filename);
$entry = getDB()->select($query, 'text');
return ($entry != null);
}
/* Set the server text acquiring an exclusive lock on the file. $serverText
* is a string. */
function setServerText($filename, $serverText) {
$query = array('filename' => $filename);
$entry = getDB()->create($query, 'text');
if($entry == null) return null;
$entry->put_value($serverText);
}
/* Return the server text for the given filename as a string or an empty string
* if no server text exists. */
function getServerText($filename) {
$query = array('filename' => $filename);
$entry = getDB()->select($query, 'text');
if($entry == null) return null;
return $entry->get_value();
}
/* Return the color of the given user. */
function getColorForUser($user) {
/* Check if the color is already defined for the
* user. */
$query = array('user' => $user);
$entry = getDB()->select($query, 'color');
if ($entry != null) {
return $entry->get_value();
}
/* If the color is not defined for the given user,
* we pick an unused color. */
$colors = array(
"#0000FF",
"#FF0000",
"#00FF00",
"#FF00FF",
"#0F00F0",
"#F0000F",
"#0F0F0F",
"#F0F0F0"
);
/* Retreive all used colors. */
$query = array('user' => '*');
$entries = getDB()->select($query, 'color');
$usedColors = array();
foreach ($entries as $entry) {
$usedColors[] = $entry->get_value();
}
$colors = array_diff($colors, $usedColors);
if(count($colors) > 0) {
$color = array_shift($colors);
}
else {
$color = "#FFFFFF";
}
/* Save the picked color. */
$query = array('user' => $user);
$entry = getDB()->create($query, 'color');
$entry->put_value($color);
return $color;
}
/* Remove the color file for the given user. */
function resetColorForUser($user) {
$query = array('user' => $user);
$entry = getDB()->create($query, 'color');
if($entry != null) $entry->remove();
}
/* This function is called when a new collaborator
/* is connected. */
function onCollaboratorConnect($user) {
//debug('User connected: '.$user);
}
/* This function is called when a collaborator is
* disconnected. */
function onCollaboratorDisconnect($user) {
//debug('User disconnected: '.$user);
resetColorForUser($user);
}
?>

View file

@ -1,307 +0,0 @@
<?php
/*
* Copyright (c) Luc Verdier & Florent Galland, distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
/*
* Suppose a user wants to register as a collaborator of file '/test/test.js'.
* He registers to a specific file by creating a marker file
* 'data/_test_test.js%%filename%%username%%registered', and he can
* unregister by deleting this file. Then his current selection will be in
* file 'data/_test_test.js%%username%%selection'.
* The collaborative editing algorithm is based on the differential synchronization
* algorithm by Neil Fraser. The text shadow and server text are stored
* respectively in 'data/_test_test.js%%filename%%username%%shadow' and
* 'data/_test_test.js%%filename%%text'.
* At regular time intervals, the user send an heartbeat which is stored in
* 'data/_test_test.js%%username%%heartbeat' .
*/
/* */
class file_db {
/* They should be the same as those
* in the file_db_entry class. */
private $separator = '|';
private $separator_regex = '\|';
private $key_value_separator = ':';
private $key_value_separator_regex = '\:';
private $index_name = 'index.db';
private $base_path;
function __construct($base_path) {
$this->base_path = $base_path;
if(!is_dir($base_path)) {
mkdir($base_path);
}
}
/* Create a new entry into the data base. */
public function create($query, $group=null) {
$query = $this->_normalize_query($query);
if(!$this->_is_direct_query($query)) {
return null;
}
$base_path = $this->base_path;
if($group != null) {
$base_path .= '/' . $group;
}
$index_file = $base_path . '/' . $this->index_name;
if(!is_dir($base_path)) {
mkdir($base_path);
}
$entry_name = $this->_make_entry_name($query);
$entry_hash = md5($entry_name);
$entry_file = $base_path . '/' . $entry_hash;
if(!file_exists($entry_file)) {
if(!file_exists($index_file)) {
touch($index_file);
}
$entry = $entry_name . '>' . $entry_hash . '>' . PHP_EOL;
file_put_contents($index_file, $entry, FILE_APPEND | LOCK_EX);
touch($entry_file);
}
$entry = new file_db_entry($entry_name, $entry_file, $index_file, $group);
$entry->clear();
if(file_exists($entry_file)) {
return $entry;
}
return null;
}
/* Get the content for the given query. */
public function select($query, $group=null) {
$query = $this->_normalize_query($query);
$base_path = $this->base_path;
if($group != null) {
$base_path .= '/' . $group;
}
$index_file = $base_path . '/' . $this->index_name;
if($this->_is_direct_query($query)) {
$entry_name = $this->_make_entry_name($query);
$entry_hash = md5($entry_name);
$entry_file = $base_path . '/' . $entry_hash;
if(file_exists($entry_file)) {
return new file_db_entry($entry_name, $entry_file, $index_file, $group);
}
return null;
}
$entries = array();
if(file_exists($index_file)) {
$regex = $this->_make_regex($query);
$file = fopen($index_file, 'r');
while(!feof($file)) {
$line = fgets($file);
if (preg_match($regex, $line, $matches)) {
$entry_file = $base_path . '/' . $matches[2];
if(file_exists($entry_file)) {
$entries[] = new file_db_entry($matches[1], $entry_file, $index_file, $group);
}
}
}
fclose($file);
}
return $entries;
}
/* Select all entries into the given group. */
public function select_group($group) {
$entries = array();
$base_path = $this->base_path . '/' . $group;
$index_file = $base_path . '/' . $this->index_name;
if(file_exists($index_file)) {
$sep = $this->separator_regex;
$regex = '/(' . $sep . '.*?' . $sep . ')\>(.*?)\>/';
$file = fopen($index_file, 'r');
while(!feof($file)) {
$line = fgets($file);
if (preg_match($regex, $line, $matches)) {
$entry_file = $base_path . '/' . $matches[2];
$entries[] = new file_db_entry($matches[1], $entry_file, $index_file, $group);
}
}
fclose($file);
}
return $entries;
}
/* Make the regex for the given query. */
private function _make_regex($query) {
$regex = '/(' . $this->separator_regex;
foreach($query as $key => $value) {
$regex .= $key . $this->key_value_separator_regex;
if($value == '%2A') { // %2A=*
$regex .= '.*?';
}
else {
$regex .= $value;
}
$regex .= $this->separator_regex;
}
$regex .= ')' . '\>(.*?)\>' . '/';
return $regex;
}
/* Make an entry name from the given normalized query. */
private function _make_entry_name($query) {
$filename = $this->separator;
foreach($query as $key => $value) {
$filename .= $key . $this->key_value_separator . $value;
$filename .= $this->separator;
}
return $filename;
}
/* Check if the given query is a direct query. */
private function _is_direct_query($query) {
foreach($query as $key => $value) {
if($value == '%2A'){ // %2A=*
return false;
}
}
return true;
}
/* Normalize the given query. */
private function &_normalize_query(&$query) {
ksort($query);
foreach($query as $key => $value) {
$query[$key] = rawurlencode($value);
}
return $query;
}
}
/* */
class file_db_entry {
/* They should be the same as those
* in the file_db class. */
private $separator = '|';
private $separator_regex = '\|';
private $key_value_separator = ':';
private $key_value_separator_regex = '\:';
private $entry_name;
private $entry_hash;
private $entry_file;
private $index_file;
private $group;
private $handler;
/* Construct the entry with the given filename. */
public function __construct($entry_name, $entry_file, $index_file, $group) {
$this->entry_name = $entry_name;
$this->entry_file = $entry_file;
$this->index_file = $index_file;
$this->group = $group;
}
/* Get the value of the field with the given name. */
public function get_field($name) {
$regex = '/'
. $this->separator_regex
. rawurlencode($name)
. $this->key_value_separator_regex
. '(.*?)' . $this->separator_regex
. '/';
if(preg_match($regex, $this->entry_name, $matches)) {
return rawurldecode($matches[1]);
}
return null;
}
/* Get the group name of the entry. */
public function get_group() {
return $this->group;
}
/* Set the value of the entry. */
public function put_value($value) {
file_put_contents($this->entry_file, serialize($value), LOCK_EX);
}
/* Get the value of the entry. */
public function get_value() {
if(file_exists($this->entry_file)) {
return unserialize(file_get_contents($this->entry_file));
}
return null;
}
/* Remove the entry. */
public function remove() {
$success = false;
if(file_exists($this->index_file)) {
$lines = file($this->index_file, FILE_SKIP_EMPTY_LINES);
$file = fopen($this->index_file, 'w');
flock($file, LOCK_EX);
foreach($lines as $line) {
if (strpos($line, $this->entry_name) !== 0) {
fwrite($file, $line);
}
else {
$success = true;
}
}
flock($file, LOCK_UN);
fclose($file);
}
if($success && file_exists($this->entry_file)) {
unlink($this->entry_file);
return true;
}
return false;
}
/* Clear the value of the entry. */
public function clear() {
$this->put_value('');
}
/* Lock the entry. */
public function lock() {
$lock = $this->entry_file . '.lock';
while(file_exists($lock)) {
usleep(100);
}
touch($this->entry_file . '.lock');
}
/* Unlock the entry. */
public function unlock() {
$lock = $this->entry_file . '.lock';
if(file_exists($lock)) {
unlink($lock);
}
}
}
?>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) Codiad (codiad.com) & Florent Galland & Luc Verdier,
* Copyright (c) Codiad (codiad.com) & Isaac Brown (telaaedifex.com),
* distributed as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
@ -7,21 +7,221 @@
(function (global, $) {
var codiad = global.codiad,
scripts= document.getElementsByTagName('script'),
scripts = document.getElementsByTagName('script'),
path = scripts[scripts.length-1].src.split('?')[0],
curpath = path.split('/').slice(0, -1).join('/')+'/';
/* FIXME Dynamically load diff match patch lib. Is there any better way? */
$.getScript('lib/diff_match_patch.js');
var site_id = codiad.system.site_id;
var session_id = window.session_id;
var editor = null;
var collaborator = null;
var buffer_dumped = false;
var last_applied_change = null;
var just_cleared_buffer = null;
var current_editor = codiad.active.getPath();
var just_opened = false;
var loaded = false;
var initial = false;
var loading = true;
var codiad = global.codiad;
function Collaborator( file_path, session_id ) {
$(function () {
if (typeof(codiad.collaborative) == 'undefined') {
codiad.collab.init();
} else {
codiad.modal.load(400, curpath+"dialog.php?action=warn");
this.collaboration_socket = null
let file_id = btoa( current_editor );
this.collaboration_socket = io.connect( "https://local.telaaedifex.com:1337", {'forceNew': true, query:'?session=' + session_id + "&file=" + site_id + current_editor} );
this.collaboration_socket.on( "change", function(delta) {
if( current_editor !== codiad.active.getPath() || editor === null ) {
return;
}
delta = JSON.parse( delta ) ;
last_applied_change = delta ;
editor.getSession().getDocument().applyDeltas( [delta] ) ;
}.bind() );
this.collaboration_socket.on( "clear_buffer", function() {
just_cleared_buffer = true ;
console.log( "setting editor contents" ) ;
editor.setValue( "" ) ;
}.bind() );
this.collaboration_socket.on( "recieve_init", function(delta) {
delta = JSON.parse( delta ) ;
console.log( 'Recieved dump buffer JSON', delta.message, delta.initial );
initial = delta.initial;
if ( delta.initial === true ) {
console.log( 'Setting initial content...' );
codiad.editor.setContent( '' );
codiad.editor.setContent( delta.content )
inital = false;
}
}.bind() );
this.collaboration_socket.on( "recieve_content", function( ) {
console.log( 'Someone is joining...' );
// Remove change callback
editor.removeEventListener( "change", handle_change );
codiad.editor.disableEditing();
codiad.editor.setContent( '' );
collaborator.dump_buffer();
// registering change callback
editor.addEventListener( "change", handle_change );
setTimeout(function(){codiad.editor.enableEditing();}, 500);
}.bind() );
window.collaboration_socket = this.collaboration_socket;
}
Collaborator.prototype.change = function( delta ) {
this.collaboration_socket.emit( "change", delta );
}
Collaborator.prototype.clear_buffer = function() {
this.collaboration_socket.emit( "clear_buffer" );
}
Collaborator.prototype.disconnect = function() {
this.collaboration_socket.emit( "disconnect" );
}
Collaborator.prototype.dump_buffer = function() {
this.collaboration_socket.emit( "dump_buffer" );
}
Collaborator.prototype.send_init = function( content ) {
this.collaboration_socket.emit( "send_init", content );
}
function handle_change( e ) {
// TODO, we could make things more efficient and not likely to conflict by keeping track of change IDs
if( last_applied_change!=e && !just_cleared_buffer ) {
collaborator.change( JSON.stringify(e) );
}
just_cleared_buffer = false;
}
function close() {
if( typeof window.collaboration_socket === 'undefined' ) {
return;
}
if( window.collaboration_socket !== null ) {
window.collaboration_socket.disconnect();
}
if( editor !== null ) {
editor.removeEventListener( "change", handle_change );
}
editor = null;
loaded = false;
//current_editor = null;
window.collaboration_socket = null;
console.log( 'Cleared buffer and closed editor.' );
}
function body_loaded() {
if( collaborator !== null && editor !== null && initial === false ) {
if( last_applied_change !== null ) {
editor.setValue( "" )
collaborator.dump_buffer()
}
//document.getElementsByTagName('textarea')[0].focus() ;
last_applied_change = null ;
just_cleared_buffer = false ;
return;
}
current_editor = codiad.active.getPath();
editor = ace.edit( codiad.editor.getActive() );
if( editor === null ) {
return;
}
let content = null;
collaborator = new Collaborator( session_id );
//collaborator.open_file( )
content = codiad.editor.getContent()
codiad.editor.setContent( '' )
collaborator.send_init( content )
// registering change callback
editor.addEventListener( "change", handle_change );
//editor.setTheme( "ace/theme/monokai") ;
editor.$blockScrolling = Infinity;
//collaborator.dump_buffer();
let dumped_content = null;
dumped_content = codiad.editor.getContent()
collaborator.dump_buffer();
loaded = true;
}
collaborator = new Collaborator( session_id );
collaborator.send_init()
if( window.collaboration_socket !== null ) {
window.collaboration_socket.disconnect();
}
/* Subscribe to know when a file is being closed. */
amplify.subscribe('active.onClose', function (path) {
close()
});
$(window).blur(function() {
close();
});
/* Subscribe to know when a file become active. */
amplify.subscribe('active.onFocus', function (path) {
just_opened = true;
if( current_editor !== codiad.active.getPath() && current_editor !== null ) {
console.log( 'Closing Socket' );+
close();
}
console.log( 'Last Editor: ' + current_editor );
if( loaded === false ) {
console.log( 'Loading Body' );
body_loaded();
}
console.log( 'Focused Editor: ' + codiad.active.getPath() );
});
//////////////////////////////////////////////////////////////////
@ -33,615 +233,7 @@
//
//////////////////////////////////////////////////////////////////
codiad.collab = {
controller: curpath + 'controller.php',
/* The filename of the file to wich we are currently registered as a
* collaborator. Might be null if we are not collaborating to any file. */
currentFilename: null,
/* Store the text shadows for every edited files.
* {'filename': shadowString, ... } */
shadows: {},
/* Store the currently displayed usernames and their corresponding
* current selection.
* [username: {start: {row: 12, column: 14}, end: {row: 14, column: 19}}, ... ] */
displayedSelections: [],
/* Time interval in milisecond to send an heartbeat to the server. */
heartbeatInterval: 5000,
/* Status of the collaboration logic. */
enableCollaboration: false,
init: function () {
var _this = this;
/* Make sure to start clean by unregistering from any file first. */
this.unregisterAsCollaboratorFromAllFiles();
this.removeSelectionAndChangesForAllFiles();
/* TODO For debug only, remove this for production. */
//this.removeServerTextForAllFiles();
this.$onSelectionChange = this.onSelectionChange.bind(this);
this.$onChange = this.onChange.bind(this);
this.$postSelectionChange = this.postSelectionChange.bind(this);
this.$updateCollaboratorsSelections = this.updateCollaboratorsSelections.bind(this);
this.$displaySelections = this.displaySelections.bind(this);
this.$synchronizeText = this.synchronizeText.bind(this);
this.$postSynchronizeText = this.postSynchronizeText.bind(this);
this.$sendHeartbeat = this.sendHeartbeat.bind(this);
/* Subscribe to know when a file is being closed. */
amplify.subscribe('active.onClose', function (path) {
if (_this.currentFilename === path) {
_this.unregisterAsCollaboratorOfCurrentFile();
_this.removeAllSelections();
}
});
/* Subscribe to know when a file become active. */
amplify.subscribe('active.onFocus', function (path) {
_this.unregisterAsCollaboratorOfCurrentFile();
_this.registerAsCollaboratorOfActiveFile();
/* Create the initial shadow for the current file. */
_this.shadows[_this.currentFilename] = _this._getCurrentFileText();
_this.sendAsShadow(_this.currentFilename, _this.shadows[_this.currentFilename]);
_this.addListeners();
});
/* Start to send an heartbeat to notify the server that we are
* alive. */
setInterval(this.$sendHeartbeat, this.heartbeatInterval);
/* Start the collaboration logic. */
this.setCollaborationStatus(true);
$(".collaborative-selection,.collaborative-selection-tooltip").live({
mouseenter: function () {
var markup = $(this).parent();
_this.showTooltipForMarkup(markup);
},
mouseleave: function () {
var markup = $(this).parent();
_this.showTooltipForMarkup(markup, 500);
}
});
},
/* Start or stop the collaboration logic. */
setCollaborationStatus: function (enableCollaboration) {
/* Some static variables to hold the setInterval reference. */
if (typeof this.setCollaborationStatus.updateSelectionsIntervalRef === 'undefined') {
this.setCollaborationStatus.updateSelectionsIntervalRef = null;
}
if (typeof this.setCollaborationStatus.synchronizeTextIntervalRef === 'undefined') {
this.setCollaborationStatus.synchronizeTextIntervalRef = null;
}
if (enableCollaboration && !this.enableCollaboration) {
console.log('Starting collaboration logic.');
this.enableCollaboration = true;
/* Start to ask periodically for the potential other collaborators
* selection. */
this.setCollaborationStatus.updateSelectionsIntervalRef =
setInterval(this.$updateCollaboratorsSelections, 500);
/* Start to ask periodically for the potential other collaborators
* changes. */
this.setCollaborationStatus.synchronizeTextIntervalRef =
setInterval(this.$synchronizeText, 500);
/* Sync right away for responsiveness - there's often already a
* server copy of the collab file */
this.$synchronizeText();
} else if (!enableCollaboration && this.enableCollaboration) {
console.log('Stopping collaboration logic.');
this.enableCollaboration = false;
clearInterval(this.setCollaborationStatus.updateSelectionsIntervalRef);
clearInterval(this.setCollaborationStatus.synchronizeTextIntervalRef);
this.removeAllSelections();
}
},
removeSelectionAndChangesForAllFiles: function () {
$.post(this.controller,
{ action: 'removeSelectionAndChangesForAllFiles' },
function (data) {
// console.log('complete unregistering from all');
// console.log(data);
codiad.jsend.parse(data);
});
},
removeServerTextForAllFiles: function () {
$.post(this.controller,
{ action: 'removeServerTextForAllFiles' },
function (data) {
// console.log('complete unregistering from all');
// console.log(data);
codiad.jsend.parse(data);
});
},
unregisterAsCollaboratorFromAllFiles: function () {
$.post(this.controller,
{ action: 'unregisterFromAllFiles' },
function (data) {
// console.log('complete unregistering from all');
// console.log(data);
codiad.jsend.parse(data);
});
},
registerAsCollaboratorOfActiveFile: function () {
var filename = codiad.active.getPath();
this.currentFilename = filename;
$.post(this.controller,
{ action: 'registerToFile', filename: filename },
function (data) {
// console.log('complete registering');
// console.log(data);
codiad.jsend.parse(data);
});
},
unregisterAsCollaboratorOfCurrentFile: function () {
// console.log('unregister ' + this.currentFilename);
if (this.currentFilename !== null) {
$.post(this.controller,
{ action: 'unregisterFromFile', filename: this.currentFilename },
function (data) {
// console.log('complete unregistering');
// console.log(data);
codiad.jsend.parse(data);
});
this.currentFilename = null;
}
},
sendHeartbeat: function () {
var _this = this;
$.post(this.controller,
{ action: 'sendHeartbeat' },
function (data) {
/* The data returned by the server contains the number
* of connected collaborators. */
data = codiad.jsend.parse(data);
if (data.collaboratorCount > 1) {
/* Someone else is connected, start the
* collaboration logic. */
_this.setCollaborationStatus(true);
} else {
/* We are the only conected user, stop the
* collaboration logic. */
_this.setCollaborationStatus(false);
}
});
},
/* Add appropriate listeners to the current EditSession. */
addListeners: function () {
this.addListenerToOnSelectionChange();
this.addListenerToOnChange();
},
/* Remove listeners from the current EditSession. */
removeListeners: function () {
this.removeListenerToOnSelectionChange();
this.removeListenerToOnChange();
},
addListenerToOnSelectionChange: function () {
var selection = this._getSelection();
selection.addEventListener('changeCursor', this.$onSelectionChange);
selection.addEventListener('changeSelection', this.$onSelectionChange);
},
removeListenerToOnSelectionChange: function () {
var selection = this._getSelection();
selection.removeEventListener('changeCursor', this.$onSelectionChange);
selection.removeEventListener('changeSelection', this.$onSelectionChange);
},
addListenerToOnChange: function () {
var editor = this._getEditor();
editor.addEventListener('change', this.$onChange);
},
removeListenerToOnChange: function () {
var editor = this._getEditor();
editor.removeEventListener('change', this.$onChange);
},
onChange: function(e) {
this.$synchronizeText();
},
/* Throttling mechanism for postSelectionChange */
onSelectionChange: function (e) {
var minInterval = 250;
var now = new Date().getTime();
if (typeof(this.onSelectionChange.lastSelectionChange) === 'undefined') {
this.onSelectionChange.lastSelectionChange = now;
}
var interval = now - this.onSelectionChange.lastSelectionChange;
this.onSelectionChange.lastSelectionChange = now;
if (interval < minInterval) {
var intervalDifference = minInterval - interval;
clearTimeout(this.onSelectionChange.deferredPost);
this.onSelectionChange.deferredPost = setTimeout(this.$postSelectionChange, intervalDifference);
}
else {
this.$postSelectionChange();
}
},
postSelectionChange: function () {
var post = { action: 'sendSelectionChange',
filename: codiad.active.getPath(),
selection: JSON.stringify(this._getSelection().getRange()) };
$.post(this.controller, post, function (data) {
// console.log('complete selection change');
// console.log(data);
codiad.jsend.parse(data);
});
},
/* Request the server for the collaborators selections for the current
* file. */
updateCollaboratorsSelections: function () {
var _this = this;
if (this.currentFilename !== null) {
$.post(this.controller,
{ action: 'getUsersAndSelectionsForFile', filename: this.currentFilename },
function (data) {
// console.log('complete getUsersAndSelectionsForFile');
// console.log(data);
var selections = codiad.jsend.parse(data);
_this.$displaySelections(selections);
/* The server returned the selections for the
* currently active users. If a user which is no
* more active has a visible selection, remove it. */
if (_this.displayedSelections !== null) {
for (var username in _this.displayedSelections) {
if (_this.displayedSelections.hasOwnProperty(username)) {
if (selections === null || !(username in selections)) {
_this.removeSelection(username);
}
}
}
}
_this.displayedSelections = selections;
});
}
},
/* Displays a selection in the current file for the given user.
* The expected selection object is compatible with what is returned
* from the getUsersAndSelectionsForFile action on the server
* controller.
* Selection object example:
* {username: {start: {row: 12, column: 14}, end: {row: 14, column: 19}}} */
displaySelections: function (selections) {
// console.log('displaySelection');
for (var username in selections) {
if (selections.hasOwnProperty(username)) {
var markup = $('#selection-' + username);
if (markup.length === 0) {
/* The markup for the selection of this user does not
* exist yet. Append it to the dom. */
markup = $(this.getSelectionMarkupForUser(username));
$('body').append(markup);
}
var screenCoordinates = this._getEditor().renderer
.textToScreenCoordinates(selections[username].selection.start.row,
selections[username].selection.start.column);
/* Check if the selection has changed. */
if (markup.css('left').slice(0, -2) !== String(screenCoordinates.pageX) ||
markup.css('top').slice(0, -2) !== String(screenCoordinates.pageY)) {
markup.css({
left: screenCoordinates.pageX,
top: screenCoordinates.pageY
});
markup.children('.collaborative-selection').css('background-color', selections[username].color);
markup.children('.collaborative-selection-tooltip').css('background-color', selections[username].color);
this.showTooltipForMarkup(markup, 2000);
}
}
}
},
/* Show the tooltip of the given markup. If duration is defined,
* the tooltip is automaticaly hidden when the time is elapsed. */
showTooltipForMarkup: function (markup, duration) {
var timeoutRef = markup.attr('hideTooltipTimeoutRef');
if (timeoutRef !== undefined) {
clearTimeout(timeoutRef);
markup.removeAttr('hideTooltipTimeoutRef');
}
markup.children('.collaborative-selection-tooltip').fadeIn('fast');
if (duration !== undefined) {
timeoutRef = setTimeout(this._hideTooltipAndRemoveAttrForBoundMarkup.bind(markup), duration);
markup.attr('hideTooltipTimeoutRef', timeoutRef);
}
},
/* This function must be bound with the markup which contains
* the tooltip to hide. */
_hideTooltipAndRemoveAttrForBoundMarkup: function () {
this.children('.collaborative-selection-tooltip').fadeOut('fast');
this.removeAttr('hideTooltipTimeoutRef');
},
/* Remove the selection corresponding to the given username. */
removeSelection: function (username) {
console.log('remove ' + username);
$('#selection-' + username).remove();
delete this.displayedSelections[username];
},
/* Remove all the visible selections. */
removeAllSelections: function () {
if (this.displayedSelections !== null) {
for (var username in this.displayedSelections) {
if (this.displayedSelections.hasOwnProperty(username)) {
this.removeSelection(username);
}
}
}
},
/* Throttling mechanism for postSynchronizeText */
synchronizeText: function () {
var _this = this;
var now = new Date().getTime();
var minInterval = 350;
if (typeof(this.synchronizeText.lastRun) === 'undefined') {
this.synchronizeText.lastRun = now;
}
var interval = now - this.synchronizeText.lastRun;
var _this = this;
var successCallback = function() {
_this.synchronizeText.lastRun = now;
_this.$postSynchronizeText();
};
clearTimeout(this.synchronizeText.deferredPost);
if (interval < minInterval) {
var intervalDifference = minInterval - interval;
this.synchronizeText.deferredPost = setTimeout(successCallback, intervalDifference);
}
else {
successCallback();
}
},
/* Make a diff of the current file text with the shadow and send it to
* the server. */
postSynchronizeText: function () {
var _this = this;
var currentFilename = this.currentFilename;
/* Do not send any request if no file is focused. */
if (currentFilename === null) {
return;
}
/* Save the current text state, because it can be modified by the
* user on the UI thread. */
var currentText = this._getCurrentFileText();
/* Make a diff between the current text and the previously saved
* shadow. */
codiad.workerManager.addTask({
taskType: 'diff',
id: 'collaborative_' + currentFilename,
original: _this.shadows[currentFilename],
changed: currentText
}, function (success, patch) {
if (success) {
/* Send our edits to the server, and get in response a
* patch of the edits in the server text. */
// console.log(patch);
_this.shadows[currentFilename] = currentText;
var post = { action: 'synchronizeText',
filename: currentFilename,
patch: patch };
// console.log(post);
$.post(this.controller, post, function (data) {
// console.log('complete synchronizeText');
// console.log(data);
var patchFromServer = codiad.jsend.parse(data);
if (patchFromServer === 'error') { return; }
// console.log(patchFromServer);
/* Apply the patch from the server text to the shadow
* and the current text. */
var dmp = new diff_match_patch();
var patchedShadow = dmp.patch_apply(dmp.patch_fromText(patchFromServer), _this.shadows[currentFilename]);
// console.log(patchedShadow);
_this.shadows[currentFilename] = patchedShadow[0];
/* Update the current text. */
currentText = _this._getCurrentFileText();
var patchedCurrentText = dmp.patch_apply(dmp.patch_fromText(patchFromServer), currentText)[0];
var diff = dmp.diff_main(currentText, patchedCurrentText);
var deltas = _this.diffToAceDeltas(diff, currentText);
_this._getDocument().applyDeltas(deltas);
});
} else {
console.log('problem diffing');
console.log(patch);
}
}, this);
},
/* Send the string 'shadow' as server shadow for 'filename'. */
sendAsShadow: function (filename, shadow) {
$.post(this.controller,
{ action: 'sendShadow',
filename: filename,
shadow: shadow },
function (data) {
// console.log('complete sendShadow');
// console.log(data);
codiad.jsend.parse(data);
});
},
/* Helper method that return a Ace editor delta change from a
* diff_match_patch diff object and the original text that was
* used to compute the diff. */
diffToAceDeltas: function (diff, originalText) {
var dmp = new diff_match_patch();
var deltas = dmp.diff_toDelta(diff).split('\t');
/*
* Code deeply inspired by chaoscollective / Space_Editor
*/
var offset = 0;
var row = 1;
var col = 1;
var aceDeltas = [];
var aceDelta = {};
for (var i = 0; i < deltas.length; ++i) {
var type = deltas[i].charAt(0);
var data = decodeURI(deltas[i].substring(1));
switch (type) {
case "=":
/* The new text is equal to the original text for a
* number of characters. */
var unchangedCharactersCount = parseInt(data, 10);
for (var j = 0; j < unchangedCharactersCount; ++j) {
if (originalText.charAt(offset + j) == "\n") {
++row;
col = 1;
} else {
col++;
}
}
offset += unchangedCharactersCount;
break;
case "+":
/* Some characters were added. */
var startRow = row;
var startCol = col;
var innerRows = data.split("\n");
var innerRowsCount = innerRows.length - 1;
row += innerRowsCount;
if (innerRowsCount <= 0) {
col += data.length;
} else {
col = innerRows[innerRowsCount].length + 1;
}
aceDelta = {
action: "insert",
start: {row: (startRow - 1), column: (startCol - 1)},
end: {row: (row - 1), column: (col - 1)},
lines: innerRows
};
aceDeltas.push(aceDelta);
break;
case "-":
/* Some characters were subtracted. */
var deletedCharactersCount = parseInt(data, 10);
var removedData = originalText.substring(offset, offset + deletedCharactersCount);
var removedRows = removedData.split("\n");
var removedRowsCount = removedRows.length - 1;
var endRow = row + removedRowsCount;
var endCol = col;
if (removedRowsCount <= 0) {
endCol = col + deletedCharactersCount;
} else {
endCol = removedRows[removedRowsCount].length + 1;
}
aceDelta = {
action: "remove",
start: {row: (row - 1), column: (col - 1)},
end: {row: (endRow - 1), column: (endCol - 1)},
lines: removedRows
};
aceDeltas.push(aceDelta);
offset += deletedCharactersCount;
break;
default:
/* Return an innofensive empty list of Ace deltas. */
console.log("Unhandled case '" + type + "' while building Ace deltas.");
return [];
}
}
return aceDeltas;
},
getSelectionMarkupForUser: function (username) {
return '<div id="selection-' + username + '" class="collaborative-selection-wrapper">' +
'<div class="collaborative-selection"></div>' +
'<div class="collaborative-selection-tooltip">' + username + '</div>' +
'</div>';
},
/* Set of helper methods to manipulate the editor. */
_getEditor: function () {
return codiad.editor.getActive();
},
_getEditSession: function () {
return codiad.editor.getActive().getSession();
},
_getSelection: function () {
return codiad.editor.getActive().getSelection();
},
_getDocument: function () {
return codiad.editor.getActive().getSession().getDocument();
},
_getCurrentFileText: function () {
return codiad.editor.getActive().getSession().getValue();
}
codiad.collaborative = {
};
})(this, jQuery);

View file

@ -0,0 +1,224 @@
1.3.5 / 2018-02-28
==================
* deps: mime-types@~2.1.18
- deps: mime-db@~1.33.0
1.3.4 / 2017-08-22
==================
* deps: mime-types@~2.1.16
- deps: mime-db@~1.29.0
1.3.3 / 2016-05-02
==================
* deps: mime-types@~2.1.11
- deps: mime-db@~1.23.0
* deps: negotiator@0.6.1
- perf: improve `Accept` parsing speed
- perf: improve `Accept-Charset` parsing speed
- perf: improve `Accept-Encoding` parsing speed
- perf: improve `Accept-Language` parsing speed
1.3.2 / 2016-03-08
==================
* deps: mime-types@~2.1.10
- Fix extension of `application/dash+xml`
- Update primary extension for `audio/mp4`
- deps: mime-db@~1.22.0
1.3.1 / 2016-01-19
==================
* deps: mime-types@~2.1.9
- deps: mime-db@~1.21.0
1.3.0 / 2015-09-29
==================
* deps: mime-types@~2.1.7
- deps: mime-db@~1.19.0
* deps: negotiator@0.6.0
- Fix including type extensions in parameters in `Accept` parsing
- Fix parsing `Accept` parameters with quoted equals
- Fix parsing `Accept` parameters with quoted semicolons
- Lazy-load modules from main entry point
- perf: delay type concatenation until needed
- perf: enable strict mode
- perf: hoist regular expressions
- perf: remove closures getting spec properties
- perf: remove a closure from media type parsing
- perf: remove property delete from media type parsing
1.2.13 / 2015-09-06
===================
* deps: mime-types@~2.1.6
- deps: mime-db@~1.18.0
1.2.12 / 2015-07-30
===================
* deps: mime-types@~2.1.4
- deps: mime-db@~1.16.0
1.2.11 / 2015-07-16
===================
* deps: mime-types@~2.1.3
- deps: mime-db@~1.15.0
1.2.10 / 2015-07-01
===================
* deps: mime-types@~2.1.2
- deps: mime-db@~1.14.0
1.2.9 / 2015-06-08
==================
* deps: mime-types@~2.1.1
- perf: fix deopt during mapping
1.2.8 / 2015-06-07
==================
* deps: mime-types@~2.1.0
- deps: mime-db@~1.13.0
* perf: avoid argument reassignment & argument slice
* perf: avoid negotiator recursive construction
* perf: enable strict mode
* perf: remove unnecessary bitwise operator
1.2.7 / 2015-05-10
==================
* deps: negotiator@0.5.3
- Fix media type parameter matching to be case-insensitive
1.2.6 / 2015-05-07
==================
* deps: mime-types@~2.0.11
- deps: mime-db@~1.9.1
* deps: negotiator@0.5.2
- Fix comparing media types with quoted values
- Fix splitting media types with quoted commas
1.2.5 / 2015-03-13
==================
* deps: mime-types@~2.0.10
- deps: mime-db@~1.8.0
1.2.4 / 2015-02-14
==================
* Support Node.js 0.6
* deps: mime-types@~2.0.9
- deps: mime-db@~1.7.0
* deps: negotiator@0.5.1
- Fix preference sorting to be stable for long acceptable lists
1.2.3 / 2015-01-31
==================
* deps: mime-types@~2.0.8
- deps: mime-db@~1.6.0
1.2.2 / 2014-12-30
==================
* deps: mime-types@~2.0.7
- deps: mime-db@~1.5.0
1.2.1 / 2014-12-30
==================
* deps: mime-types@~2.0.5
- deps: mime-db@~1.3.1
1.2.0 / 2014-12-19
==================
* deps: negotiator@0.5.0
- Fix list return order when large accepted list
- Fix missing identity encoding when q=0 exists
- Remove dynamic building of Negotiator class
1.1.4 / 2014-12-10
==================
* deps: mime-types@~2.0.4
- deps: mime-db@~1.3.0
1.1.3 / 2014-11-09
==================
* deps: mime-types@~2.0.3
- deps: mime-db@~1.2.0
1.1.2 / 2014-10-14
==================
* deps: negotiator@0.4.9
- Fix error when media type has invalid parameter
1.1.1 / 2014-09-28
==================
* deps: mime-types@~2.0.2
- deps: mime-db@~1.1.0
* deps: negotiator@0.4.8
- Fix all negotiations to be case-insensitive
- Stable sort preferences of same quality according to client order
1.1.0 / 2014-09-02
==================
* update `mime-types`
1.0.7 / 2014-07-04
==================
* Fix wrong type returned from `type` when match after unknown extension
1.0.6 / 2014-06-24
==================
* deps: negotiator@0.4.7
1.0.5 / 2014-06-20
==================
* fix crash when unknown extension given
1.0.4 / 2014-06-19
==================
* use `mime-types`
1.0.3 / 2014-06-11
==================
* deps: negotiator@0.4.6
- Order by specificity when quality is the same
1.0.2 / 2014-05-29
==================
* Fix interpretation when header not in request
* deps: pin negotiator@0.4.5
1.0.1 / 2014-01-18
==================
* Identity encoding isn't always acceptable
* deps: negotiator@~0.4.0
1.0.0 / 2013-12-27
==================
* Genesis

View file

@ -0,0 +1,23 @@
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,143 @@
# accepts
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator).
Extracted from [koa](https://www.npmjs.com/package/koa) for general use.
In addition to negotiator, it allows:
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])`
as well as `('text/html', 'application/json')`.
- Allows type shorthands such as `json`.
- Returns `false` when no types match
- Treats non-existent headers as `*`
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```sh
$ npm install accepts
```
## API
<!-- eslint-disable no-unused-vars -->
```js
var accepts = require('accepts')
```
### accepts(req)
Create a new `Accepts` object for the given `req`.
#### .charset(charsets)
Return the first accepted charset. If nothing in `charsets` is accepted,
then `false` is returned.
#### .charsets()
Return the charsets that the request accepts, in the order of the client's
preference (most preferred first).
#### .encoding(encodings)
Return the first accepted encoding. If nothing in `encodings` is accepted,
then `false` is returned.
#### .encodings()
Return the encodings that the request accepts, in the order of the client's
preference (most preferred first).
#### .language(languages)
Return the first accepted language. If nothing in `languages` is accepted,
then `false` is returned.
#### .languages()
Return the languages that the request accepts, in the order of the client's
preference (most preferred first).
#### .type(types)
Return the first accepted type (and it is returned as the same text as what
appears in the `types` array). If nothing in `types` is accepted, then `false`
is returned.
The `types` array can contain full MIME types or file extensions. Any value
that is not a full MIME types is passed to `require('mime-types').lookup`.
#### .types()
Return the types that the request accepts, in the order of the client's
preference (most preferred first).
## Examples
### Simple type negotiation
This simple example shows how to use `accepts` to return a different typed
respond body based on what the client wants to accept. The server lists it's
preferences in order and will get back the best match between the client and
server.
```js
var accepts = require('accepts')
var http = require('http')
function app (req, res) {
var accept = accepts(req)
// the order of this list is significant; should be server preferred order
switch (accept.type(['json', 'html'])) {
case 'json':
res.setHeader('Content-Type', 'application/json')
res.write('{"hello":"world!"}')
break
case 'html':
res.setHeader('Content-Type', 'text/html')
res.write('<b>hello, world!</b>')
break
default:
// the fallback is text/plain, so no need to specify it above
res.setHeader('Content-Type', 'text/plain')
res.write('hello, world!')
break
}
res.end()
}
http.createServer(app).listen(3000)
```
You can test this out with the cURL program:
```sh
curl -I -H'Accept: text/html' http://localhost:3000/
```
## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/accepts.svg
[npm-url]: https://npmjs.org/package/accepts
[node-version-image]: https://img.shields.io/node/v/accepts.svg
[node-version-url]: https://nodejs.org/en/download/
[travis-image]: https://img.shields.io/travis/jshttp/accepts/master.svg
[travis-url]: https://travis-ci.org/jshttp/accepts
[coveralls-image]: https://img.shields.io/coveralls/jshttp/accepts/master.svg
[coveralls-url]: https://coveralls.io/r/jshttp/accepts
[downloads-image]: https://img.shields.io/npm/dm/accepts.svg
[downloads-url]: https://npmjs.org/package/accepts

View file

@ -0,0 +1,238 @@
/*!
* accepts
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var Negotiator = require('negotiator')
var mime = require('mime-types')
/**
* Module exports.
* @public
*/
module.exports = Accepts
/**
* Create a new Accepts object for the given req.
*
* @param {object} req
* @public
*/
function Accepts (req) {
if (!(this instanceof Accepts)) {
return new Accepts(req)
}
this.headers = req.headers
this.negotiator = new Negotiator(req)
}
/**
* Check if the given `type(s)` is acceptable, returning
* the best match when true, otherwise `undefined`, in which
* case you should respond with 406 "Not Acceptable".
*
* The `type` value may be a single mime type string
* such as "application/json", the extension name
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
* or array is given the _best_ match, if any is returned.
*
* Examples:
*
* // Accept: text/html
* this.types('html');
* // => "html"
*
* // Accept: text/*, application/json
* this.types('html');
* // => "html"
* this.types('text/html');
* // => "text/html"
* this.types('json', 'text');
* // => "json"
* this.types('application/json');
* // => "application/json"
*
* // Accept: text/*, application/json
* this.types('image/png');
* this.types('png');
* // => undefined
*
* // Accept: text/*;q=.5, application/json
* this.types(['html', 'json']);
* this.types('html', 'json');
* // => "json"
*
* @param {String|Array} types...
* @return {String|Array|Boolean}
* @public
*/
Accepts.prototype.type =
Accepts.prototype.types = function (types_) {
var types = types_
// support flattened arguments
if (types && !Array.isArray(types)) {
types = new Array(arguments.length)
for (var i = 0; i < types.length; i++) {
types[i] = arguments[i]
}
}
// no types, return all requested types
if (!types || types.length === 0) {
return this.negotiator.mediaTypes()
}
// no accept header, return first given type
if (!this.headers.accept) {
return types[0]
}
var mimes = types.map(extToMime)
var accepts = this.negotiator.mediaTypes(mimes.filter(validMime))
var first = accepts[0]
return first
? types[mimes.indexOf(first)]
: false
}
/**
* Return accepted encodings or best fit based on `encodings`.
*
* Given `Accept-Encoding: gzip, deflate`
* an array sorted by quality is returned:
*
* ['gzip', 'deflate']
*
* @param {String|Array} encodings...
* @return {String|Array}
* @public
*/
Accepts.prototype.encoding =
Accepts.prototype.encodings = function (encodings_) {
var encodings = encodings_
// support flattened arguments
if (encodings && !Array.isArray(encodings)) {
encodings = new Array(arguments.length)
for (var i = 0; i < encodings.length; i++) {
encodings[i] = arguments[i]
}
}
// no encodings, return all requested encodings
if (!encodings || encodings.length === 0) {
return this.negotiator.encodings()
}
return this.negotiator.encodings(encodings)[0] || false
}
/**
* Return accepted charsets or best fit based on `charsets`.
*
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
* an array sorted by quality is returned:
*
* ['utf-8', 'utf-7', 'iso-8859-1']
*
* @param {String|Array} charsets...
* @return {String|Array}
* @public
*/
Accepts.prototype.charset =
Accepts.prototype.charsets = function (charsets_) {
var charsets = charsets_
// support flattened arguments
if (charsets && !Array.isArray(charsets)) {
charsets = new Array(arguments.length)
for (var i = 0; i < charsets.length; i++) {
charsets[i] = arguments[i]
}
}
// no charsets, return all requested charsets
if (!charsets || charsets.length === 0) {
return this.negotiator.charsets()
}
return this.negotiator.charsets(charsets)[0] || false
}
/**
* Return accepted languages or best fit based on `langs`.
*
* Given `Accept-Language: en;q=0.8, es, pt`
* an array sorted by quality is returned:
*
* ['es', 'pt', 'en']
*
* @param {String|Array} langs...
* @return {Array|String}
* @public
*/
Accepts.prototype.lang =
Accepts.prototype.langs =
Accepts.prototype.language =
Accepts.prototype.languages = function (languages_) {
var languages = languages_
// support flattened arguments
if (languages && !Array.isArray(languages)) {
languages = new Array(arguments.length)
for (var i = 0; i < languages.length; i++) {
languages[i] = arguments[i]
}
}
// no languages, return all requested languages
if (!languages || languages.length === 0) {
return this.negotiator.languages()
}
return this.negotiator.languages(languages)[0] || false
}
/**
* Convert extnames to mime.
*
* @param {String} type
* @return {String}
* @private
*/
function extToMime (type) {
return type.indexOf('/') === -1
? mime.lookup(type)
: type
}
/**
* Check if mime is valid.
*
* @param {String} type
* @return {String}
* @private
*/
function validMime (type) {
return typeof type === 'string'
}

View file

@ -0,0 +1,114 @@
{
"_args": [
[
"accepts@~1.3.4",
"/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io"
]
],
"_from": "accepts@>=1.3.4 <1.4.0",
"_id": "accepts@1.3.5",
"_inCache": true,
"_installable": true,
"_location": "/accepts",
"_nodeVersion": "6.11.1",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/accepts_1.3.5_1519869527663_0.6663620712347182"
},
"_npmUser": {
"email": "doug@somethingdoug.com",
"name": "dougwilson"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {},
"_requested": {
"name": "accepts",
"raw": "accepts@~1.3.4",
"rawSpec": "~1.3.4",
"scope": null,
"spec": ">=1.3.4 <1.4.0",
"type": "range"
},
"_requiredBy": [
"/engine.io"
],
"_resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
"_shasum": "eb777df6011723a3b14e8a72c0805c8e86746bd2",
"_shrinkwrap": null,
"_spec": "accepts@~1.3.4",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io",
"bugs": {
"url": "https://github.com/jshttp/accepts/issues"
},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
}
],
"dependencies": {
"mime-types": "~2.1.18",
"negotiator": "0.6.1"
},
"description": "Higher-level content negotiation",
"devDependencies": {
"eslint": "4.18.1",
"eslint-config-standard": "11.0.0",
"eslint-plugin-import": "2.9.0",
"eslint-plugin-markdown": "1.0.0-beta.6",
"eslint-plugin-node": "6.0.1",
"eslint-plugin-promise": "3.6.0",
"eslint-plugin-standard": "3.0.1",
"istanbul": "0.4.5",
"mocha": "~1.21.5"
},
"directories": {},
"dist": {
"fileCount": 5,
"shasum": "eb777df6011723a3b14e8a72c0805c8e86746bd2",
"tarball": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
"unpackedSize": 16555
},
"engines": {
"node": ">= 0.6"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js"
],
"gitHead": "c38d0e968cdc1526f7cc7a718977ee76655c84f5",
"homepage": "https://github.com/jshttp/accepts#readme",
"keywords": [
"accept",
"accepts",
"content",
"negotiation"
],
"license": "MIT",
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"name": "accepts",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/jshttp/accepts.git"
},
"scripts": {
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"version": "1.3.5"
}

View file

@ -0,0 +1,2 @@
node_modules
.monitor

View file

@ -0,0 +1,12 @@
language: node_js
node_js:
- 0.6
- 0.8
- 0.9
- 0.10
- 0.12
- 4.2.4
- 5.4.1
- iojs-1
- iojs-2
- iojs-3

View file

@ -0,0 +1,19 @@
Copyright (c) 2011 Raynos.
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.

View file

@ -0,0 +1,115 @@
# After [![Build Status][1]][2]
Invoke callback after n calls
## Status: production ready
## Example
```js
var after = require("after")
var db = require("./db") // some db.
var updateUser = function (req, res) {
// use after to run two tasks in parallel,
// namely get request body and get session
// then run updateUser with the results
var next = after(2, updateUser)
var results = {}
getJSONBody(req, res, function (err, body) {
if (err) return next(err)
results.body = body
next(null, results)
})
getSessionUser(req, res, function (err, user) {
if (err) return next(err)
results.user = user
next(null, results)
})
// now do the thing!
function updateUser(err, result) {
if (err) {
res.statusCode = 500
return res.end("Unexpected Error")
}
if (!result.user || result.user.role !== "admin") {
res.statusCode = 403
return res.end("Permission Denied")
}
db.put("users:" + req.params.userId, result.body, function (err) {
if (err) {
res.statusCode = 500
return res.end("Unexpected Error")
}
res.statusCode = 200
res.end("Ok")
})
}
}
```
## Naive Example
```js
var after = require("after")
, next = after(3, logItWorks)
next()
next()
next() // it works
function logItWorks() {
console.log("it works!")
}
```
## Example with error handling
```js
var after = require("after")
, next = after(3, logError)
next()
next(new Error("oops")) // logs oops
next() // does nothing
// This callback is only called once.
// If there is an error the callback gets called immediately
// this avoids the situation where errors get lost.
function logError(err) {
console.log(err)
}
```
## Installation
`npm install after`
## Tests
`npm test`
## Contributors
- Raynos
- defunctzombie
## MIT Licenced
[1]: https://secure.travis-ci.org/Raynos/after.png
[2]: http://travis-ci.org/Raynos/after
[3]: http://raynos.org/blog/2/Flow-control-in-node.js
[4]: http://stackoverflow.com/questions/6852059/determining-the-end-of-asynchronous-operations-javascript/6852307#6852307
[5]: http://stackoverflow.com/questions/6869872/in-javascript-what-are-best-practices-for-executing-multiple-asynchronous-functi/6870031#6870031
[6]: http://stackoverflow.com/questions/6864397/javascript-performance-long-running-tasks/6889419#6889419
[7]: http://stackoverflow.com/questions/6597493/synchronous-database-queries-with-node-js/6620091#6620091
[8]: http://github.com/Raynos/iterators
[9]: http://github.com/Raynos/composite

View file

@ -0,0 +1,28 @@
module.exports = after
function after(count, callback, err_cb) {
var bail = false
err_cb = err_cb || noop
proxy.count = count
return (count === 0) ? callback() : proxy
function proxy(err, result) {
if (proxy.count <= 0) {
throw new Error('after called too many times')
}
--proxy.count
// after first error, rest are passed to err_cb
if (err) {
bail = true
callback(err)
// future error callbacks will go to error handler
callback = err_cb
} else if (proxy.count === 0 && !bail) {
callback(null, result)
}
}
}
function noop() {}

View file

@ -0,0 +1,95 @@
{
"_args": [
[
"after@0.8.2",
"/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io-parser"
]
],
"_from": "after@0.8.2",
"_id": "after@0.8.2",
"_inCache": true,
"_installable": true,
"_location": "/after",
"_nodeVersion": "0.10.32",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/after-0.8.2.tgz_1471308639186_0.9132961586583406"
},
"_npmUser": {
"email": "raynos2@gmail.com",
"name": "raynos"
},
"_npmVersion": "2.15.9",
"_phantomChildren": {},
"_requested": {
"name": "after",
"raw": "after@0.8.2",
"rawSpec": "0.8.2",
"scope": null,
"spec": "0.8.2",
"type": "version"
},
"_requiredBy": [
"/engine.io-parser"
],
"_resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz",
"_shasum": "fedb394f9f0e02aa9768e702bda23b505fae7e1f",
"_shrinkwrap": null,
"_spec": "after@0.8.2",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io-parser",
"author": {
"email": "raynos2@gmail.com",
"name": "Raynos"
},
"bugs": {
"url": "https://github.com/Raynos/after/issues"
},
"contributors": [
{
"name": "Raynos",
"email": "raynos2@gmail.com",
"url": "http://raynos.org"
}
],
"dependencies": {},
"description": "after - tiny flow control",
"devDependencies": {
"mocha": "~1.8.1"
},
"directories": {},
"dist": {
"shasum": "fedb394f9f0e02aa9768e702bda23b505fae7e1f",
"tarball": "https://registry.npmjs.org/after/-/after-0.8.2.tgz"
},
"gitHead": "e8c26046f36962b90e68dc5df33a9672a54b25f5",
"homepage": "https://github.com/Raynos/after#readme",
"keywords": [
"after",
"arch",
"control",
"flow",
"flowcontrol"
],
"license": "MIT",
"maintainers": [
{
"name": "raynos",
"email": "raynos2@gmail.com"
},
{
"name": "defunctzombie",
"email": "shtylman@gmail.com"
}
],
"name": "after",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/Raynos/after.git"
},
"scripts": {
"test": "mocha --ui tdd --reporter spec test/*.js"
},
"version": "0.8.2"
}

View file

@ -0,0 +1,120 @@
/*global suite, test*/
var assert = require("assert")
, after = require("../")
test("exists", function () {
assert(typeof after === "function", "after is not a function")
})
test("after when called with 0 invokes", function (done) {
after(0, done)
});
test("after 1", function (done) {
var next = after(1, done)
next()
})
test("after 5", function (done) {
var next = after(5, done)
, i = 5
while (i--) {
next()
}
})
test("manipulate count", function (done) {
var next = after(1, done)
, i = 5
next.count = i
while (i--) {
next()
}
})
test("after terminates on error", function (done) {
var next = after(2, function(err) {
assert.equal(err.message, 'test');
done();
})
next(new Error('test'))
next(new Error('test2'))
})
test('gee', function(done) {
done = after(2, done)
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
assert.equal(err.message, 2)
done()
});
next()
next(new Error(1))
next(new Error(2))
})
test('eee', function(done) {
done = after(3, done)
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
assert.equal(err.message, 2)
done()
});
next(new Error(1))
next(new Error(2))
next(new Error(2))
})
test('gge', function(done) {
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
// should not happen
assert.ok(false);
});
next()
next()
next(new Error(1))
})
test('egg', function(done) {
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
// should not happen
assert.ok(false);
});
next(new Error(1))
next()
next()
})
test('throws on too many calls', function(done) {
var next = after(1, done);
next()
assert.throws(next, /after called too many times/);
});

View file

@ -0,0 +1,17 @@
lib-cov
lcov.info
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
build
.grunt
node_modules

View file

@ -0,0 +1,18 @@
Copyright (C) 2013 Rase-
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.

View file

@ -0,0 +1,8 @@
REPORTER = dot
test:
@./node_modules/.bin/mocha \
--reporter $(REPORTER)
.PHONY: test

View file

@ -0,0 +1,17 @@
# How to
```javascript
var sliceBuffer = require('arraybuffer.slice');
var ab = (new Int8Array(5)).buffer;
var sliced = sliceBuffer(ab, 1, 3);
sliced = sliceBuffer(ab, 1);
```
# Licence (MIT)
Copyright (C) 2013 Rase-
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.

View file

@ -0,0 +1,29 @@
/**
* An abstraction for slicing an arraybuffer even when
* ArrayBuffer.prototype.slice is not supported
*
* @api public
*/
module.exports = function(arraybuffer, start, end) {
var bytes = arraybuffer.byteLength;
start = start || 0;
end = end || bytes;
if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
if (start < 0) { start += bytes; }
if (end < 0) { end += bytes; }
if (end > bytes) { end = bytes; }
if (start >= bytes || start >= end || bytes === 0) {
return new ArrayBuffer(0);
}
var abv = new Uint8Array(arraybuffer);
var result = new Uint8Array(end - start);
for (var i = start, ii = 0; i < end; i++, ii++) {
result[ii] = abv[i];
}
return result.buffer;
};

View file

@ -0,0 +1,72 @@
{
"_args": [
[
"arraybuffer.slice@~0.0.7",
"/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io-parser"
]
],
"_from": "arraybuffer.slice@>=0.0.7 <0.1.0",
"_id": "arraybuffer.slice@0.0.7",
"_inCache": true,
"_installable": true,
"_location": "/arraybuffer.slice",
"_nodeVersion": "8.4.0",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/arraybuffer.slice-0.0.7.tgz_1503998406760_0.431125596864149"
},
"_npmUser": {
"email": "tonykovanen@hotmail.com",
"name": "rase-"
},
"_npmVersion": "5.3.0",
"_phantomChildren": {},
"_requested": {
"name": "arraybuffer.slice",
"raw": "arraybuffer.slice@~0.0.7",
"rawSpec": "~0.0.7",
"scope": null,
"spec": ">=0.0.7 <0.1.0",
"type": "range"
},
"_requiredBy": [
"/engine.io-parser"
],
"_resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz",
"_shasum": "3bbc4275dd584cc1b10809b89d4e8b63a69e7675",
"_shrinkwrap": null,
"_spec": "arraybuffer.slice@~0.0.7",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io-parser",
"bugs": {
"url": "https://github.com/rase-/arraybuffer.slice/issues"
},
"dependencies": {},
"description": "Exports a function for slicing ArrayBuffers (no polyfilling)",
"devDependencies": {
"expect.js": "0.2.0",
"mocha": "1.17.1"
},
"directories": {},
"dist": {
"integrity": "sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog==",
"shasum": "3bbc4275dd584cc1b10809b89d4e8b63a69e7675",
"tarball": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz"
},
"gitHead": "6779b3ca590f15c0910181bf7ccc51061f7eb7ac",
"homepage": "https://github.com/rase-/arraybuffer.slice",
"license": "MIT",
"maintainers": [
{
"name": "rase-",
"email": "tonykovanen@hotmail.com"
}
],
"name": "arraybuffer.slice",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/rase-/arraybuffer.slice.git"
},
"version": "0.0.7"
}

View file

@ -0,0 +1,227 @@
/*
* Test dependencies
*/
var sliceBuffer = require('../index.js');
var expect = require('expect.js');
/**
* Tests
*/
describe('sliceBuffer', function() {
describe('using standard slice', function() {
it('should slice correctly with only start provided', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, 3);
var sabv = new Uint8Array(sliced);
for (var i = 3, ii = 0; i < abv.length; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with start and end provided', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, 3, 8);
var sabv = new Uint8Array(sliced);
for (var i = 3, ii = 0; i < 8; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with negative start', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, -3);
var sabv = new Uint8Array(sliced);
for (var i = abv.length - 3, ii = 0; i < abv.length; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with negative end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, 0, -3);
var sabv = new Uint8Array(sliced);
for (var i = 0, ii = 0; i < abv.length - 3; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with negative start and end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, -6, -3);
var sabv = new Uint8Array(sliced);
for (var i = abv.length - 6, ii = 0; i < abv.length - 3; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with equal start and end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, 1, 1);
expect(sliced.byteLength).to.equal(0);
});
it('should slice correctly when end larger than buffer', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, 0, 100);
expect(new Uint8Array(sliced)).to.eql(abv);
});
it('shoud slice correctly when start larger than end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var sliced = sliceBuffer(abv.buffer, 6, 5);
expect(sliced.byteLength).to.equal(0);
});
});
describe('using fallback', function() {
it('should slice correctly with only start provided', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, 3);
var sabv = new Uint8Array(sliced);
for (var i = 3, ii = 0; i < abv.length; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with start and end provided', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, 3, 8);
var sabv = new Uint8Array(sliced);
for (var i = 3, ii = 0; i < 8; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with negative start', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, -3);
var sabv = new Uint8Array(sliced);
for (var i = abv.length - 3, ii = 0; i < abv.length; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with negative end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, 0, -3);
var sabv = new Uint8Array(sliced);
for (var i = 0, ii = 0; i < abv.length - 3; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with negative start and end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, -6, -3);
var sabv = new Uint8Array(sliced);
for (var i = abv.length - 6, ii = 0; i < abv.length - 3; i++, ii++) {
expect(abv[i]).to.equal(sabv[ii]);
}
});
it('should slice correctly with equal start and end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, 1, 1);
expect(sliced.byteLength).to.equal(0);
});
it('should slice correctly when end larger than buffer', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, 0, 100);
var sabv = new Uint8Array(sliced);
for (var i = 0; i < abv.length; i++) {
expect(abv[i]).to.equal(sabv[i]);
}
});
it('shoud slice correctly when start larger than end', function() {
var abv = new Uint8Array(10);
for (var i = 0; i < abv.length; i++) {
abv[i] = i;
}
var ab = abv.buffer;
ab.slice = undefined;
var sliced = sliceBuffer(ab, 6, 5);
expect(sliced.byteLength).to.equal(0);
});
});
});

View file

@ -0,0 +1,7 @@
language: node_js
node_js:
- "6"
- "node"
script: npm run travis
cache:
yarn: true

View file

@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2017 Samuel Reed <samuel.trace.reed@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.

View file

@ -0,0 +1 @@
{"/Users/samuelreed/git/forks/async-throttle/index.js":{"path":"/Users/samuelreed/git/forks/async-throttle/index.js","s":{"1":1,"2":7,"3":1,"4":6,"5":6,"6":6,"7":6,"8":6,"9":6,"10":1,"11":1,"12":3,"13":13,"14":13,"15":13,"16":1,"17":19,"18":1,"19":45,"20":6,"21":39,"22":13,"23":13,"24":13,"25":13,"26":39,"27":18,"28":6,"29":6,"30":1,"31":6,"32":6,"33":6,"34":1,"35":13,"36":13,"37":1},"b":{"1":[1,6],"2":[6,5],"3":[6,5],"4":[6,39],"5":[13,26],"6":[18,21],"7":[6,0]},"f":{"1":7,"2":3,"3":13,"4":19,"5":45,"6":6,"7":13},"fnMap":{"1":{"name":"Queue","line":3,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":24}}},"2":{"name":"(anonymous_2)","line":22,"loc":{"start":{"line":22,"column":24},"end":{"line":22,"column":41}}},"3":{"name":"(anonymous_3)","line":23,"loc":{"start":{"line":23,"column":28},"end":{"line":23,"column":39}}},"4":{"name":"(anonymous_4)","line":31,"loc":{"start":{"line":31,"column":7},"end":{"line":31,"column":18}}},"5":{"name":"(anonymous_5)","line":36,"loc":{"start":{"line":36,"column":23},"end":{"line":36,"column":34}}},"6":{"name":"(anonymous_6)","line":55,"loc":{"start":{"line":55,"column":25},"end":{"line":55,"column":38}}},"7":{"name":"done","line":62,"loc":{"start":{"line":62,"column":0},"end":{"line":62,"column":16}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":14,"column":1}},"2":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},"3":{"start":{"line":5,"column":4},"end":{"line":5,"column":30}},"4":{"start":{"line":8,"column":2},"end":{"line":8,"column":26}},"5":{"start":{"line":9,"column":2},"end":{"line":9,"column":53}},"6":{"start":{"line":10,"column":2},"end":{"line":10,"column":19}},"7":{"start":{"line":11,"column":2},"end":{"line":11,"column":17}},"8":{"start":{"line":12,"column":2},"end":{"line":12,"column":16}},"9":{"start":{"line":13,"column":2},"end":{"line":13,"column":31}},"10":{"start":{"line":16,"column":0},"end":{"line":20,"column":2}},"11":{"start":{"line":22,"column":0},"end":{"line":28,"column":3}},"12":{"start":{"line":23,"column":2},"end":{"line":27,"column":4}},"13":{"start":{"line":24,"column":4},"end":{"line":24,"column":75}},"14":{"start":{"line":25,"column":4},"end":{"line":25,"column":16}},"15":{"start":{"line":26,"column":4},"end":{"line":26,"column":24}},"16":{"start":{"line":30,"column":0},"end":{"line":34,"column":3}},"17":{"start":{"line":32,"column":4},"end":{"line":32,"column":43}},"18":{"start":{"line":36,"column":0},"end":{"line":53,"column":2}},"19":{"start":{"line":37,"column":2},"end":{"line":39,"column":3}},"20":{"start":{"line":38,"column":4},"end":{"line":38,"column":11}},"21":{"start":{"line":40,"column":2},"end":{"line":45,"column":3}},"22":{"start":{"line":41,"column":4},"end":{"line":41,"column":32}},"23":{"start":{"line":42,"column":4},"end":{"line":42,"column":19}},"24":{"start":{"line":43,"column":4},"end":{"line":43,"column":20}},"25":{"start":{"line":44,"column":4},"end":{"line":44,"column":16}},"26":{"start":{"line":47,"column":2},"end":{"line":52,"column":3}},"27":{"start":{"line":48,"column":4},"end":{"line":51,"column":5}},"28":{"start":{"line":49,"column":6},"end":{"line":49,"column":30}},"29":{"start":{"line":50,"column":6},"end":{"line":50,"column":27}},"30":{"start":{"line":55,"column":0},"end":{"line":60,"column":2}},"31":{"start":{"line":56,"column":2},"end":{"line":59,"column":3}},"32":{"start":{"line":57,"column":4},"end":{"line":57,"column":22}},"33":{"start":{"line":58,"column":4},"end":{"line":58,"column":16}},"34":{"start":{"line":62,"column":0},"end":{"line":65,"column":1}},"35":{"start":{"line":63,"column":2},"end":{"line":63,"column":17}},"36":{"start":{"line":64,"column":2},"end":{"line":64,"column":14}},"37":{"start":{"line":67,"column":0},"end":{"line":67,"column":23}}},"branchMap":{"1":{"line":4,"type":"if","locations":[{"start":{"line":4,"column":2},"end":{"line":4,"column":2}},{"start":{"line":4,"column":2},"end":{"line":4,"column":2}}]},"2":{"line":8,"type":"binary-expr","locations":[{"start":{"line":8,"column":12},"end":{"line":8,"column":19}},{"start":{"line":8,"column":23},"end":{"line":8,"column":25}}]},"3":{"line":9,"type":"binary-expr","locations":[{"start":{"line":9,"column":21},"end":{"line":9,"column":40}},{"start":{"line":9,"column":44},"end":{"line":9,"column":52}}]},"4":{"line":37,"type":"if","locations":[{"start":{"line":37,"column":2},"end":{"line":37,"column":2}},{"start":{"line":37,"column":2},"end":{"line":37,"column":2}}]},"5":{"line":40,"type":"if","locations":[{"start":{"line":40,"column":2},"end":{"line":40,"column":2}},{"start":{"line":40,"column":2},"end":{"line":40,"column":2}}]},"6":{"line":47,"type":"if","locations":[{"start":{"line":47,"column":2},"end":{"line":47,"column":2}},{"start":{"line":47,"column":2},"end":{"line":47,"column":2}}]},"7":{"line":56,"type":"if","locations":[{"start":{"line":56,"column":2},"end":{"line":56,"column":2}},{"start":{"line":56,"column":2},"end":{"line":56,"column":2}}]}}}}

View file

@ -0,0 +1,73 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for async-throttle/</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../prettify.css">
<link rel="stylesheet" href="../base.css">
<style type='text/css'>
div.coverage-summary .sorter {
background-image: url(../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class="header high">
<h1>Code coverage report for <span class="entity">async-throttle/</span></h1>
<h2>
Statements: <span class="metric">100% <small>(37 / 37)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Branches: <span class="metric">92.86% <small>(13 / 14)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Functions: <span class="metric">100% <small>(7 / 7)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Lines: <span class="metric">100% <small>(37 / 37)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Ignored: <span class="metric"><span class="ignore-none">none</span></span> &nbsp;&nbsp;&nbsp;&nbsp;
</h2>
<div class="path"><a href="../index.html">All files</a> &#187; async-throttle/</div>
</div>
<div class="body">
<div class="coverage-summary">
<table>
<thead>
<tr>
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="index.js"><a href="index.js.html">index.js</a></td>
<td data-value="100" class="pic high"><span class="cover-fill cover-full" style="width: 100px;"></span><span class="cover-empty" style="width:0px;"></span></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="37" class="abs high">(37&nbsp;/&nbsp;37)</td>
<td data-value="92.86" class="pct high">92.86%</td>
<td data-value="14" class="abs high">(13&nbsp;/&nbsp;14)</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="7" class="abs high">(7&nbsp;/&nbsp;7)</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="37" class="abs high">(37&nbsp;/&nbsp;37)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="footer">
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Sep 11 2017 11:14:14 GMT-0500 (CDT)</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../sorter.js"></script>
</body>
</html>

View file

@ -0,0 +1,246 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for async-throttle/index.js</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../prettify.css">
<link rel="stylesheet" href="../base.css">
<style type='text/css'>
div.coverage-summary .sorter {
background-image: url(../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class="header high">
<h1>Code coverage report for <span class="entity">async-throttle/index.js</span></h1>
<h2>
Statements: <span class="metric">100% <small>(37 / 37)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Branches: <span class="metric">92.86% <small>(13 / 14)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Functions: <span class="metric">100% <small>(7 / 7)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Lines: <span class="metric">100% <small>(37 / 37)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Ignored: <span class="metric"><span class="ignore-none">none</span></span> &nbsp;&nbsp;&nbsp;&nbsp;
</h2>
<div class="path"><a href="../index.html">All files</a> &#187; <a href="index.html">async-throttle/</a> &#187; index.js</div>
</div>
<div class="body">
<pre><table class="coverage">
<tr><td class="line-count">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68</td><td class="line-coverage"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">7</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">3</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">19</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">45</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">39</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">39</span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-yes">6</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-yes">13</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
&nbsp;
function Queue(options) {
if (!(this instanceof Queue)) {
return new Queue(options);
}
&nbsp;
options = options || {};
this.concurrency = options.concurrency || Infinity;
this.pending = 0;
this.jobs = [];
this.cbs = [];
this._done = done.bind(this);
}
&nbsp;
var arrayAddMethods = [
'push',
'unshift',
'splice'
];
&nbsp;
arrayAddMethods.forEach(function(method) {
Queue.prototype[method] = function() {
var methodResult = Array.prototype[method].apply(this.jobs, arguments);
this._run();
return methodResult;
};
});
&nbsp;
Object.defineProperty(Queue.prototype, 'length', {
get: function() {
return this.pending + this.jobs.length;
}
});
&nbsp;
Queue.prototype._run = function() {
if (this.pending === this.concurrency) {
return;
}
if (this.jobs.length) {
var job = this.jobs.shift();
this.pending++;
job(this._done);
this._run();
}
&nbsp;
if (this.pending === 0) {
while (this.cbs.length !== 0) {
var cb = this.cbs.pop();
process.nextTick(cb);
}
}
};
&nbsp;
Queue.prototype.onDone = function(cb) {
<span class="missing-if-branch" title="else path not taken" >E</span>if (typeof cb === 'function') {
this.cbs.push(cb);
this._run();
}
};
&nbsp;
function done() {
this.pending--;
this._run();
}
&nbsp;
module.exports = Queue;
&nbsp;</pre></td></tr>
</table></pre>
</div>
<div class="footer">
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Sep 11 2017 11:14:14 GMT-0500 (CDT)</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../sorter.js"></script>
</body>
</html>

View file

@ -0,0 +1,182 @@
body, html {
margin:0; padding: 0;
}
body {
font-family: Helvetica Neue, Helvetica,Arial;
font-size: 10pt;
}
div.header, div.footer {
background: #eee;
padding: 1em;
}
div.header {
z-index: 100;
position: fixed;
top: 0;
border-bottom: 1px solid #666;
width: 100%;
}
div.footer {
border-top: 1px solid #666;
}
div.body {
margin-top: 10em;
}
div.meta {
font-size: 90%;
text-align: center;
}
h1, h2, h3 {
font-weight: normal;
}
h1 {
font-size: 12pt;
}
h2 {
font-size: 10pt;
}
pre {
font-family: Consolas, Menlo, Monaco, monospace;
margin: 0;
padding: 0;
line-height: 1.3;
font-size: 14px;
-moz-tab-size: 2;
-o-tab-size: 2;
tab-size: 2;
}
div.path { font-size: 110%; }
div.path a:link, div.path a:visited { color: #000; }
table.coverage { border-collapse: collapse; margin:0; padding: 0 }
table.coverage td {
margin: 0;
padding: 0;
color: #111;
vertical-align: top;
}
table.coverage td.line-count {
width: 50px;
text-align: right;
padding-right: 5px;
}
table.coverage td.line-coverage {
color: #777 !important;
text-align: right;
border-left: 1px solid #666;
border-right: 1px solid #666;
}
table.coverage td.text {
}
table.coverage td span.cline-any {
display: inline-block;
padding: 0 5px;
width: 40px;
}
table.coverage td span.cline-neutral {
background: #eee;
}
table.coverage td span.cline-yes {
background: #b5d592;
color: #999;
}
table.coverage td span.cline-no {
background: #fc8c84;
}
.cstat-yes { color: #111; }
.cstat-no { background: #fc8c84; color: #111; }
.fstat-no { background: #ffc520; color: #111 !important; }
.cbranch-no { background: yellow !important; color: #111; }
.cstat-skip { background: #ddd; color: #111; }
.fstat-skip { background: #ddd; color: #111 !important; }
.cbranch-skip { background: #ddd !important; color: #111; }
.missing-if-branch {
display: inline-block;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: black;
color: yellow;
}
.skip-if-branch {
display: none;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: #ccc;
color: white;
}
.missing-if-branch .typ, .skip-if-branch .typ {
color: inherit !important;
}
.entity, .metric { font-weight: bold; }
.metric { display: inline-block; border: 1px solid #333; padding: 0.3em; background: white; }
.metric small { font-size: 80%; font-weight: normal; color: #666; }
div.coverage-summary table { border-collapse: collapse; margin: 3em; font-size: 110%; }
div.coverage-summary td, div.coverage-summary table th { margin: 0; padding: 0.25em 1em; border-top: 1px solid #666; border-bottom: 1px solid #666; }
div.coverage-summary th { text-align: left; border: 1px solid #666; background: #eee; font-weight: normal; }
div.coverage-summary th.file { border-right: none !important; }
div.coverage-summary th.pic { border-left: none !important; text-align: right; }
div.coverage-summary th.pct { border-right: none !important; }
div.coverage-summary th.abs { border-left: none !important; text-align: right; }
div.coverage-summary td.pct { text-align: right; border-left: 1px solid #666; }
div.coverage-summary td.abs { text-align: right; font-size: 90%; color: #444; border-right: 1px solid #666; }
div.coverage-summary td.file { border-left: 1px solid #666; white-space: nowrap; }
div.coverage-summary td.pic { min-width: 120px !important; }
div.coverage-summary a:link { text-decoration: none; color: #000; }
div.coverage-summary a:visited { text-decoration: none; color: #777; }
div.coverage-summary a:hover { text-decoration: underline; }
div.coverage-summary tfoot td { border-top: 1px solid #666; }
div.coverage-summary .sorter {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
}
div.coverage-summary .sorted .sorter {
background-position: 0 -20px;
}
div.coverage-summary .sorted-desc .sorter {
background-position: 0 -10px;
}
.high { background: #b5d592 !important; }
.medium { background: #ffe87c !important; }
.low { background: #fc8c84 !important; }
span.cover-fill, span.cover-empty {
display:inline-block;
border:1px solid #444;
background: white;
height: 12px;
}
span.cover-fill {
background: #ccc;
border-right: 1px solid #444;
}
span.cover-empty {
background: white;
border-left: none;
}
span.cover-full {
border-right: none !important;
}
pre.prettyprint {
border: none !important;
padding: 0 !important;
margin: 0 !important;
}
.com { color: #999 !important; }
.ignore-none { color: #999; font-weight: normal; }

View file

@ -0,0 +1,73 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for All files</title>
<meta charset="utf-8">
<link rel="stylesheet" href="prettify.css">
<link rel="stylesheet" href="base.css">
<style type='text/css'>
div.coverage-summary .sorter {
background-image: url(sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class="header high">
<h1>Code coverage report for <span class="entity">All files</span></h1>
<h2>
Statements: <span class="metric">100% <small>(37 / 37)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Branches: <span class="metric">92.86% <small>(13 / 14)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Functions: <span class="metric">100% <small>(7 / 7)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Lines: <span class="metric">100% <small>(37 / 37)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Ignored: <span class="metric"><span class="ignore-none">none</span></span> &nbsp;&nbsp;&nbsp;&nbsp;
</h2>
<div class="path"></div>
</div>
<div class="body">
<div class="coverage-summary">
<table>
<thead>
<tr>
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="async-throttle/"><a href="async-throttle/index.html">async-throttle/</a></td>
<td data-value="100" class="pic high"><span class="cover-fill cover-full" style="width: 100px;"></span><span class="cover-empty" style="width:0px;"></span></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="37" class="abs high">(37&nbsp;/&nbsp;37)</td>
<td data-value="92.86" class="pct high">92.86%</td>
<td data-value="14" class="abs high">(13&nbsp;/&nbsp;14)</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="7" class="abs high">(7&nbsp;/&nbsp;7)</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="37" class="abs high">(37&nbsp;/&nbsp;37)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="footer">
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Sep 11 2017 11:14:14 GMT-0500 (CDT)</div>
</div>
<script src="prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="sorter.js"></script>
</body>
</html>

View file

@ -0,0 +1 @@
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

View file

@ -0,0 +1,156 @@
var addSorting = (function () {
"use strict";
var cols,
currentSort = {
index: 0,
desc: false
};
// returns the summary table element
function getTable() { return document.querySelector('.coverage-summary table'); }
// returns the thead element of the summary table
function getTableHeader() { return getTable().querySelector('thead tr'); }
// returns the tbody element of the summary table
function getTableBody() { return getTable().querySelector('tbody'); }
// returns the th element for nth column
function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; }
// loads all columns
function loadColumns() {
var colNodes = getTableHeader().querySelectorAll('th'),
colNode,
cols = [],
col,
i;
for (i = 0; i < colNodes.length; i += 1) {
colNode = colNodes[i];
col = {
key: colNode.getAttribute('data-col'),
sortable: !colNode.getAttribute('data-nosort'),
type: colNode.getAttribute('data-type') || 'string'
};
cols.push(col);
if (col.sortable) {
col.defaultDescSort = col.type === 'number';
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
}
}
return cols;
}
// attaches a data attribute to every tr element with an object
// of data values keyed by column name
function loadRowData(tableRow) {
var tableCols = tableRow.querySelectorAll('td'),
colNode,
col,
data = {},
i,
val;
for (i = 0; i < tableCols.length; i += 1) {
colNode = tableCols[i];
col = cols[i];
val = colNode.getAttribute('data-value');
if (col.type === 'number') {
val = Number(val);
}
data[col.key] = val;
}
return data;
}
// loads all row data
function loadData() {
var rows = getTableBody().querySelectorAll('tr'),
i;
for (i = 0; i < rows.length; i += 1) {
rows[i].data = loadRowData(rows[i]);
}
}
// sorts the table using the data for the ith column
function sortByIndex(index, desc) {
var key = cols[index].key,
sorter = function (a, b) {
a = a.data[key];
b = b.data[key];
return a < b ? -1 : a > b ? 1 : 0;
},
finalSorter = sorter,
tableBody = document.querySelector('.coverage-summary tbody'),
rowNodes = tableBody.querySelectorAll('tr'),
rows = [],
i;
if (desc) {
finalSorter = function (a, b) {
return -1 * sorter(a, b);
};
}
for (i = 0; i < rowNodes.length; i += 1) {
rows.push(rowNodes[i]);
tableBody.removeChild(rowNodes[i]);
}
rows.sort(finalSorter);
for (i = 0; i < rows.length; i += 1) {
tableBody.appendChild(rows[i]);
}
}
// removes sort indicators for current column being sorted
function removeSortIndicators() {
var col = getNthColumn(currentSort.index),
cls = col.className;
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
col.className = cls;
}
// adds sort indicators for current column being sorted
function addSortIndicators() {
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
}
// adds event listeners for all sorter widgets
function enableUI() {
var i,
el,
ithSorter = function ithSorter(i) {
var col = cols[i];
return function () {
var desc = col.defaultDescSort;
if (currentSort.index === i) {
desc = !currentSort.desc;
}
sortByIndex(i, desc);
removeSortIndicators();
currentSort.index = i;
currentSort.desc = desc;
addSortIndicators();
};
};
for (i =0 ; i < cols.length; i += 1) {
if (cols[i].sortable) {
el = getNthColumn(i).querySelector('.sorter');
if (el.addEventListener) {
el.addEventListener('click', ithSorter(i));
} else {
el.attachEvent('onclick', ithSorter(i));
}
}
}
}
// adds sorting functionality to the UI
return function () {
if (!getTable()) {
return;
}
cols = loadColumns();
loadData(cols);
addSortIndicators();
enableUI();
};
})();
window.addEventListener('load', addSorting);

View file

@ -0,0 +1,74 @@
TN:
SF:/Users/samuelreed/git/forks/async-throttle/index.js
FN:3,Queue
FN:22,(anonymous_2)
FN:23,(anonymous_3)
FN:31,(anonymous_4)
FN:36,(anonymous_5)
FN:55,(anonymous_6)
FN:62,done
FNF:7
FNH:7
FNDA:7,Queue
FNDA:3,(anonymous_2)
FNDA:13,(anonymous_3)
FNDA:19,(anonymous_4)
FNDA:45,(anonymous_5)
FNDA:6,(anonymous_6)
FNDA:13,done
DA:3,1
DA:4,7
DA:5,1
DA:8,6
DA:9,6
DA:10,6
DA:11,6
DA:12,6
DA:13,6
DA:16,1
DA:22,1
DA:23,3
DA:24,13
DA:25,13
DA:26,13
DA:30,1
DA:32,19
DA:36,1
DA:37,45
DA:38,6
DA:40,39
DA:41,13
DA:42,13
DA:43,13
DA:44,13
DA:47,39
DA:48,18
DA:49,6
DA:50,6
DA:55,1
DA:56,6
DA:57,6
DA:58,6
DA:62,1
DA:63,13
DA:64,13
DA:67,1
LF:37
LH:37
BRDA:4,1,0,1
BRDA:4,1,1,6
BRDA:8,2,0,6
BRDA:8,2,1,5
BRDA:9,3,0,6
BRDA:9,3,1,5
BRDA:37,4,0,6
BRDA:37,4,1,39
BRDA:40,5,0,13
BRDA:40,5,1,26
BRDA:47,6,0,18
BRDA:47,6,1,21
BRDA:56,7,0,6
BRDA:56,7,1,0
BRF:14
BRH:13
end_of_record

View file

@ -0,0 +1,67 @@
'use strict';
function Queue(options) {
if (!(this instanceof Queue)) {
return new Queue(options);
}
options = options || {};
this.concurrency = options.concurrency || Infinity;
this.pending = 0;
this.jobs = [];
this.cbs = [];
this._done = done.bind(this);
}
var arrayAddMethods = [
'push',
'unshift',
'splice'
];
arrayAddMethods.forEach(function(method) {
Queue.prototype[method] = function() {
var methodResult = Array.prototype[method].apply(this.jobs, arguments);
this._run();
return methodResult;
};
});
Object.defineProperty(Queue.prototype, 'length', {
get: function() {
return this.pending + this.jobs.length;
}
});
Queue.prototype._run = function() {
if (this.pending === this.concurrency) {
return;
}
if (this.jobs.length) {
var job = this.jobs.shift();
this.pending++;
job(this._done);
this._run();
}
if (this.pending === 0) {
while (this.cbs.length !== 0) {
var cb = this.cbs.pop();
process.nextTick(cb);
}
}
};
Queue.prototype.onDone = function(cb) {
if (typeof cb === 'function') {
this.cbs.push(cb);
this._run();
}
};
function done() {
this.pending--;
this._run();
}
module.exports = Queue;

View file

@ -0,0 +1,97 @@
{
"_args": [
[
"async-limiter@~1.0.0",
"/var/www/html/code/workspace/codiad/Testing/node_modules/ws"
]
],
"_from": "async-limiter@>=1.0.0 <1.1.0",
"_id": "async-limiter@1.0.0",
"_inCache": true,
"_installable": true,
"_location": "/async-limiter",
"_nodeVersion": "8.4.0",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/async-limiter-1.0.0.tgz_1505149068503_0.15003100014291704"
},
"_npmUser": {
"email": "samuel.trace.reed@gmail.com",
"name": "strml"
},
"_npmVersion": "5.4.1",
"_phantomChildren": {},
"_requested": {
"name": "async-limiter",
"raw": "async-limiter@~1.0.0",
"rawSpec": "~1.0.0",
"scope": null,
"spec": ">=1.0.0 <1.1.0",
"type": "range"
},
"_requiredBy": [
"/ws"
],
"_resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"_shasum": "78faed8c3d074ab81f22b4e985d79e8738f720f8",
"_shrinkwrap": null,
"_spec": "async-limiter@~1.0.0",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/ws",
"author": {
"name": "Samuel Reed"
},
"bugs": {
"url": "https://github.com/strml/async-limiter/issues"
},
"dependencies": {},
"description": "asynchronous function queue with adjustable concurrency",
"devDependencies": {
"coveralls": "^2.11.2",
"eslint": "^4.6.1",
"eslint-plugin-mocha": "^4.11.0",
"intelli-espower-loader": "^1.0.1",
"istanbul": "^0.3.2",
"mocha": "^3.5.2",
"power-assert": "^1.4.4"
},
"directories": {},
"dist": {
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==",
"shasum": "78faed8c3d074ab81f22b4e985d79e8738f720f8",
"tarball": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz"
},
"gitHead": "02c8b498279dc7cc1ecc1c4f6fc9ca320c0ce39b",
"homepage": "https://github.com/strml/async-limiter#readme",
"keywords": [
"async",
"asynchronous",
"concurrency",
"concurrent",
"job",
"limiter",
"task",
"throttle"
],
"license": "MIT",
"maintainers": [
{
"name": "strml",
"email": "samuel.trace.reed@gmail.com"
}
],
"name": "async-limiter",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/strml/async-limiter.git"
},
"scripts": {
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls",
"example": "node example",
"lint": "eslint .",
"test": "mocha --R intelli-espower-loader test/",
"travis": "npm run lint && npm run coverage"
},
"version": "1.0.0"
}

View file

@ -0,0 +1,132 @@
# Async-Limiter
A module for limiting concurrent asynchronous actions in flight. Forked from [queue](https://github.com/jessetane/queue).
[![npm](http://img.shields.io/npm/v/async-limiter.svg?style=flat-square)](http://www.npmjs.org/async-limiter)
[![tests](https://img.shields.io/travis/STRML/async-limiter.svg?style=flat-square&branch=master)](https://travis-ci.org/STRML/async-limiter)
[![coverage](https://img.shields.io/coveralls/STRML/async-limiter.svg?style=flat-square&branch=master)](https://coveralls.io/r/STRML/async-limiter)
This module exports a class `Limiter` that implements some of the `Array` API.
Pass async functions (ones that accept a callback or return a promise) to an instance's additive array methods.
## Motivation
Certain functions, like `zlib`, have [undesirable behavior](https://github.com/nodejs/node/issues/8871#issuecomment-250915913) when
run at infinite concurrency.
In this case, it is actually faster, and takes far less memory, to limit concurrency.
This module should do the absolute minimum work necessary to queue up functions. PRs are welcome that would
make this module faster or lighter, but new functionality is not desired.
Style should confirm to nodejs/node style.
## Example
``` javascript
var Limiter = require('async-limiter')
var t = new Limiter({concurrency: 2});
var results = []
// add jobs using the familiar Array API
t.push(function (cb) {
results.push('two')
cb()
})
t.push(
function (cb) {
results.push('four')
cb()
},
function (cb) {
results.push('five')
cb()
}
)
t.unshift(function (cb) {
results.push('one')
cb()
})
t.splice(2, 0, function (cb) {
results.push('three')
cb()
})
// Jobs run automatically. If you want a callback when all are done,
// call 'onDone()'.
t.onDone(function () {
console.log('all done:', results)
})
```
## Zlib Example
```js
const zlib = require('zlib');
const Limiter = require('async-limiter');
const message = {some: "data"};
const payload = new Buffer(JSON.stringify(message));
// Try with different concurrency values to see how this actually
// slows significantly with higher concurrency!
//
// 5: 1398.607ms
// 10: 1375.668ms
// Infinity: 4423.300ms
//
const t = new Limiter({concurrency: 5});
function deflate(payload, cb) {
t.push(function(done) {
zlib.deflate(payload, function(err, buffer) {
done();
cb(err, buffer);
});
});
}
console.time('deflate');
for(let i = 0; i < 30000; ++i) {
deflate(payload, function (err, buffer) {});
}
q.onDone(function() {
console.timeEnd('deflate');
});
```
## Install
`npm install async-limiter`
## Test
`npm test`
## API
### `var t = new Limiter([opts])`
Constructor. `opts` may contain inital values for:
* `q.concurrency`
## Instance methods
### `q.onDone(fn)`
`fn` will be called once and only once, when the queue is empty.
## Instance methods mixed in from `Array`
Mozilla has docs on how these methods work [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
### `q.push(element1, ..., elementN)`
### `q.unshift(element1, ..., elementN)`
### `q.splice(index , howMany[, element1[, ...[, elementN]]])`
## Properties
### `q.concurrency`
Max number of jobs the queue should process concurrently, defaults to `Infinity`.
### `q.length`
Jobs pending + jobs to process (readonly).

View file

@ -0,0 +1 @@
node_modules/

View file

@ -0,0 +1,12 @@
1.0.1 / 2014-02-17
==================
* go away decimal point
* history
1.0.0 / 2014-02-17
==================
* add jitter option
* Initial commit

View file

@ -0,0 +1,8 @@
test:
@./node_modules/.bin/mocha \
--require should \
--reporter dot \
--bail
.PHONY: test

View file

@ -0,0 +1,34 @@
# backo
Simple exponential backoff because the others seem to have weird abstractions.
## Installation
```
$ npm install backo
```
## Options
- `min` initial timeout in milliseconds [100]
- `max` max timeout [10000]
- `jitter` [0]
- `factor` [2]
## Example
```js
var Backoff = require('backo');
var backoff = new Backoff({ min: 100, max: 20000 });
setTimeout(function(){
something.reconnect();
}, backoff.duration());
// later when something works
backoff.reset()
```
# License
MIT

View file

@ -0,0 +1,11 @@
{
"name": "backo",
"repo": "segmentio/backo",
"dependencies": {},
"version": "1.0.1",
"description": "simple backoff without the weird abstractions",
"keywords": ["backoff"],
"license": "MIT",
"scripts": ["index.js"],
"main": "index.js"
}

View file

@ -0,0 +1,85 @@
/**
* Expose `Backoff`.
*/
module.exports = Backoff;
/**
* Initialize backoff timer with `opts`.
*
* - `min` initial timeout in milliseconds [100]
* - `max` max timeout [10000]
* - `jitter` [0]
* - `factor` [2]
*
* @param {Object} opts
* @api public
*/
function Backoff(opts) {
opts = opts || {};
this.ms = opts.min || 100;
this.max = opts.max || 10000;
this.factor = opts.factor || 2;
this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
this.attempts = 0;
}
/**
* Return the backoff duration.
*
* @return {Number}
* @api public
*/
Backoff.prototype.duration = function(){
var ms = this.ms * Math.pow(this.factor, this.attempts++);
if (this.jitter) {
var rand = Math.random();
var deviation = Math.floor(rand * this.jitter * ms);
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
}
return Math.min(ms, this.max) | 0;
};
/**
* Reset the number of attempts.
*
* @api public
*/
Backoff.prototype.reset = function(){
this.attempts = 0;
};
/**
* Set the minimum duration
*
* @api public
*/
Backoff.prototype.setMin = function(min){
this.ms = min;
};
/**
* Set the maximum duration
*
* @api public
*/
Backoff.prototype.setMax = function(max){
this.max = max;
};
/**
* Set the jitter
*
* @api public
*/
Backoff.prototype.setJitter = function(jitter){
this.jitter = jitter;
};

View file

@ -0,0 +1,70 @@
{
"_args": [
[
"backo2@1.0.2",
"/var/www/html/code/workspace/codiad/Testing/node_modules/socket.io-client"
]
],
"_from": "backo2@1.0.2",
"_id": "backo2@1.0.2",
"_inCache": true,
"_installable": true,
"_location": "/backo2",
"_npmUser": {
"email": "mokesmokes@gmail.com",
"name": "mokesmokes"
},
"_npmVersion": "1.4.28",
"_phantomChildren": {},
"_requested": {
"name": "backo2",
"raw": "backo2@1.0.2",
"rawSpec": "1.0.2",
"scope": null,
"spec": "1.0.2",
"type": "version"
},
"_requiredBy": [
"/socket.io-client"
],
"_resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
"_shasum": "31ab1ac8b129363463e35b3ebb69f4dfcfba7947",
"_shrinkwrap": null,
"_spec": "backo2@1.0.2",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/socket.io-client",
"bugs": {
"url": "https://github.com/mokesmokes/backo/issues"
},
"dependencies": {},
"description": "simple backoff based on segmentio/backo",
"devDependencies": {
"mocha": "*",
"should": "*"
},
"directories": {},
"dist": {
"shasum": "31ab1ac8b129363463e35b3ebb69f4dfcfba7947",
"tarball": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz"
},
"gitHead": "3e695bade7756fef2295e8883bf3570a06e5d9ec",
"homepage": "https://github.com/mokesmokes/backo",
"keywords": [
"backoff"
],
"license": "MIT",
"maintainers": [
{
"name": "mokesmokes",
"email": "mokesmokes@gmail.com"
}
],
"name": "backo2",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/mokesmokes/backo.git"
},
"scripts": {},
"version": "1.0.2"
}

View file

@ -0,0 +1,18 @@
var Backoff = require('..');
var assert = require('assert');
describe('.duration()', function(){
it('should increase the backoff', function(){
var b = new Backoff;
assert(100 == b.duration());
assert(200 == b.duration());
assert(400 == b.duration());
assert(800 == b.duration());
b.reset();
assert(100 == b.duration());
assert(200 == b.duration());
})
})

View file

@ -0,0 +1,3 @@
/node_modules/
Gruntfile.js
/test/

View file

@ -0,0 +1,19 @@
language: node_js
node_js:
- '0.12'
- iojs-1
- iojs-2
- iojs-3
- '4.1'
before_script:
- npm install
before_install: npm install -g npm@'>=2.13.5'
deploy:
provider: npm
email: niklasvh@gmail.com
api_key:
secure: oHV9ArprTj5WOk7MP1UF7QMJ70huXw+y7xXb5wF4+V2H8Hyfa5TfE0DiOmqrube1WXTeH1FLgq54shp/sJWi47Hkg/GyeoB5NnsPhYEaJkaON9UG5blML+ODiNVsEnq/1kNBQ8e0+0JItMPLGySKyFmuZ3yflulXKS8O88mfINo=
on:
tags: true
branch: master
repo: niklasvh/base64-arraybuffer

View file

@ -0,0 +1,22 @@
Copyright (c) 2012 Niklas von Hertzen
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.

View file

@ -0,0 +1,20 @@
# base64-arraybuffer
[![Build Status](https://travis-ci.org/niklasvh/base64-arraybuffer.png)](https://travis-ci.org/niklasvh/base64-arraybuffer)
[![NPM Downloads](https://img.shields.io/npm/dm/base64-arraybuffer.svg)](https://www.npmjs.org/package/base64-arraybuffer)
[![NPM Version](https://img.shields.io/npm/v/base64-arraybuffer.svg)](https://www.npmjs.org/package/base64-arraybuffer)
Encode/decode base64 data into ArrayBuffers
## Getting Started
Install the module with: `npm install base64-arraybuffer`
## API
The library encodes and decodes base64 to and from ArrayBuffers
- __encode(buffer)__ - Encodes `ArrayBuffer` into base64 string
- __decode(str)__ - Decodes base64 string to `ArrayBuffer`
## License
Copyright (c) 2012 Niklas von Hertzen
Licensed under the MIT license.

View file

@ -0,0 +1,67 @@
/*
* base64-arraybuffer
* https://github.com/niklasvh/base64-arraybuffer
*
* Copyright (c) 2012 Niklas von Hertzen
* Licensed under the MIT license.
*/
(function(){
"use strict";
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
// Use a lookup table to find the index.
var lookup = new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
exports.encode = function(arraybuffer) {
var bytes = new Uint8Array(arraybuffer),
i, len = bytes.length, base64 = "";
for (i = 0; i < len; i+=3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if ((len % 3) === 2) {
base64 = base64.substring(0, base64.length - 1) + "=";
} else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + "==";
}
return base64;
};
exports.decode = function(base64) {
var bufferLength = base64.length * 0.75,
len = base64.length, i, p = 0,
encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === "=") {
bufferLength--;
if (base64[base64.length - 2] === "=") {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength),
bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i+=4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i+1)];
encoded3 = lookup[base64.charCodeAt(i+2)];
encoded4 = lookup[base64.charCodeAt(i+3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
})();

View file

@ -0,0 +1,89 @@
{
"_args": [
[
"base64-arraybuffer@0.1.5",
"/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io-parser"
]
],
"_from": "base64-arraybuffer@0.1.5",
"_id": "base64-arraybuffer@0.1.5",
"_inCache": true,
"_installable": true,
"_location": "/base64-arraybuffer",
"_nodeVersion": "2.5.0",
"_npmUser": {
"email": "niklasvh@gmail.com",
"name": "niklasvh"
},
"_npmVersion": "3.4.0",
"_phantomChildren": {},
"_requested": {
"name": "base64-arraybuffer",
"raw": "base64-arraybuffer@0.1.5",
"rawSpec": "0.1.5",
"scope": null,
"spec": "0.1.5",
"type": "version"
},
"_requiredBy": [
"/engine.io-parser",
"/socket.io-client"
],
"_resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz",
"_shasum": "73926771923b5a19747ad666aa5cd4bf9c6e9ce8",
"_shrinkwrap": null,
"_spec": "base64-arraybuffer@0.1.5",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io-parser",
"author": {
"email": "niklasvh@gmail.com",
"name": "Niklas von Hertzen",
"url": "http://hertzen.com"
},
"bugs": {
"url": "https://github.com/niklasvh/base64-arraybuffer/issues"
},
"dependencies": {},
"description": "Encode/decode base64 data into ArrayBuffers",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.11.2",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-contrib-watch": "^0.6.1"
},
"directories": {},
"dist": {
"shasum": "73926771923b5a19747ad666aa5cd4bf9c6e9ce8",
"tarball": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz"
},
"engines": {
"node": ">= 0.6.0"
},
"gitHead": "e9457ccb7b140f5ae54a2880c8e9b967ffb03a7d",
"homepage": "https://github.com/niklasvh/base64-arraybuffer",
"keywords": [],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/niklasvh/base64-arraybuffer/blob/master/LICENSE-MIT"
}
],
"main": "lib/base64-arraybuffer",
"maintainers": [
{
"name": "niklasvh",
"email": "niklasvh@gmail.com"
}
],
"name": "base64-arraybuffer",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/niklasvh/base64-arraybuffer.git"
},
"scripts": {
"test": "grunt nodeunit"
},
"version": "0.1.5"
}

View file

@ -0,0 +1,3 @@
support
test
examples

View file

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2012-2016 Kristian Faeldt <faeldt_kristian@cyberagent.co.jp>
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.

View file

@ -0,0 +1,18 @@
base64id
========
Node.js module that generates a base64 id.
Uses crypto.randomBytes when available, falls back to unsafe methods for node.js <= 0.4.
To increase performance, random bytes are buffered to minimize the number of synchronous calls to crypto.randomBytes.
## Installation
$ npm install base64id
## Usage
var base64id = require('base64id');
var id = base64id.generateId();

View file

@ -0,0 +1,103 @@
/*!
* base64id v0.1.0
*/
/**
* Module dependencies
*/
var crypto = require('crypto');
/**
* Constructor
*/
var Base64Id = function() { };
/**
* Get random bytes
*
* Uses a buffer if available, falls back to crypto.randomBytes
*/
Base64Id.prototype.getRandomBytes = function(bytes) {
var BUFFER_SIZE = 4096
var self = this;
bytes = bytes || 12;
if (bytes > BUFFER_SIZE) {
return crypto.randomBytes(bytes);
}
var bytesInBuffer = parseInt(BUFFER_SIZE/bytes);
var threshold = parseInt(bytesInBuffer*0.85);
if (!threshold) {
return crypto.randomBytes(bytes);
}
if (this.bytesBufferIndex == null) {
this.bytesBufferIndex = -1;
}
if (this.bytesBufferIndex == bytesInBuffer) {
this.bytesBuffer = null;
this.bytesBufferIndex = -1;
}
// No buffered bytes available or index above threshold
if (this.bytesBufferIndex == -1 || this.bytesBufferIndex > threshold) {
if (!this.isGeneratingBytes) {
this.isGeneratingBytes = true;
crypto.randomBytes(BUFFER_SIZE, function(err, bytes) {
self.bytesBuffer = bytes;
self.bytesBufferIndex = 0;
self.isGeneratingBytes = false;
});
}
// Fall back to sync call when no buffered bytes are available
if (this.bytesBufferIndex == -1) {
return crypto.randomBytes(bytes);
}
}
var result = this.bytesBuffer.slice(bytes*this.bytesBufferIndex, bytes*(this.bytesBufferIndex+1));
this.bytesBufferIndex++;
return result;
}
/**
* Generates a base64 id
*
* (Original version from socket.io <http://socket.io>)
*/
Base64Id.prototype.generateId = function () {
var rand = new Buffer(15); // multiple of 3 for base64
if (!rand.writeInt32BE) {
return Math.abs(Math.random() * Math.random() * Date.now() | 0).toString()
+ Math.abs(Math.random() * Math.random() * Date.now() | 0).toString();
}
this.sequenceNumber = (this.sequenceNumber + 1) | 0;
rand.writeInt32BE(this.sequenceNumber, 11);
if (crypto.randomBytes) {
this.getRandomBytes(12).copy(rand);
} else {
// not secure for node 0.4
[0, 4, 8].forEach(function(i) {
rand.writeInt32BE(Math.random() * Math.pow(2, 32) | 0, i);
});
}
return rand.toString('base64').replace(/\//g, '_').replace(/\+/g, '-');
};
/**
* Export
*/
exports = module.exports = new Base64Id();

View file

@ -0,0 +1,81 @@
{
"_args": [
[
"base64id@1.0.0",
"/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io"
]
],
"_from": "base64id@1.0.0",
"_id": "base64id@1.0.0",
"_inCache": true,
"_installable": true,
"_location": "/base64id",
"_nodeVersion": "4.4.7",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/base64id-1.0.0.tgz_1480551701495_0.042360062478110194"
},
"_npmUser": {
"email": "damien.arrachequesne@gmail.com",
"name": "darrachequesne"
},
"_npmVersion": "2.15.8",
"_phantomChildren": {},
"_requested": {
"name": "base64id",
"raw": "base64id@1.0.0",
"rawSpec": "1.0.0",
"scope": null,
"spec": "1.0.0",
"type": "version"
},
"_requiredBy": [
"/engine.io"
],
"_resolved": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz",
"_shasum": "47688cb99bb6804f0e06d3e763b1c32e57d8e6b6",
"_shrinkwrap": null,
"_spec": "base64id@1.0.0",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/engine.io",
"author": {
"email": "faeldt_kristian@cyberagent.co.jp",
"name": "Kristian Faeldt"
},
"bugs": {
"url": "https://github.com/faeldt/base64id/issues"
},
"dependencies": {},
"description": "Generates a base64 id",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "47688cb99bb6804f0e06d3e763b1c32e57d8e6b6",
"tarball": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz"
},
"engines": {
"node": ">= 0.4.0"
},
"gitHead": "3c846f0818ff88b683ad39fde2f8e015ce0f9807",
"homepage": "https://github.com/faeldt/base64id#readme",
"license": "MIT",
"main": "./lib/base64id.js",
"maintainers": [
{
"name": "darrachequesne",
"email": "damien.arrachequesne@gmail.com"
},
{
"name": "faeldt_kristian",
"email": "kristian.faeldt@gmail.com"
}
],
"name": "base64id",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/faeldt/base64id.git"
},
"scripts": {},
"version": "1.0.0"
}

View file

@ -0,0 +1,4 @@
support
test
examples
*.sock

View file

@ -0,0 +1,15 @@
1.0.0 / 2013-02-03
==================
* Stop using the removed magic __stack global getter
0.1.0 / 2012-10-04
==================
* add throwing of AssertionError for test frameworks etc
0.0.1 / 2010-01-03
==================
* Initial release

View file

@ -0,0 +1,5 @@
test:
@echo "populate me"
.PHONY: test

View file

@ -0,0 +1,61 @@
# better-assert
Better c-style assertions using [callsite](https://github.com/visionmedia/callsite) for
self-documenting failure messages.
## Installation
$ npm install better-assert
## Example
By default assertions are enabled, however the __NO_ASSERT__ environment variable
will deactivate them when truthy.
```js
var assert = require('better-assert');
test();
function test() {
var user = { name: 'tobi' };
assert('tobi' == user.name);
assert('number' == typeof user.age);
}
AssertionError: 'number' == typeof user.age
at test (/Users/tj/projects/better-assert/example.js:9:3)
at Object.<anonymous> (/Users/tj/projects/better-assert/example.js:4:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
```
## License
(The MIT License)
Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
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.

View file

@ -0,0 +1,10 @@
var assert = require('./');
test();
function test() {
var user = { name: 'tobi' };
assert('tobi' == user.name);
assert('number' == typeof user.age);
}

View file

@ -0,0 +1,38 @@
/**
* Module dependencies.
*/
var AssertionError = require('assert').AssertionError
, callsite = require('callsite')
, fs = require('fs')
/**
* Expose `assert`.
*/
module.exports = process.env.NO_ASSERT
? function(){}
: assert;
/**
* Assert the given `expr`.
*/
function assert(expr) {
if (expr) return;
var stack = callsite();
var call = stack[1];
var file = call.getFileName();
var lineno = call.getLineNumber();
var src = fs.readFileSync(file, 'utf8');
var line = src.split('\n')[lineno-1];
var src = line.match(/assert\((.*)\)/)[1];
var err = new AssertionError({
message: src,
stackStartFunction: stack[0].getFunction()
});
throw err;
}

View file

@ -0,0 +1,91 @@
{
"_args": [
[
"better-assert@~1.0.0",
"/var/www/html/code/workspace/codiad/Testing/node_modules/parseqs"
]
],
"_from": "better-assert@>=1.0.0 <1.1.0",
"_id": "better-assert@1.0.2",
"_inCache": true,
"_installable": true,
"_location": "/better-assert",
"_npmUser": {
"email": "coolhzb@163.com",
"name": "tony_ado"
},
"_npmVersion": "1.4.9",
"_phantomChildren": {},
"_requested": {
"name": "better-assert",
"raw": "better-assert@~1.0.0",
"rawSpec": "~1.0.0",
"scope": null,
"spec": ">=1.0.0 <1.1.0",
"type": "range"
},
"_requiredBy": [
"/parseqs",
"/parseuri"
],
"_resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz",
"_shasum": "40866b9e1b9e0b55b481894311e68faffaebc522",
"_shrinkwrap": null,
"_spec": "better-assert@~1.0.0",
"_where": "/var/www/html/code/workspace/codiad/Testing/node_modules/parseqs",
"author": {
"email": "tj@vision-media.ca",
"name": "TJ Holowaychuk"
},
"bugs": {
"url": "https://github.com/visionmedia/better-assert/issues"
},
"contributors": [
{
"name": "TonyHe",
"email": "coolhzb@163.com"
},
{
"name": "ForbesLindesay"
}
],
"dependencies": {
"callsite": "1.0.0"
},
"description": "Better assertions for node, reporting the expr, filename, lineno etc",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "40866b9e1b9e0b55b481894311e68faffaebc522",
"tarball": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz"
},
"engines": {
"node": "*"
},
"homepage": "https://github.com/visionmedia/better-assert",
"keywords": [
"assert",
"debug",
"stack",
"trace"
],
"main": "index",
"maintainers": [
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "tony_ado",
"email": "coolhzb@163.com"
}
],
"name": "better-assert",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/visionmedia/better-assert.git"
},
"version": "1.0.2"
}

Some files were not shown because too many files have changed in this diff Show more