codecombat/vendor/scripts/fuzzaldrin.js

657 lines
18 KiB
JavaScript
Raw Normal View History

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (process){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length - 1; i >= 0; i--) {
var last = parts[i];
if (last === '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
return parts;
}
// Split a filename into [root, dir, basename, ext], unix version
// 'root' is just a slash, or nothing.
var splitPathRe =
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
var splitPath = function(filename) {
return splitPathRe.exec(filename).slice(1);
};
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : process.cwd();
// Skip empty and invalid entries
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// path.normalize(path)
// posix version
exports.normalize = function(path) {
var isAbsolute = exports.isAbsolute(path),
trailingSlash = substr(path, -1) === '/';
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isAbsolute).join('/');
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isAbsolute ? '/' : '') + path;
};
// posix version
exports.isAbsolute = function(path) {
return path.charAt(0) === '/';
};
// posix version
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function(p, index) {
if (typeof p !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
}).join('/'));
};
// path.relative(from, to)
// posix version
exports.relative = function(from, to) {
from = exports.resolve(from).substr(1);
to = exports.resolve(to).substr(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== '') break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== '') break;
}
if (start > end) return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split('/'));
var toParts = trim(to.split('/'));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push('..');
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join('/');
};
exports.sep = '/';
exports.delimiter = ':';
exports.dirname = function(path) {
var result = splitPath(path),
root = result[0],
dir = result[1];
if (!root && !dir) {
// No dirname whatsoever
return '.';
}
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substr(0, dir.length - 1);
}
return root + dir;
};
exports.basename = function(path, ext) {
var f = splitPath(path)[2];
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function(path) {
return splitPath(path)[3];
};
function filter (xs, f) {
if (xs.filter) return xs.filter(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
if (f(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
// String.prototype.substr - negative index don't work in IE8
var substr = 'ab'.substr(-1) === 'b'
? function (str, start, len) { return str.substr(start, len) }
: function (str, start, len) {
if (start < 0) start = str.length + start;
return str.substr(start, len);
}
;
}).call(this,require('_process'))
},{"_process":2}],2:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
(function () {
try {
cachedSetTimeout = setTimeout;
} catch (e) {
cachedSetTimeout = function () {
throw new Error('setTimeout is not defined');
}
}
try {
cachedClearTimeout = clearTimeout;
} catch (e) {
cachedClearTimeout = function () {
throw new Error('clearTimeout is not defined');
}
}
} ())
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = cachedSetTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
cachedClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
cachedSetTimeout(drainQueue, 0);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}],3:[function(require,module,exports){
(function() {
var pluckCandidates, scorer, sortCandidates;
scorer = require('./scorer');
pluckCandidates = function(a) {
return a.candidate;
};
sortCandidates = function(a, b) {
return b.score - a.score;
};
module.exports = function(candidates, query, queryHasSlashes, _arg) {
var candidate, key, maxResults, score, scoredCandidates, string, _i, _len, _ref;
_ref = _arg != null ? _arg : {}, key = _ref.key, maxResults = _ref.maxResults;
if (query) {
scoredCandidates = [];
for (_i = 0, _len = candidates.length; _i < _len; _i++) {
candidate = candidates[_i];
string = key != null ? candidate[key] : candidate;
if (!string) {
continue;
}
score = scorer.score(string, query, queryHasSlashes);
if (!queryHasSlashes) {
score = scorer.basenameScore(string, query, score);
}
if (score > 0) {
scoredCandidates.push({
candidate: candidate,
score: score
});
}
}
scoredCandidates.sort(sortCandidates);
candidates = scoredCandidates.map(pluckCandidates);
}
if (maxResults != null) {
candidates = candidates.slice(0, maxResults);
}
return candidates;
};
}).call(this);
},{"./scorer":6}],4:[function(require,module,exports){
(function() {
var PathSeparator, SpaceRegex, filter, matcher, scorer;
scorer = require('./scorer');
filter = require('./filter');
matcher = require('./matcher');
PathSeparator = require('path').sep;
SpaceRegex = /\ /g;
module.exports = {
filter: function(candidates, query, options) {
var queryHasSlashes;
if (query) {
queryHasSlashes = query.indexOf(PathSeparator) !== -1;
query = query.replace(SpaceRegex, '');
}
return filter(candidates, query, queryHasSlashes, options);
},
score: function(string, query) {
var queryHasSlashes, score;
if (!string) {
return 0;
}
if (!query) {
return 0;
}
if (string === query) {
return 2;
}
queryHasSlashes = query.indexOf(PathSeparator) !== -1;
query = query.replace(SpaceRegex, '');
score = scorer.score(string, query);
if (!queryHasSlashes) {
score = scorer.basenameScore(string, query, score);
}
return score;
},
match: function(string, query) {
var baseMatches, index, matches, queryHasSlashes, seen, _i, _ref, _results;
if (!string) {
return [];
}
if (!query) {
return [];
}
if (string === query) {
return (function() {
_results = [];
for (var _i = 0, _ref = string.length; 0 <= _ref ? _i < _ref : _i > _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }
return _results;
}).apply(this);
}
queryHasSlashes = query.indexOf(PathSeparator) !== -1;
query = query.replace(SpaceRegex, '');
matches = matcher.match(string, query);
if (!queryHasSlashes) {
baseMatches = matcher.basenameMatch(string, query);
matches = matches.concat(baseMatches).sort(function(a, b) {
return a - b;
});
seen = null;
index = 0;
while (index < matches.length) {
if (index && seen === matches[index]) {
matches.splice(index, 1);
} else {
seen = matches[index];
index++;
}
}
}
return matches;
}
};
}).call(this);
},{"./filter":3,"./matcher":5,"./scorer":6,"path":1}],5:[function(require,module,exports){
(function() {
var PathSeparator;
PathSeparator = require('path').sep;
exports.basenameMatch = function(string, query) {
var base, index, lastCharacter, slashCount;
index = string.length - 1;
while (string[index] === PathSeparator) {
index--;
}
slashCount = 0;
lastCharacter = index;
base = null;
while (index >= 0) {
if (string[index] === PathSeparator) {
slashCount++;
if (base == null) {
base = string.substring(index + 1, lastCharacter + 1);
}
} else if (index === 0) {
if (lastCharacter < string.length - 1) {
if (base == null) {
base = string.substring(0, lastCharacter + 1);
}
} else {
if (base == null) {
base = string;
}
}
}
index--;
}
return exports.match(base, query, string.length - base.length);
};
exports.match = function(string, query, stringOffset) {
var character, indexInQuery, indexInString, lowerCaseIndex, matches, minIndex, queryLength, stringLength, upperCaseIndex, _i, _ref, _results;
if (stringOffset == null) {
stringOffset = 0;
}
if (string === query) {
return (function() {
_results = [];
for (var _i = stringOffset, _ref = stringOffset + string.length; stringOffset <= _ref ? _i < _ref : _i > _ref; stringOffset <= _ref ? _i++ : _i--){ _results.push(_i); }
return _results;
}).apply(this);
}
queryLength = query.length;
stringLength = string.length;
indexInQuery = 0;
indexInString = 0;
matches = [];
while (indexInQuery < queryLength) {
character = query[indexInQuery++];
lowerCaseIndex = string.indexOf(character.toLowerCase());
upperCaseIndex = string.indexOf(character.toUpperCase());
minIndex = Math.min(lowerCaseIndex, upperCaseIndex);
if (minIndex === -1) {
minIndex = Math.max(lowerCaseIndex, upperCaseIndex);
}
indexInString = minIndex;
if (indexInString === -1) {
return [];
}
matches.push(stringOffset + indexInString);
stringOffset += indexInString + 1;
string = string.substring(indexInString + 1, stringLength);
}
return matches;
};
}).call(this);
},{"path":1}],6:[function(require,module,exports){
(function() {
var PathSeparator, queryIsLastPathSegment;
PathSeparator = require('path').sep;
exports.basenameScore = function(string, query, score) {
var base, depth, index, lastCharacter, segmentCount, slashCount;
index = string.length - 1;
while (string[index] === PathSeparator) {
index--;
}
slashCount = 0;
lastCharacter = index;
base = null;
while (index >= 0) {
if (string[index] === PathSeparator) {
slashCount++;
if (base == null) {
base = string.substring(index + 1, lastCharacter + 1);
}
} else if (index === 0) {
if (lastCharacter < string.length - 1) {
if (base == null) {
base = string.substring(0, lastCharacter + 1);
}
} else {
if (base == null) {
base = string;
}
}
}
index--;
}
if (base === string) {
score *= 2;
} else if (base) {
score += exports.score(base, query);
}
segmentCount = slashCount + 1;
depth = Math.max(1, 10 - segmentCount);
score *= depth * 0.01;
return score;
};
exports.score = function(string, query) {
var character, characterScore, indexInQuery, indexInString, lowerCaseIndex, minIndex, queryLength, queryScore, stringLength, totalCharacterScore, upperCaseIndex, _ref;
if (string === query) {
return 1;
}
if (queryIsLastPathSegment(string, query)) {
return 1;
}
totalCharacterScore = 0;
queryLength = query.length;
stringLength = string.length;
indexInQuery = 0;
indexInString = 0;
while (indexInQuery < queryLength) {
character = query[indexInQuery++];
lowerCaseIndex = string.indexOf(character.toLowerCase());
upperCaseIndex = string.indexOf(character.toUpperCase());
minIndex = Math.min(lowerCaseIndex, upperCaseIndex);
if (minIndex === -1) {
minIndex = Math.max(lowerCaseIndex, upperCaseIndex);
}
indexInString = minIndex;
if (indexInString === -1) {
return 0;
}
characterScore = 0.1;
if (string[indexInString] === character) {
characterScore += 0.1;
}
if (indexInString === 0 || string[indexInString - 1] === PathSeparator) {
characterScore += 0.8;
} else if ((_ref = string[indexInString - 1]) === '-' || _ref === '_' || _ref === ' ') {
characterScore += 0.7;
}
string = string.substring(indexInString + 1, stringLength);
totalCharacterScore += characterScore;
}
queryScore = totalCharacterScore / queryLength;
return ((queryScore * (queryLength / stringLength)) + queryScore) / 2;
};
queryIsLastPathSegment = function(string, query) {
if (string[string.length - query.length - 1] === PathSeparator) {
return string.lastIndexOf(query) === string.length - query.length;
}
};
}).call(this);
},{"path":1}],7:[function(require,module,exports){
(function pushToGlobal(root, factory) {
root["fuzzaldrin"] = factory();
})(Function("return this")(), function() {
var x = require('fuzzaldrin');
return x;
});
},{"fuzzaldrin":4}]},{},[7]);