mirror of
https://github.com/apache/cordova-android.git
synced 2026-03-16 00:00:02 +08:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8815c24fa | ||
|
|
4b74367e61 | ||
|
|
fe5ef2bfef | ||
|
|
603f994f3f | ||
|
|
ada35e0e00 | ||
|
|
fc778006ef | ||
|
|
11760afddd | ||
|
|
d78ae309f1 | ||
|
|
73fd9e4dfa | ||
|
|
fb9cf60c41 | ||
|
|
b6a329d479 | ||
|
|
70bc7b39b7 | ||
|
|
03777067cd | ||
|
|
f5271431fb | ||
|
|
c30eeee5d8 | ||
|
|
dac02bef8c | ||
|
|
32edaee3a2 | ||
|
|
ff1c58def4 | ||
|
|
f9372f5578 | ||
|
|
6afc16c33b | ||
|
|
74a3d2028f |
94
.gitattributes
vendored
Normal file
94
.gitattributes
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
* text eol=lf
|
||||
|
||||
# source code
|
||||
*.php text
|
||||
*.css text
|
||||
*.sass text
|
||||
*.scss text
|
||||
*.less text
|
||||
*.styl text
|
||||
*.js text
|
||||
*.coffee text
|
||||
*.json text
|
||||
*.htm text
|
||||
*.html text
|
||||
*.xml text
|
||||
*.svg text
|
||||
*.txt text
|
||||
*.ini text
|
||||
*.inc text
|
||||
*.pl text
|
||||
*.rb text
|
||||
*.py text
|
||||
*.scm text
|
||||
*.sql text
|
||||
*.sh text
|
||||
*.bat text
|
||||
|
||||
# templates
|
||||
*.ejs text
|
||||
*.hbt text
|
||||
*.jade text
|
||||
*.haml text
|
||||
*.hbs text
|
||||
*.dot text
|
||||
*.tmpl text
|
||||
*.phtml text
|
||||
|
||||
# server config
|
||||
.htaccess text
|
||||
|
||||
# git config
|
||||
.gitattributes text
|
||||
.gitignore text
|
||||
.gitconfig text
|
||||
|
||||
# code analysis config
|
||||
.jshintrc text
|
||||
.jscsrc text
|
||||
.jshintignore text
|
||||
.csslintrc text
|
||||
|
||||
# misc config
|
||||
*.yaml text
|
||||
*.yml text
|
||||
.editorconfig text
|
||||
|
||||
# build config
|
||||
*.npmignore text
|
||||
*.bowerrc text
|
||||
|
||||
# Heroku
|
||||
Procfile text
|
||||
.slugignore text
|
||||
|
||||
# Documentation
|
||||
*.md text
|
||||
LICENSE text
|
||||
AUTHORS text
|
||||
|
||||
|
||||
#
|
||||
## These files are binary and should be left untouched
|
||||
#
|
||||
|
||||
# (binary is a macro for -text -diff)
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
||||
*.gif binary
|
||||
*.ico binary
|
||||
*.mov binary
|
||||
*.mp4 binary
|
||||
*.mp3 binary
|
||||
*.flv binary
|
||||
*.fla binary
|
||||
*.swf binary
|
||||
*.gz binary
|
||||
*.zip binary
|
||||
*.7z binary
|
||||
*.ttf binary
|
||||
*.eot binary
|
||||
*.woff binary
|
||||
*.pyc binary
|
||||
*.pdf binary
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -39,5 +39,5 @@ Desktop.ini
|
||||
*.iml
|
||||
.idea
|
||||
npm-debug.log
|
||||
/node_modules
|
||||
/framework/build
|
||||
node_modules/
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
language: android
|
||||
sudo: false
|
||||
install:
|
||||
- "(pushd .. && git clone https://github.com/apache/cordova-lib.git && popd)"
|
||||
- npm link ../cordova-lib/cordova-common
|
||||
- npm install
|
||||
- echo y | android update sdk -u --filter android-23
|
||||
- echo y | android update sdk -u --filter android-22,android-23
|
||||
script:
|
||||
- npm test
|
||||
- npm run test-build
|
||||
|
||||
@@ -19,7 +19,19 @@
|
||||
#
|
||||
-->
|
||||
## Release Notes for Cordova (Android) ##
|
||||
Update these notes using: git log --pretty=format:'* %s' --topo-order --no-merges *remote*/4.1.x...HEAD
|
||||
|
||||
### 5.1.0 (Jan 19, 2016)
|
||||
* CB-10386 Add `android.useDeprecatedNdk=true` to support `NDK` in `gradle`
|
||||
* CB-8864: Fixing this to mitigate CB-8685 and CB-10104
|
||||
* CB-10105: Spot fix for tilde errors on paths.
|
||||
* Update theme to `Theme.DeviceDefault.NoActionBar`
|
||||
* CB-10014: Set gradle `applicationId` to `package name`.
|
||||
* CB-9949: Fixing menu button event not fired in **Android**
|
||||
* CB-9479: Fixing the conditionals again, we should
|
||||
* CB-8917: New Plugin API for passing results on resume after Activity destruction
|
||||
* CB-9971 Suppress `gradlew _JAVA_OPTIONS` output during build
|
||||
* CB-9836 Add `.gitattributes` to prevent `CRLF` line endings in repos
|
||||
* added node_modules back into `.gitignore`
|
||||
|
||||
### 5.0.0 (Nov 01, 2015)
|
||||
* Update CordovaWebViewEngine.java
|
||||
|
||||
14
bin/templates/cordova/lib/build.js
vendored
14
bin/templates/cordova/lib/build.js
vendored
@@ -61,13 +61,13 @@ function parseOpts(options, resolvedTarget) {
|
||||
if (options.nobuild) ret.buildMethod = 'none';
|
||||
|
||||
if (options.argv.versionCode)
|
||||
ret.extraArgs.push('-PcdvVersionCode=' + options.versionCode);
|
||||
ret.extraArgs.push('-PcdvVersionCode=' + options.argv.versionCode);
|
||||
|
||||
if (options.argv.minSdkVersion)
|
||||
ret.extraArgs.push('-PcdvMinSdkVersion=' + options.minSdkVersion);
|
||||
ret.extraArgs.push('-PcdvMinSdkVersion=' + options.argv.minSdkVersion);
|
||||
|
||||
if (options.argv.gradleArg)
|
||||
ret.extraArgs.push(options.gradleArg);
|
||||
ret.extraArgs.push(options.argv.gradleArg);
|
||||
|
||||
var packageArgs = {};
|
||||
|
||||
@@ -88,11 +88,17 @@ function parseOpts(options, resolvedTarget) {
|
||||
throw new Error('Specified build config file does not exist: ' + buildConfig);
|
||||
}
|
||||
events.emit('log', 'Reading build config file: '+ path.resolve(buildConfig));
|
||||
var config = JSON.parse(fs.readFileSync(buildConfig, 'utf8'));
|
||||
var buildjson = fs.readFileSync(buildConfig, 'utf8');
|
||||
//var config = JSON.parse(fs.readFileSync(buildConfig, 'utf8'));
|
||||
var config = JSON.parse(buildjson);
|
||||
if (config.android && config.android[ret.buildType]) {
|
||||
var androidInfo = config.android[ret.buildType];
|
||||
if(androidInfo.keystore && !packageArgs.keystore) {
|
||||
if(androidInfo.keystore.substr(0,1) === '~') {
|
||||
androidInfo.keystore = process.env.HOME + androidInfo.keystore.substr(1);
|
||||
}
|
||||
packageArgs.keystore = path.resolve(path.dirname(buildConfig), androidInfo.keystore);
|
||||
events.emit('log', 'Reading the keystore from: ' + packageArgs.keystore);
|
||||
}
|
||||
|
||||
['alias', 'storePassword', 'password','keystoreType'].forEach(function (key){
|
||||
|
||||
@@ -22,6 +22,7 @@ var fs = require('fs');
|
||||
var util = require('util');
|
||||
var path = require('path');
|
||||
var shell = require('shelljs');
|
||||
var child_process = require('child_process');
|
||||
var spawn = require('cordova-common').superspawn.spawn;
|
||||
var CordovaError = require('cordova-common').CordovaError;
|
||||
var check_reqs = require('../check_reqs');
|
||||
@@ -55,6 +56,8 @@ GradleBuilder.prototype.getArgs = function(cmd, opts) {
|
||||
|
||||
// 10 seconds -> 6 seconds
|
||||
args.push('-Dorg.gradle.daemon=true');
|
||||
// allow NDK to be used - required by Gradle 1.5 plugin
|
||||
args.push('-Pandroid.useDeprecatedNdk=true');
|
||||
args.push.apply(args, opts.extraArgs);
|
||||
// Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
|
||||
// args.push('-Dorg.gradle.parallel=true');
|
||||
@@ -182,9 +185,7 @@ GradleBuilder.prototype.prepEnv = function(opts) {
|
||||
GradleBuilder.prototype.build = function(opts) {
|
||||
var wrapper = path.join(this.root, 'gradlew');
|
||||
var args = this.getArgs(opts.buildType == 'debug' ? 'debug' : 'release', opts);
|
||||
return Q().then(function() {
|
||||
return spawn(wrapper, args, {stdio: 'inherit'});
|
||||
});
|
||||
return spawnAndSuppressJavaOptions(wrapper, args);
|
||||
};
|
||||
|
||||
GradleBuilder.prototype.clean = function(opts) {
|
||||
@@ -211,3 +212,64 @@ module.exports = GradleBuilder;
|
||||
function isAutoGenerated(file) {
|
||||
return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* A special superspawn-like implementation, required to workaround the issue
|
||||
* with Java printing some unwanted information to stderr instead of stdout.
|
||||
* This function suppresses 'Picked up _JAVA_OPTIONS' message from being
|
||||
* printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
|
||||
* explanation.
|
||||
*
|
||||
* This function needed because superspawn does not provide a way to get and
|
||||
* manage spawned process output streams. There is a CB-10052 which describes
|
||||
* an improvements for superspawn, needed to get rid of this.
|
||||
* TODO: Once this improvement added to cordova-common, we could remove this functionality.
|
||||
*
|
||||
* @param {String} cmd A command to spawn
|
||||
* @param {String[]} args Command arguments. Note that on Windows arguments
|
||||
* will be concatenated into string and passed to 'cmd.exe' along with '/s'
|
||||
* and '/c' switches for proper space-in-path handling
|
||||
*
|
||||
* @return {Promise} A promise, rejected with error message if
|
||||
* underlying command exits with nonzero exit code, fulfilled otherwise
|
||||
*/
|
||||
function spawnAndSuppressJavaOptions(cmd, args) {
|
||||
var opts = { stdio: 'pipe' };
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Work around spawn not being able to find .bat files.
|
||||
var joinedArgs = [cmd]
|
||||
.concat(args)
|
||||
.map(function(a){
|
||||
// Add quotes to arguments which contains whitespaces
|
||||
if (/^[^"].* .*[^"]/.test(a)) return '"' + a + '"';
|
||||
return a;
|
||||
}).join(' ');
|
||||
|
||||
args = ['/s', '/c'].concat('"' + joinedArgs + '"');
|
||||
cmd = 'cmd';
|
||||
opts.windowsVerbatimArguments = true;
|
||||
}
|
||||
|
||||
return Q.Promise(function (resolve, reject) {
|
||||
var proc = child_process.spawn(cmd, args, opts);
|
||||
|
||||
proc.stdout.on('data', process.stdout.write.bind(process.stdout));
|
||||
proc.stderr.on('data', function (data) {
|
||||
var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(data.toString());
|
||||
if (suppressThisLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
process.stderr.write(data);
|
||||
});
|
||||
|
||||
proc.on('exit', function(code) {
|
||||
if (code) {
|
||||
reject('Error code ' + code + ' for command: ' + cmd + ' with args: ' + args);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
// Coho updates this line:
|
||||
var VERSION = "5.0.0-dev";
|
||||
var VERSION = "5.1.0";
|
||||
|
||||
module.exports.version = VERSION;
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<activity android:name="__ACTIVITY__"
|
||||
android:label="@string/activity_name"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
|
||||
<intent-filter android:label="@string/launcher_name">
|
||||
|
||||
243
bin/templates/project/assets/www/cordova.js
vendored
243
bin/templates/project/assets/www/cordova.js
vendored
@@ -1,5 +1,5 @@
|
||||
// Platform: android
|
||||
// a83e94b489774dc8e514671e81c6154eda650af1
|
||||
// ded62dda172755defaf75378ed007dc05730ec22
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
@@ -19,7 +19,7 @@
|
||||
under the License.
|
||||
*/
|
||||
;(function() {
|
||||
var PLATFORM_VERSION_BUILD_LABEL = '4.2.0-dev';
|
||||
var PLATFORM_VERSION_BUILD_LABEL = '5.1.0';
|
||||
// file: src/scripts/require.js
|
||||
|
||||
/*jshint -W079 */
|
||||
@@ -101,7 +101,9 @@ if (typeof module === "object" && typeof require === "function") {
|
||||
// file: src/cordova.js
|
||||
define("cordova", function(require, exports, module) {
|
||||
|
||||
if(window.cordova){
|
||||
// Workaround for Windows 10 in hosted environment case
|
||||
// http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
|
||||
if (window.cordova && !(window.cordova instanceof HTMLElement)) {
|
||||
throw new Error("cordova already defined");
|
||||
}
|
||||
|
||||
@@ -328,7 +330,7 @@ module.exports = cordova;
|
||||
|
||||
});
|
||||
|
||||
// file: D:/cordova/cordova-android/cordova-js-src/android/nativeapiprovider.js
|
||||
// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/android/nativeapiprovider.js
|
||||
define("cordova/android/nativeapiprovider", function(require, exports, module) {
|
||||
|
||||
/**
|
||||
@@ -351,7 +353,7 @@ module.exports = {
|
||||
|
||||
});
|
||||
|
||||
// file: D:/cordova/cordova-android/cordova-js-src/android/promptbasednativeapi.js
|
||||
// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/android/promptbasednativeapi.js
|
||||
define("cordova/android/promptbasednativeapi", function(require, exports, module) {
|
||||
|
||||
/**
|
||||
@@ -376,7 +378,6 @@ module.exports = {
|
||||
// file: src/common/argscheck.js
|
||||
define("cordova/argscheck", function(require, exports, module) {
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var utils = require('cordova/utils');
|
||||
|
||||
var moduleExports = module.exports;
|
||||
@@ -861,7 +862,7 @@ module.exports = channel;
|
||||
|
||||
});
|
||||
|
||||
// file: D:/cordova/cordova-android/cordova-js-src/exec.js
|
||||
// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/exec.js
|
||||
define("cordova/exec", function(require, exports, module) {
|
||||
|
||||
/**
|
||||
@@ -1230,6 +1231,7 @@ if (!window.console.warn) {
|
||||
// Register pause, resume and deviceready channels as events on document.
|
||||
channel.onPause = cordova.addDocumentEventHandler('pause');
|
||||
channel.onResume = cordova.addDocumentEventHandler('resume');
|
||||
channel.onActivated = cordova.addDocumentEventHandler('activated');
|
||||
channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
|
||||
|
||||
// Listen for DOMContentLoaded and notify our channel subscribers.
|
||||
@@ -1291,10 +1293,12 @@ define("cordova/init_b", function(require, exports, module) {
|
||||
|
||||
var channel = require('cordova/channel');
|
||||
var cordova = require('cordova');
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
var platform = require('cordova/platform');
|
||||
var pluginloader = require('cordova/pluginloader');
|
||||
var utils = require('cordova/utils');
|
||||
|
||||
var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady];
|
||||
var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady, channel.onPluginsReady];
|
||||
|
||||
// setting exec
|
||||
cordova.exec = require('cordova/exec');
|
||||
@@ -1357,6 +1361,7 @@ if (!window.console.warn) {
|
||||
// Register pause, resume and deviceready channels as events on document.
|
||||
channel.onPause = cordova.addDocumentEventHandler('pause');
|
||||
channel.onResume = cordova.addDocumentEventHandler('resume');
|
||||
channel.onActivated = cordova.addDocumentEventHandler('activated');
|
||||
channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
|
||||
|
||||
// Listen for DOMContentLoaded and notify our channel subscribers.
|
||||
@@ -1378,10 +1383,19 @@ if (window._nativeReady) {
|
||||
// Call the platform-specific initialization.
|
||||
platform.bootstrap && platform.bootstrap();
|
||||
|
||||
// Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
|
||||
// The delay allows the attached modules to be defined before the plugin loader looks for them.
|
||||
setTimeout(function() {
|
||||
pluginloader.load(function() {
|
||||
channel.onPluginsReady.fire();
|
||||
});
|
||||
}, 0);
|
||||
|
||||
/**
|
||||
* Create all cordova objects once native side is ready.
|
||||
*/
|
||||
channel.join(function() {
|
||||
modulemapper.mapModules(window);
|
||||
|
||||
platform.initialize && platform.initialize();
|
||||
|
||||
@@ -1500,7 +1514,104 @@ exports.reset();
|
||||
|
||||
});
|
||||
|
||||
// file: D:/cordova/cordova-android/cordova-js-src/platform.js
|
||||
// file: src/common/modulemapper_b.js
|
||||
define("cordova/modulemapper_b", function(require, exports, module) {
|
||||
|
||||
var builder = require('cordova/builder'),
|
||||
symbolList = [],
|
||||
deprecationMap;
|
||||
|
||||
exports.reset = function() {
|
||||
symbolList = [];
|
||||
deprecationMap = {};
|
||||
};
|
||||
|
||||
function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
|
||||
symbolList.push(strategy, moduleName, symbolPath);
|
||||
if (opt_deprecationMessage) {
|
||||
deprecationMap[symbolPath] = opt_deprecationMessage;
|
||||
}
|
||||
}
|
||||
|
||||
// Note: Android 2.3 does have Function.bind().
|
||||
exports.clobbers = function(moduleName, symbolPath, opt_deprecationMessage) {
|
||||
addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
|
||||
};
|
||||
|
||||
exports.merges = function(moduleName, symbolPath, opt_deprecationMessage) {
|
||||
addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
|
||||
};
|
||||
|
||||
exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) {
|
||||
addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
|
||||
};
|
||||
|
||||
exports.runs = function(moduleName) {
|
||||
addEntry('r', moduleName, null);
|
||||
};
|
||||
|
||||
function prepareNamespace(symbolPath, context) {
|
||||
if (!symbolPath) {
|
||||
return context;
|
||||
}
|
||||
var parts = symbolPath.split('.');
|
||||
var cur = context;
|
||||
for (var i = 0, part; part = parts[i]; ++i) {
|
||||
cur = cur[part] = cur[part] || {};
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
|
||||
exports.mapModules = function(context) {
|
||||
var origSymbols = {};
|
||||
context.CDV_origSymbols = origSymbols;
|
||||
for (var i = 0, len = symbolList.length; i < len; i += 3) {
|
||||
var strategy = symbolList[i];
|
||||
var moduleName = symbolList[i + 1];
|
||||
var module = require(moduleName);
|
||||
// <runs/>
|
||||
if (strategy == 'r') {
|
||||
continue;
|
||||
}
|
||||
var symbolPath = symbolList[i + 2];
|
||||
var lastDot = symbolPath.lastIndexOf('.');
|
||||
var namespace = symbolPath.substr(0, lastDot);
|
||||
var lastName = symbolPath.substr(lastDot + 1);
|
||||
|
||||
var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
|
||||
var parentObj = prepareNamespace(namespace, context);
|
||||
var target = parentObj[lastName];
|
||||
|
||||
if (strategy == 'm' && target) {
|
||||
builder.recursiveMerge(target, module);
|
||||
} else if ((strategy == 'd' && !target) || (strategy != 'd')) {
|
||||
if (!(symbolPath in origSymbols)) {
|
||||
origSymbols[symbolPath] = target;
|
||||
}
|
||||
builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.getOriginalSymbol = function(context, symbolPath) {
|
||||
var origSymbols = context.CDV_origSymbols;
|
||||
if (origSymbols && (symbolPath in origSymbols)) {
|
||||
return origSymbols[symbolPath];
|
||||
}
|
||||
var parts = symbolPath.split('.');
|
||||
var obj = context;
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
obj = obj && obj[parts[i]];
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
exports.reset();
|
||||
|
||||
|
||||
});
|
||||
|
||||
// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/platform.js
|
||||
define("cordova/platform", function(require, exports, module) {
|
||||
|
||||
module.exports = {
|
||||
@@ -1563,12 +1674,26 @@ function onMessageFromNative(msg) {
|
||||
case 'searchbutton':
|
||||
// App life cycle events
|
||||
case 'pause':
|
||||
case 'resume':
|
||||
// Volume events
|
||||
case 'volumedownbutton':
|
||||
case 'volumeupbutton':
|
||||
cordova.fireDocumentEvent(action);
|
||||
break;
|
||||
case 'resume':
|
||||
if(arguments.length > 1 && msg.pendingResult) {
|
||||
if(arguments.length === 2) {
|
||||
msg.pendingResult.result = arguments[1];
|
||||
} else {
|
||||
// The plugin returned a multipart message
|
||||
var res = [];
|
||||
for(var i = 1; i < arguments.length; i++) {
|
||||
res.push(arguments[i]);
|
||||
}
|
||||
msg.pendingResult.result = res;
|
||||
}
|
||||
}
|
||||
cordova.fireDocumentEvent(action, msg);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown event action ' + action);
|
||||
}
|
||||
@@ -1576,7 +1701,7 @@ function onMessageFromNative(msg) {
|
||||
|
||||
});
|
||||
|
||||
// file: D:/cordova/cordova-android/cordova-js-src/plugin/android/app.js
|
||||
// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/plugin/android/app.js
|
||||
define("cordova/plugin/android/app", function(require, exports, module) {
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
@@ -1779,6 +1904,54 @@ exports.load = function(callback) {
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
// file: src/common/pluginloader_b.js
|
||||
define("cordova/pluginloader_b", function(require, exports, module) {
|
||||
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
|
||||
// Handler for the cordova_plugins.js content.
|
||||
// See plugman's plugin_loader.js for the details of this object.
|
||||
function handlePluginsObject(moduleList) {
|
||||
// if moduleList is not defined or empty, we've nothing to do
|
||||
if (!moduleList || !moduleList.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through all the modules and then through their clobbers and merges.
|
||||
for (var i = 0, module; module = moduleList[i]; i++) {
|
||||
if (module.clobbers && module.clobbers.length) {
|
||||
for (var j = 0; j < module.clobbers.length; j++) {
|
||||
modulemapper.clobbers(module.id, module.clobbers[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (module.merges && module.merges.length) {
|
||||
for (var k = 0; k < module.merges.length; k++) {
|
||||
modulemapper.merges(module.id, module.merges[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, if runs is truthy we want to simply require() the module.
|
||||
if (module.runs) {
|
||||
modulemapper.runs(module.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loads all plugins' js-modules. Plugin loading is syncronous in browserified bundle
|
||||
// but the method accepts callback to be compatible with non-browserify flow.
|
||||
// onDeviceReady is blocked on onPluginsReady. onPluginsReady is fired when there are
|
||||
// no plugins to load, or they are all done.
|
||||
exports.load = function(callback) {
|
||||
var moduleList = require("cordova/plugin_list");
|
||||
handlePluginsObject(moduleList);
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
// file: src/common/urlutil.js
|
||||
@@ -1860,15 +2033,14 @@ utils.typeName = function(val) {
|
||||
/**
|
||||
* Returns an indication of whether the argument is an array or not
|
||||
*/
|
||||
utils.isArray = function(a) {
|
||||
return utils.typeName(a) == 'Array';
|
||||
};
|
||||
utils.isArray = Array.isArray ||
|
||||
function(a) {return utils.typeName(a) == 'Array';};
|
||||
|
||||
/**
|
||||
* Returns an indication of whether the argument is a Date or not
|
||||
*/
|
||||
utils.isDate = function(d) {
|
||||
return utils.typeName(d) == 'Date';
|
||||
return (d instanceof Date);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1902,17 +2074,25 @@ utils.clone = function(obj) {
|
||||
* Returns a wrapped version of the function
|
||||
*/
|
||||
utils.close = function(context, func, params) {
|
||||
if (typeof params == 'undefined') {
|
||||
return function() {
|
||||
return func.apply(context, arguments);
|
||||
};
|
||||
} else {
|
||||
return function() {
|
||||
return func.apply(context, params);
|
||||
};
|
||||
}
|
||||
return function() {
|
||||
var args = params || arguments;
|
||||
return func.apply(context, args);
|
||||
};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function UUIDcreatePart(length) {
|
||||
var uuidpart = "";
|
||||
for (var i=0; i<length; i++) {
|
||||
var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
|
||||
if (uuidchar.length == 1) {
|
||||
uuidchar = "0" + uuidchar;
|
||||
}
|
||||
uuidpart += uuidchar;
|
||||
}
|
||||
return uuidpart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a UUID
|
||||
*/
|
||||
@@ -1924,6 +2104,7 @@ utils.createUUID = function() {
|
||||
UUIDcreatePart(6);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Extends a child object from a parent object using classical inheritance
|
||||
* pattern.
|
||||
@@ -1933,6 +2114,7 @@ utils.extend = (function() {
|
||||
var F = function() {};
|
||||
// extend Child from Parent
|
||||
return function(Child, Parent) {
|
||||
|
||||
F.prototype = Parent.prototype;
|
||||
Child.prototype = new F();
|
||||
Child.__super__ = Parent.prototype;
|
||||
@@ -1952,18 +2134,7 @@ utils.alert = function(msg) {
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function UUIDcreatePart(length) {
|
||||
var uuidpart = "";
|
||||
for (var i=0; i<length; i++) {
|
||||
var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
|
||||
if (uuidchar.length == 1) {
|
||||
uuidchar = "0" + uuidchar;
|
||||
}
|
||||
uuidpart += uuidchar;
|
||||
}
|
||||
return uuidpart;
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -30,20 +30,10 @@ buildscript {
|
||||
// installed version of Gradle. This dependency is documented at
|
||||
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
|
||||
// and https://issues.apache.org/jira/browse/CB-8143
|
||||
if (gradle.gradleVersion >= "2.2") {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.0.0+'
|
||||
}
|
||||
} else if (gradle.gradleVersion >= "2.1") {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:0.14.0+'
|
||||
}
|
||||
} else {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:0.12.0+'
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.5.0'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Allow plugins to declare Maven dependencies via build-extras.gradle.
|
||||
repositories {
|
||||
@@ -51,7 +41,7 @@ repositories {
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
gradleVersion = '2.8'
|
||||
}
|
||||
|
||||
// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
|
||||
@@ -173,11 +163,17 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
|
||||
applicationId privateHelpers.extractStringFromManifest("package")
|
||||
|
||||
if (cdvMinSdkVersion != null) {
|
||||
minSdkVersion cdvMinSdkVersion
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false;
|
||||
}
|
||||
|
||||
compileSdkVersion cdvCompileSdkVersion
|
||||
buildToolsVersion cdvBuildToolsVersion
|
||||
|
||||
|
||||
16
cordova-js-src/platform.js
vendored
16
cordova-js-src/platform.js
vendored
@@ -79,12 +79,26 @@ function onMessageFromNative(msg) {
|
||||
case 'searchbutton':
|
||||
// App life cycle events
|
||||
case 'pause':
|
||||
case 'resume':
|
||||
// Volume events
|
||||
case 'volumedownbutton':
|
||||
case 'volumeupbutton':
|
||||
cordova.fireDocumentEvent(action);
|
||||
break;
|
||||
case 'resume':
|
||||
if(arguments.length > 1 && msg.pendingResult) {
|
||||
if(arguments.length === 2) {
|
||||
msg.pendingResult.result = arguments[1];
|
||||
} else {
|
||||
// The plugin returned a multipart message
|
||||
var res = [];
|
||||
for(var i = 1; i < arguments.length; i++) {
|
||||
res.push(arguments[i]);
|
||||
}
|
||||
msg.pendingResult.result = res;
|
||||
}
|
||||
}
|
||||
cordova.fireDocumentEvent(action, msg);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown event action ' + action);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.0.0+'
|
||||
classpath 'com.android.tools.build:gradle:1.5.0'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -128,6 +128,14 @@ def doExtractIntFromManifest(name) {
|
||||
return Integer.parseInt(matcher.group(1))
|
||||
}
|
||||
|
||||
def doExtractStringFromManifest(name) {
|
||||
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
|
||||
def pattern = Pattern.compile(name + "=\"(\\S+)\"")
|
||||
def matcher = pattern.matcher(manifestFile.getText())
|
||||
matcher.find()
|
||||
return matcher.group(1)
|
||||
}
|
||||
|
||||
def doPromptForPassword(msg) {
|
||||
if (System.console() == null) {
|
||||
def ret = null
|
||||
@@ -179,6 +187,7 @@ ext {
|
||||
privateHelpers.getProjectTarget = { doGetProjectTarget() }
|
||||
privateHelpers.findLatestInstalledBuildTools = { doFindLatestInstalledBuildTools('19.1.0') }
|
||||
privateHelpers.extractIntFromManifest = { name -> doExtractIntFromManifest(name) }
|
||||
privateHelpers.extractStringFromManifest = { name -> doExtractStringFromManifest(name) }
|
||||
privateHelpers.promptForPassword = { msg -> doPromptForPassword(msg) }
|
||||
privateHelpers.ensureValueExists = { filePath, props, key -> doEnsureValueExists(filePath, props, key) }
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class CallbackContext {
|
||||
|
||||
private String callbackId;
|
||||
private CordovaWebView webView;
|
||||
private boolean finished;
|
||||
protected boolean finished;
|
||||
private int changingThreads;
|
||||
|
||||
public CallbackContext(String callbackId, CordovaWebView webView) {
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package org.apache.cordova;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -28,6 +27,7 @@ import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -46,6 +46,8 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
protected CordovaPlugin permissionResultCallback;
|
||||
protected String initCallbackService;
|
||||
protected int activityResultRequestCode;
|
||||
protected boolean activityWasDestroyed = false;
|
||||
protected Bundle savedPluginState;
|
||||
|
||||
public CordovaInterfaceImpl(Activity activity) {
|
||||
this(activity, Executors.newCachedThreadPool());
|
||||
@@ -95,12 +97,28 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches any pending onActivityResult callbacks.
|
||||
* Dispatches any pending onActivityResult callbacks and sends the resume event if the
|
||||
* Activity was destroyed by the OS.
|
||||
*/
|
||||
public void onCordovaInit(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
if (savedResult != null) {
|
||||
onActivityResult(savedResult.requestCode, savedResult.resultCode, savedResult.intent);
|
||||
} else if(activityWasDestroyed) {
|
||||
// If there was no Activity result, we still need to send out the resume event if the
|
||||
// Activity was destroyed by the OS
|
||||
activityWasDestroyed = false;
|
||||
|
||||
CoreAndroid appPlugin = (CoreAndroid) pluginManager.getPlugin(CoreAndroid.PLUGIN_NAME);
|
||||
if(appPlugin != null) {
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("action", "resume");
|
||||
} catch (JSONException e) {
|
||||
LOG.e(TAG, "Failed to create event message", e);
|
||||
}
|
||||
appPlugin.sendResumeEvent(new PluginResult(PluginResult.Status.OK, obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +133,10 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
savedResult = new ActivityResultHolder(requestCode, resultCode, intent);
|
||||
if (pluginManager != null) {
|
||||
callback = pluginManager.getPlugin(initCallbackService);
|
||||
if(callback != null) {
|
||||
callback.onRestoreStateForActivityResult(savedPluginState.getBundle(callback.getServiceName()),
|
||||
new ResumeCallback(callback.getServiceName(), pluginManager));
|
||||
}
|
||||
}
|
||||
}
|
||||
activityResultCallback = null;
|
||||
@@ -126,7 +148,7 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
callback.onActivityResult(requestCode, resultCode, intent);
|
||||
return true;
|
||||
}
|
||||
Log.w(TAG, "Got an activity result, but no plugin was registered to receive it" + (savedResult != null ? " yet!": "."));
|
||||
Log.w(TAG, "Got an activity result, but no plugin was registered to receive it" + (savedResult != null ? " yet!" : "."));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -147,6 +169,8 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
String serviceName = activityResultCallback.getServiceName();
|
||||
outState.putString("callbackService", serviceName);
|
||||
}
|
||||
|
||||
outState.putBundle("plugin", pluginManager.onSaveInstanceState());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,6 +178,8 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
*/
|
||||
public void restoreInstanceState(Bundle savedInstanceState) {
|
||||
initCallbackService = savedInstanceState.getString("callbackService");
|
||||
savedPluginState = savedInstanceState.getBundle("plugin");
|
||||
activityWasDestroyed = true;
|
||||
}
|
||||
|
||||
private static class ActivityResultHolder {
|
||||
@@ -209,6 +235,4 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -77,7 +78,7 @@ public class CordovaPlugin {
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the request.
|
||||
*
|
||||
@@ -174,6 +175,29 @@ public class CordovaPlugin {
|
||||
public void onDestroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Activity is being destroyed (e.g. if a plugin calls out to an external
|
||||
* Activity and the OS kills the CordovaActivity in the background). The plugin should save its
|
||||
* state in this method only if it is awaiting the result of an external Activity and needs
|
||||
* to preserve some information so as to handle that result; onRestoreStateForActivityResult()
|
||||
* will only be called if the plugin is the recipient of an Activity result
|
||||
*
|
||||
* @return Bundle containing the state of the plugin or null if state does not need to be saved
|
||||
*/
|
||||
public Bundle onSaveInstanceState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a plugin is the recipient of an Activity result after the CordovaActivity has
|
||||
* been destroyed. The Bundle will be the same as the one the plugin returned in
|
||||
* onSaveInstanceState()
|
||||
*
|
||||
* @param state Bundle containing the state of the plugin
|
||||
* @param callbackContext Replacement Context to return the plugin result to
|
||||
*/
|
||||
public void onRestoreStateForActivityResult(Bundle state, CallbackContext callbackContext) {}
|
||||
|
||||
/**
|
||||
* Called when a message is sent to plugin.
|
||||
*
|
||||
@@ -323,7 +347,7 @@ public class CordovaPlugin {
|
||||
*/
|
||||
public void onReset() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the system received an HTTP authentication request. Plugin can use
|
||||
* the supplied HttpAuthHandler to process this auth challenge.
|
||||
@@ -332,14 +356,14 @@ public class CordovaPlugin {
|
||||
* @param handler The HttpAuthHandler used to set the WebView's response
|
||||
* @param host The host requiring authentication
|
||||
* @param realm The realm for which authentication is required
|
||||
*
|
||||
*
|
||||
* @return Returns True if plugin will resolve this auth challenge, otherwise False
|
||||
*
|
||||
*
|
||||
*/
|
||||
public boolean onReceivedHttpAuthRequest(CordovaWebView view, ICordovaHttpAuthHandler handler, String host, String realm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when he system received an SSL client certificate request. Plugin can use
|
||||
* the supplied ClientCertRequest to process this certificate challenge.
|
||||
|
||||
@@ -31,7 +31,7 @@ import android.webkit.WebChromeClient.CustomViewCallback;
|
||||
* are not expected to implement it.
|
||||
*/
|
||||
public interface CordovaWebView {
|
||||
public static final String CORDOVA_VERSION = "5.0.0-dev";
|
||||
public static final String CORDOVA_VERSION = "5.1.0";
|
||||
|
||||
void init(CordovaInterface cordova, List<PluginEntry> pluginEntries, CordovaPreferences preferences);
|
||||
|
||||
|
||||
@@ -354,6 +354,7 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
case KeyEvent.KEYCODE_MENU:
|
||||
// TODO: Why are search and menu buttons handled separately?
|
||||
if (override) {
|
||||
boundKeyCodes.add(keyCode);
|
||||
@@ -445,7 +446,10 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
||||
// Resume JavaScript timers. This affects all webviews within the app!
|
||||
engine.setPaused(false);
|
||||
this.pluginManager.onResume(keepRunning);
|
||||
// To be the same as other platforms, fire this event only when resumed after a "pause".
|
||||
|
||||
// In order to match the behavior of the other platforms, we only send onResume after an
|
||||
// onPause has occurred. The resume event might still be sent if the Activity was killed
|
||||
// while waiting for the result of an external Activity once the result is obtained
|
||||
if (hasPausedEver) {
|
||||
sendJavascriptEvent("resume");
|
||||
}
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
|
||||
package org.apache.cordova;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.LOG;
|
||||
import org.apache.cordova.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -45,6 +41,8 @@ class CoreAndroid extends CordovaPlugin {
|
||||
protected static final String TAG = "CordovaApp";
|
||||
private BroadcastReceiver telephonyReceiver;
|
||||
private CallbackContext messageChannel;
|
||||
private PluginResult pendingResume;
|
||||
private final Object messageChannelLock = new Object();
|
||||
|
||||
/**
|
||||
* Send an event to be fired on the Javascript side.
|
||||
@@ -112,7 +110,13 @@ class CoreAndroid extends CordovaPlugin {
|
||||
this.exitApp();
|
||||
}
|
||||
else if (action.equals("messageChannel")) {
|
||||
messageChannel = callbackContext;
|
||||
synchronized(messageChannelLock) {
|
||||
messageChannel = callbackContext;
|
||||
if (pendingResume != null) {
|
||||
sendEventMessage(pendingResume);
|
||||
pendingResume = null;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -248,6 +252,9 @@ class CoreAndroid extends CordovaPlugin {
|
||||
else if (button.equals("volumedown")) {
|
||||
webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_VOLUME_DOWN, override);
|
||||
}
|
||||
else if (button.equals("menubutton")) {
|
||||
webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_MENU, override);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,10 +320,13 @@ class CoreAndroid extends CordovaPlugin {
|
||||
} catch (JSONException e) {
|
||||
LOG.e(TAG, "Failed to create event message", e);
|
||||
}
|
||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, obj);
|
||||
pluginResult.setKeepCallback(true);
|
||||
sendEventMessage(new PluginResult(PluginResult.Status.OK, obj));
|
||||
}
|
||||
|
||||
private void sendEventMessage(PluginResult payload) {
|
||||
payload.setKeepCallback(true);
|
||||
if (messageChannel != null) {
|
||||
messageChannel.sendPluginResult(pluginResult);
|
||||
messageChannel.sendPluginResult(payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,4 +338,23 @@ class CoreAndroid extends CordovaPlugin {
|
||||
{
|
||||
webView.getContext().unregisterReceiver(this.telephonyReceiver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to send the resume event in the case that the Activity is destroyed by the OS
|
||||
*
|
||||
* @param resumeEvent PluginResult containing the payload for the resume event to be fired
|
||||
*/
|
||||
public void sendResumeEvent(PluginResult resumeEvent) {
|
||||
// This operation must be synchronized because plugin results that trigger resume
|
||||
// events can be processed asynchronously
|
||||
synchronized(messageChannelLock) {
|
||||
if (messageChannel != null) {
|
||||
sendEventMessage(resumeEvent);
|
||||
} else {
|
||||
// Might get called before the page loads, so we need to store it until the
|
||||
// messageChannel gets created
|
||||
this.pendingResume = resumeEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.json.JSONException;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Debug;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -511,4 +512,16 @@ public class PluginManager {
|
||||
}
|
||||
}
|
||||
|
||||
public Bundle onSaveInstanceState() {
|
||||
Bundle state = new Bundle();
|
||||
for (CordovaPlugin plugin : this.pluginMap.values()) {
|
||||
if (plugin != null) {
|
||||
Bundle pluginState = plugin.onSaveInstanceState();
|
||||
if(pluginState != null) {
|
||||
state.putBundle(plugin.getServiceName(), pluginState);
|
||||
}
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
76
framework/src/org/apache/cordova/ResumeCallback.java
Normal file
76
framework/src/org/apache/cordova/ResumeCallback.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package org.apache.cordova;
|
||||
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ResumeCallback extends CallbackContext {
|
||||
private final String TAG = "CordovaResumeCallback";
|
||||
private String serviceName;
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public ResumeCallback(String serviceName, PluginManager pluginManager) {
|
||||
super("resumecallback", null);
|
||||
this.serviceName = serviceName;
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginResult(PluginResult pluginResult) {
|
||||
synchronized (this) {
|
||||
if (finished) {
|
||||
LOG.w(TAG, serviceName + " attempted to send a second callback to ResumeCallback\nResult was: " + pluginResult.getMessage());
|
||||
return;
|
||||
} else {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject event = new JSONObject();
|
||||
JSONObject pluginResultObject = new JSONObject();
|
||||
|
||||
try {
|
||||
pluginResultObject.put("pluginServiceName", this.serviceName);
|
||||
pluginResultObject.put("pluginStatus", PluginResult.StatusMessages[pluginResult.getStatus()]);
|
||||
|
||||
event.put("action", "resume");
|
||||
event.put("pendingResult", pluginResultObject);
|
||||
} catch (JSONException e) {
|
||||
LOG.e(TAG, "Unable to create resume object for Activity Result");
|
||||
}
|
||||
|
||||
PluginResult eventResult = new PluginResult(PluginResult.Status.OK, event);
|
||||
|
||||
// We send a list of results to the js so that we don't have to decode
|
||||
// the PluginResult passed to this CallbackContext into JSON twice.
|
||||
// The results are combined into an event payload before the event is
|
||||
// fired on the js side of things (see platform.js)
|
||||
List<PluginResult> result = new ArrayList<PluginResult>();
|
||||
result.add(eventResult);
|
||||
result.add(pluginResult);
|
||||
|
||||
CoreAndroid appPlugin = (CoreAndroid) pluginManager.getPlugin(CoreAndroid.PLUGIN_NAME);
|
||||
appPlugin.sendResumeEvent(new PluginResult(PluginResult.Status.OK, result));
|
||||
}
|
||||
}
|
||||
22
node_modules/cordova-common/node_modules/bplist-parser/bplistParser.js
generated
vendored
22
node_modules/cordova-common/node_modules/bplist-parser/bplistParser.js
generated
vendored
@@ -3,6 +3,7 @@
|
||||
// adapted from http://code.google.com/p/plist/source/browse/trunk/src/com/dd/plist/BinaryPropertyListParser.java
|
||||
|
||||
var fs = require('fs');
|
||||
var bigInt = require("big-integer");
|
||||
var debug = false;
|
||||
|
||||
exports.maxObjectSize = 100 * 1000 * 1000; // 100Meg
|
||||
@@ -138,9 +139,28 @@ var parseBuffer = exports.parseBuffer = function (buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
function bufferToHexString(buffer) {
|
||||
var str = '';
|
||||
var i;
|
||||
for (i = 0; i < buffer.length; i++) {
|
||||
if (buffer[i] != 0x00) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; i < buffer.length; i++) {
|
||||
var part = '00' + buffer[i].toString(16);
|
||||
str += part.substr(part.length - 2);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function parseInteger() {
|
||||
var length = Math.pow(2, objInfo);
|
||||
if (length < exports.maxObjectSize) {
|
||||
if (length > 4) {
|
||||
var data = buffer.slice(offset + 1, offset + 1 + length);
|
||||
var str = bufferToHexString(data);
|
||||
return bigInt(str, 16);
|
||||
} if (length < exports.maxObjectSize) {
|
||||
return readUInt(buffer.slice(offset + 1, offset + 1 + length));
|
||||
} else {
|
||||
throw new Error("To little heap space available! Wanted to read " + length + " bytes, but only " + exports.maxObjectSize + " are available.");
|
||||
|
||||
3
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/.gitconfig
generated
vendored
Normal file
3
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/.gitconfig
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[remote "github"]
|
||||
push = +refs/heads/master:refs/heads/gh-pages
|
||||
push = +refs/heads/master:refs/heads/master
|
||||
8
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/.zuul.yml
generated
vendored
Normal file
8
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/.zuul.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
ui: jasmine2
|
||||
browsers:
|
||||
- name: chrome
|
||||
version: 27
|
||||
- name: ie
|
||||
version: latest
|
||||
- name: iphone
|
||||
version: 6.1
|
||||
2
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/.zuulrc
generated
vendored
Normal file
2
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/.zuulrc
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
sauce_username: peterolson
|
||||
sauce_key: 3553a315-10c0-4661-9d8e-7150d87064c7
|
||||
1181
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/BigInteger.js
generated
vendored
Normal file
1181
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/BigInteger.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/BigInteger.min.js
generated
vendored
Normal file
1
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/BigInteger.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
24
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/LICENSE
generated
vendored
Normal file
24
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
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 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.
|
||||
|
||||
For more information, please refer to <http://unlicense.org>
|
||||
506
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/README.md
generated
vendored
Normal file
506
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/README.md
generated
vendored
Normal file
@@ -0,0 +1,506 @@
|
||||
# BigInteger.js [![Build Status][travis-img]][travis-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Monthly Downloads][downloads-img]][downloads-url]
|
||||
|
||||
[travis-url]: https://travis-ci.org/peterolson/BigInteger.js
|
||||
[travis-img]: https://travis-ci.org/peterolson/BigInteger.js.svg?branch=master
|
||||
[coveralls-url]: https://coveralls.io/github/peterolson/BigInteger.js?branch=master
|
||||
[coveralls-img]: https://coveralls.io/repos/peterolson/BigInteger.js/badge.svg?branch=master&service=github
|
||||
[downloads-url]: https://www.npmjs.com/package/big-integer
|
||||
[downloads-img]: https://img.shields.io/npm/dm/big-integer.svg
|
||||
|
||||
**BigInteger.js** is an arbitrary-length integer library for Javascript, allowing arithmetic operations on integers of unlimited size, notwithstanding memory and time limitations.
|
||||
|
||||
## Installation
|
||||
|
||||
If you are using a browser, you can download [BigInteger.js from GitHub](http://peterolson.github.com/BigInteger.js/BigInteger.min.js) or just hotlink to it:
|
||||
|
||||
<script src="http://peterolson.github.com/BigInteger.js/BigInteger.min.js"></script>
|
||||
|
||||
If you are using node, you can install BigInteger with [npm](https://npmjs.org/).
|
||||
|
||||
npm install big-integer
|
||||
|
||||
Then you can include it in your code:
|
||||
|
||||
var bigInt = require("big-integer");
|
||||
|
||||
|
||||
## Usage
|
||||
### `bigInt(number, [base])`
|
||||
|
||||
You can create a bigInt by calling the `bigInt` function. You can pass in
|
||||
|
||||
- a string, which it will parse as an bigInt and throw an `"Invalid integer"` error if the parsing fails.
|
||||
- a Javascript number, which it will parse as an bigInt and throw an `"Invalid integer"` error if the parsing fails.
|
||||
- another bigInt.
|
||||
- nothing, and it will return `bigInt.zero`.
|
||||
|
||||
If you provide a second parameter, then it will parse `number` as a number in base `base`. Note that `base` can be any bigInt (even negative or zero). The letters "a-z" and "A-Z" will be interpreted as the numbers 10 to 35. Higher digits can be specified in angle brackets (`<` and `>`).
|
||||
|
||||
Examples:
|
||||
|
||||
var zero = bigInt();
|
||||
var ninetyThree = bigInt(93);
|
||||
var largeNumber = bigInt("75643564363473453456342378564387956906736546456235345");
|
||||
var googol = bigInt("1e100");
|
||||
var bigNumber = bigInt(largeNumber);
|
||||
|
||||
var maximumByte = bigInt("FF", 16);
|
||||
var fiftyFiveGoogol = bigInt("<55>0", googol);
|
||||
|
||||
Note that Javascript numbers larger than `9007199254740992` and smaller than `-9007199254740992` are not precisely represented numbers and will not produce exact results. If you are dealing with numbers outside that range, it is better to pass in strings.
|
||||
|
||||
### Method Chaining
|
||||
|
||||
Note that bigInt operations return bigInts, which allows you to chain methods, for example:
|
||||
|
||||
var salary = bigInt(dollarsPerHour).times(hoursWorked).plus(randomBonuses)
|
||||
|
||||
### Constants
|
||||
|
||||
There are three named constants already stored that you do not have to construct with the `bigInt` function yourself:
|
||||
|
||||
- `bigInt.one`, equivalent to `bigInt(1)`
|
||||
- `bigInt.zero`, equivalent to `bigInt(0)`
|
||||
- `bigInt.minusOne`, equivalent to `bigInt(-1)`
|
||||
|
||||
The numbers from -999 to 999 are also already prestored and can be accessed using `bigInt[index]`, for example:
|
||||
|
||||
- `bigInt[-999]`, equivalent to `bigInt(-999)`
|
||||
- `bigInt[256]`, equivalent to `bigInt(256)`
|
||||
|
||||
### Methods
|
||||
|
||||
#### `abs()`
|
||||
|
||||
Returns the absolute value of a bigInt.
|
||||
|
||||
- `bigInt(-45).abs()` => `45`
|
||||
- `bigInt(45).abs()` => `45`
|
||||
|
||||
#### `add(number)`
|
||||
|
||||
Performs addition.
|
||||
|
||||
- `bigInt(5).add(7)` => `12`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Addition)
|
||||
|
||||
#### `and(number)`
|
||||
|
||||
Performs the bitwise AND operation. The operands are treated as if they were represented using [two's complement representation](http://en.wikipedia.org/wiki/Two%27s_complement).
|
||||
|
||||
- `bigInt(6).and(3)` => `2`
|
||||
- `bigInt(6).and(-3)` => `4`
|
||||
|
||||
#### `compare(number)`
|
||||
|
||||
Performs a comparison between two numbers. If the numbers are equal, it returns `0`. If the first number is greater, it returns `1`. If the first number is lesser, it returns `-1`.
|
||||
|
||||
- `bigInt(5).compare(5)` => `0`
|
||||
- `bigInt(5).compare(4)` => `1`
|
||||
- `bigInt(4).compare(5)` => `-1`
|
||||
|
||||
#### `compareAbs(number)`
|
||||
|
||||
Performs a comparison between the absolute value of two numbers.
|
||||
|
||||
- `bigInt(5).compareAbs(-5)` => `0`
|
||||
- `bigInt(5).compareAbs(4)` => `1`
|
||||
- `bigInt(4).compareAbs(-5)` => `-1`
|
||||
|
||||
#### `compareTo(number)`
|
||||
|
||||
Alias for the `compare` method.
|
||||
|
||||
#### `divide(number)`
|
||||
|
||||
Performs integer division, disregarding the remainder.
|
||||
|
||||
- `bigInt(59).divide(5)` => `11`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)
|
||||
|
||||
#### `divmod(number)`
|
||||
|
||||
Performs division and returns an object with two properties: `quotient` and `remainder`. The sign of the remainder will match the sign of the dividend.
|
||||
|
||||
- `bigInt(59).divmod(5)` => `{quotient: bigInt(11), remainder: bigInt(4) }`
|
||||
- `bigInt(-5).divmod(2)` => `{quotient: bigInt(-2), remainder: bigInt(-1) }`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)
|
||||
|
||||
#### `eq(number)`
|
||||
|
||||
Alias for the `equals` method.
|
||||
|
||||
#### `equals(number)`
|
||||
|
||||
Checks if two numbers are equal.
|
||||
|
||||
- `bigInt(5).equals(5)` => `true`
|
||||
- `bigInt(4).equals(7)` => `false`
|
||||
|
||||
#### `geq(number)`
|
||||
|
||||
Alias for the `greaterOrEquals` method.
|
||||
|
||||
|
||||
#### `greater(number)`
|
||||
|
||||
Checks if the first number is greater than the second.
|
||||
|
||||
- `bigInt(5).greater(6)` => `false`
|
||||
- `bigInt(5).greater(5)` => `false`
|
||||
- `bigInt(5).greater(4)` => `true`
|
||||
|
||||
#### `greaterOrEquals(number)`
|
||||
|
||||
Checks if the first number is greater than or equal to the second.
|
||||
|
||||
- `bigInt(5).greaterOrEquals(6)` => `false`
|
||||
- `bigInt(5).greaterOrEquals(5)` => `true`
|
||||
- `bigInt(5).greaterOrEquals(4)` => `true`
|
||||
|
||||
#### `gt(number)`
|
||||
|
||||
Alias for the `greater` method.
|
||||
|
||||
#### `isDivisibleBy(number)`
|
||||
|
||||
Returns `true` if the first number is divisible by the second number, `false` otherwise.
|
||||
|
||||
- `bigInt(999).isDivisibleBy(333)` => `true`
|
||||
- `bigInt(99).isDivisibleBy(5)` => `false`
|
||||
|
||||
#### `isEven()`
|
||||
|
||||
Returns `true` if the number is even, `false` otherwise.
|
||||
|
||||
- `bigInt(6).isEven()` => `true`
|
||||
- `bigInt(3).isEven()` => `false`
|
||||
|
||||
#### `isNegative()`
|
||||
|
||||
Returns `true` if the number is negative, `false` otherwise.
|
||||
Returns `false` for `0` and `-0`.
|
||||
|
||||
- `bigInt(-23).isNegative()` => `true`
|
||||
- `bigInt(50).isNegative()` => `false`
|
||||
|
||||
#### `isOdd()`
|
||||
|
||||
Returns `true` if the number is odd, `false` otherwise.
|
||||
|
||||
- `bigInt(13).isOdd()` => `true`
|
||||
- `bigInt(40).isOdd()` => `false`
|
||||
|
||||
#### `isPositive()`
|
||||
|
||||
Return `true` if the number is positive, `false` otherwise.
|
||||
Returns `false` for `0` and `-0`.
|
||||
|
||||
- `bigInt(54).isPositive()` => `true`
|
||||
- `bigInt(-1).isPositive()` => `false`
|
||||
|
||||
#### `isPrime()`
|
||||
|
||||
Returns `true` if the number is prime, `false` otherwise.
|
||||
|
||||
- `bigInt(5).isPrime()` => `true`
|
||||
- `bigInt(6).isPrime()` => `false`
|
||||
|
||||
#### `isProbablePrime([iterations])`
|
||||
|
||||
Returns `true` if the number is very likely to be positive, `false` otherwise.
|
||||
Argument is optional and determines the amount of iterations of the test (default: `5`). The more iterations, the lower chance of getting a false positive.
|
||||
This uses the [Fermat primality test](https://en.wikipedia.org/wiki/Fermat_primality_test).
|
||||
|
||||
- `bigInt(5).isProbablePrime()` => `true`
|
||||
- `bigInt(49).isProbablePrime()` => `false`
|
||||
- `bigInt(1729).isProbablePrime(50)` => `false`
|
||||
|
||||
Note that this function is not deterministic, since it relies on random sampling of factors, so the result for some numbers is not always the same. [Carmichael numbers](https://en.wikipedia.org/wiki/Carmichael_number) are particularly prone to give unreliable results.
|
||||
|
||||
For example, `bigInt(1729).isProbablePrime()` returns `false` about 76% of the time and `true` about 24% of the time. The correct result is `false`.
|
||||
|
||||
#### `isUnit()`
|
||||
|
||||
Returns `true` if the number is `1` or `-1`, `false` otherwise.
|
||||
|
||||
- `bigInt.one.isUnit()` => `true`
|
||||
- `bigInt.minusOne.isUnit()` => `true`
|
||||
- `bigInt(5).isUnit()` => `false`
|
||||
|
||||
#### `isZero()`
|
||||
|
||||
Return `true` if the number is `0` or `-0`, `false` otherwise.
|
||||
|
||||
- `bigInt.zero.isZero()` => `true`
|
||||
- `bigInt("-0").isZero()` => `true`
|
||||
- `bigInt(50).isZero()` => `false`
|
||||
|
||||
#### `leq(number)`
|
||||
|
||||
Alias for the `lesserOrEquals` method.
|
||||
|
||||
#### `lesser(number)`
|
||||
|
||||
Checks if the first number is lesser than the second.
|
||||
|
||||
- `bigInt(5).lesser(6)` => `true`
|
||||
- `bigInt(5).lesser(5)` => `false`
|
||||
- `bigInt(5).lesser(4)` => `false`
|
||||
|
||||
#### `lesserOrEquals(number)`
|
||||
|
||||
Checks if the first number is less than or equal to the second.
|
||||
|
||||
- `bigInt(5).lesserOrEquals(6)` => `true`
|
||||
- `bigInt(5).lesserOrEquals(5)` => `true`
|
||||
- `bigInt(5).lesserOrEquals(4)` => `false`
|
||||
|
||||
#### `lt(number)`
|
||||
|
||||
Alias for the `lesser` method.
|
||||
|
||||
#### `minus(number)`
|
||||
|
||||
Alias for the `subtract` method.
|
||||
|
||||
- `bigInt(3).minus(5)` => `-2`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Subtraction)
|
||||
|
||||
#### `mod(number)`
|
||||
|
||||
Performs division and returns the remainder, disregarding the quotient. The sign of the remainder will match the sign of the dividend.
|
||||
|
||||
- `bigInt(59).mod(5)` => `4`
|
||||
- `bigInt(-5).mod(2)` => `-1`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)
|
||||
|
||||
#### `modPow(exp, mod)`
|
||||
|
||||
Takes the number to the power `exp` modulo `mod`.
|
||||
|
||||
- `bigInt(10).modPow(3, 30)` => `10`
|
||||
|
||||
#### `multiply(number)`
|
||||
|
||||
Performs multiplication.
|
||||
|
||||
- `bigInt(111).multiply(111)` => `12321`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Multiplication)
|
||||
|
||||
#### `neq(number)`
|
||||
|
||||
Alias for the `notEquals` method.
|
||||
|
||||
#### `next()`
|
||||
|
||||
Adds one to the number.
|
||||
|
||||
- `bigInt(6).next()` => `7`
|
||||
|
||||
#### `not()`
|
||||
|
||||
Performs the bitwise NOT operation. The operands are treated as if they were represented using [two's complement representation](http://en.wikipedia.org/wiki/Two%27s_complement).
|
||||
|
||||
- `bigInt(10).not()` => `-11`
|
||||
- `bigInt(0).not()` => `-1`
|
||||
|
||||
#### `notEquals(number)`
|
||||
|
||||
Checks if two numbers are not equal.
|
||||
|
||||
- `bigInt(5).notEquals(5)` => `false`
|
||||
- `bigInt(4).notEquals(7)` => `true`
|
||||
|
||||
#### `or(number)`
|
||||
|
||||
Performs the bitwise OR operation. The operands are treated as if they were represented using [two's complement representation](http://en.wikipedia.org/wiki/Two%27s_complement).
|
||||
|
||||
- `bigInt(13).or(10)` => `15`
|
||||
- `bigInt(13).or(-8)` => `-3`
|
||||
|
||||
#### `over(number)`
|
||||
|
||||
Alias for the `divide` method.
|
||||
|
||||
- `bigInt(59).over(5)` => `11`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)
|
||||
|
||||
#### `plus(number)`
|
||||
|
||||
Alias for the `add` method.
|
||||
|
||||
- `bigInt(5).plus(7)` => `12`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Addition)
|
||||
|
||||
#### `pow(number)`
|
||||
|
||||
Performs exponentiation. If the exponent is less than `0`, `pow` returns `0`. `bigInt.zero.pow(0)` returns `1`.
|
||||
|
||||
- `bigInt(16).pow(16)` => `18446744073709551616`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Exponentiation)
|
||||
|
||||
#### `prev(number)`
|
||||
|
||||
Subtracts one from the number.
|
||||
|
||||
- `bigInt(6).prev()` => `5`
|
||||
|
||||
#### `remainder(number)`
|
||||
|
||||
Alias for the `mod` method.
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)
|
||||
|
||||
#### `shiftLeft(n)`
|
||||
|
||||
Shifts the number left by `n` places in its binary representation. If a negative number is provided, it will shift right. Throws an error if `n` is outside of the range `[-9007199254740992, 9007199254740992]`.
|
||||
|
||||
- `bigInt(8).shiftLeft(2)` => `32`
|
||||
- `bigInt(8).shiftLeft(-2)` => `2`
|
||||
|
||||
#### `shiftRight(n)`
|
||||
|
||||
Shifts the number right by `n` places in its binary representation. If a negative number is provided, it will shift left. Throws an error if `n` is outside of the range `[-9007199254740992, 9007199254740992]`.
|
||||
|
||||
- `bigInt(8).shiftRight(2)` => `2`
|
||||
- `bigInt(8).shiftRight(-2)` => `32`
|
||||
|
||||
#### `square()`
|
||||
|
||||
Squares the number
|
||||
|
||||
- `bigInt(3).square()` => `9`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Squaring)
|
||||
|
||||
#### `subtract(number)`
|
||||
|
||||
Performs subtraction.
|
||||
|
||||
- `bigInt(3).subtract(5)` => `-2`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Subtraction)
|
||||
|
||||
#### `times(number)`
|
||||
|
||||
Alias for the `multiply` method.
|
||||
|
||||
- `bigInt(111).times(111)` => `12321`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Multiplication)
|
||||
|
||||
#### `toJSNumber()`
|
||||
|
||||
Converts a bigInt into a native Javascript number. Loses precision for numbers outside the range `[-9007199254740992, 9007199254740992]`.
|
||||
|
||||
- `bigInt("18446744073709551616").toJSNumber()` => `18446744073709552000`
|
||||
|
||||
#### `xor(number)`
|
||||
|
||||
Performs the bitwise XOR operation. The operands are treated as if they were represented using [two's complement representation](http://en.wikipedia.org/wiki/Two%27s_complement).
|
||||
|
||||
- `bigInt(12).xor(5)` => `9`
|
||||
- `bigInt(12).xor(-5)` => `-9`
|
||||
|
||||
### Static Methods
|
||||
|
||||
#### `gcd(a, b)`
|
||||
|
||||
Finds the greatest common denominator of `a` and `b`.
|
||||
|
||||
- `bigInt.gcd(42,56)` => `14`
|
||||
|
||||
#### `isInstance(x)`
|
||||
|
||||
Returns `true` if `x` is a BigInteger, `false` otherwise.
|
||||
|
||||
- `bigInt.isInstance(bigInt(14))` => `true`
|
||||
- `bigInt.isInstance(14)` => `false`
|
||||
|
||||
#### `lcm(a,b)`
|
||||
|
||||
Finds the least common multiple of `a` and `b`.
|
||||
|
||||
- `bigInt.lcm(21, 6)` => `42`
|
||||
|
||||
#### `max(a,b)`
|
||||
|
||||
Returns the largest of `a` and `b`.
|
||||
|
||||
- `bigInt.max(77, 432)` => `432`
|
||||
|
||||
#### `min(a,b)`
|
||||
|
||||
Returns the smallest of `a` and `b`.
|
||||
|
||||
- `bigInt.min(77, 432)` => `77`
|
||||
|
||||
#### `randBetween(min, max)`
|
||||
|
||||
Returns a random number between `min` and `max`.
|
||||
|
||||
- `bigInt.randBetween("-1e100", "1e100")` => (for example) `8494907165436643479673097939554427056789510374838494147955756275846226209006506706784609314471378745`
|
||||
|
||||
|
||||
### Override Methods
|
||||
|
||||
#### `toString(radix = 10)`
|
||||
|
||||
Converts a bigInt to a string. There is an optional radix parameter (which defaults to 10) that converts the number to the given radix. Digits in the range `10-35` will use the letters `a-z`.
|
||||
|
||||
- `bigInt("1e9").toString()` => `"1000000000"`
|
||||
- `bigInt("1e9").toString(16)` => `"3b9aca00"`
|
||||
|
||||
**Note that arithmetical operators will trigger the `valueOf` function rather than the `toString` function.** When converting a bigInteger to a string, you should use the `toString` method or the `String` function instead of adding the empty string.
|
||||
|
||||
- `bigInt("999999999999999999").toString()` => `"999999999999999999"`
|
||||
- `String(bigInt("999999999999999999"))` => `"999999999999999999"`
|
||||
- `bigInt("999999999999999999") + ""` => `1000000000000000000`
|
||||
|
||||
Bases larger than 36 are supported. If a digit is greater than or equal to 36, it will be enclosed in angle brackets.
|
||||
|
||||
- `bigInt(567890).toString(100)` => `"<56><78><90>"`
|
||||
|
||||
Negative bases are also supported.
|
||||
|
||||
- `bigInt(12345).toString(-10)` => `"28465"`
|
||||
|
||||
Base 1 and base -1 are also supported.
|
||||
|
||||
- `bigInt(-15).toString(1)` => `"-111111111111111"`
|
||||
- `bigInt(-15).toString(-1)` => `"101010101010101010101010101010"`
|
||||
|
||||
Base 0 is only allowed for the number zero.
|
||||
|
||||
- `bigInt(0).toString(0)` => `0`
|
||||
- `bigInt(1).toString(0)` => `Error: Cannot convert nonzero numbers to base 0.`
|
||||
|
||||
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#toString)
|
||||
|
||||
#### `valueOf()`
|
||||
|
||||
Converts a bigInt to a native Javascript number. This override allows you to use native arithmetic operators without explicit conversion:
|
||||
|
||||
- `bigInt("100") + bigInt("200") === 300; //true`
|
||||
|
||||
## Contributors
|
||||
|
||||
To contribute, just fork the project, make some changes, and submit a pull request. Please verify that the unit tests pass before submitting.
|
||||
|
||||
The unit tests are contained in the `spec/spec.js` file. You can run them locally by opening the `spec/SpecRunner.html` or file or running `npm test`. You can also [run the tests online from GitHub](http://peterolson.github.io/BigInteger.js/spec/SpecRunner.html).
|
||||
|
||||
There are performance benchmarks that can be viewed from the `benchmarks/index.html` page. You can [run them online from GitHub](http://peterolson.github.io/BigInteger.js/benchmark/).
|
||||
|
||||
## License
|
||||
|
||||
This project is public domain. For more details, read about the [Unlicense](http://unlicense.org/).
|
||||
70
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/package.json
generated
vendored
Normal file
70
node_modules/cordova-common/node_modules/bplist-parser/node_modules/big-integer/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"name": "big-integer",
|
||||
"version": "1.6.10",
|
||||
"author": {
|
||||
"name": "Peter Olson",
|
||||
"email": "peter.e.c.olson+npm@gmail.com"
|
||||
},
|
||||
"description": "An arbitrary length integer library for Javascript",
|
||||
"contributors": [],
|
||||
"bin": {},
|
||||
"scripts": {
|
||||
"test": "karma start my.conf.js"
|
||||
},
|
||||
"main": "./BigInteger",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/peterolson/BigInteger.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"math",
|
||||
"big",
|
||||
"bignum",
|
||||
"bigint",
|
||||
"biginteger",
|
||||
"integer",
|
||||
"arbitrary",
|
||||
"precision",
|
||||
"arithmetic"
|
||||
],
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.4",
|
||||
"jasmine": "2.1.x",
|
||||
"jasmine-core": "^2.3.4",
|
||||
"karma": "^0.13.3",
|
||||
"karma-coverage": "^0.4.2",
|
||||
"karma-jasmine": "^0.3.6",
|
||||
"karma-phantomjs-launcher": "~0.1"
|
||||
},
|
||||
"license": "Unlicense",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"gitHead": "e9a739fa1a15fe3da4eb302ea7072112ec91e318",
|
||||
"bugs": {
|
||||
"url": "https://github.com/peterolson/BigInteger.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/peterolson/BigInteger.js#readme",
|
||||
"_id": "big-integer@1.6.10",
|
||||
"_shasum": "0f05dcce24278bc33bd8eb9297f4858acacb1fea",
|
||||
"_from": "big-integer@>=1.6.7 <2.0.0",
|
||||
"_npmVersion": "2.9.1",
|
||||
"_nodeVersion": "0.12.3",
|
||||
"_npmUser": {
|
||||
"name": "peterolson",
|
||||
"email": "peter.e.c.olson+npm@gmail.com"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "peterolson",
|
||||
"email": "peter.e.c.olson+npm@gmail.com"
|
||||
}
|
||||
],
|
||||
"dist": {
|
||||
"shasum": "0f05dcce24278bc33bd8eb9297f4858acacb1fea",
|
||||
"tarball": "http://registry.npmjs.org/big-integer/-/big-integer-1.6.10.tgz"
|
||||
},
|
||||
"directories": {},
|
||||
"_resolved": "http://registry.npmjs.org/big-integer/-/big-integer-1.6.10.tgz",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
34
node_modules/cordova-common/node_modules/bplist-parser/package.json
generated
vendored
34
node_modules/cordova-common/node_modules/bplist-parser/package.json
generated
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bplist-parser",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"description": "Binary plist parser.",
|
||||
"main": "bplistParser.js",
|
||||
"scripts": {
|
||||
@@ -23,14 +23,34 @@
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nearinfinity/node-bplist-parser.git"
|
||||
},
|
||||
"readme": "bplist-parser\n=============\n\nBinary Mac OS X Plist (property list) parser.\n\n## Installation\n\n```bash\n$ npm install bplist-parser\n```\n\n## Quick Examples\n\n```javascript\nvar bplist = require('bplist-parser');\n\nbplist.parseFile('myPlist.bplist', function(err, obj) {\n if (err) throw err;\n\n console.log(JSON.stringify(obj));\n});\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 Near Infinity Corporation\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
|
||||
"readmeFilename": "README.md",
|
||||
"dependencies": {
|
||||
"big-integer": "^1.6.7"
|
||||
},
|
||||
"gitHead": "c4f22650de2cc95edd21a6e609ff0654a2b951bd",
|
||||
"bugs": {
|
||||
"url": "https://github.com/nearinfinity/node-bplist-parser/issues"
|
||||
},
|
||||
"homepage": "https://github.com/nearinfinity/node-bplist-parser#readme",
|
||||
"_id": "bplist-parser@0.1.0",
|
||||
"_shasum": "630823f2056437d4dbefc20e84017f8bac48e008",
|
||||
"_resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.1.0.tgz",
|
||||
"_from": "bplist-parser@>=0.1.0 <0.2.0"
|
||||
"_id": "bplist-parser@0.1.1",
|
||||
"_shasum": "d60d5dcc20cba6dc7e1f299b35d3e1f95dafbae6",
|
||||
"_from": "bplist-parser@>=0.1.0 <0.2.0",
|
||||
"_npmVersion": "3.4.0",
|
||||
"_nodeVersion": "5.1.0",
|
||||
"_npmUser": {
|
||||
"name": "joeferner",
|
||||
"email": "joe@fernsroth.com"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "d60d5dcc20cba6dc7e1f299b35d3e1f95dafbae6",
|
||||
"tarball": "http://registry.npmjs.org/bplist-parser/-/bplist-parser-0.1.1.tgz"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "joeferner",
|
||||
"email": "joe@fernsroth.com"
|
||||
}
|
||||
],
|
||||
"directories": {},
|
||||
"_resolved": "http://registry.npmjs.org/bplist-parser/-/bplist-parser-0.1.1.tgz",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
|
||||
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/airplay.bplist
generated
vendored
Normal file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/airplay.bplist
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/iTunes-small.bplist
generated
vendored
Normal file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/iTunes-small.bplist
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/int64.bplist
generated
vendored
Normal file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/int64.bplist
generated
vendored
Normal file
Binary file not shown.
10
node_modules/cordova-common/node_modules/bplist-parser/test/int64.xml
generated
vendored
Normal file
10
node_modules/cordova-common/node_modules/bplist-parser/test/int64.xml
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>zero</key>
|
||||
<integer>0</integer>
|
||||
<key>int64item</key>
|
||||
<integer>12345678901234567890</integer>
|
||||
</dict>
|
||||
</plist>
|
||||
159
node_modules/cordova-common/node_modules/bplist-parser/test/parseTest.js
generated
vendored
Normal file
159
node_modules/cordova-common/node_modules/bplist-parser/test/parseTest.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
'use strict';
|
||||
|
||||
// tests are adapted from https://github.com/TooTallNate/node-plist
|
||||
|
||||
var path = require('path');
|
||||
var nodeunit = require('nodeunit');
|
||||
var bplist = require('../');
|
||||
|
||||
module.exports = {
|
||||
'iTunes Small': function (test) {
|
||||
var file = path.join(__dirname, "iTunes-small.bplist");
|
||||
var startTime1 = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime1) + 'ms');
|
||||
var dict = dicts[0];
|
||||
test.equal(dict['Application Version'], "9.0.3");
|
||||
test.equal(dict['Library Persistent ID'], "6F81D37F95101437");
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'sample1': function (test) {
|
||||
var file = path.join(__dirname, "sample1.bplist");
|
||||
var startTime = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
|
||||
var dict = dicts[0];
|
||||
test.equal(dict['CFBundleIdentifier'], 'com.apple.dictionary.MySample');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'sample2': function (test) {
|
||||
var file = path.join(__dirname, "sample2.bplist");
|
||||
var startTime = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
|
||||
var dict = dicts[0];
|
||||
test.equal(dict['PopupMenu'][2]['Key'], "\n #import <Cocoa/Cocoa.h>\n\n#import <MacRuby/MacRuby.h>\n\nint main(int argc, char *argv[])\n{\n return macruby_main(\"rb_main.rb\", argc, argv);\n}\n");
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'airplay': function (test) {
|
||||
var file = path.join(__dirname, "airplay.bplist");
|
||||
var startTime = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
|
||||
|
||||
var dict = dicts[0];
|
||||
test.equal(dict['duration'], 5555.0495000000001);
|
||||
test.equal(dict['position'], 4.6269989039999997);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'utf16': function (test) {
|
||||
var file = path.join(__dirname, "utf16.bplist");
|
||||
var startTime = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
|
||||
|
||||
var dict = dicts[0];
|
||||
test.equal(dict['CFBundleName'], 'sellStuff');
|
||||
test.equal(dict['CFBundleShortVersionString'], '2.6.1');
|
||||
test.equal(dict['NSHumanReadableCopyright'], '©2008-2012, sellStuff, Inc.');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'utf16chinese': function (test) {
|
||||
var file = path.join(__dirname, "utf16_chinese.plist");
|
||||
var startTime = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
|
||||
|
||||
var dict = dicts[0];
|
||||
test.equal(dict['CFBundleName'], '天翼阅读');
|
||||
test.equal(dict['CFBundleDisplayName'], '天翼阅读');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
'uid': function (test) {
|
||||
var file = path.join(__dirname, "uid.bplist");
|
||||
var startTime = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
|
||||
|
||||
var dict = dicts[0];
|
||||
test.deepEqual(dict['$objects'][1]['NS.keys'], [{UID:2}, {UID:3}, {UID:4}]);
|
||||
test.deepEqual(dict['$objects'][1]['NS.objects'], [{UID: 5}, {UID:6}, {UID:7}]);
|
||||
test.deepEqual(dict['$top']['root'], {UID:1});
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'int64': function (test) {
|
||||
var file = path.join(__dirname, "int64.bplist");
|
||||
var startTime = new Date();
|
||||
|
||||
bplist.parseFile(file, function (err, dicts) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var endTime = new Date();
|
||||
console.log('Parsed "' + file + '" in ' + (endTime - startTime) + 'ms');
|
||||
var dict = dicts[0];
|
||||
test.equal(dict['zero'], '0');
|
||||
test.equal(dict['int64item'], '12345678901234567890');
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
};
|
||||
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/sample1.bplist
generated
vendored
Normal file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/sample1.bplist
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/sample2.bplist
generated
vendored
Normal file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/sample2.bplist
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/uid.bplist
generated
vendored
Normal file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/uid.bplist
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/utf16.bplist
generated
vendored
Normal file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/utf16.bplist
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/utf16_chinese.plist
generated
vendored
Executable file
BIN
node_modules/cordova-common/node_modules/bplist-parser/test/utf16_chinese.plist
generated
vendored
Executable file
Binary file not shown.
10
node_modules/cordova-common/node_modules/cordova-registry-mapper/index.js
generated
vendored
10
node_modules/cordova-common/node_modules/cordova-registry-mapper/index.js
generated
vendored
@@ -182,18 +182,20 @@ var map = {
|
||||
'com.ios.libgoogleadmobads': 'cordova-libgoogleadmobads',
|
||||
'com.google.play.services': 'cordova-google-play-services',
|
||||
'android.support.v13': 'cordova-android-support-v13',
|
||||
'android.support.v4': 'cordova-android-support-v4',
|
||||
'android.support.v4': 'cordova-android-support-v4', // Duplicated key ;)
|
||||
'com.analytics.google': 'cordova-plugin-analytics',
|
||||
'com.analytics.adid.google': 'cordova-plugin-analytics-adid',
|
||||
'com.chariotsolutions.nfc.plugin': 'phonegap-nfc',
|
||||
'com.samz.mixpanel': 'cordova-plugin-mixpanel'
|
||||
}
|
||||
'com.samz.mixpanel': 'cordova-plugin-mixpanel',
|
||||
'de.appplant.cordova.common.RegisterUserNotificationSettings': 'cordova-plugin-registerusernotificationsettings',
|
||||
'plugin.google.maps': 'cordova-plugin-googlemaps'
|
||||
};
|
||||
|
||||
module.exports.oldToNew = map;
|
||||
|
||||
var reverseMap = {};
|
||||
Object.keys(map).forEach(function(elem){
|
||||
reverseMap[map[elem]] = elem;
|
||||
})
|
||||
});
|
||||
|
||||
module.exports.newToOld = reverseMap;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/node_modules
|
||||
@@ -1,4 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
@@ -1,18 +0,0 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
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.
|
||||
140
node_modules/cordova-common/node_modules/cordova-registry-mapper/node_modules/tape/index.js
generated
vendored
140
node_modules/cordova-common/node_modules/cordova-registry-mapper/node_modules/tape/index.js
generated
vendored
@@ -1,140 +0,0 @@
|
||||
var defined = require('defined');
|
||||
var createDefaultStream = require('./lib/default_stream');
|
||||
var Test = require('./lib/test');
|
||||
var createResult = require('./lib/results');
|
||||
var through = require('through');
|
||||
|
||||
var canEmitExit = typeof process !== 'undefined' && process
|
||||
&& typeof process.on === 'function' && process.browser !== true
|
||||
;
|
||||
var canExit = typeof process !== 'undefined' && process
|
||||
&& typeof process.exit === 'function'
|
||||
;
|
||||
|
||||
var nextTick = typeof setImmediate !== 'undefined'
|
||||
? setImmediate
|
||||
: process.nextTick
|
||||
;
|
||||
|
||||
exports = module.exports = (function () {
|
||||
var harness;
|
||||
var lazyLoad = function () {
|
||||
return getHarness().apply(this, arguments);
|
||||
};
|
||||
|
||||
lazyLoad.only = function () {
|
||||
return getHarness().only.apply(this, arguments);
|
||||
};
|
||||
|
||||
lazyLoad.createStream = function (opts) {
|
||||
if (!opts) opts = {};
|
||||
if (!harness) {
|
||||
var output = through();
|
||||
getHarness({ stream: output, objectMode: opts.objectMode });
|
||||
return output;
|
||||
}
|
||||
return harness.createStream(opts);
|
||||
};
|
||||
|
||||
return lazyLoad
|
||||
|
||||
function getHarness (opts) {
|
||||
if (!opts) opts = {};
|
||||
opts.autoclose = !canEmitExit;
|
||||
if (!harness) harness = createExitHarness(opts);
|
||||
return harness;
|
||||
}
|
||||
})();
|
||||
|
||||
function createExitHarness (conf) {
|
||||
if (!conf) conf = {};
|
||||
var harness = createHarness({
|
||||
autoclose: defined(conf.autoclose, false)
|
||||
});
|
||||
|
||||
var stream = harness.createStream({ objectMode: conf.objectMode });
|
||||
var es = stream.pipe(conf.stream || createDefaultStream());
|
||||
if (canEmitExit) {
|
||||
es.on('error', function (err) { harness._exitCode = 1 });
|
||||
}
|
||||
|
||||
var ended = false;
|
||||
stream.on('end', function () { ended = true });
|
||||
|
||||
if (conf.exit === false) return harness;
|
||||
if (!canEmitExit || !canExit) return harness;
|
||||
|
||||
var inErrorState = false;
|
||||
|
||||
process.on('exit', function (code) {
|
||||
// let the process exit cleanly.
|
||||
if (code !== 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!ended) {
|
||||
var only = harness._results._only;
|
||||
for (var i = 0; i < harness._tests.length; i++) {
|
||||
var t = harness._tests[i];
|
||||
if (only && t.name !== only) continue;
|
||||
t._exit();
|
||||
}
|
||||
}
|
||||
harness.close();
|
||||
process.exit(code || harness._exitCode);
|
||||
});
|
||||
|
||||
return harness;
|
||||
}
|
||||
|
||||
exports.createHarness = createHarness;
|
||||
exports.Test = Test;
|
||||
exports.test = exports; // tap compat
|
||||
exports.test.skip = Test.skip;
|
||||
|
||||
var exitInterval;
|
||||
|
||||
function createHarness (conf_) {
|
||||
if (!conf_) conf_ = {};
|
||||
var results = createResult();
|
||||
if (conf_.autoclose !== false) {
|
||||
results.once('done', function () { results.close() });
|
||||
}
|
||||
|
||||
var test = function (name, conf, cb) {
|
||||
var t = new Test(name, conf, cb);
|
||||
test._tests.push(t);
|
||||
|
||||
(function inspectCode (st) {
|
||||
st.on('test', function sub (st_) {
|
||||
inspectCode(st_);
|
||||
});
|
||||
st.on('result', function (r) {
|
||||
if (!r.ok) test._exitCode = 1
|
||||
});
|
||||
})(t);
|
||||
|
||||
results.push(t);
|
||||
return t;
|
||||
};
|
||||
test._results = results;
|
||||
|
||||
test._tests = [];
|
||||
|
||||
test.createStream = function (opts) {
|
||||
return results.createStream(opts);
|
||||
};
|
||||
|
||||
var only = false;
|
||||
test.only = function (name) {
|
||||
if (only) throw new Error('there can only be one only test');
|
||||
results.only(name);
|
||||
only = true;
|
||||
return test.apply(null, arguments);
|
||||
};
|
||||
test._exitCode = 0;
|
||||
|
||||
test.close = function () { results.close() };
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
var through = require('through');
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = function () {
|
||||
var line = '';
|
||||
var stream = through(write, flush);
|
||||
return stream;
|
||||
|
||||
function write (buf) {
|
||||
for (var i = 0; i < buf.length; i++) {
|
||||
var c = typeof buf === 'string'
|
||||
? buf.charAt(i)
|
||||
: String.fromCharCode(buf[i])
|
||||
;
|
||||
if (c === '\n') flush();
|
||||
else line += c;
|
||||
}
|
||||
}
|
||||
|
||||
function flush () {
|
||||
if (fs.writeSync && /^win/.test(process.platform)) {
|
||||
try { fs.writeSync(1, line + '\n'); }
|
||||
catch (e) { stream.emit('error', e) }
|
||||
}
|
||||
else {
|
||||
try { console.log(line) }
|
||||
catch (e) { stream.emit('error', e) }
|
||||
}
|
||||
line = '';
|
||||
}
|
||||
};
|
||||
@@ -1,189 +0,0 @@
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var inherits = require('inherits');
|
||||
var through = require('through');
|
||||
var resumer = require('resumer');
|
||||
var inspect = require('object-inspect');
|
||||
var nextTick = typeof setImmediate !== 'undefined'
|
||||
? setImmediate
|
||||
: process.nextTick
|
||||
;
|
||||
|
||||
module.exports = Results;
|
||||
inherits(Results, EventEmitter);
|
||||
|
||||
function Results () {
|
||||
if (!(this instanceof Results)) return new Results;
|
||||
this.count = 0;
|
||||
this.fail = 0;
|
||||
this.pass = 0;
|
||||
this._stream = through();
|
||||
this.tests = [];
|
||||
}
|
||||
|
||||
Results.prototype.createStream = function (opts) {
|
||||
if (!opts) opts = {};
|
||||
var self = this;
|
||||
var output, testId = 0;
|
||||
if (opts.objectMode) {
|
||||
output = through();
|
||||
self.on('_push', function ontest (t, extra) {
|
||||
if (!extra) extra = {};
|
||||
var id = testId++;
|
||||
t.once('prerun', function () {
|
||||
var row = {
|
||||
type: 'test',
|
||||
name: t.name,
|
||||
id: id
|
||||
};
|
||||
if (has(extra, 'parent')) {
|
||||
row.parent = extra.parent;
|
||||
}
|
||||
output.queue(row);
|
||||
});
|
||||
t.on('test', function (st) {
|
||||
ontest(st, { parent: id });
|
||||
});
|
||||
t.on('result', function (res) {
|
||||
res.test = id;
|
||||
res.type = 'assert';
|
||||
output.queue(res);
|
||||
});
|
||||
t.on('end', function () {
|
||||
output.queue({ type: 'end', test: id });
|
||||
});
|
||||
});
|
||||
self.on('done', function () { output.queue(null) });
|
||||
}
|
||||
else {
|
||||
output = resumer();
|
||||
output.queue('TAP version 13\n');
|
||||
self._stream.pipe(output);
|
||||
}
|
||||
|
||||
nextTick(function next() {
|
||||
var t;
|
||||
while (t = getNextTest(self)) {
|
||||
t.run();
|
||||
if (!t.ended) return t.once('end', function(){ nextTick(next); });
|
||||
}
|
||||
self.emit('done');
|
||||
});
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
Results.prototype.push = function (t) {
|
||||
var self = this;
|
||||
self.tests.push(t);
|
||||
self._watch(t);
|
||||
self.emit('_push', t);
|
||||
};
|
||||
|
||||
Results.prototype.only = function (name) {
|
||||
if (this._only) {
|
||||
self.count ++;
|
||||
self.fail ++;
|
||||
write('not ok ' + self.count + ' already called .only()\n');
|
||||
}
|
||||
this._only = name;
|
||||
};
|
||||
|
||||
Results.prototype._watch = function (t) {
|
||||
var self = this;
|
||||
var write = function (s) { self._stream.queue(s) };
|
||||
t.once('prerun', function () {
|
||||
write('# ' + t.name + '\n');
|
||||
});
|
||||
|
||||
t.on('result', function (res) {
|
||||
if (typeof res === 'string') {
|
||||
write('# ' + res + '\n');
|
||||
return;
|
||||
}
|
||||
write(encodeResult(res, self.count + 1));
|
||||
self.count ++;
|
||||
|
||||
if (res.ok) self.pass ++
|
||||
else self.fail ++
|
||||
});
|
||||
|
||||
t.on('test', function (st) { self._watch(st) });
|
||||
};
|
||||
|
||||
Results.prototype.close = function () {
|
||||
var self = this;
|
||||
if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED'));
|
||||
self.closed = true;
|
||||
var write = function (s) { self._stream.queue(s) };
|
||||
|
||||
write('\n1..' + self.count + '\n');
|
||||
write('# tests ' + self.count + '\n');
|
||||
write('# pass ' + self.pass + '\n');
|
||||
if (self.fail) write('# fail ' + self.fail + '\n')
|
||||
else write('\n# ok\n')
|
||||
|
||||
self._stream.queue(null);
|
||||
};
|
||||
|
||||
function encodeResult (res, count) {
|
||||
var output = '';
|
||||
output += (res.ok ? 'ok ' : 'not ok ') + count;
|
||||
output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
|
||||
|
||||
if (res.skip) output += ' # SKIP';
|
||||
else if (res.todo) output += ' # TODO';
|
||||
|
||||
output += '\n';
|
||||
if (res.ok) return output;
|
||||
|
||||
var outer = ' ';
|
||||
var inner = outer + ' ';
|
||||
output += outer + '---\n';
|
||||
output += inner + 'operator: ' + res.operator + '\n';
|
||||
|
||||
if (has(res, 'expected') || has(res, 'actual')) {
|
||||
var ex = inspect(res.expected);
|
||||
var ac = inspect(res.actual);
|
||||
|
||||
if (Math.max(ex.length, ac.length) > 65) {
|
||||
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
|
||||
output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
|
||||
}
|
||||
else {
|
||||
output += inner + 'expected: ' + ex + '\n';
|
||||
output += inner + 'actual: ' + ac + '\n';
|
||||
}
|
||||
}
|
||||
if (res.at) {
|
||||
output += inner + 'at: ' + res.at + '\n';
|
||||
}
|
||||
if (res.operator === 'error' && res.actual && res.actual.stack) {
|
||||
var lines = String(res.actual.stack).split('\n');
|
||||
output += inner + 'stack:\n';
|
||||
output += inner + ' ' + lines[0] + '\n';
|
||||
for (var i = 1; i < lines.length; i++) {
|
||||
output += inner + lines[i] + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
output += outer + '...\n';
|
||||
return output;
|
||||
}
|
||||
|
||||
function getNextTest (results) {
|
||||
if (!results._only) {
|
||||
return results.tests.shift();
|
||||
}
|
||||
|
||||
do {
|
||||
var t = results.tests.shift();
|
||||
if (!t) continue;
|
||||
if (results._only === t.name) {
|
||||
return t;
|
||||
}
|
||||
} while (results.tests.length !== 0)
|
||||
}
|
||||
|
||||
function has (obj, prop) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||
}
|
||||
@@ -1,496 +0,0 @@
|
||||
var deepEqual = require('deep-equal');
|
||||
var defined = require('defined');
|
||||
var path = require('path');
|
||||
var inherits = require('inherits');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
module.exports = Test;
|
||||
|
||||
var nextTick = typeof setImmediate !== 'undefined'
|
||||
? setImmediate
|
||||
: process.nextTick
|
||||
;
|
||||
|
||||
inherits(Test, EventEmitter);
|
||||
|
||||
var getTestArgs = function (name_, opts_, cb_) {
|
||||
var name = '(anonymous)';
|
||||
var opts = {};
|
||||
var cb;
|
||||
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var arg = arguments[i];
|
||||
var t = typeof arg;
|
||||
if (t === 'string') {
|
||||
name = arg;
|
||||
}
|
||||
else if (t === 'object') {
|
||||
opts = arg || opts;
|
||||
}
|
||||
else if (t === 'function') {
|
||||
cb = arg;
|
||||
}
|
||||
}
|
||||
return { name: name, opts: opts, cb: cb };
|
||||
};
|
||||
|
||||
function Test (name_, opts_, cb_) {
|
||||
if (! (this instanceof Test)) {
|
||||
return new Test(name_, opts_, cb_);
|
||||
}
|
||||
|
||||
var args = getTestArgs(name_, opts_, cb_);
|
||||
|
||||
this.readable = true;
|
||||
this.name = args.name || '(anonymous)';
|
||||
this.assertCount = 0;
|
||||
this.pendingCount = 0;
|
||||
this._skip = args.opts.skip || false;
|
||||
this._plan = undefined;
|
||||
this._cb = args.cb;
|
||||
this._progeny = [];
|
||||
this._ok = true;
|
||||
|
||||
if (args.opts.timeout !== undefined) {
|
||||
this.timeoutAfter(args.opts.timeout);
|
||||
}
|
||||
|
||||
for (var prop in this) {
|
||||
this[prop] = (function bind(self, val) {
|
||||
if (typeof val === 'function') {
|
||||
return function bound() {
|
||||
return val.apply(self, arguments);
|
||||
};
|
||||
}
|
||||
else return val;
|
||||
})(this, this[prop]);
|
||||
}
|
||||
}
|
||||
|
||||
Test.prototype.run = function () {
|
||||
if (!this._cb || this._skip) {
|
||||
return this._end();
|
||||
}
|
||||
this.emit('prerun');
|
||||
this._cb(this);
|
||||
this.emit('run');
|
||||
};
|
||||
|
||||
Test.prototype.test = function (name, opts, cb) {
|
||||
var self = this;
|
||||
var t = new Test(name, opts, cb);
|
||||
this._progeny.push(t);
|
||||
this.pendingCount++;
|
||||
this.emit('test', t);
|
||||
t.on('prerun', function () {
|
||||
self.assertCount++;
|
||||
})
|
||||
|
||||
if (!self._pendingAsserts()) {
|
||||
nextTick(function () {
|
||||
self._end();
|
||||
});
|
||||
}
|
||||
|
||||
nextTick(function() {
|
||||
if (!self._plan && self.pendingCount == self._progeny.length) {
|
||||
self._end();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.comment = function (msg) {
|
||||
this.emit('result', msg.trim().replace(/^#\s*/, ''));
|
||||
};
|
||||
|
||||
Test.prototype.plan = function (n) {
|
||||
this._plan = n;
|
||||
this.emit('plan', n);
|
||||
};
|
||||
|
||||
Test.prototype.timeoutAfter = function(ms) {
|
||||
if (!ms) throw new Error('timeoutAfter requires a timespan');
|
||||
var self = this;
|
||||
var timeout = setTimeout(function() {
|
||||
self.fail('test timed out after ' + ms + 'ms');
|
||||
self.end();
|
||||
}, ms);
|
||||
this.once('end', function() {
|
||||
clearTimeout(timeout);
|
||||
});
|
||||
}
|
||||
|
||||
Test.prototype.end = function (err) {
|
||||
var self = this;
|
||||
if (arguments.length >= 1) {
|
||||
this.ifError(err);
|
||||
}
|
||||
|
||||
if (this.calledEnd) {
|
||||
this.fail('.end() called twice');
|
||||
}
|
||||
this.calledEnd = true;
|
||||
this._end();
|
||||
};
|
||||
|
||||
Test.prototype._end = function (err) {
|
||||
var self = this;
|
||||
if (this._progeny.length) {
|
||||
var t = this._progeny.shift();
|
||||
t.on('end', function () { self._end() });
|
||||
t.run();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.ended) this.emit('end');
|
||||
var pendingAsserts = this._pendingAsserts();
|
||||
if (!this._planError && this._plan !== undefined && pendingAsserts) {
|
||||
this._planError = true;
|
||||
this.fail('plan != count', {
|
||||
expected : this._plan,
|
||||
actual : this.assertCount
|
||||
});
|
||||
}
|
||||
this.ended = true;
|
||||
};
|
||||
|
||||
Test.prototype._exit = function () {
|
||||
if (this._plan !== undefined &&
|
||||
!this._planError && this.assertCount !== this._plan) {
|
||||
this._planError = true;
|
||||
this.fail('plan != count', {
|
||||
expected : this._plan,
|
||||
actual : this.assertCount,
|
||||
exiting : true
|
||||
});
|
||||
}
|
||||
else if (!this.ended) {
|
||||
this.fail('test exited without ending', {
|
||||
exiting: true
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Test.prototype._pendingAsserts = function () {
|
||||
if (this._plan === undefined) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return this._plan - (this._progeny.length + this.assertCount);
|
||||
}
|
||||
};
|
||||
|
||||
Test.prototype._assert = function assert (ok, opts) {
|
||||
var self = this;
|
||||
var extra = opts.extra || {};
|
||||
|
||||
var res = {
|
||||
id : self.assertCount ++,
|
||||
ok : Boolean(ok),
|
||||
skip : defined(extra.skip, opts.skip),
|
||||
name : defined(extra.message, opts.message, '(unnamed assert)'),
|
||||
operator : defined(extra.operator, opts.operator)
|
||||
};
|
||||
if (has(opts, 'actual') || has(extra, 'actual')) {
|
||||
res.actual = defined(extra.actual, opts.actual);
|
||||
}
|
||||
if (has(opts, 'expected') || has(extra, 'expected')) {
|
||||
res.expected = defined(extra.expected, opts.expected);
|
||||
}
|
||||
this._ok = Boolean(this._ok && ok);
|
||||
|
||||
if (!ok) {
|
||||
res.error = defined(extra.error, opts.error, new Error(res.name));
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
var e = new Error('exception');
|
||||
var err = (e.stack || '').split('\n');
|
||||
var dir = path.dirname(__dirname) + '/';
|
||||
|
||||
for (var i = 0; i < err.length; i++) {
|
||||
var m = /^[^\s]*\s*\bat\s+(.+)/.exec(err[i]);
|
||||
if (!m) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var s = m[1].split(/\s+/);
|
||||
var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]);
|
||||
if (!filem) {
|
||||
filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[2]);
|
||||
|
||||
if (!filem) {
|
||||
filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]);
|
||||
|
||||
if (!filem) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filem[1].slice(0, dir.length) === dir) {
|
||||
continue;
|
||||
}
|
||||
|
||||
res.functionName = s[0];
|
||||
res.file = filem[1];
|
||||
res.line = Number(filem[2]);
|
||||
if (filem[3]) res.column = filem[3];
|
||||
|
||||
res.at = m[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
self.emit('result', res);
|
||||
|
||||
var pendingAsserts = self._pendingAsserts();
|
||||
if (!pendingAsserts) {
|
||||
if (extra.exiting) {
|
||||
self._end();
|
||||
} else {
|
||||
nextTick(function () {
|
||||
self._end();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!self._planError && pendingAsserts < 0) {
|
||||
self._planError = true;
|
||||
self.fail('plan != count', {
|
||||
expected : self._plan,
|
||||
actual : self._plan - pendingAsserts
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Test.prototype.fail = function (msg, extra) {
|
||||
this._assert(false, {
|
||||
message : msg,
|
||||
operator : 'fail',
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.pass = function (msg, extra) {
|
||||
this._assert(true, {
|
||||
message : msg,
|
||||
operator : 'pass',
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.skip = function (msg, extra) {
|
||||
this._assert(true, {
|
||||
message : msg,
|
||||
operator : 'skip',
|
||||
skip : true,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.ok
|
||||
= Test.prototype['true']
|
||||
= Test.prototype.assert
|
||||
= function (value, msg, extra) {
|
||||
this._assert(value, {
|
||||
message : msg,
|
||||
operator : 'ok',
|
||||
expected : true,
|
||||
actual : value,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.notOk
|
||||
= Test.prototype['false']
|
||||
= Test.prototype.notok
|
||||
= function (value, msg, extra) {
|
||||
this._assert(!value, {
|
||||
message : msg,
|
||||
operator : 'notOk',
|
||||
expected : false,
|
||||
actual : value,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.error
|
||||
= Test.prototype.ifError
|
||||
= Test.prototype.ifErr
|
||||
= Test.prototype.iferror
|
||||
= function (err, msg, extra) {
|
||||
this._assert(!err, {
|
||||
message : defined(msg, String(err)),
|
||||
operator : 'error',
|
||||
actual : err,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.equal
|
||||
= Test.prototype.equals
|
||||
= Test.prototype.isEqual
|
||||
= Test.prototype.is
|
||||
= Test.prototype.strictEqual
|
||||
= Test.prototype.strictEquals
|
||||
= function (a, b, msg, extra) {
|
||||
this._assert(a === b, {
|
||||
message : defined(msg, 'should be equal'),
|
||||
operator : 'equal',
|
||||
actual : a,
|
||||
expected : b,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.notEqual
|
||||
= Test.prototype.notEquals
|
||||
= Test.prototype.notStrictEqual
|
||||
= Test.prototype.notStrictEquals
|
||||
= Test.prototype.isNotEqual
|
||||
= Test.prototype.isNot
|
||||
= Test.prototype.not
|
||||
= Test.prototype.doesNotEqual
|
||||
= Test.prototype.isInequal
|
||||
= function (a, b, msg, extra) {
|
||||
this._assert(a !== b, {
|
||||
message : defined(msg, 'should not be equal'),
|
||||
operator : 'notEqual',
|
||||
actual : a,
|
||||
notExpected : b,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.deepEqual
|
||||
= Test.prototype.deepEquals
|
||||
= Test.prototype.isEquivalent
|
||||
= Test.prototype.same
|
||||
= function (a, b, msg, extra) {
|
||||
this._assert(deepEqual(a, b, { strict: true }), {
|
||||
message : defined(msg, 'should be equivalent'),
|
||||
operator : 'deepEqual',
|
||||
actual : a,
|
||||
expected : b,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.deepLooseEqual
|
||||
= Test.prototype.looseEqual
|
||||
= Test.prototype.looseEquals
|
||||
= function (a, b, msg, extra) {
|
||||
this._assert(deepEqual(a, b), {
|
||||
message : defined(msg, 'should be equivalent'),
|
||||
operator : 'deepLooseEqual',
|
||||
actual : a,
|
||||
expected : b,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.notDeepEqual
|
||||
= Test.prototype.notEquivalent
|
||||
= Test.prototype.notDeeply
|
||||
= Test.prototype.notSame
|
||||
= Test.prototype.isNotDeepEqual
|
||||
= Test.prototype.isNotDeeply
|
||||
= Test.prototype.isNotEquivalent
|
||||
= Test.prototype.isInequivalent
|
||||
= function (a, b, msg, extra) {
|
||||
this._assert(!deepEqual(a, b, { strict: true }), {
|
||||
message : defined(msg, 'should not be equivalent'),
|
||||
operator : 'notDeepEqual',
|
||||
actual : a,
|
||||
notExpected : b,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.notDeepLooseEqual
|
||||
= Test.prototype.notLooseEqual
|
||||
= Test.prototype.notLooseEquals
|
||||
= function (a, b, msg, extra) {
|
||||
this._assert(!deepEqual(a, b), {
|
||||
message : defined(msg, 'should be equivalent'),
|
||||
operator : 'notDeepLooseEqual',
|
||||
actual : a,
|
||||
expected : b,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype['throws'] = function (fn, expected, msg, extra) {
|
||||
if (typeof expected === 'string') {
|
||||
msg = expected;
|
||||
expected = undefined;
|
||||
}
|
||||
|
||||
var caught = undefined;
|
||||
|
||||
try {
|
||||
fn();
|
||||
} catch (err) {
|
||||
caught = { error : err };
|
||||
var message = err.message;
|
||||
delete err.message;
|
||||
err.message = message;
|
||||
}
|
||||
|
||||
var passed = caught;
|
||||
|
||||
if (expected instanceof RegExp) {
|
||||
passed = expected.test(caught && caught.error);
|
||||
expected = String(expected);
|
||||
}
|
||||
|
||||
if (typeof expected === 'function') {
|
||||
passed = caught.error instanceof expected;
|
||||
caught.error = caught.error.constructor;
|
||||
}
|
||||
|
||||
this._assert(passed, {
|
||||
message : defined(msg, 'should throw'),
|
||||
operator : 'throws',
|
||||
actual : caught && caught.error,
|
||||
expected : expected,
|
||||
error: !passed && caught && caught.error,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.doesNotThrow = function (fn, expected, msg, extra) {
|
||||
if (typeof expected === 'string') {
|
||||
msg = expected;
|
||||
expected = undefined;
|
||||
}
|
||||
var caught = undefined;
|
||||
try {
|
||||
fn();
|
||||
}
|
||||
catch (err) {
|
||||
caught = { error : err };
|
||||
}
|
||||
this._assert(!caught, {
|
||||
message : defined(msg, 'should not throw'),
|
||||
operator : 'throws',
|
||||
actual : caught && caught.error,
|
||||
expected : expected,
|
||||
error : caught && caught.error,
|
||||
extra : extra
|
||||
});
|
||||
};
|
||||
|
||||
function has (obj, prop) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||
}
|
||||
|
||||
Test.skip = function (name_, _opts, _cb) {
|
||||
var args = getTestArgs.apply(null, arguments);
|
||||
args.opts.skip = true;
|
||||
return Test(args.name, args.opts, args.cb);
|
||||
};
|
||||
|
||||
// vim: set softtabstop=4 shiftwidth=4:
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.4
|
||||
- 0.6
|
||||
@@ -1,18 +0,0 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,94 +0,0 @@
|
||||
var pSlice = Array.prototype.slice;
|
||||
var objectKeys = require('./lib/keys.js');
|
||||
var isArguments = require('./lib/is_arguments.js');
|
||||
|
||||
var deepEqual = module.exports = function (actual, expected, opts) {
|
||||
if (!opts) opts = {};
|
||||
// 7.1. All identical values are equivalent, as determined by ===.
|
||||
if (actual === expected) {
|
||||
return true;
|
||||
|
||||
} else if (actual instanceof Date && expected instanceof Date) {
|
||||
return actual.getTime() === expected.getTime();
|
||||
|
||||
// 7.3. Other pairs that do not both pass typeof value == 'object',
|
||||
// equivalence is determined by ==.
|
||||
} else if (typeof actual != 'object' && typeof expected != 'object') {
|
||||
return opts.strict ? actual === expected : actual == expected;
|
||||
|
||||
// 7.4. For all other Object pairs, including Array objects, equivalence is
|
||||
// determined by having the same number of owned properties (as verified
|
||||
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
||||
// (although not necessarily the same order), equivalent values for every
|
||||
// corresponding key, and an identical 'prototype' property. Note: this
|
||||
// accounts for both named and indexed properties on Arrays.
|
||||
} else {
|
||||
return objEquiv(actual, expected, opts);
|
||||
}
|
||||
}
|
||||
|
||||
function isUndefinedOrNull(value) {
|
||||
return value === null || value === undefined;
|
||||
}
|
||||
|
||||
function isBuffer (x) {
|
||||
if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
|
||||
if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
|
||||
return false;
|
||||
}
|
||||
if (x.length > 0 && typeof x[0] !== 'number') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function objEquiv(a, b, opts) {
|
||||
var i, key;
|
||||
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
||||
return false;
|
||||
// an identical 'prototype' property.
|
||||
if (a.prototype !== b.prototype) return false;
|
||||
//~~~I've managed to break Object.keys through screwy arguments passing.
|
||||
// Converting to array solves the problem.
|
||||
if (isArguments(a)) {
|
||||
if (!isArguments(b)) {
|
||||
return false;
|
||||
}
|
||||
a = pSlice.call(a);
|
||||
b = pSlice.call(b);
|
||||
return deepEqual(a, b, opts);
|
||||
}
|
||||
if (isBuffer(a)) {
|
||||
if (!isBuffer(b)) {
|
||||
return false;
|
||||
}
|
||||
if (a.length !== b.length) return false;
|
||||
for (i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
var ka = objectKeys(a),
|
||||
kb = objectKeys(b);
|
||||
} catch (e) {//happens when one is a string literal and the other isn't
|
||||
return false;
|
||||
}
|
||||
// having the same number of owned properties (keys incorporates
|
||||
// hasOwnProperty)
|
||||
if (ka.length != kb.length)
|
||||
return false;
|
||||
//the same set of keys (although not necessarily the same order),
|
||||
ka.sort();
|
||||
kb.sort();
|
||||
//~~~cheap key test
|
||||
for (i = ka.length - 1; i >= 0; i--) {
|
||||
if (ka[i] != kb[i])
|
||||
return false;
|
||||
}
|
||||
//equivalent values for every corresponding key, and
|
||||
//~~~possibly expensive deep test
|
||||
for (i = ka.length - 1; i >= 0; i--) {
|
||||
key = ka[i];
|
||||
if (!deepEqual(a[key], b[key], opts)) return false;
|
||||
}
|
||||
return typeof a === typeof b;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
var supportsArgumentsClass = (function(){
|
||||
return Object.prototype.toString.call(arguments)
|
||||
})() == '[object Arguments]';
|
||||
|
||||
exports = module.exports = supportsArgumentsClass ? supported : unsupported;
|
||||
|
||||
exports.supported = supported;
|
||||
function supported(object) {
|
||||
return Object.prototype.toString.call(object) == '[object Arguments]';
|
||||
};
|
||||
|
||||
exports.unsupported = unsupported;
|
||||
function unsupported(object){
|
||||
return object &&
|
||||
typeof object == 'object' &&
|
||||
typeof object.length == 'number' &&
|
||||
Object.prototype.hasOwnProperty.call(object, 'callee') &&
|
||||
!Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
|
||||
false;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
exports = module.exports = typeof Object.keys === 'function'
|
||||
? Object.keys : shim;
|
||||
|
||||
exports.shim = shim;
|
||||
function shim (obj) {
|
||||
var keys = [];
|
||||
for (var key in obj) keys.push(key);
|
||||
return keys;
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
{
|
||||
"name": "deep-equal",
|
||||
"version": "0.2.2",
|
||||
"description": "node's assert.deepEqual algorithm",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"lib": ".",
|
||||
"example": "example",
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tape": "^3.5.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/substack/node-deep-equal.git"
|
||||
},
|
||||
"keywords": [
|
||||
"equality",
|
||||
"equal",
|
||||
"compare"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"license": "MIT",
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": {
|
||||
"ie": [
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9
|
||||
],
|
||||
"ff": [
|
||||
3.5,
|
||||
10,
|
||||
15
|
||||
],
|
||||
"chrome": [
|
||||
10,
|
||||
22
|
||||
],
|
||||
"safari": [
|
||||
5.1
|
||||
],
|
||||
"opera": [
|
||||
12
|
||||
]
|
||||
}
|
||||
},
|
||||
"gitHead": "05cd26a25f0d7babf0c2758827b4dafec9d0582e",
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/node-deep-equal/issues"
|
||||
},
|
||||
"homepage": "https://github.com/substack/node-deep-equal",
|
||||
"_id": "deep-equal@0.2.2",
|
||||
"_shasum": "84b745896f34c684e98f2ce0e42abaf43bba017d",
|
||||
"_from": "deep-equal@>=0.2.0 <0.3.0",
|
||||
"_npmVersion": "2.3.0",
|
||||
"_nodeVersion": "0.10.35",
|
||||
"_npmUser": {
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
}
|
||||
],
|
||||
"dist": {
|
||||
"shasum": "84b745896f34c684e98f2ce0e42abaf43bba017d",
|
||||
"tarball": "http://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz"
|
||||
},
|
||||
"_resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
# deep-equal
|
||||
|
||||
Node's `assert.deepEqual() algorithm` as a standalone module.
|
||||
|
||||
This module is around [5 times faster](https://gist.github.com/2790507)
|
||||
than wrapping `assert.deepEqual()` in a `try/catch`.
|
||||
|
||||
[](https://ci.testling.com/substack/node-deep-equal)
|
||||
|
||||
[](https://travis-ci.org/substack/node-deep-equal)
|
||||
|
||||
# example
|
||||
|
||||
``` js
|
||||
var equal = require('deep-equal');
|
||||
console.dir([
|
||||
equal(
|
||||
{ a : [ 2, 3 ], b : [ 4 ] },
|
||||
{ a : [ 2, 3 ], b : [ 4 ] }
|
||||
),
|
||||
equal(
|
||||
{ x : 5, y : [6] },
|
||||
{ x : 5, y : 6 }
|
||||
)
|
||||
]);
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var deepEqual = require('deep-equal')
|
||||
```
|
||||
|
||||
## deepEqual(a, b, opts)
|
||||
|
||||
Compare objects `a` and `b`, returning whether they are equal according to a
|
||||
recursive equality algorithm.
|
||||
|
||||
If `opts.strict` is `true`, use strict equality (`===`) to compare leaf nodes.
|
||||
The default is to use coercive equality (`==`) because that's how
|
||||
`assert.deepEqual()` works by default.
|
||||
|
||||
# install
|
||||
|
||||
With [npm](http://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install deep-equal
|
||||
```
|
||||
|
||||
# test
|
||||
|
||||
With [npm](http://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT. Derived largely from node's assert module.
|
||||
@@ -1,4 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.8
|
||||
@@ -1,18 +0,0 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,5 +0,0 @@
|
||||
module.exports = function () {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
if (arguments[i] !== undefined) return arguments[i];
|
||||
}
|
||||
};
|
||||
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"name": "defined",
|
||||
"version": "0.0.0",
|
||||
"description": "return the first argument that is `!== undefined`",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"example": "example",
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"tap": "~0.3.0",
|
||||
"tape": "~0.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/substack/defined.git"
|
||||
},
|
||||
"homepage": "https://github.com/substack/defined",
|
||||
"keywords": [
|
||||
"undefined",
|
||||
"short-circuit",
|
||||
"||",
|
||||
"or",
|
||||
"//",
|
||||
"defined-or"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"license": "MIT",
|
||||
"_id": "defined@0.0.0",
|
||||
"dist": {
|
||||
"shasum": "f35eea7d705e933baf13b2f03b3f83d921403b3e",
|
||||
"tarball": "http://registry.npmjs.org/defined/-/defined-0.0.0.tgz"
|
||||
},
|
||||
"_npmVersion": "1.1.59",
|
||||
"_npmUser": {
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
}
|
||||
],
|
||||
"_shasum": "f35eea7d705e933baf13b2f03b3f83d921403b3e",
|
||||
"_resolved": "https://registry.npmjs.org/defined/-/defined-0.0.0.tgz",
|
||||
"_from": "defined@>=0.0.0 <0.1.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/defined/issues"
|
||||
},
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
# defined
|
||||
|
||||
return the first argument that is `!== undefined`
|
||||
|
||||
[](http://travis-ci.org/substack/defined)
|
||||
|
||||
Most of the time when I chain together `||`s, I actually just want the first
|
||||
item that is not `undefined`, not the first non-falsy item.
|
||||
|
||||
This module is like the defined-or (`//`) operator in perl 5.10+.
|
||||
|
||||
# example
|
||||
|
||||
``` js
|
||||
var defined = require('defined');
|
||||
var opts = { y : false, w : 4 };
|
||||
var x = defined(opts.x, opts.y, opts.w, 100);
|
||||
console.log(x);
|
||||
```
|
||||
|
||||
```
|
||||
$ node example/defined.js
|
||||
false
|
||||
```
|
||||
|
||||
The return value is `false` because `false` is the first item that is
|
||||
`!== undefined`.
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var defined = require('defined')
|
||||
```
|
||||
|
||||
## var x = defined(a, b, c...)
|
||||
|
||||
Return the first item in the argument list `a, b, c...` that is `!== undefined`.
|
||||
|
||||
If all the items are `=== undefined`, return undefined.
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install defined
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
||||
@@ -1,2 +0,0 @@
|
||||
.*.swp
|
||||
test/a/
|
||||
@@ -1,3 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
@@ -1,27 +0,0 @@
|
||||
Copyright (c) Isaac Z. Schlueter ("Author")
|
||||
All rights reserved.
|
||||
|
||||
The BSD License
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,250 +0,0 @@
|
||||
# Glob
|
||||
|
||||
Match files using the patterns the shell uses, like stars and stuff.
|
||||
|
||||
This is a glob implementation in JavaScript. It uses the `minimatch`
|
||||
library to do its matching.
|
||||
|
||||
## Attention: node-glob users!
|
||||
|
||||
The API has changed dramatically between 2.x and 3.x. This library is
|
||||
now 100% JavaScript, and the integer flags have been replaced with an
|
||||
options object.
|
||||
|
||||
Also, there's an event emitter class, proper tests, and all the other
|
||||
things you've come to expect from node modules.
|
||||
|
||||
And best of all, no compilation!
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var glob = require("glob")
|
||||
|
||||
// options is optional
|
||||
glob("**/*.js", options, function (er, files) {
|
||||
// files is an array of filenames.
|
||||
// If the `nonull` option is set, and nothing
|
||||
// was found, then files is ["**/*.js"]
|
||||
// er is an error object or null.
|
||||
})
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
Please see the [minimatch
|
||||
documentation](https://github.com/isaacs/minimatch) for more details.
|
||||
|
||||
Supports these glob features:
|
||||
|
||||
* Brace Expansion
|
||||
* Extended glob matching
|
||||
* "Globstar" `**` matching
|
||||
|
||||
See:
|
||||
|
||||
* `man sh`
|
||||
* `man bash`
|
||||
* `man 3 fnmatch`
|
||||
* `man 5 gitignore`
|
||||
* [minimatch documentation](https://github.com/isaacs/minimatch)
|
||||
|
||||
## glob(pattern, [options], cb)
|
||||
|
||||
* `pattern` {String} Pattern to be matched
|
||||
* `options` {Object}
|
||||
* `cb` {Function}
|
||||
* `err` {Error | null}
|
||||
* `matches` {Array<String>} filenames found matching the pattern
|
||||
|
||||
Perform an asynchronous glob search.
|
||||
|
||||
## glob.sync(pattern, [options])
|
||||
|
||||
* `pattern` {String} Pattern to be matched
|
||||
* `options` {Object}
|
||||
* return: {Array<String>} filenames found matching the pattern
|
||||
|
||||
Perform a synchronous glob search.
|
||||
|
||||
## Class: glob.Glob
|
||||
|
||||
Create a Glob object by instanting the `glob.Glob` class.
|
||||
|
||||
```javascript
|
||||
var Glob = require("glob").Glob
|
||||
var mg = new Glob(pattern, options, cb)
|
||||
```
|
||||
|
||||
It's an EventEmitter, and starts walking the filesystem to find matches
|
||||
immediately.
|
||||
|
||||
### new glob.Glob(pattern, [options], [cb])
|
||||
|
||||
* `pattern` {String} pattern to search for
|
||||
* `options` {Object}
|
||||
* `cb` {Function} Called when an error occurs, or matches are found
|
||||
* `err` {Error | null}
|
||||
* `matches` {Array<String>} filenames found matching the pattern
|
||||
|
||||
Note that if the `sync` flag is set in the options, then matches will
|
||||
be immediately available on the `g.found` member.
|
||||
|
||||
### Properties
|
||||
|
||||
* `minimatch` The minimatch object that the glob uses.
|
||||
* `options` The options object passed in.
|
||||
* `error` The error encountered. When an error is encountered, the
|
||||
glob object is in an undefined state, and should be discarded.
|
||||
* `aborted` Boolean which is set to true when calling `abort()`. There
|
||||
is no way at this time to continue a glob search after aborting, but
|
||||
you can re-use the statCache to avoid having to duplicate syscalls.
|
||||
* `statCache` Collection of all the stat results the glob search
|
||||
performed.
|
||||
* `cache` Convenience object. Each field has the following possible
|
||||
values:
|
||||
* `false` - Path does not exist
|
||||
* `true` - Path exists
|
||||
* `1` - Path exists, and is not a directory
|
||||
* `2` - Path exists, and is a directory
|
||||
* `[file, entries, ...]` - Path exists, is a directory, and the
|
||||
array value is the results of `fs.readdir`
|
||||
|
||||
### Events
|
||||
|
||||
* `end` When the matching is finished, this is emitted with all the
|
||||
matches found. If the `nonull` option is set, and no match was found,
|
||||
then the `matches` list contains the original pattern. The matches
|
||||
are sorted, unless the `nosort` flag is set.
|
||||
* `match` Every time a match is found, this is emitted with the matched.
|
||||
* `error` Emitted when an unexpected error is encountered, or whenever
|
||||
any fs error occurs if `options.strict` is set.
|
||||
* `abort` When `abort()` is called, this event is raised.
|
||||
|
||||
### Methods
|
||||
|
||||
* `abort` Stop the search.
|
||||
|
||||
### Options
|
||||
|
||||
All the options that can be passed to Minimatch can also be passed to
|
||||
Glob to change pattern matching behavior. Also, some have been added,
|
||||
or have glob-specific ramifications.
|
||||
|
||||
All options are false by default, unless otherwise noted.
|
||||
|
||||
All options are added to the glob object, as well.
|
||||
|
||||
* `cwd` The current working directory in which to search. Defaults
|
||||
to `process.cwd()`.
|
||||
* `root` The place where patterns starting with `/` will be mounted
|
||||
onto. Defaults to `path.resolve(options.cwd, "/")` (`/` on Unix
|
||||
systems, and `C:\` or some such on Windows.)
|
||||
* `dot` Include `.dot` files in normal matches and `globstar` matches.
|
||||
Note that an explicit dot in a portion of the pattern will always
|
||||
match dot files.
|
||||
* `nomount` By default, a pattern starting with a forward-slash will be
|
||||
"mounted" onto the root setting, so that a valid filesystem path is
|
||||
returned. Set this flag to disable that behavior.
|
||||
* `mark` Add a `/` character to directory matches. Note that this
|
||||
requires additional stat calls.
|
||||
* `nosort` Don't sort the results.
|
||||
* `stat` Set to true to stat *all* results. This reduces performance
|
||||
somewhat, and is completely unnecessary, unless `readdir` is presumed
|
||||
to be an untrustworthy indicator of file existence. It will cause
|
||||
ELOOP to be triggered one level sooner in the case of cyclical
|
||||
symbolic links.
|
||||
* `silent` When an unusual error is encountered
|
||||
when attempting to read a directory, a warning will be printed to
|
||||
stderr. Set the `silent` option to true to suppress these warnings.
|
||||
* `strict` When an unusual error is encountered
|
||||
when attempting to read a directory, the process will just continue on
|
||||
in search of other matches. Set the `strict` option to raise an error
|
||||
in these cases.
|
||||
* `cache` See `cache` property above. Pass in a previously generated
|
||||
cache object to save some fs calls.
|
||||
* `statCache` A cache of results of filesystem information, to prevent
|
||||
unnecessary stat calls. While it should not normally be necessary to
|
||||
set this, you may pass the statCache from one glob() call to the
|
||||
options object of another, if you know that the filesystem will not
|
||||
change between calls. (See "Race Conditions" below.)
|
||||
* `sync` Perform a synchronous glob search.
|
||||
* `nounique` In some cases, brace-expanded patterns can result in the
|
||||
same file showing up multiple times in the result set. By default,
|
||||
this implementation prevents duplicates in the result set.
|
||||
Set this flag to disable that behavior.
|
||||
* `nonull` Set to never return an empty set, instead returning a set
|
||||
containing the pattern itself. This is the default in glob(3).
|
||||
* `nocase` Perform a case-insensitive match. Note that case-insensitive
|
||||
filesystems will sometimes result in glob returning results that are
|
||||
case-insensitively matched anyway, since readdir and stat will not
|
||||
raise an error.
|
||||
* `debug` Set to enable debug logging in minimatch and glob.
|
||||
* `globDebug` Set to enable debug logging in glob, but not minimatch.
|
||||
|
||||
## Comparisons to other fnmatch/glob implementations
|
||||
|
||||
While strict compliance with the existing standards is a worthwhile
|
||||
goal, some discrepancies exist between node-glob and other
|
||||
implementations, and are intentional.
|
||||
|
||||
If the pattern starts with a `!` character, then it is negated. Set the
|
||||
`nonegate` flag to suppress this behavior, and treat leading `!`
|
||||
characters normally. This is perhaps relevant if you wish to start the
|
||||
pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
|
||||
characters at the start of a pattern will negate the pattern multiple
|
||||
times.
|
||||
|
||||
If a pattern starts with `#`, then it is treated as a comment, and
|
||||
will not match anything. Use `\#` to match a literal `#` at the
|
||||
start of a line, or set the `nocomment` flag to suppress this behavior.
|
||||
|
||||
The double-star character `**` is supported by default, unless the
|
||||
`noglobstar` flag is set. This is supported in the manner of bsdglob
|
||||
and bash 4.1, where `**` only has special significance if it is the only
|
||||
thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
|
||||
`a/**b` will not.
|
||||
|
||||
If an escaped pattern has no matches, and the `nonull` flag is set,
|
||||
then glob returns the pattern as-provided, rather than
|
||||
interpreting the character escapes. For example,
|
||||
`glob.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
|
||||
`"*a?"`. This is akin to setting the `nullglob` option in bash, except
|
||||
that it does not resolve escaped pattern characters.
|
||||
|
||||
If brace expansion is not disabled, then it is performed before any
|
||||
other interpretation of the glob pattern. Thus, a pattern like
|
||||
`+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
|
||||
**first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
|
||||
checked for validity. Since those two are valid, matching proceeds.
|
||||
|
||||
## Windows
|
||||
|
||||
**Please only use forward-slashes in glob expressions.**
|
||||
|
||||
Though windows uses either `/` or `\` as its path separator, only `/`
|
||||
characters are used by this glob implementation. You must use
|
||||
forward-slashes **only** in glob expressions. Back-slashes will always
|
||||
be interpreted as escape characters, not path separators.
|
||||
|
||||
Results from absolute patterns such as `/foo/*` are mounted onto the
|
||||
root setting using `path.join`. On windows, this will by default result
|
||||
in `/foo/*` matching `C:\foo\bar.txt`.
|
||||
|
||||
## Race Conditions
|
||||
|
||||
Glob searching, by its very nature, is susceptible to race conditions,
|
||||
since it relies on directory walking and such.
|
||||
|
||||
As a result, it is possible that a file that exists when glob looks for
|
||||
it may have been deleted or modified by the time it returns the result.
|
||||
|
||||
As part of its internal implementation, this program caches all stat
|
||||
and readdir calls that it makes, in order to cut down on system
|
||||
overhead. However, this also makes it even more susceptible to races,
|
||||
especially if the cache or statCache objects are reused between glob
|
||||
calls.
|
||||
|
||||
Users are thus advised not to use a glob result as a guarantee of
|
||||
filesystem state in the face of rapid changes. For the vast majority
|
||||
of operations, this is never a problem.
|
||||
@@ -1,9 +0,0 @@
|
||||
var Glob = require("../").Glob
|
||||
|
||||
var pattern = "test/a/**/[cg]/../[cg]"
|
||||
console.log(pattern)
|
||||
|
||||
var mg = new Glob(pattern, {mark: true, sync:true}, function (er, matches) {
|
||||
console.log("matches", matches)
|
||||
})
|
||||
console.log("after")
|
||||
@@ -1,9 +0,0 @@
|
||||
var Glob = require("../").Glob
|
||||
|
||||
var pattern = "{./*/*,/*,/usr/local/*}"
|
||||
console.log(pattern)
|
||||
|
||||
var mg = new Glob(pattern, {mark: true}, function (er, matches) {
|
||||
console.log("matches", matches)
|
||||
})
|
||||
console.log("after")
|
||||
@@ -1,728 +0,0 @@
|
||||
// Approach:
|
||||
//
|
||||
// 1. Get the minimatch set
|
||||
// 2. For each pattern in the set, PROCESS(pattern)
|
||||
// 3. Store matches per-set, then uniq them
|
||||
//
|
||||
// PROCESS(pattern)
|
||||
// Get the first [n] items from pattern that are all strings
|
||||
// Join these together. This is PREFIX.
|
||||
// If there is no more remaining, then stat(PREFIX) and
|
||||
// add to matches if it succeeds. END.
|
||||
// readdir(PREFIX) as ENTRIES
|
||||
// If fails, END
|
||||
// If pattern[n] is GLOBSTAR
|
||||
// // handle the case where the globstar match is empty
|
||||
// // by pruning it out, and testing the resulting pattern
|
||||
// PROCESS(pattern[0..n] + pattern[n+1 .. $])
|
||||
// // handle other cases.
|
||||
// for ENTRY in ENTRIES (not dotfiles)
|
||||
// // attach globstar + tail onto the entry
|
||||
// PROCESS(pattern[0..n] + ENTRY + pattern[n .. $])
|
||||
//
|
||||
// else // not globstar
|
||||
// for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
|
||||
// Test ENTRY against pattern[n]
|
||||
// If fails, continue
|
||||
// If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
|
||||
//
|
||||
// Caveat:
|
||||
// Cache all stats and readdirs results to minimize syscall. Since all
|
||||
// we ever care about is existence and directory-ness, we can just keep
|
||||
// `true` for files, and [children,...] for directories, or `false` for
|
||||
// things that don't exist.
|
||||
|
||||
|
||||
|
||||
module.exports = glob
|
||||
|
||||
var fs = require("fs")
|
||||
, minimatch = require("minimatch")
|
||||
, Minimatch = minimatch.Minimatch
|
||||
, inherits = require("inherits")
|
||||
, EE = require("events").EventEmitter
|
||||
, path = require("path")
|
||||
, isDir = {}
|
||||
, assert = require("assert").ok
|
||||
|
||||
function glob (pattern, options, cb) {
|
||||
if (typeof options === "function") cb = options, options = {}
|
||||
if (!options) options = {}
|
||||
|
||||
if (typeof options === "number") {
|
||||
deprecated()
|
||||
return
|
||||
}
|
||||
|
||||
var g = new Glob(pattern, options, cb)
|
||||
return g.sync ? g.found : g
|
||||
}
|
||||
|
||||
glob.fnmatch = deprecated
|
||||
|
||||
function deprecated () {
|
||||
throw new Error("glob's interface has changed. Please see the docs.")
|
||||
}
|
||||
|
||||
glob.sync = globSync
|
||||
function globSync (pattern, options) {
|
||||
if (typeof options === "number") {
|
||||
deprecated()
|
||||
return
|
||||
}
|
||||
|
||||
options = options || {}
|
||||
options.sync = true
|
||||
return glob(pattern, options)
|
||||
}
|
||||
|
||||
this._processingEmitQueue = false
|
||||
|
||||
glob.Glob = Glob
|
||||
inherits(Glob, EE)
|
||||
function Glob (pattern, options, cb) {
|
||||
if (!(this instanceof Glob)) {
|
||||
return new Glob(pattern, options, cb)
|
||||
}
|
||||
|
||||
if (typeof options === "function") {
|
||||
cb = options
|
||||
options = null
|
||||
}
|
||||
|
||||
if (typeof cb === "function") {
|
||||
this.on("error", cb)
|
||||
this.on("end", function (matches) {
|
||||
cb(null, matches)
|
||||
})
|
||||
}
|
||||
|
||||
options = options || {}
|
||||
|
||||
this._endEmitted = false
|
||||
this.EOF = {}
|
||||
this._emitQueue = []
|
||||
|
||||
this.paused = false
|
||||
this._processingEmitQueue = false
|
||||
|
||||
this.maxDepth = options.maxDepth || 1000
|
||||
this.maxLength = options.maxLength || Infinity
|
||||
this.cache = options.cache || {}
|
||||
this.statCache = options.statCache || {}
|
||||
|
||||
this.changedCwd = false
|
||||
var cwd = process.cwd()
|
||||
if (!options.hasOwnProperty("cwd")) this.cwd = cwd
|
||||
else {
|
||||
this.cwd = options.cwd
|
||||
this.changedCwd = path.resolve(options.cwd) !== cwd
|
||||
}
|
||||
|
||||
this.root = options.root || path.resolve(this.cwd, "/")
|
||||
this.root = path.resolve(this.root)
|
||||
if (process.platform === "win32")
|
||||
this.root = this.root.replace(/\\/g, "/")
|
||||
|
||||
this.nomount = !!options.nomount
|
||||
|
||||
if (!pattern) {
|
||||
throw new Error("must provide pattern")
|
||||
}
|
||||
|
||||
// base-matching: just use globstar for that.
|
||||
if (options.matchBase && -1 === pattern.indexOf("/")) {
|
||||
if (options.noglobstar) {
|
||||
throw new Error("base matching requires globstar")
|
||||
}
|
||||
pattern = "**/" + pattern
|
||||
}
|
||||
|
||||
this.strict = options.strict !== false
|
||||
this.dot = !!options.dot
|
||||
this.mark = !!options.mark
|
||||
this.sync = !!options.sync
|
||||
this.nounique = !!options.nounique
|
||||
this.nonull = !!options.nonull
|
||||
this.nosort = !!options.nosort
|
||||
this.nocase = !!options.nocase
|
||||
this.stat = !!options.stat
|
||||
|
||||
this.debug = !!options.debug || !!options.globDebug
|
||||
if (this.debug)
|
||||
this.log = console.error
|
||||
|
||||
this.silent = !!options.silent
|
||||
|
||||
var mm = this.minimatch = new Minimatch(pattern, options)
|
||||
this.options = mm.options
|
||||
pattern = this.pattern = mm.pattern
|
||||
|
||||
this.error = null
|
||||
this.aborted = false
|
||||
|
||||
// list of all the patterns that ** has resolved do, so
|
||||
// we can avoid visiting multiple times.
|
||||
this._globstars = {}
|
||||
|
||||
EE.call(this)
|
||||
|
||||
// process each pattern in the minimatch set
|
||||
var n = this.minimatch.set.length
|
||||
|
||||
// The matches are stored as {<filename>: true,...} so that
|
||||
// duplicates are automagically pruned.
|
||||
// Later, we do an Object.keys() on these.
|
||||
// Keep them as a list so we can fill in when nonull is set.
|
||||
this.matches = new Array(n)
|
||||
|
||||
this.minimatch.set.forEach(iterator.bind(this))
|
||||
function iterator (pattern, i, set) {
|
||||
this._process(pattern, 0, i, function (er) {
|
||||
if (er) this.emit("error", er)
|
||||
if (-- n <= 0) this._finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype.log = function () {}
|
||||
|
||||
Glob.prototype._finish = function () {
|
||||
assert(this instanceof Glob)
|
||||
|
||||
var nou = this.nounique
|
||||
, all = nou ? [] : {}
|
||||
|
||||
for (var i = 0, l = this.matches.length; i < l; i ++) {
|
||||
var matches = this.matches[i]
|
||||
this.log("matches[%d] =", i, matches)
|
||||
// do like the shell, and spit out the literal glob
|
||||
if (!matches) {
|
||||
if (this.nonull) {
|
||||
var literal = this.minimatch.globSet[i]
|
||||
if (nou) all.push(literal)
|
||||
else all[literal] = true
|
||||
}
|
||||
} else {
|
||||
// had matches
|
||||
var m = Object.keys(matches)
|
||||
if (nou) all.push.apply(all, m)
|
||||
else m.forEach(function (m) {
|
||||
all[m] = true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (!nou) all = Object.keys(all)
|
||||
|
||||
if (!this.nosort) {
|
||||
all = all.sort(this.nocase ? alphasorti : alphasort)
|
||||
}
|
||||
|
||||
if (this.mark) {
|
||||
// at *some* point we statted all of these
|
||||
all = all.map(this._mark, this)
|
||||
}
|
||||
|
||||
this.log("emitting end", all)
|
||||
|
||||
this.EOF = this.found = all
|
||||
this.emitMatch(this.EOF)
|
||||
}
|
||||
|
||||
function alphasorti (a, b) {
|
||||
a = a.toLowerCase()
|
||||
b = b.toLowerCase()
|
||||
return alphasort(a, b)
|
||||
}
|
||||
|
||||
function alphasort (a, b) {
|
||||
return a > b ? 1 : a < b ? -1 : 0
|
||||
}
|
||||
|
||||
Glob.prototype._mark = function (p) {
|
||||
var c = this.cache[p]
|
||||
var m = p
|
||||
if (c) {
|
||||
var isDir = c === 2 || Array.isArray(c)
|
||||
var slash = p.slice(-1) === '/'
|
||||
|
||||
if (isDir && !slash)
|
||||
m += '/'
|
||||
else if (!isDir && slash)
|
||||
m = m.slice(0, -1)
|
||||
|
||||
if (m !== p) {
|
||||
this.statCache[m] = this.statCache[p]
|
||||
this.cache[m] = this.cache[p]
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
Glob.prototype.abort = function () {
|
||||
this.aborted = true
|
||||
this.emit("abort")
|
||||
}
|
||||
|
||||
Glob.prototype.pause = function () {
|
||||
if (this.paused) return
|
||||
if (this.sync)
|
||||
this.emit("error", new Error("Can't pause/resume sync glob"))
|
||||
this.paused = true
|
||||
this.emit("pause")
|
||||
}
|
||||
|
||||
Glob.prototype.resume = function () {
|
||||
if (!this.paused) return
|
||||
if (this.sync)
|
||||
this.emit("error", new Error("Can't pause/resume sync glob"))
|
||||
this.paused = false
|
||||
this.emit("resume")
|
||||
this._processEmitQueue()
|
||||
//process.nextTick(this.emit.bind(this, "resume"))
|
||||
}
|
||||
|
||||
Glob.prototype.emitMatch = function (m) {
|
||||
this.log('emitMatch', m)
|
||||
this._emitQueue.push(m)
|
||||
this._processEmitQueue()
|
||||
}
|
||||
|
||||
Glob.prototype._processEmitQueue = function (m) {
|
||||
this.log("pEQ paused=%j processing=%j m=%j", this.paused,
|
||||
this._processingEmitQueue, m)
|
||||
var done = false
|
||||
while (!this._processingEmitQueue &&
|
||||
!this.paused) {
|
||||
this._processingEmitQueue = true
|
||||
var m = this._emitQueue.shift()
|
||||
this.log(">processEmitQueue", m === this.EOF ? ":EOF:" : m)
|
||||
if (!m) {
|
||||
this.log(">processEmitQueue, falsey m")
|
||||
this._processingEmitQueue = false
|
||||
break
|
||||
}
|
||||
|
||||
if (m === this.EOF || !(this.mark && !this.stat)) {
|
||||
this.log("peq: unmarked, or eof")
|
||||
next.call(this, 0, false)
|
||||
} else if (this.statCache[m]) {
|
||||
var sc = this.statCache[m]
|
||||
var exists
|
||||
if (sc)
|
||||
exists = sc.isDirectory() ? 2 : 1
|
||||
this.log("peq: stat cached")
|
||||
next.call(this, exists, exists === 2)
|
||||
} else {
|
||||
this.log("peq: _stat, then next")
|
||||
this._stat(m, next)
|
||||
}
|
||||
|
||||
function next(exists, isDir) {
|
||||
this.log("next", m, exists, isDir)
|
||||
var ev = m === this.EOF ? "end" : "match"
|
||||
|
||||
// "end" can only happen once.
|
||||
assert(!this._endEmitted)
|
||||
if (ev === "end")
|
||||
this._endEmitted = true
|
||||
|
||||
if (exists) {
|
||||
// Doesn't mean it necessarily doesn't exist, it's possible
|
||||
// we just didn't check because we don't care that much, or
|
||||
// this is EOF anyway.
|
||||
if (isDir && !m.match(/\/$/)) {
|
||||
m = m + "/"
|
||||
} else if (!isDir && m.match(/\/$/)) {
|
||||
m = m.replace(/\/+$/, "")
|
||||
}
|
||||
}
|
||||
this.log("emit", ev, m)
|
||||
this.emit(ev, m)
|
||||
this._processingEmitQueue = false
|
||||
if (done && m !== this.EOF && !this.paused)
|
||||
this._processEmitQueue()
|
||||
}
|
||||
}
|
||||
done = true
|
||||
}
|
||||
|
||||
Glob.prototype._process = function (pattern, depth, index, cb_) {
|
||||
assert(this instanceof Glob)
|
||||
|
||||
var cb = function cb (er, res) {
|
||||
assert(this instanceof Glob)
|
||||
if (this.paused) {
|
||||
if (!this._processQueue) {
|
||||
this._processQueue = []
|
||||
this.once("resume", function () {
|
||||
var q = this._processQueue
|
||||
this._processQueue = null
|
||||
q.forEach(function (cb) { cb() })
|
||||
})
|
||||
}
|
||||
this._processQueue.push(cb_.bind(this, er, res))
|
||||
} else {
|
||||
cb_.call(this, er, res)
|
||||
}
|
||||
}.bind(this)
|
||||
|
||||
if (this.aborted) return cb()
|
||||
|
||||
if (depth > this.maxDepth) return cb()
|
||||
|
||||
// Get the first [n] parts of pattern that are all strings.
|
||||
var n = 0
|
||||
while (typeof pattern[n] === "string") {
|
||||
n ++
|
||||
}
|
||||
// now n is the index of the first one that is *not* a string.
|
||||
|
||||
// see if there's anything else
|
||||
var prefix
|
||||
switch (n) {
|
||||
// if not, then this is rather simple
|
||||
case pattern.length:
|
||||
prefix = pattern.join("/")
|
||||
this._stat(prefix, function (exists, isDir) {
|
||||
// either it's there, or it isn't.
|
||||
// nothing more to do, either way.
|
||||
if (exists) {
|
||||
if (prefix && isAbsolute(prefix) && !this.nomount) {
|
||||
if (prefix.charAt(0) === "/") {
|
||||
prefix = path.join(this.root, prefix)
|
||||
} else {
|
||||
prefix = path.resolve(this.root, prefix)
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === "win32")
|
||||
prefix = prefix.replace(/\\/g, "/")
|
||||
|
||||
this.matches[index] = this.matches[index] || {}
|
||||
this.matches[index][prefix] = true
|
||||
this.emitMatch(prefix)
|
||||
}
|
||||
return cb()
|
||||
})
|
||||
return
|
||||
|
||||
case 0:
|
||||
// pattern *starts* with some non-trivial item.
|
||||
// going to readdir(cwd), but not include the prefix in matches.
|
||||
prefix = null
|
||||
break
|
||||
|
||||
default:
|
||||
// pattern has some string bits in the front.
|
||||
// whatever it starts with, whether that's "absolute" like /foo/bar,
|
||||
// or "relative" like "../baz"
|
||||
prefix = pattern.slice(0, n)
|
||||
prefix = prefix.join("/")
|
||||
break
|
||||
}
|
||||
|
||||
// get the list of entries.
|
||||
var read
|
||||
if (prefix === null) read = "."
|
||||
else if (isAbsolute(prefix) || isAbsolute(pattern.join("/"))) {
|
||||
if (!prefix || !isAbsolute(prefix)) {
|
||||
prefix = path.join("/", prefix)
|
||||
}
|
||||
read = prefix = path.resolve(prefix)
|
||||
|
||||
// if (process.platform === "win32")
|
||||
// read = prefix = prefix.replace(/^[a-zA-Z]:|\\/g, "/")
|
||||
|
||||
this.log('absolute: ', prefix, this.root, pattern, read)
|
||||
} else {
|
||||
read = prefix
|
||||
}
|
||||
|
||||
this.log('readdir(%j)', read, this.cwd, this.root)
|
||||
|
||||
return this._readdir(read, function (er, entries) {
|
||||
if (er) {
|
||||
// not a directory!
|
||||
// this means that, whatever else comes after this, it can never match
|
||||
return cb()
|
||||
}
|
||||
|
||||
// globstar is special
|
||||
if (pattern[n] === minimatch.GLOBSTAR) {
|
||||
// test without the globstar, and with every child both below
|
||||
// and replacing the globstar.
|
||||
var s = [ pattern.slice(0, n).concat(pattern.slice(n + 1)) ]
|
||||
entries.forEach(function (e) {
|
||||
if (e.charAt(0) === "." && !this.dot) return
|
||||
// instead of the globstar
|
||||
s.push(pattern.slice(0, n).concat(e).concat(pattern.slice(n + 1)))
|
||||
// below the globstar
|
||||
s.push(pattern.slice(0, n).concat(e).concat(pattern.slice(n)))
|
||||
}, this)
|
||||
|
||||
s = s.filter(function (pattern) {
|
||||
var key = gsKey(pattern)
|
||||
var seen = !this._globstars[key]
|
||||
this._globstars[key] = true
|
||||
return seen
|
||||
}, this)
|
||||
|
||||
if (!s.length)
|
||||
return cb()
|
||||
|
||||
// now asyncForEach over this
|
||||
var l = s.length
|
||||
, errState = null
|
||||
s.forEach(function (gsPattern) {
|
||||
this._process(gsPattern, depth + 1, index, function (er) {
|
||||
if (errState) return
|
||||
if (er) return cb(errState = er)
|
||||
if (--l <= 0) return cb()
|
||||
})
|
||||
}, this)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// not a globstar
|
||||
// It will only match dot entries if it starts with a dot, or if
|
||||
// dot is set. Stuff like @(.foo|.bar) isn't allowed.
|
||||
var pn = pattern[n]
|
||||
var rawGlob = pattern[n]._glob
|
||||
, dotOk = this.dot || rawGlob.charAt(0) === "."
|
||||
|
||||
entries = entries.filter(function (e) {
|
||||
return (e.charAt(0) !== "." || dotOk) &&
|
||||
e.match(pattern[n])
|
||||
})
|
||||
|
||||
// If n === pattern.length - 1, then there's no need for the extra stat
|
||||
// *unless* the user has specified "mark" or "stat" explicitly.
|
||||
// We know that they exist, since the readdir returned them.
|
||||
if (n === pattern.length - 1 &&
|
||||
!this.mark &&
|
||||
!this.stat) {
|
||||
entries.forEach(function (e) {
|
||||
if (prefix) {
|
||||
if (prefix !== "/") e = prefix + "/" + e
|
||||
else e = prefix + e
|
||||
}
|
||||
if (e.charAt(0) === "/" && !this.nomount) {
|
||||
e = path.join(this.root, e)
|
||||
}
|
||||
|
||||
if (process.platform === "win32")
|
||||
e = e.replace(/\\/g, "/")
|
||||
|
||||
this.matches[index] = this.matches[index] || {}
|
||||
this.matches[index][e] = true
|
||||
this.emitMatch(e)
|
||||
}, this)
|
||||
return cb.call(this)
|
||||
}
|
||||
|
||||
|
||||
// now test all the remaining entries as stand-ins for that part
|
||||
// of the pattern.
|
||||
var l = entries.length
|
||||
, errState = null
|
||||
if (l === 0) return cb() // no matches possible
|
||||
entries.forEach(function (e) {
|
||||
var p = pattern.slice(0, n).concat(e).concat(pattern.slice(n + 1))
|
||||
this._process(p, depth + 1, index, function (er) {
|
||||
if (errState) return
|
||||
if (er) return cb(errState = er)
|
||||
if (--l === 0) return cb.call(this)
|
||||
})
|
||||
}, this)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function gsKey (pattern) {
|
||||
return '**' + pattern.map(function (p) {
|
||||
return (p === minimatch.GLOBSTAR) ? '**' : (''+p)
|
||||
}).join('/')
|
||||
}
|
||||
|
||||
Glob.prototype._stat = function (f, cb) {
|
||||
assert(this instanceof Glob)
|
||||
var abs = f
|
||||
if (f.charAt(0) === "/") {
|
||||
abs = path.join(this.root, f)
|
||||
} else if (this.changedCwd) {
|
||||
abs = path.resolve(this.cwd, f)
|
||||
}
|
||||
|
||||
if (f.length > this.maxLength) {
|
||||
var er = new Error("Path name too long")
|
||||
er.code = "ENAMETOOLONG"
|
||||
er.path = f
|
||||
return this._afterStat(f, abs, cb, er)
|
||||
}
|
||||
|
||||
this.log('stat', [this.cwd, f, '=', abs])
|
||||
|
||||
if (!this.stat && this.cache.hasOwnProperty(f)) {
|
||||
var exists = this.cache[f]
|
||||
, isDir = exists && (Array.isArray(exists) || exists === 2)
|
||||
if (this.sync) return cb.call(this, !!exists, isDir)
|
||||
return process.nextTick(cb.bind(this, !!exists, isDir))
|
||||
}
|
||||
|
||||
var stat = this.statCache[abs]
|
||||
if (this.sync || stat) {
|
||||
var er
|
||||
try {
|
||||
stat = fs.statSync(abs)
|
||||
} catch (e) {
|
||||
er = e
|
||||
}
|
||||
this._afterStat(f, abs, cb, er, stat)
|
||||
} else {
|
||||
fs.stat(abs, this._afterStat.bind(this, f, abs, cb))
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype._afterStat = function (f, abs, cb, er, stat) {
|
||||
var exists
|
||||
assert(this instanceof Glob)
|
||||
|
||||
if (abs.slice(-1) === "/" && stat && !stat.isDirectory()) {
|
||||
this.log("should be ENOTDIR, fake it")
|
||||
|
||||
er = new Error("ENOTDIR, not a directory '" + abs + "'")
|
||||
er.path = abs
|
||||
er.code = "ENOTDIR"
|
||||
stat = null
|
||||
}
|
||||
|
||||
var emit = !this.statCache[abs]
|
||||
this.statCache[abs] = stat
|
||||
|
||||
if (er || !stat) {
|
||||
exists = false
|
||||
} else {
|
||||
exists = stat.isDirectory() ? 2 : 1
|
||||
if (emit)
|
||||
this.emit('stat', f, stat)
|
||||
}
|
||||
this.cache[f] = this.cache[f] || exists
|
||||
cb.call(this, !!exists, exists === 2)
|
||||
}
|
||||
|
||||
Glob.prototype._readdir = function (f, cb) {
|
||||
assert(this instanceof Glob)
|
||||
var abs = f
|
||||
if (f.charAt(0) === "/") {
|
||||
abs = path.join(this.root, f)
|
||||
} else if (isAbsolute(f)) {
|
||||
abs = f
|
||||
} else if (this.changedCwd) {
|
||||
abs = path.resolve(this.cwd, f)
|
||||
}
|
||||
|
||||
if (f.length > this.maxLength) {
|
||||
var er = new Error("Path name too long")
|
||||
er.code = "ENAMETOOLONG"
|
||||
er.path = f
|
||||
return this._afterReaddir(f, abs, cb, er)
|
||||
}
|
||||
|
||||
this.log('readdir', [this.cwd, f, abs])
|
||||
if (this.cache.hasOwnProperty(f)) {
|
||||
var c = this.cache[f]
|
||||
if (Array.isArray(c)) {
|
||||
if (this.sync) return cb.call(this, null, c)
|
||||
return process.nextTick(cb.bind(this, null, c))
|
||||
}
|
||||
|
||||
if (!c || c === 1) {
|
||||
// either ENOENT or ENOTDIR
|
||||
var code = c ? "ENOTDIR" : "ENOENT"
|
||||
, er = new Error((c ? "Not a directory" : "Not found") + ": " + f)
|
||||
er.path = f
|
||||
er.code = code
|
||||
this.log(f, er)
|
||||
if (this.sync) return cb.call(this, er)
|
||||
return process.nextTick(cb.bind(this, er))
|
||||
}
|
||||
|
||||
// at this point, c === 2, meaning it's a dir, but we haven't
|
||||
// had to read it yet, or c === true, meaning it's *something*
|
||||
// but we don't have any idea what. Need to read it, either way.
|
||||
}
|
||||
|
||||
if (this.sync) {
|
||||
var er, entries
|
||||
try {
|
||||
entries = fs.readdirSync(abs)
|
||||
} catch (e) {
|
||||
er = e
|
||||
}
|
||||
return this._afterReaddir(f, abs, cb, er, entries)
|
||||
}
|
||||
|
||||
fs.readdir(abs, this._afterReaddir.bind(this, f, abs, cb))
|
||||
}
|
||||
|
||||
Glob.prototype._afterReaddir = function (f, abs, cb, er, entries) {
|
||||
assert(this instanceof Glob)
|
||||
if (entries && !er) {
|
||||
this.cache[f] = entries
|
||||
// if we haven't asked to stat everything for suresies, then just
|
||||
// assume that everything in there exists, so we can avoid
|
||||
// having to stat it a second time. This also gets us one step
|
||||
// further into ELOOP territory.
|
||||
if (!this.mark && !this.stat) {
|
||||
entries.forEach(function (e) {
|
||||
if (f === "/") e = f + e
|
||||
else e = f + "/" + e
|
||||
this.cache[e] = true
|
||||
}, this)
|
||||
}
|
||||
|
||||
return cb.call(this, er, entries)
|
||||
}
|
||||
|
||||
// now handle errors, and cache the information
|
||||
if (er) switch (er.code) {
|
||||
case "ENOTDIR": // totally normal. means it *does* exist.
|
||||
this.cache[f] = 1
|
||||
return cb.call(this, er)
|
||||
case "ENOENT": // not terribly unusual
|
||||
case "ELOOP":
|
||||
case "ENAMETOOLONG":
|
||||
case "UNKNOWN":
|
||||
this.cache[f] = false
|
||||
return cb.call(this, er)
|
||||
default: // some unusual error. Treat as failure.
|
||||
this.cache[f] = false
|
||||
if (this.strict) this.emit("error", er)
|
||||
if (!this.silent) console.error("glob error", er)
|
||||
return cb.call(this, er)
|
||||
}
|
||||
}
|
||||
|
||||
var isAbsolute = process.platform === "win32" ? absWin : absUnix
|
||||
|
||||
function absWin (p) {
|
||||
if (absUnix(p)) return true
|
||||
// pull off the device/UNC bit from a windows path.
|
||||
// from node's lib/path.js
|
||||
var splitDeviceRe =
|
||||
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/
|
||||
, result = splitDeviceRe.exec(p)
|
||||
, device = result[1] || ''
|
||||
, isUnc = device && device.charAt(1) !== ':'
|
||||
, isAbsolute = !!result[2] || isUnc // UNC paths are always absolute
|
||||
|
||||
return isAbsolute
|
||||
}
|
||||
|
||||
function absUnix (p) {
|
||||
return p.charAt(0) === "/" || p === ""
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
node_modules
|
||||
@@ -1,23 +0,0 @@
|
||||
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,218 +0,0 @@
|
||||
# minimatch
|
||||
|
||||
A minimal matching utility.
|
||||
|
||||
[](http://travis-ci.org/isaacs/minimatch)
|
||||
|
||||
|
||||
This is the matching library used internally by npm.
|
||||
|
||||
Eventually, it will replace the C binding in node-glob.
|
||||
|
||||
It works by converting glob expressions into JavaScript `RegExp`
|
||||
objects.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var minimatch = require("minimatch")
|
||||
|
||||
minimatch("bar.foo", "*.foo") // true!
|
||||
minimatch("bar.foo", "*.bar") // false!
|
||||
minimatch("bar.foo", "*.+(bar|foo)", { debug: true }) // true, and noisy!
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
Supports these glob features:
|
||||
|
||||
* Brace Expansion
|
||||
* Extended glob matching
|
||||
* "Globstar" `**` matching
|
||||
|
||||
See:
|
||||
|
||||
* `man sh`
|
||||
* `man bash`
|
||||
* `man 3 fnmatch`
|
||||
* `man 5 gitignore`
|
||||
|
||||
## Minimatch Class
|
||||
|
||||
Create a minimatch object by instanting the `minimatch.Minimatch` class.
|
||||
|
||||
```javascript
|
||||
var Minimatch = require("minimatch").Minimatch
|
||||
var mm = new Minimatch(pattern, options)
|
||||
```
|
||||
|
||||
### Properties
|
||||
|
||||
* `pattern` The original pattern the minimatch object represents.
|
||||
* `options` The options supplied to the constructor.
|
||||
* `set` A 2-dimensional array of regexp or string expressions.
|
||||
Each row in the
|
||||
array corresponds to a brace-expanded pattern. Each item in the row
|
||||
corresponds to a single path-part. For example, the pattern
|
||||
`{a,b/c}/d` would expand to a set of patterns like:
|
||||
|
||||
[ [ a, d ]
|
||||
, [ b, c, d ] ]
|
||||
|
||||
If a portion of the pattern doesn't have any "magic" in it
|
||||
(that is, it's something like `"foo"` rather than `fo*o?`), then it
|
||||
will be left as a string rather than converted to a regular
|
||||
expression.
|
||||
|
||||
* `regexp` Created by the `makeRe` method. A single regular expression
|
||||
expressing the entire pattern. This is useful in cases where you wish
|
||||
to use the pattern somewhat like `fnmatch(3)` with `FNM_PATH` enabled.
|
||||
* `negate` True if the pattern is negated.
|
||||
* `comment` True if the pattern is a comment.
|
||||
* `empty` True if the pattern is `""`.
|
||||
|
||||
### Methods
|
||||
|
||||
* `makeRe` Generate the `regexp` member if necessary, and return it.
|
||||
Will return `false` if the pattern is invalid.
|
||||
* `match(fname)` Return true if the filename matches the pattern, or
|
||||
false otherwise.
|
||||
* `matchOne(fileArray, patternArray, partial)` Take a `/`-split
|
||||
filename, and match it against a single row in the `regExpSet`. This
|
||||
method is mainly for internal use, but is exposed so that it can be
|
||||
used by a glob-walker that needs to avoid excessive filesystem calls.
|
||||
|
||||
All other methods are internal, and will be called as necessary.
|
||||
|
||||
## Functions
|
||||
|
||||
The top-level exported function has a `cache` property, which is an LRU
|
||||
cache set to store 100 items. So, calling these methods repeatedly
|
||||
with the same pattern and options will use the same Minimatch object,
|
||||
saving the cost of parsing it multiple times.
|
||||
|
||||
### minimatch(path, pattern, options)
|
||||
|
||||
Main export. Tests a path against the pattern using the options.
|
||||
|
||||
```javascript
|
||||
var isJS = minimatch(file, "*.js", { matchBase: true })
|
||||
```
|
||||
|
||||
### minimatch.filter(pattern, options)
|
||||
|
||||
Returns a function that tests its
|
||||
supplied argument, suitable for use with `Array.filter`. Example:
|
||||
|
||||
```javascript
|
||||
var javascripts = fileList.filter(minimatch.filter("*.js", {matchBase: true}))
|
||||
```
|
||||
|
||||
### minimatch.match(list, pattern, options)
|
||||
|
||||
Match against the list of
|
||||
files, in the style of fnmatch or glob. If nothing is matched, and
|
||||
options.nonull is set, then return a list containing the pattern itself.
|
||||
|
||||
```javascript
|
||||
var javascripts = minimatch.match(fileList, "*.js", {matchBase: true}))
|
||||
```
|
||||
|
||||
### minimatch.makeRe(pattern, options)
|
||||
|
||||
Make a regular expression object from the pattern.
|
||||
|
||||
## Options
|
||||
|
||||
All options are `false` by default.
|
||||
|
||||
### debug
|
||||
|
||||
Dump a ton of stuff to stderr.
|
||||
|
||||
### nobrace
|
||||
|
||||
Do not expand `{a,b}` and `{1..3}` brace sets.
|
||||
|
||||
### noglobstar
|
||||
|
||||
Disable `**` matching against multiple folder names.
|
||||
|
||||
### dot
|
||||
|
||||
Allow patterns to match filenames starting with a period, even if
|
||||
the pattern does not explicitly have a period in that spot.
|
||||
|
||||
Note that by default, `a/**/b` will **not** match `a/.d/b`, unless `dot`
|
||||
is set.
|
||||
|
||||
### noext
|
||||
|
||||
Disable "extglob" style patterns like `+(a|b)`.
|
||||
|
||||
### nocase
|
||||
|
||||
Perform a case-insensitive match.
|
||||
|
||||
### nonull
|
||||
|
||||
When a match is not found by `minimatch.match`, return a list containing
|
||||
the pattern itself if this option is set. When not set, an empty list
|
||||
is returned if there are no matches.
|
||||
|
||||
### matchBase
|
||||
|
||||
If set, then patterns without slashes will be matched
|
||||
against the basename of the path if it contains slashes. For example,
|
||||
`a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
|
||||
|
||||
### nocomment
|
||||
|
||||
Suppress the behavior of treating `#` at the start of a pattern as a
|
||||
comment.
|
||||
|
||||
### nonegate
|
||||
|
||||
Suppress the behavior of treating a leading `!` character as negation.
|
||||
|
||||
### flipNegate
|
||||
|
||||
Returns from negate expressions the same as if they were not negated.
|
||||
(Ie, true on a hit, false on a miss.)
|
||||
|
||||
|
||||
## Comparisons to other fnmatch/glob implementations
|
||||
|
||||
While strict compliance with the existing standards is a worthwhile
|
||||
goal, some discrepancies exist between minimatch and other
|
||||
implementations, and are intentional.
|
||||
|
||||
If the pattern starts with a `!` character, then it is negated. Set the
|
||||
`nonegate` flag to suppress this behavior, and treat leading `!`
|
||||
characters normally. This is perhaps relevant if you wish to start the
|
||||
pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
|
||||
characters at the start of a pattern will negate the pattern multiple
|
||||
times.
|
||||
|
||||
If a pattern starts with `#`, then it is treated as a comment, and
|
||||
will not match anything. Use `\#` to match a literal `#` at the
|
||||
start of a line, or set the `nocomment` flag to suppress this behavior.
|
||||
|
||||
The double-star character `**` is supported by default, unless the
|
||||
`noglobstar` flag is set. This is supported in the manner of bsdglob
|
||||
and bash 4.1, where `**` only has special significance if it is the only
|
||||
thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
|
||||
`a/**b` will not.
|
||||
|
||||
If an escaped pattern has no matches, and the `nonull` flag is set,
|
||||
then minimatch.match returns the pattern as-provided, rather than
|
||||
interpreting the character escapes. For example,
|
||||
`minimatch.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
|
||||
`"*a?"`. This is akin to setting the `nullglob` option in bash, except
|
||||
that it does not resolve escaped pattern characters.
|
||||
|
||||
If brace expansion is not disabled, then it is performed before any
|
||||
other interpretation of the glob pattern. Thus, a pattern like
|
||||
`+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
|
||||
**first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
|
||||
checked for validity. Since those two are valid, matching proceeds.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
/node_modules
|
||||
@@ -1,8 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0.8'
|
||||
- '0.10'
|
||||
- '0.12'
|
||||
- 'iojs'
|
||||
before_install:
|
||||
- npm install -g npm@latest
|
||||
@@ -1,14 +0,0 @@
|
||||
# Authors, sorted by whether or not they are me
|
||||
Isaac Z. Schlueter <i@izs.me>
|
||||
Brian Cottingham <spiffytech@gmail.com>
|
||||
Carlos Brito Lage <carlos@carloslage.net>
|
||||
Jesse Dailey <jesse.dailey@gmail.com>
|
||||
Kevin O'Hara <kevinohara80@gmail.com>
|
||||
Marco Rogers <marco.rogers@gmail.com>
|
||||
Mark Cavage <mcavage@gmail.com>
|
||||
Marko Mikulicic <marko.mikulicic@isti.cnr.it>
|
||||
Nathan Rajlich <nathan@tootallnate.net>
|
||||
Satheesh Natesan <snateshan@myspace-inc.com>
|
||||
Trent Mick <trentm@gmail.com>
|
||||
ashleybrener <ashley@starlogik.com>
|
||||
n4kz <n4kz@n4kz.com>
|
||||
@@ -1,119 +0,0 @@
|
||||
# lru cache
|
||||
|
||||
A cache object that deletes the least-recently-used items.
|
||||
|
||||
## Usage:
|
||||
|
||||
```javascript
|
||||
var LRU = require("lru-cache")
|
||||
, options = { max: 500
|
||||
, length: function (n) { return n * 2 }
|
||||
, dispose: function (key, n) { n.close() }
|
||||
, maxAge: 1000 * 60 * 60 }
|
||||
, cache = LRU(options)
|
||||
, otherCache = LRU(50) // sets just the max size
|
||||
|
||||
cache.set("key", "value")
|
||||
cache.get("key") // "value"
|
||||
|
||||
cache.reset() // empty the cache
|
||||
```
|
||||
|
||||
If you put more stuff in it, then items will fall out.
|
||||
|
||||
If you try to put an oversized thing in it, then it'll fall out right
|
||||
away.
|
||||
|
||||
## Options
|
||||
|
||||
* `max` The maximum size of the cache, checked by applying the length
|
||||
function to all values in the cache. Not setting this is kind of
|
||||
silly, since that's the whole purpose of this lib, but it defaults
|
||||
to `Infinity`.
|
||||
* `maxAge` Maximum age in ms. Items are not pro-actively pruned out
|
||||
as they age, but if you try to get an item that is too old, it'll
|
||||
drop it and return undefined instead of giving it to you.
|
||||
* `length` Function that is used to calculate the length of stored
|
||||
items. If you're storing strings or buffers, then you probably want
|
||||
to do something like `function(n){return n.length}`. The default is
|
||||
`function(n){return 1}`, which is fine if you want to store `max`
|
||||
like-sized things.
|
||||
* `dispose` Function that is called on items when they are dropped
|
||||
from the cache. This can be handy if you want to close file
|
||||
descriptors or do other cleanup tasks when items are no longer
|
||||
accessible. Called with `key, value`. It's called *before*
|
||||
actually removing the item from the internal cache, so if you want
|
||||
to immediately put it back in, you'll have to do that in a
|
||||
`nextTick` or `setTimeout` callback or it won't do anything.
|
||||
* `stale` By default, if you set a `maxAge`, it'll only actually pull
|
||||
stale items out of the cache when you `get(key)`. (That is, it's
|
||||
not pre-emptively doing a `setTimeout` or anything.) If you set
|
||||
`stale:true`, it'll return the stale value before deleting it. If
|
||||
you don't set this, then it'll return `undefined` when you try to
|
||||
get a stale entry, as if it had already been deleted.
|
||||
|
||||
## API
|
||||
|
||||
* `set(key, value, maxAge)`
|
||||
* `get(key) => value`
|
||||
|
||||
Both of these will update the "recently used"-ness of the key.
|
||||
They do what you think. `max` is optional and overrides the
|
||||
cache `max` option if provided.
|
||||
|
||||
* `peek(key)`
|
||||
|
||||
Returns the key value (or `undefined` if not found) without
|
||||
updating the "recently used"-ness of the key.
|
||||
|
||||
(If you find yourself using this a lot, you *might* be using the
|
||||
wrong sort of data structure, but there are some use cases where
|
||||
it's handy.)
|
||||
|
||||
* `del(key)`
|
||||
|
||||
Deletes a key out of the cache.
|
||||
|
||||
* `reset()`
|
||||
|
||||
Clear the cache entirely, throwing away all values.
|
||||
|
||||
* `has(key)`
|
||||
|
||||
Check if a key is in the cache, without updating the recent-ness
|
||||
or deleting it for being stale.
|
||||
|
||||
* `forEach(function(value,key,cache), [thisp])`
|
||||
|
||||
Just like `Array.prototype.forEach`. Iterates over all the keys
|
||||
in the cache, in order of recent-ness. (Ie, more recently used
|
||||
items are iterated over first.)
|
||||
|
||||
* `keys()`
|
||||
|
||||
Return an array of the keys in the cache.
|
||||
|
||||
* `values()`
|
||||
|
||||
Return an array of the values in the cache.
|
||||
|
||||
* `length()`
|
||||
|
||||
Return total length of objects in cache taking into account
|
||||
`length` options function.
|
||||
|
||||
* `itemCount`
|
||||
|
||||
Return total quantity of objects currently in cache. Note, that
|
||||
`stale` (see options) items are returned as part of this item
|
||||
count.
|
||||
|
||||
* `dump()`
|
||||
|
||||
Return an array of the cache entries ready for serialization and usage
|
||||
with 'destinationCache.load(arr)`.
|
||||
|
||||
* `load(cacheEntriesArray)`
|
||||
|
||||
Loads another cache entries array, obtained with `sourceCache.dump()`,
|
||||
into the cache. The destination cache is reset before loading new entries
|
||||
@@ -1,318 +0,0 @@
|
||||
;(function () { // closure for web browsers
|
||||
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
module.exports = LRUCache
|
||||
} else {
|
||||
// just set the global for non-node platforms.
|
||||
this.LRUCache = LRUCache
|
||||
}
|
||||
|
||||
function hOP (obj, key) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, key)
|
||||
}
|
||||
|
||||
function naiveLength () { return 1 }
|
||||
|
||||
function LRUCache (options) {
|
||||
if (!(this instanceof LRUCache))
|
||||
return new LRUCache(options)
|
||||
|
||||
if (typeof options === 'number')
|
||||
options = { max: options }
|
||||
|
||||
if (!options)
|
||||
options = {}
|
||||
|
||||
this._max = options.max
|
||||
// Kind of weird to have a default max of Infinity, but oh well.
|
||||
if (!this._max || !(typeof this._max === "number") || this._max <= 0 )
|
||||
this._max = Infinity
|
||||
|
||||
this._lengthCalculator = options.length || naiveLength
|
||||
if (typeof this._lengthCalculator !== "function")
|
||||
this._lengthCalculator = naiveLength
|
||||
|
||||
this._allowStale = options.stale || false
|
||||
this._maxAge = options.maxAge || null
|
||||
this._dispose = options.dispose
|
||||
this.reset()
|
||||
}
|
||||
|
||||
// resize the cache when the max changes.
|
||||
Object.defineProperty(LRUCache.prototype, "max",
|
||||
{ set : function (mL) {
|
||||
if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity
|
||||
this._max = mL
|
||||
if (this._length > this._max) trim(this)
|
||||
}
|
||||
, get : function () { return this._max }
|
||||
, enumerable : true
|
||||
})
|
||||
|
||||
// resize the cache when the lengthCalculator changes.
|
||||
Object.defineProperty(LRUCache.prototype, "lengthCalculator",
|
||||
{ set : function (lC) {
|
||||
if (typeof lC !== "function") {
|
||||
this._lengthCalculator = naiveLength
|
||||
this._length = this._itemCount
|
||||
for (var key in this._cache) {
|
||||
this._cache[key].length = 1
|
||||
}
|
||||
} else {
|
||||
this._lengthCalculator = lC
|
||||
this._length = 0
|
||||
for (var key in this._cache) {
|
||||
this._cache[key].length = this._lengthCalculator(this._cache[key].value)
|
||||
this._length += this._cache[key].length
|
||||
}
|
||||
}
|
||||
|
||||
if (this._length > this._max) trim(this)
|
||||
}
|
||||
, get : function () { return this._lengthCalculator }
|
||||
, enumerable : true
|
||||
})
|
||||
|
||||
Object.defineProperty(LRUCache.prototype, "length",
|
||||
{ get : function () { return this._length }
|
||||
, enumerable : true
|
||||
})
|
||||
|
||||
|
||||
Object.defineProperty(LRUCache.prototype, "itemCount",
|
||||
{ get : function () { return this._itemCount }
|
||||
, enumerable : true
|
||||
})
|
||||
|
||||
LRUCache.prototype.forEach = function (fn, thisp) {
|
||||
thisp = thisp || this
|
||||
var i = 0
|
||||
var itemCount = this._itemCount
|
||||
|
||||
for (var k = this._mru - 1; k >= 0 && i < itemCount; k--) if (this._lruList[k]) {
|
||||
i++
|
||||
var hit = this._lruList[k]
|
||||
if (isStale(this, hit)) {
|
||||
del(this, hit)
|
||||
if (!this._allowStale) hit = undefined
|
||||
}
|
||||
if (hit) {
|
||||
fn.call(thisp, hit.value, hit.key, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LRUCache.prototype.keys = function () {
|
||||
var keys = new Array(this._itemCount)
|
||||
var i = 0
|
||||
for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
|
||||
var hit = this._lruList[k]
|
||||
keys[i++] = hit.key
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
LRUCache.prototype.values = function () {
|
||||
var values = new Array(this._itemCount)
|
||||
var i = 0
|
||||
for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
|
||||
var hit = this._lruList[k]
|
||||
values[i++] = hit.value
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
LRUCache.prototype.reset = function () {
|
||||
if (this._dispose && this._cache) {
|
||||
for (var k in this._cache) {
|
||||
this._dispose(k, this._cache[k].value)
|
||||
}
|
||||
}
|
||||
|
||||
this._cache = Object.create(null) // hash of items by key
|
||||
this._lruList = Object.create(null) // list of items in order of use recency
|
||||
this._mru = 0 // most recently used
|
||||
this._lru = 0 // least recently used
|
||||
this._length = 0 // number of items in the list
|
||||
this._itemCount = 0
|
||||
}
|
||||
|
||||
LRUCache.prototype.dump = function () {
|
||||
var arr = []
|
||||
var i = 0
|
||||
|
||||
for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
|
||||
var hit = this._lruList[k]
|
||||
if (!isStale(this, hit)) {
|
||||
//Do not store staled hits
|
||||
++i
|
||||
arr.push({
|
||||
k: hit.key,
|
||||
v: hit.value,
|
||||
e: hit.now + (hit.maxAge || 0)
|
||||
});
|
||||
}
|
||||
}
|
||||
//arr has the most read first
|
||||
return arr
|
||||
}
|
||||
|
||||
LRUCache.prototype.dumpLru = function () {
|
||||
return this._lruList
|
||||
}
|
||||
|
||||
LRUCache.prototype.set = function (key, value, maxAge) {
|
||||
maxAge = maxAge || this._maxAge
|
||||
var now = maxAge ? Date.now() : 0
|
||||
var len = this._lengthCalculator(value)
|
||||
|
||||
if (hOP(this._cache, key)) {
|
||||
if (len > this._max) {
|
||||
del(this, this._cache[key])
|
||||
return false
|
||||
}
|
||||
// dispose of the old one before overwriting
|
||||
if (this._dispose)
|
||||
this._dispose(key, this._cache[key].value)
|
||||
|
||||
this._cache[key].now = now
|
||||
this._cache[key].maxAge = maxAge
|
||||
this._cache[key].value = value
|
||||
this._length += (len - this._cache[key].length)
|
||||
this._cache[key].length = len
|
||||
this.get(key)
|
||||
|
||||
if (this._length > this._max)
|
||||
trim(this)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
var hit = new Entry(key, value, this._mru++, len, now, maxAge)
|
||||
|
||||
// oversized objects fall out of cache automatically.
|
||||
if (hit.length > this._max) {
|
||||
if (this._dispose) this._dispose(key, value)
|
||||
return false
|
||||
}
|
||||
|
||||
this._length += hit.length
|
||||
this._lruList[hit.lu] = this._cache[key] = hit
|
||||
this._itemCount ++
|
||||
|
||||
if (this._length > this._max)
|
||||
trim(this)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
LRUCache.prototype.has = function (key) {
|
||||
if (!hOP(this._cache, key)) return false
|
||||
var hit = this._cache[key]
|
||||
if (isStale(this, hit)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
LRUCache.prototype.get = function (key) {
|
||||
return get(this, key, true)
|
||||
}
|
||||
|
||||
LRUCache.prototype.peek = function (key) {
|
||||
return get(this, key, false)
|
||||
}
|
||||
|
||||
LRUCache.prototype.pop = function () {
|
||||
var hit = this._lruList[this._lru]
|
||||
del(this, hit)
|
||||
return hit || null
|
||||
}
|
||||
|
||||
LRUCache.prototype.del = function (key) {
|
||||
del(this, this._cache[key])
|
||||
}
|
||||
|
||||
LRUCache.prototype.load = function (arr) {
|
||||
//reset the cache
|
||||
this.reset();
|
||||
|
||||
var now = Date.now()
|
||||
//A previous serialized cache has the most recent items first
|
||||
for (var l = arr.length - 1; l >= 0; l-- ) {
|
||||
var hit = arr[l]
|
||||
var expiresAt = hit.e || 0
|
||||
if (expiresAt === 0) {
|
||||
//the item was created without expiration in a non aged cache
|
||||
this.set(hit.k, hit.v)
|
||||
} else {
|
||||
var maxAge = expiresAt - now
|
||||
//dont add already expired items
|
||||
if (maxAge > 0) this.set(hit.k, hit.v, maxAge)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get (self, key, doUse) {
|
||||
var hit = self._cache[key]
|
||||
if (hit) {
|
||||
if (isStale(self, hit)) {
|
||||
del(self, hit)
|
||||
if (!self._allowStale) hit = undefined
|
||||
} else {
|
||||
if (doUse) use(self, hit)
|
||||
}
|
||||
if (hit) hit = hit.value
|
||||
}
|
||||
return hit
|
||||
}
|
||||
|
||||
function isStale(self, hit) {
|
||||
if (!hit || (!hit.maxAge && !self._maxAge)) return false
|
||||
var stale = false;
|
||||
var diff = Date.now() - hit.now
|
||||
if (hit.maxAge) {
|
||||
stale = diff > hit.maxAge
|
||||
} else {
|
||||
stale = self._maxAge && (diff > self._maxAge)
|
||||
}
|
||||
return stale;
|
||||
}
|
||||
|
||||
function use (self, hit) {
|
||||
shiftLU(self, hit)
|
||||
hit.lu = self._mru ++
|
||||
self._lruList[hit.lu] = hit
|
||||
}
|
||||
|
||||
function trim (self) {
|
||||
while (self._lru < self._mru && self._length > self._max)
|
||||
del(self, self._lruList[self._lru])
|
||||
}
|
||||
|
||||
function shiftLU (self, hit) {
|
||||
delete self._lruList[ hit.lu ]
|
||||
while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++
|
||||
}
|
||||
|
||||
function del (self, hit) {
|
||||
if (hit) {
|
||||
if (self._dispose) self._dispose(hit.key, hit.value)
|
||||
self._length -= hit.length
|
||||
self._itemCount --
|
||||
delete self._cache[ hit.key ]
|
||||
shiftLU(self, hit)
|
||||
}
|
||||
}
|
||||
|
||||
// classy, since V8 prefers predictable objects.
|
||||
function Entry (key, value, lu, length, now, maxAge) {
|
||||
this.key = key
|
||||
this.value = value
|
||||
this.lu = lu
|
||||
this.length = length
|
||||
this.now = now
|
||||
if (maxAge) this.maxAge = maxAge
|
||||
}
|
||||
|
||||
})()
|
||||
@@ -1,58 +0,0 @@
|
||||
{
|
||||
"name": "lru-cache",
|
||||
"description": "A cache object that deletes the least-recently-used items.",
|
||||
"version": "2.7.0",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me"
|
||||
},
|
||||
"keywords": [
|
||||
"mru",
|
||||
"lru",
|
||||
"cache"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "tap test --gc"
|
||||
},
|
||||
"main": "lib/lru-cache.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/node-lru-cache.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^1.2.0",
|
||||
"weak": ""
|
||||
},
|
||||
"license": "ISC",
|
||||
"gitHead": "fc6ee93093f4e463e5946736d4c48adc013724d1",
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/node-lru-cache/issues"
|
||||
},
|
||||
"homepage": "https://github.com/isaacs/node-lru-cache#readme",
|
||||
"_id": "lru-cache@2.7.0",
|
||||
"_shasum": "aaa376a4cd970f9cebf5ec1909566ec034f07ee6",
|
||||
"_from": "lru-cache@>=2.0.0 <3.0.0",
|
||||
"_npmVersion": "3.3.2",
|
||||
"_nodeVersion": "4.0.0",
|
||||
"_npmUser": {
|
||||
"name": "isaacs",
|
||||
"email": "isaacs@npmjs.com"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "aaa376a4cd970f9cebf5ec1909566ec034f07ee6",
|
||||
"tarball": "http://registry.npmjs.org/lru-cache/-/lru-cache-2.7.0.tgz"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "isaacs",
|
||||
"email": "isaacs@npmjs.com"
|
||||
},
|
||||
{
|
||||
"name": "othiym23",
|
||||
"email": "ogd@aoaioxxysz.net"
|
||||
}
|
||||
],
|
||||
"directories": {},
|
||||
"_resolved": "http://registry.npmjs.org/lru-cache/-/lru-cache-2.7.0.tgz",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
# sigmund
|
||||
|
||||
Quick and dirty signatures for Objects.
|
||||
|
||||
This is like a much faster `deepEquals` comparison, which returns a
|
||||
string key suitable for caches and the like.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
function doSomething (someObj) {
|
||||
var key = sigmund(someObj, maxDepth) // max depth defaults to 10
|
||||
var cached = cache.get(key)
|
||||
if (cached) return cached
|
||||
|
||||
var result = expensiveCalculation(someObj)
|
||||
cache.set(key, result)
|
||||
return result
|
||||
}
|
||||
```
|
||||
|
||||
The resulting key will be as unique and reproducible as calling
|
||||
`JSON.stringify` or `util.inspect` on the object, but is much faster.
|
||||
In order to achieve this speed, some differences are glossed over.
|
||||
For example, the object `{0:'foo'}` will be treated identically to the
|
||||
array `['foo']`.
|
||||
|
||||
Also, just as there is no way to summon the soul from the scribblings
|
||||
of a cocaine-addled psychoanalyst, there is no way to revive the object
|
||||
from the signature string that sigmund gives you. In fact, it's
|
||||
barely even readable.
|
||||
|
||||
As with `util.inspect` and `JSON.stringify`, larger objects will
|
||||
produce larger signature strings.
|
||||
|
||||
Because sigmund is a bit less strict than the more thorough
|
||||
alternatives, the strings will be shorter, and also there is a
|
||||
slightly higher chance for collisions. For example, these objects
|
||||
have the same signature:
|
||||
|
||||
var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}
|
||||
var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}
|
||||
|
||||
Like a good Freudian, sigmund is most effective when you already have
|
||||
some understanding of what you're looking for. It can help you help
|
||||
yourself, but you must be willing to do some work as well.
|
||||
|
||||
Cycles are handled, and cyclical objects are silently omitted (though
|
||||
the key is included in the signature output.)
|
||||
|
||||
The second argument is the maximum depth, which defaults to 10,
|
||||
because that is the maximum object traversal depth covered by most
|
||||
insurance carriers.
|
||||
@@ -1,283 +0,0 @@
|
||||
// different ways to id objects
|
||||
// use a req/res pair, since it's crazy deep and cyclical
|
||||
|
||||
// sparseFE10 and sigmund are usually pretty close, which is to be expected,
|
||||
// since they are essentially the same algorithm, except that sigmund handles
|
||||
// regular expression objects properly.
|
||||
|
||||
|
||||
var http = require('http')
|
||||
var util = require('util')
|
||||
var sigmund = require('./sigmund.js')
|
||||
var sreq, sres, creq, cres, test
|
||||
|
||||
http.createServer(function (q, s) {
|
||||
sreq = q
|
||||
sres = s
|
||||
sres.end('ok')
|
||||
this.close(function () { setTimeout(function () {
|
||||
start()
|
||||
}, 200) })
|
||||
}).listen(1337, function () {
|
||||
creq = http.get({ port: 1337 })
|
||||
creq.on('response', function (s) { cres = s })
|
||||
})
|
||||
|
||||
function start () {
|
||||
test = [sreq, sres, creq, cres]
|
||||
// test = sreq
|
||||
// sreq.sres = sres
|
||||
// sreq.creq = creq
|
||||
// sreq.cres = cres
|
||||
|
||||
for (var i in exports.compare) {
|
||||
console.log(i)
|
||||
var hash = exports.compare[i]()
|
||||
console.log(hash)
|
||||
console.log(hash.length)
|
||||
console.log('')
|
||||
}
|
||||
|
||||
require('bench').runMain()
|
||||
}
|
||||
|
||||
function customWs (obj, md, d) {
|
||||
d = d || 0
|
||||
var to = typeof obj
|
||||
if (to === 'undefined' || to === 'function' || to === null) return ''
|
||||
if (d > md || !obj || to !== 'object') return ('' + obj).replace(/[\n ]+/g, '')
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(function (i, _, __) {
|
||||
return customWs(i, md, d + 1)
|
||||
}).reduce(function (a, b) { return a + b }, '')
|
||||
}
|
||||
|
||||
var keys = Object.keys(obj)
|
||||
return keys.map(function (k, _, __) {
|
||||
return k + ':' + customWs(obj[k], md, d + 1)
|
||||
}).reduce(function (a, b) { return a + b }, '')
|
||||
}
|
||||
|
||||
function custom (obj, md, d) {
|
||||
d = d || 0
|
||||
var to = typeof obj
|
||||
if (to === 'undefined' || to === 'function' || to === null) return ''
|
||||
if (d > md || !obj || to !== 'object') return '' + obj
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(function (i, _, __) {
|
||||
return custom(i, md, d + 1)
|
||||
}).reduce(function (a, b) { return a + b }, '')
|
||||
}
|
||||
|
||||
var keys = Object.keys(obj)
|
||||
return keys.map(function (k, _, __) {
|
||||
return k + ':' + custom(obj[k], md, d + 1)
|
||||
}).reduce(function (a, b) { return a + b }, '')
|
||||
}
|
||||
|
||||
function sparseFE2 (obj, maxDepth) {
|
||||
var seen = []
|
||||
var soFar = ''
|
||||
function ch (v, depth) {
|
||||
if (depth > maxDepth) return
|
||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
||||
if (typeof v !== 'object' || !v) {
|
||||
soFar += v
|
||||
return
|
||||
}
|
||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
||||
seen.push(v)
|
||||
soFar += '{'
|
||||
Object.keys(v).forEach(function (k, _, __) {
|
||||
// pseudo-private values. skip those.
|
||||
if (k.charAt(0) === '_') return
|
||||
var to = typeof v[k]
|
||||
if (to === 'function' || to === 'undefined') return
|
||||
soFar += k + ':'
|
||||
ch(v[k], depth + 1)
|
||||
})
|
||||
soFar += '}'
|
||||
}
|
||||
ch(obj, 0)
|
||||
return soFar
|
||||
}
|
||||
|
||||
function sparseFE (obj, maxDepth) {
|
||||
var seen = []
|
||||
var soFar = ''
|
||||
function ch (v, depth) {
|
||||
if (depth > maxDepth) return
|
||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
||||
if (typeof v !== 'object' || !v) {
|
||||
soFar += v
|
||||
return
|
||||
}
|
||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
||||
seen.push(v)
|
||||
soFar += '{'
|
||||
Object.keys(v).forEach(function (k, _, __) {
|
||||
// pseudo-private values. skip those.
|
||||
if (k.charAt(0) === '_') return
|
||||
var to = typeof v[k]
|
||||
if (to === 'function' || to === 'undefined') return
|
||||
soFar += k
|
||||
ch(v[k], depth + 1)
|
||||
})
|
||||
}
|
||||
ch(obj, 0)
|
||||
return soFar
|
||||
}
|
||||
|
||||
function sparse (obj, maxDepth) {
|
||||
var seen = []
|
||||
var soFar = ''
|
||||
function ch (v, depth) {
|
||||
if (depth > maxDepth) return
|
||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
||||
if (typeof v !== 'object' || !v) {
|
||||
soFar += v
|
||||
return
|
||||
}
|
||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
||||
seen.push(v)
|
||||
soFar += '{'
|
||||
for (var k in v) {
|
||||
// pseudo-private values. skip those.
|
||||
if (k.charAt(0) === '_') continue
|
||||
var to = typeof v[k]
|
||||
if (to === 'function' || to === 'undefined') continue
|
||||
soFar += k
|
||||
ch(v[k], depth + 1)
|
||||
}
|
||||
}
|
||||
ch(obj, 0)
|
||||
return soFar
|
||||
}
|
||||
|
||||
function noCommas (obj, maxDepth) {
|
||||
var seen = []
|
||||
var soFar = ''
|
||||
function ch (v, depth) {
|
||||
if (depth > maxDepth) return
|
||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
||||
if (typeof v !== 'object' || !v) {
|
||||
soFar += v
|
||||
return
|
||||
}
|
||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
||||
seen.push(v)
|
||||
soFar += '{'
|
||||
for (var k in v) {
|
||||
// pseudo-private values. skip those.
|
||||
if (k.charAt(0) === '_') continue
|
||||
var to = typeof v[k]
|
||||
if (to === 'function' || to === 'undefined') continue
|
||||
soFar += k + ':'
|
||||
ch(v[k], depth + 1)
|
||||
}
|
||||
soFar += '}'
|
||||
}
|
||||
ch(obj, 0)
|
||||
return soFar
|
||||
}
|
||||
|
||||
|
||||
function flatten (obj, maxDepth) {
|
||||
var seen = []
|
||||
var soFar = ''
|
||||
function ch (v, depth) {
|
||||
if (depth > maxDepth) return
|
||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
||||
if (typeof v !== 'object' || !v) {
|
||||
soFar += v
|
||||
return
|
||||
}
|
||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
||||
seen.push(v)
|
||||
soFar += '{'
|
||||
for (var k in v) {
|
||||
// pseudo-private values. skip those.
|
||||
if (k.charAt(0) === '_') continue
|
||||
var to = typeof v[k]
|
||||
if (to === 'function' || to === 'undefined') continue
|
||||
soFar += k + ':'
|
||||
ch(v[k], depth + 1)
|
||||
soFar += ','
|
||||
}
|
||||
soFar += '}'
|
||||
}
|
||||
ch(obj, 0)
|
||||
return soFar
|
||||
}
|
||||
|
||||
exports.compare =
|
||||
{
|
||||
// 'custom 2': function () {
|
||||
// return custom(test, 2, 0)
|
||||
// },
|
||||
// 'customWs 2': function () {
|
||||
// return customWs(test, 2, 0)
|
||||
// },
|
||||
'JSON.stringify (guarded)': function () {
|
||||
var seen = []
|
||||
return JSON.stringify(test, function (k, v) {
|
||||
if (typeof v !== 'object' || !v) return v
|
||||
if (seen.indexOf(v) !== -1) return undefined
|
||||
seen.push(v)
|
||||
return v
|
||||
})
|
||||
},
|
||||
|
||||
'flatten 10': function () {
|
||||
return flatten(test, 10)
|
||||
},
|
||||
|
||||
// 'flattenFE 10': function () {
|
||||
// return flattenFE(test, 10)
|
||||
// },
|
||||
|
||||
'noCommas 10': function () {
|
||||
return noCommas(test, 10)
|
||||
},
|
||||
|
||||
'sparse 10': function () {
|
||||
return sparse(test, 10)
|
||||
},
|
||||
|
||||
'sparseFE 10': function () {
|
||||
return sparseFE(test, 10)
|
||||
},
|
||||
|
||||
'sparseFE2 10': function () {
|
||||
return sparseFE2(test, 10)
|
||||
},
|
||||
|
||||
sigmund: function() {
|
||||
return sigmund(test, 10)
|
||||
},
|
||||
|
||||
|
||||
// 'util.inspect 1': function () {
|
||||
// return util.inspect(test, false, 1, false)
|
||||
// },
|
||||
// 'util.inspect undefined': function () {
|
||||
// util.inspect(test)
|
||||
// },
|
||||
// 'util.inspect 2': function () {
|
||||
// util.inspect(test, false, 2, false)
|
||||
// },
|
||||
// 'util.inspect 3': function () {
|
||||
// util.inspect(test, false, 3, false)
|
||||
// },
|
||||
// 'util.inspect 4': function () {
|
||||
// util.inspect(test, false, 4, false)
|
||||
// },
|
||||
// 'util.inspect Infinity': function () {
|
||||
// util.inspect(test, false, Infinity, false)
|
||||
// }
|
||||
}
|
||||
|
||||
/** results
|
||||
**/
|
||||
@@ -1,44 +0,0 @@
|
||||
{
|
||||
"name": "sigmund",
|
||||
"version": "1.0.1",
|
||||
"description": "Quick and dirty signatures for Objects.",
|
||||
"main": "sigmund.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"tap": "~0.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js",
|
||||
"bench": "node bench.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/sigmund.git"
|
||||
},
|
||||
"keywords": [
|
||||
"object",
|
||||
"signature",
|
||||
"key",
|
||||
"data",
|
||||
"psychoanalysis"
|
||||
],
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
},
|
||||
"license": "ISC",
|
||||
"readme": "# sigmund\n\nQuick and dirty signatures for Objects.\n\nThis is like a much faster `deepEquals` comparison, which returns a\nstring key suitable for caches and the like.\n\n## Usage\n\n```javascript\nfunction doSomething (someObj) {\n var key = sigmund(someObj, maxDepth) // max depth defaults to 10\n var cached = cache.get(key)\n if (cached) return cached\n\n var result = expensiveCalculation(someObj)\n cache.set(key, result)\n return result\n}\n```\n\nThe resulting key will be as unique and reproducible as calling\n`JSON.stringify` or `util.inspect` on the object, but is much faster.\nIn order to achieve this speed, some differences are glossed over.\nFor example, the object `{0:'foo'}` will be treated identically to the\narray `['foo']`.\n\nAlso, just as there is no way to summon the soul from the scribblings\nof a cocaine-addled psychoanalyst, there is no way to revive the object\nfrom the signature string that sigmund gives you. In fact, it's\nbarely even readable.\n\nAs with `util.inspect` and `JSON.stringify`, larger objects will\nproduce larger signature strings.\n\nBecause sigmund is a bit less strict than the more thorough\nalternatives, the strings will be shorter, and also there is a\nslightly higher chance for collisions. For example, these objects\nhave the same signature:\n\n var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}\n var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}\n\nLike a good Freudian, sigmund is most effective when you already have\nsome understanding of what you're looking for. It can help you help\nyourself, but you must be willing to do some work as well.\n\nCycles are handled, and cyclical objects are silently omitted (though\nthe key is included in the signature output.)\n\nThe second argument is the maximum depth, which defaults to 10,\nbecause that is the maximum object traversal depth covered by most\ninsurance carriers.\n",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/sigmund/issues"
|
||||
},
|
||||
"homepage": "https://github.com/isaacs/sigmund#readme",
|
||||
"_id": "sigmund@1.0.1",
|
||||
"_shasum": "3ff21f198cad2175f9f3b781853fd94d0d19b590",
|
||||
"_resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
|
||||
"_from": "sigmund@>=1.0.0 <1.1.0"
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
module.exports = sigmund
|
||||
function sigmund (subject, maxSessions) {
|
||||
maxSessions = maxSessions || 10;
|
||||
var notes = [];
|
||||
var analysis = '';
|
||||
var RE = RegExp;
|
||||
|
||||
function psychoAnalyze (subject, session) {
|
||||
if (session > maxSessions) return;
|
||||
|
||||
if (typeof subject === 'function' ||
|
||||
typeof subject === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof subject !== 'object' || !subject ||
|
||||
(subject instanceof RE)) {
|
||||
analysis += subject;
|
||||
return;
|
||||
}
|
||||
|
||||
if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
|
||||
|
||||
notes.push(subject);
|
||||
analysis += '{';
|
||||
Object.keys(subject).forEach(function (issue, _, __) {
|
||||
// pseudo-private values. skip those.
|
||||
if (issue.charAt(0) === '_') return;
|
||||
var to = typeof subject[issue];
|
||||
if (to === 'function' || to === 'undefined') return;
|
||||
analysis += issue;
|
||||
psychoAnalyze(subject[issue], session + 1);
|
||||
});
|
||||
}
|
||||
psychoAnalyze(subject, 0);
|
||||
return analysis;
|
||||
}
|
||||
|
||||
// vim: set softtabstop=4 shiftwidth=4:
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,16 +0,0 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
Browser-friendly inheritance fully compatible with standard node.js
|
||||
[inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor).
|
||||
|
||||
This package exports standard `inherits` from node.js `util` module in
|
||||
node environment, but also provides alternative browser-friendly
|
||||
implementation through [browser
|
||||
field](https://gist.github.com/shtylman/4339901). Alternative
|
||||
implementation is a literal copy of standard one located in standalone
|
||||
module to avoid requiring of `util`. It also has a shim for old
|
||||
browsers with no `Object.create` support.
|
||||
|
||||
While keeping you sure you are using standard `inherits`
|
||||
implementation in node.js environment, it allows bundlers such as
|
||||
[browserify](https://github.com/substack/node-browserify) to not
|
||||
include full `util` package to your client code if all you need is
|
||||
just `inherits` function. It worth, because browser shim for `util`
|
||||
package is large and `inherits` is often the single function you need
|
||||
from it.
|
||||
|
||||
It's recommended to use this package instead of
|
||||
`require('util').inherits` for any code that has chances to be used
|
||||
not only in node.js but in browser too.
|
||||
|
||||
## usage
|
||||
|
||||
```js
|
||||
var inherits = require('inherits');
|
||||
// then use exactly as the standard one
|
||||
```
|
||||
|
||||
## note on version ~1.0
|
||||
|
||||
Version ~1.0 had completely different motivation and is not compatible
|
||||
neither with 2.0 nor with standard node.js `inherits`.
|
||||
|
||||
If you are using version ~1.0 and planning to switch to ~2.0, be
|
||||
careful:
|
||||
|
||||
* new version uses `super_` instead of `super` for referencing
|
||||
superclass
|
||||
* new version overwrites current prototype while old one preserves any
|
||||
existing fields on it
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = require('util').inherits
|
||||
@@ -1,23 +0,0 @@
|
||||
if (typeof Object.create === 'function') {
|
||||
// implementation from standard node.js 'util' module
|
||||
module.exports = function inherits(ctor, superCtor) {
|
||||
ctor.super_ = superCtor
|
||||
ctor.prototype = Object.create(superCtor.prototype, {
|
||||
constructor: {
|
||||
value: ctor,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
};
|
||||
} else {
|
||||
// old school shim for old browsers
|
||||
module.exports = function inherits(ctor, superCtor) {
|
||||
ctor.super_ = superCtor
|
||||
var TempCtor = function () {}
|
||||
TempCtor.prototype = superCtor.prototype
|
||||
ctor.prototype = new TempCtor()
|
||||
ctor.prototype.constructor = ctor
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
{
|
||||
"name": "inherits",
|
||||
"description": "Browser-friendly inheritance fully compatible with standard node.js inherits()",
|
||||
"version": "2.0.1",
|
||||
"keywords": [
|
||||
"inheritance",
|
||||
"class",
|
||||
"klass",
|
||||
"oop",
|
||||
"object-oriented",
|
||||
"inherits",
|
||||
"browser",
|
||||
"browserify"
|
||||
],
|
||||
"main": "./inherits.js",
|
||||
"browser": "./inherits_browser.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/inherits.git"
|
||||
},
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"test": "node test"
|
||||
},
|
||||
"readme": "Browser-friendly inheritance fully compatible with standard node.js\n[inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor).\n\nThis package exports standard `inherits` from node.js `util` module in\nnode environment, but also provides alternative browser-friendly\nimplementation through [browser\nfield](https://gist.github.com/shtylman/4339901). Alternative\nimplementation is a literal copy of standard one located in standalone\nmodule to avoid requiring of `util`. It also has a shim for old\nbrowsers with no `Object.create` support.\n\nWhile keeping you sure you are using standard `inherits`\nimplementation in node.js environment, it allows bundlers such as\n[browserify](https://github.com/substack/node-browserify) to not\ninclude full `util` package to your client code if all you need is\njust `inherits` function. It worth, because browser shim for `util`\npackage is large and `inherits` is often the single function you need\nfrom it.\n\nIt's recommended to use this package instead of\n`require('util').inherits` for any code that has chances to be used\nnot only in node.js but in browser too.\n\n## usage\n\n```js\nvar inherits = require('inherits');\n// then use exactly as the standard one\n```\n\n## note on version ~1.0\n\nVersion ~1.0 had completely different motivation and is not compatible\nneither with 2.0 nor with standard node.js `inherits`.\n\nIf you are using version ~1.0 and planning to switch to ~2.0, be\ncareful:\n\n* new version uses `super_` instead of `super` for referencing\n superclass\n* new version overwrites current prototype while old one preserves any\n existing fields on it\n",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/inherits/issues"
|
||||
},
|
||||
"homepage": "https://github.com/isaacs/inherits#readme",
|
||||
"_id": "inherits@2.0.1",
|
||||
"_shasum": "b17d08d326b4423e568eff719f91b0b1cbdf69f1",
|
||||
"_resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
|
||||
"_from": "inherits@>=2.0.1 <2.1.0"
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
var inherits = require('./inherits.js')
|
||||
var assert = require('assert')
|
||||
|
||||
function test(c) {
|
||||
assert(c.constructor === Child)
|
||||
assert(c.constructor.super_ === Parent)
|
||||
assert(Object.getPrototypeOf(c) === Child.prototype)
|
||||
assert(Object.getPrototypeOf(Object.getPrototypeOf(c)) === Parent.prototype)
|
||||
assert(c instanceof Child)
|
||||
assert(c instanceof Parent)
|
||||
}
|
||||
|
||||
function Child() {
|
||||
Parent.call(this)
|
||||
test(this)
|
||||
}
|
||||
|
||||
function Parent() {}
|
||||
|
||||
inherits(Child, Parent)
|
||||
|
||||
var c = new Child
|
||||
test(c)
|
||||
|
||||
console.log('ok')
|
||||
@@ -1,4 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
@@ -1,127 +0,0 @@
|
||||
module.exports = function inspect_ (obj, opts, depth, seen) {
|
||||
if (!opts) opts = {};
|
||||
|
||||
var maxDepth = opts.depth === undefined ? 5 : opts.depth;
|
||||
if (depth === undefined) depth = 0;
|
||||
if (depth > maxDepth && maxDepth > 0) return '...';
|
||||
|
||||
if (seen === undefined) seen = [];
|
||||
else if (indexOf(seen, obj) >= 0) {
|
||||
return '[Circular]';
|
||||
}
|
||||
|
||||
function inspect (value, from) {
|
||||
if (from) {
|
||||
seen = seen.slice();
|
||||
seen.push(from);
|
||||
}
|
||||
return inspect_(value, opts, depth + 1, seen);
|
||||
}
|
||||
|
||||
if (typeof obj === 'string') {
|
||||
return inspectString(obj);
|
||||
}
|
||||
else if (typeof obj === 'function') {
|
||||
var name = nameOf(obj);
|
||||
return '[Function' + (name ? ': ' + name : '') + ']';
|
||||
}
|
||||
else if (obj === null) {
|
||||
return 'null';
|
||||
}
|
||||
else if (isElement(obj)) {
|
||||
var s = '<' + String(obj.nodeName).toLowerCase();
|
||||
var attrs = obj.attributes || [];
|
||||
for (var i = 0; i < attrs.length; i++) {
|
||||
s += ' ' + attrs[i].name + '="' + quote(attrs[i].value) + '"';
|
||||
}
|
||||
s += '>';
|
||||
if (obj.childNodes && obj.childNodes.length) s += '...';
|
||||
s += '</' + String(obj.tagName).toLowerCase() + '>';
|
||||
return s;
|
||||
}
|
||||
else if (isArray(obj)) {
|
||||
if (obj.length === 0) return '[]';
|
||||
var xs = Array(obj.length);
|
||||
for (var i = 0; i < obj.length; i++) {
|
||||
xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
|
||||
}
|
||||
return '[ ' + xs.join(', ') + ' ]';
|
||||
}
|
||||
else if (typeof obj === 'object' && typeof obj.inspect === 'function') {
|
||||
return obj.inspect();
|
||||
}
|
||||
else if (typeof obj === 'object' && !isDate(obj) && !isRegExp(obj)) {
|
||||
var xs = [], keys = [];
|
||||
for (var key in obj) {
|
||||
if (has(obj, key)) keys.push(key);
|
||||
}
|
||||
keys.sort();
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
if (/[^\w$]/.test(key)) {
|
||||
xs.push(inspect(key) + ': ' + inspect(obj[key], obj));
|
||||
}
|
||||
else xs.push(key + ': ' + inspect(obj[key], obj));
|
||||
}
|
||||
if (xs.length === 0) return '{}';
|
||||
return '{ ' + xs.join(', ') + ' }';
|
||||
}
|
||||
else return String(obj);
|
||||
};
|
||||
|
||||
function quote (s) {
|
||||
return String(s).replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function isArray (obj) {
|
||||
return {}.toString.call(obj) === '[object Array]';
|
||||
}
|
||||
|
||||
function isDate (obj) {
|
||||
return {}.toString.call(obj) === '[object Date]';
|
||||
}
|
||||
|
||||
function isRegExp (obj) {
|
||||
return {}.toString.call(obj) === '[object RegExp]';
|
||||
}
|
||||
|
||||
function has (obj, key) {
|
||||
if (!{}.hasOwnProperty) return key in obj;
|
||||
return {}.hasOwnProperty.call(obj, key);
|
||||
}
|
||||
|
||||
function nameOf (f) {
|
||||
if (f.name) return f.name;
|
||||
var m = f.toString().match(/^function\s*([\w$]+)/);
|
||||
if (m) return m[1];
|
||||
}
|
||||
|
||||
function indexOf (xs, x) {
|
||||
if (xs.indexOf) return xs.indexOf(x);
|
||||
for (var i = 0, l = xs.length; i < l; i++) {
|
||||
if (xs[i] === x) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function isElement (x) {
|
||||
if (!x || typeof x !== 'object') return false;
|
||||
if (typeof HTMLElement !== 'undefined') {
|
||||
return x instanceof HTMLElement;
|
||||
}
|
||||
else return typeof x.nodeName === 'string'
|
||||
&& typeof x.getAttribute === 'function'
|
||||
;
|
||||
}
|
||||
|
||||
function inspectString (str) {
|
||||
var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte);
|
||||
return "'" + s + "'";
|
||||
|
||||
function lowbyte (c) {
|
||||
var n = c.charCodeAt(0);
|
||||
var x = { 8: 'b', 9: 't', 10: 'n', 12: 'f', 13: 'r' }[n];
|
||||
if (x) return '\\' + x;
|
||||
return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
{
|
||||
"name": "object-inspect",
|
||||
"version": "0.4.0",
|
||||
"description": "string representations of objects in node and the browser",
|
||||
"main": "index.js",
|
||||
"devDependencies": {
|
||||
"tape": "~2.6.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"testling": {
|
||||
"files": [
|
||||
"test/*.js",
|
||||
"test/browser/*.js"
|
||||
],
|
||||
"browsers": [
|
||||
"ie/6..latest",
|
||||
"chrome/latest",
|
||||
"firefox/latest",
|
||||
"safari/latest",
|
||||
"opera/latest",
|
||||
"iphone/latest",
|
||||
"ipad/latest",
|
||||
"android/latest"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/substack/object-inspect.git"
|
||||
},
|
||||
"homepage": "https://github.com/substack/object-inspect",
|
||||
"keywords": [
|
||||
"inspect",
|
||||
"util.inspect",
|
||||
"object",
|
||||
"stringify",
|
||||
"pretty"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/object-inspect/issues"
|
||||
},
|
||||
"_id": "object-inspect@0.4.0",
|
||||
"dist": {
|
||||
"shasum": "f5157c116c1455b243b06ee97703392c5ad89fec",
|
||||
"tarball": "http://registry.npmjs.org/object-inspect/-/object-inspect-0.4.0.tgz"
|
||||
},
|
||||
"_from": "object-inspect@>=0.4.0 <0.5.0",
|
||||
"_npmVersion": "1.4.4",
|
||||
"_npmUser": {
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
}
|
||||
],
|
||||
"directories": {},
|
||||
"_shasum": "f5157c116c1455b243b06ee97703392c5ad89fec",
|
||||
"_resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-0.4.0.tgz",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
# object-inspect
|
||||
|
||||
string representations of objects in node and the browser
|
||||
|
||||
[](https://ci.testling.com/substack/object-inspect)
|
||||
|
||||
[](http://travis-ci.org/substack/object-inspect)
|
||||
|
||||
# example
|
||||
|
||||
## circular
|
||||
|
||||
``` js
|
||||
var inspect = require('object-inspect');
|
||||
var obj = { a: 1, b: [3,4] };
|
||||
obj.c = obj;
|
||||
console.log(inspect(obj));
|
||||
```
|
||||
|
||||
## dom element
|
||||
|
||||
``` js
|
||||
var inspect = require('object-inspect');
|
||||
|
||||
var d = document.createElement('div');
|
||||
d.setAttribute('id', 'beep');
|
||||
d.innerHTML = '<b>wooo</b><i>iiiii</i>';
|
||||
|
||||
console.log(inspect([ d, { a: 3, b : 4, c: [5,6,[7,[8,[9]]]] } ]));
|
||||
```
|
||||
|
||||
output:
|
||||
|
||||
```
|
||||
[ <div id="beep">...</div>, { a: 3, b: 4, c: [ 5, 6, [ 7, [ 8, [ ... ] ] ] ] } ]
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var inspect = require('object-inspect')
|
||||
```
|
||||
|
||||
## var s = inspect(obj, opts={})
|
||||
|
||||
Return a string `s` with the string representation of `obj` up to a depth of
|
||||
`opts.depth`.
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install object-inspect
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
||||
@@ -1,4 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
@@ -1,18 +0,0 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,29 +0,0 @@
|
||||
var through = require('through');
|
||||
var nextTick = typeof setImmediate !== 'undefined'
|
||||
? setImmediate
|
||||
: process.nextTick
|
||||
;
|
||||
|
||||
module.exports = function (write, end) {
|
||||
var tr = through(write, end);
|
||||
tr.pause();
|
||||
var resume = tr.resume;
|
||||
var pause = tr.pause;
|
||||
var paused = false;
|
||||
|
||||
tr.pause = function () {
|
||||
paused = true;
|
||||
return pause.apply(this, arguments);
|
||||
};
|
||||
|
||||
tr.resume = function () {
|
||||
paused = false;
|
||||
return resume.apply(this, arguments);
|
||||
};
|
||||
|
||||
nextTick(function () {
|
||||
if (!paused) tr.resume();
|
||||
});
|
||||
|
||||
return tr;
|
||||
};
|
||||
@@ -1,71 +0,0 @@
|
||||
{
|
||||
"name": "resumer",
|
||||
"version": "0.0.0",
|
||||
"description": "a through stream that starts paused and resumes on the next tick",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"through": "~2.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "~0.4.0",
|
||||
"tape": "~1.0.2",
|
||||
"concat-stream": "~0.1.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": [
|
||||
"ie/6..latest",
|
||||
"chrome/20..latest",
|
||||
"firefox/10..latest",
|
||||
"safari/latest",
|
||||
"opera/11.0..latest",
|
||||
"iphone/6",
|
||||
"ipad/6"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/substack/resumer.git"
|
||||
},
|
||||
"homepage": "https://github.com/substack/resumer",
|
||||
"keywords": [
|
||||
"through",
|
||||
"stream",
|
||||
"pause",
|
||||
"resume"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"license": "MIT",
|
||||
"readme": "# resumer\n\nReturn a through stream that starts out paused and resumes on the next tick,\nunless somebody called `.pause()`.\n\nThis module has the same signature as\n[through](https://npmjs.com/package/through).\n\n[](http://ci.testling.com/substack/resumer)\n\n[](http://travis-ci.org/substack/resumer)\n\n# example\n\n``` js\nvar resumer = require('resumer');\nvar s = createStream();\ns.pipe(process.stdout);\n\nfunction createStream () {\n var stream = resumer();\n stream.queue('beep boop\\n');\n return stream;\n}\n```\n\n```\n$ node example/resume.js\nbeep boop\n```\n\n# methods\n\n``` js\nvar resumer = require('resumer')\n```\n\n## resumer(write, end)\n\nReturn a new through stream from `write` and `end`, which default to\npass-through `.queue()` functions if not specified.\n\nThe stream starts out paused and will be resumed on the next tick unless you\ncall `.pause()` first.\n\n`write` and `end` get passed directly through to\n[through](https://npmjs.com/package/through).\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install resumer\n```\n\n# license\n\nMIT\n",
|
||||
"readmeFilename": "readme.markdown",
|
||||
"_id": "resumer@0.0.0",
|
||||
"dist": {
|
||||
"shasum": "f1e8f461e4064ba39e82af3cdc2a8c893d076759",
|
||||
"tarball": "http://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz"
|
||||
},
|
||||
"_from": "resumer@>=0.0.0 <0.1.0",
|
||||
"_npmVersion": "1.2.2",
|
||||
"_npmUser": {
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
}
|
||||
],
|
||||
"directories": {},
|
||||
"_shasum": "f1e8f461e4064ba39e82af3cdc2a8c893d076759",
|
||||
"_resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz",
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/resumer/issues"
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
# resumer
|
||||
|
||||
Return a through stream that starts out paused and resumes on the next tick,
|
||||
unless somebody called `.pause()`.
|
||||
|
||||
This module has the same signature as
|
||||
[through](https://npmjs.com/package/through).
|
||||
|
||||
[](http://ci.testling.com/substack/resumer)
|
||||
|
||||
[](http://travis-ci.org/substack/resumer)
|
||||
|
||||
# example
|
||||
|
||||
``` js
|
||||
var resumer = require('resumer');
|
||||
var s = createStream();
|
||||
s.pipe(process.stdout);
|
||||
|
||||
function createStream () {
|
||||
var stream = resumer();
|
||||
stream.queue('beep boop\n');
|
||||
return stream;
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
$ node example/resume.js
|
||||
beep boop
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var resumer = require('resumer')
|
||||
```
|
||||
|
||||
## resumer(write, end)
|
||||
|
||||
Return a new through stream from `write` and `end`, which default to
|
||||
pass-through `.queue()` functions if not specified.
|
||||
|
||||
The stream starts out paused and will be resumed on the next tick unless you
|
||||
call `.pause()` first.
|
||||
|
||||
`write` and `end` get passed directly through to
|
||||
[through](https://npmjs.com/package/through).
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install resumer
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user