This commit is contained in:
2025-05-12 05:38:44 +09:00
parent dced21c3f8
commit 6d78bfa46e
8120 changed files with 1161564 additions and 0 deletions

16
book/node_modules/lunr/perf/document_store_test.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
(function () {
var setup = function () {
var store = new lunr.Store,
tokens = ['foo', 'bar', 'baz']
}
bench('documentStore#set', function () {
for (var i = 0; i < 1000; i++) {
store.set(i, tokens)
}
}, { setup: setup })
})()

79
book/node_modules/lunr/perf/env/bench.js generated vendored Normal file
View File

@ -0,0 +1,79 @@
(function () {
var BenchView = function (benchmark) {
this.benchmark = benchmark
var benchmarkTemplate = $('#benchmark-template').text()
this.html = $(Mustache.to_html(benchmarkTemplate, benchmark))
this.benchmark.on('start', this.started.bind(this))
this.benchmark.on('complete', this.completed.bind(this))
this.benchmark.on('error', this.errored.bind(this))
this.html.find('button').bind('click', function () {
benchmark.run({async: true})
})
}
BenchView.prototype.started = function () {
this.html
.addClass('is-running')
.find('.status')
.html('Running&hellip;')
}
BenchView.prototype.completed = function () {
this.html
.removeClass('is-running')
.find('.status')
.text('Done')
.end()
.find('.ops-per-sec')
.text(Benchmark.formatNumber(this.benchmark.hz.toFixed(2)))
}
BenchView.prototype.errored = function () {
this.html
.removeClass('is-running')
.addClass('is-errored')
.find('.status')
.text('Error')
throw(this.benchmark.error)
}
benchmarks = []
var bench = function (name, testFn, options) {
var benchmark = new Benchmark(name, testFn, options)
benchmarks.push(benchmark)
}
bench.runAll = function () {
for (var i = 1; i < benchmarks.length; i++) {
var benchmark = benchmarks[i],
prev = benchmarks[i - 1]
prev.on('complete', function () {
console.log(benchmark)
benchmark.run({async: true})
})
}
benchmarks[0].run({async: true})
}
$(document).ready(function () {
var benchmarksContainer = $('#benchmarks tbody')
benchmarks.forEach(function (benchmark) {
var benchView = new BenchView (benchmark)
benchmarksContainer.append(benchView.html)
})
$('button.run').click(function () {
//bench.runAll()
})
})
window.bench = bench
})()

3919
book/node_modules/lunr/perf/env/benchmark.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

8176
book/node_modules/lunr/perf/env/jquery.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

325
book/node_modules/lunr/perf/env/mustache.js generated vendored Normal file
View File

@ -0,0 +1,325 @@
/*
mustache.js — Logic-less templates in JavaScript
See http://mustache.github.com/ for more info.
*/
var Mustache = function() {
var Renderer = function() {};
Renderer.prototype = {
otag: "{{",
ctag: "}}",
pragmas: {},
buffer: [],
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},
context: {},
render: function(template, context, partials, in_recursion) {
// reset buffer & set context
if(!in_recursion) {
this.context = context;
this.buffer = []; // TODO: make this non-lazy
}
// fail fast
if(!this.includes("", template)) {
if(in_recursion) {
return template;
} else {
this.send(template);
return;
}
}
template = this.render_pragmas(template);
var html = this.render_section(template, context, partials);
if(in_recursion) {
return this.render_tags(html, context, partials, in_recursion);
}
this.render_tags(html, context, partials, in_recursion);
},
/*
Sends parsed lines
*/
send: function(line) {
if(line != "") {
this.buffer.push(line);
}
},
/*
Looks for %PRAGMAS
*/
render_pragmas: function(template) {
// no pragmas
if(!this.includes("%", template)) {
return template;
}
var that = this;
var regex = new RegExp(this.otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" +
this.ctag);
return template.replace(regex, function(match, pragma, options) {
if(!that.pragmas_implemented[pragma]) {
throw({message:
"This implementation of mustache doesn't understand the '" +
pragma + "' pragma"});
}
that.pragmas[pragma] = {};
if(options) {
var opts = options.split("=");
that.pragmas[pragma][opts[0]] = opts[1];
}
return "";
// ignore unknown pragmas silently
});
},
/*
Tries to find a partial in the curent scope and render it
*/
render_partial: function(name, context, partials) {
name = this.trim(name);
if(!partials || partials[name] === undefined) {
throw({message: "unknown_partial '" + name + "'"});
}
if(typeof(context[name]) != "object") {
return this.render(partials[name], context, partials, true);
}
return this.render(partials[name], context[name], partials, true);
},
/*
Renders inverted (^) and normal (#) sections
*/
render_section: function(template, context, partials) {
if(!this.includes("#", template) && !this.includes("^", template)) {
return template;
}
var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
"\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");
// for each {{#foo}}{{/foo}} section do...
return template.replace(regex, function(match, type, name, content) {
var value = that.find(name, context);
if(type == "^") { // inverted section
if(!value || that.is_array(value) && value.length === 0) {
// false or empty list, render it
return that.render(content, context, partials, true);
} else {
return "";
}
} else if(type == "#") { // normal section
if(that.is_array(value)) { // Enumerable, Let's loop!
return that.map(value, function(row) {
return that.render(content, that.create_context(row),
partials, true);
}).join("");
} else if(that.is_object(value)) { // Object, Use it as subcontext!
return that.render(content, that.create_context(value),
partials, true);
} else if(typeof value === "function") {
// higher order section
return value.call(context, content, function(text) {
return that.render(text, context, partials, true);
});
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {
return "";
}
}
});
},
/*
Replace {{foo}} and friends with values from our view
*/
render_tags: function(template, context, partials, in_recursion) {
// tit for tat
var that = this;
var new_regex = function() {
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" +
that.ctag + "+", "g");
};
var regex = new_regex();
var tag_replace_callback = function(match, operator, name) {
switch(operator) {
case "!": // ignore comments
return "";
case "=": // set new delimiters, rebuild the replace regexp
that.set_delimiters(name);
regex = new_regex();
return "";
case ">": // render partial
return that.render_partial(name, context, partials);
case "{": // the triple mustache is unescaped
return that.find(name, context);
default: // escape the value
return that.escape(that.find(name, context));
}
};
var lines = template.split("\n");
for(var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
if(!in_recursion) {
this.send(lines[i]);
}
}
if(in_recursion) {
return lines.join("\n");
}
},
set_delimiters: function(delimiters) {
var dels = delimiters.split(" ");
this.otag = this.escape_regex(dels[0]);
this.ctag = this.escape_regex(dels[1]);
},
escape_regex: function(text) {
// thank you Simon Willison
if(!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
},
/*
find `name` in current `context`. That is find me a value
from the view object
*/
find: function(name, context) {
name = this.trim(name);
// Checks whether a value is thruthy or false or 0
function is_kinda_truthy(bool) {
return bool === false || bool === 0 || bool;
}
var value;
if(is_kinda_truthy(context[name])) {
value = context[name];
} else if(is_kinda_truthy(this.context[name])) {
value = this.context[name];
}
if(typeof value === "function") {
return value.apply(context);
}
if(value !== undefined) {
return value;
}
// silently ignore unknown variables
return "";
},
// Utility methods
/* includes tag */
includes: function(needle, haystack) {
return haystack.indexOf(this.otag + needle) != -1;
},
/*
Does away with nasty characters
*/
escape: function(s) {
s = String(s === null ? "" : s);
return s.replace(/&(?!\w+;)|["'<>\\]/g, function(s) {
switch(s) {
case "&": return "&amp;";
case "\\": return "\\\\";
case '"': return '&quot;';
case "'": return '&#39;';
case "<": return "&lt;";
case ">": return "&gt;";
default: return s;
}
});
},
// by @langalex, support for arrays of strings
create_context: function(_context) {
if(this.is_object(_context)) {
return _context;
} else {
var iterator = ".";
if(this.pragmas["IMPLICIT-ITERATOR"]) {
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
}
var ctx = {};
ctx[iterator] = _context;
return ctx;
}
},
is_object: function(a) {
return a && typeof a == "object";
},
is_array: function(a) {
return Object.prototype.toString.call(a) === '[object Array]';
},
/*
Gets rid of leading and trailing whitespace
*/
trim: function(s) {
return s.replace(/^\s*|\s*$/g, "");
},
/*
Why, why, why? Because IE. Cry, cry cry.
*/
map: function(array, fn) {
if (typeof array.map == "function") {
return array.map(fn);
} else {
var r = [];
var l = array.length;
for(var i = 0; i < l; i++) {
r.push(fn(array[i]));
}
return r;
}
}
};
return({
name: "mustache.js",
version: "0.3.1-dev",
/*
Turns a template and view into HTML
*/
to_html: function(template, view, partials, send_fun) {
var renderer = new Renderer();
if(send_fun) {
renderer.send = send_fun;
}
renderer.render(template, view, partials);
if(!send_fun) {
return renderer.buffer.join("\n");
}
}
});
}();

22
book/node_modules/lunr/perf/env/styles.css generated vendored Normal file
View File

@ -0,0 +1,22 @@
#benchmarks li.is-running {
color: green
}
#benchmarks li.is-errored .results,
#benchmarks li.is-running .results,
#benchmarks li.is-pending .results {
display: none
}
#benchmarks li.is-complete .results {
display: block;
}
#benchmarks li.is-pending .idle {
display: block;
}
#benchmarks li.is-complete .running,
#benchmarks li.is-pending .running {
display: none
}

1
book/node_modules/lunr/perf/fixtures/questions.js generated vendored Normal file

File diff suppressed because one or more lines are too long

7
book/node_modules/lunr/perf/foo_test.js generated vendored Normal file
View File

@ -0,0 +1,7 @@
bench('addition', function () {
return 1 + 1
})
bench('subtraction', function () {
return 1 - 1
})

74
book/node_modules/lunr/perf/index.html generated vendored Normal file
View File

@ -0,0 +1,74 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Lunr tests</title>
<link rel="stylesheet" href="/perf/env/styles.css">
<!-- dependencies -->
<script src="/perf/env/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/env/mustache.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/env/benchmark.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/env/bench.js" type="text/javascript" charset="utf-8"></script>
<!-- fixtures -->
<script src="/perf/fixtures/questions.js" type="text/javascript" charset="utf-8"></script>
<script src="/test/fixtures/stemming_vocab.json" type="text/javascript" charset="utf-8"></script>
<!-- Lunr -->
<script src="/lib/lunr.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/utils.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/tokenizer.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/pipeline.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/vector.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/sorted_set.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/event_emitter.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/index.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/document_store.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/stemmer.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/stop_word_filter.js" type="text/javascript" charset="utf-8"></script>
<script src="/lib/token_store.js" type="text/javascript" charset="utf-8"></script>
<!-- Tests -->
<script src="/perf/index_test.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/vector_test.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/token_store_test.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/sorted_set_test.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/document_store_test.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/stemmer_test.js" type="text/javascript" charset="utf-8"></script>
<script src="/perf/tokenizer_test.js" type="text/javascript" charset="utf-8"></script>
<script id="benchmark-template" type="text/mustache">
<tr>
<td>{{name}}</td>
<td class="status">Ready</td>
<td class="ops-per-sec">N/A</td>
<td class="actions">
<button class="run">Run</button>
</td>
</tr>
</script>
<script>
</script>
</head>
<body>
<header>
<h1>Lunr.js Performance Tests</h1>
<button class="run">Run!</button>
</header>
<table id="benchmarks">
<thead>
<tr>
<td>Name</td>
<td>Status</td>
<td>Result</td>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>

28
book/node_modules/lunr/perf/index_test.js generated vendored Normal file
View File

@ -0,0 +1,28 @@
(function () {
var setup = function () {
var testDoc = {
id: 1,
title: 'Adding story from last story in the sprint',
body: 'So that I am not confused where the story is going to end up As a user I want the the add a story button from the last story in the sprint to create a story at the top of the backlog and not extend the sprint temporarily the add story button inserts a story at the top of the backlog. "add a new story here" prompts are not shown for stories that are currently in a sprint',
tags: 'foo bar'
}
questionsIdx.version = lunr.version
var idx = lunr.Index.load(questionsIdx)
}
bench('index#add', function () {
idx.add(testDoc)
}, { setup: setup })
bench('index#search uncommon word', function () {
idx.search('checkbox')
}, { setup: setup })
bench('index#search common word', function () {
idx.search('javascript')
}, { setup: setup })
})()

28
book/node_modules/lunr/perf/pipeline_test.js generated vendored Normal file
View File

@ -0,0 +1,28 @@
var suite = new Benchmark.Suite,
elements = [],
fn1 = function (t) { return t },
fn2 = function (t) { return t },
pipeline = new lunr.Pipeline
for (var i = 0; i < 10000; i++) {
elements[i] = Math.random() * 100
};
pipeline.add(fn1, fn2)
suite.add('pipeline#run', function () {
pipeline.run(elements)
})
suite.on('cycle', function (e) {
console.log(e.target.name)
})
suite.on('complete', function (e) {
suite.forEach(function (s) {
console.log(s.name, s.count)
})
})
suite.run({async: true})

29
book/node_modules/lunr/perf/set_index_of_test.js generated vendored Normal file
View File

@ -0,0 +1,29 @@
var suite = new Benchmark.Suite,
set = new lunr.SortedSet
for (var i = 0; i < 1000; i++) {
set.add(Math.random() * 100)
};
suite.add('native indexOf', function () {
set.elements.indexOf(50)
})
suite.add('bsearch indexOf', function () {
set.indexOf(50)
})
suite.on('cycle', function (e) {
console.log(e.target.name)
})
suite.on('complete', function (e) {
suite.forEach(function (s) {
console.log(s.name, s.count)
})
var fastest = this.filter('fastest').pluck('name')
console.log('fastest is: ', fastest)
})
suite.run({async: true})

26
book/node_modules/lunr/perf/sorted_set_test.js generated vendored Normal file
View File

@ -0,0 +1,26 @@
(function () {
var setup = function () {
var filledSet = new lunr.SortedSet
for (var i = 0; i < 10000; i++) {
filledSet.add(i * 2)
}
}
bench('sortedSet#add non-duplicate', function () {
var sortedSet = new lunr.SortedSet
sortedSet.elements = filledSet.elements
sortedSet.add(3131)
}, { setup: setup })
bench('sortedSet#add duplicate', function () {
var sortedSet = new lunr.SortedSet
sortedSet.elements = filledSet.elements
sortedSet.add(2000)
}, { setup: setup })
bench("sortedSet#indexOf", function () {
filledSet.indexOf(321)
}, { setup: setup })
})()

7
book/node_modules/lunr/perf/stemmer_test.js generated vendored Normal file
View File

@ -0,0 +1,7 @@
(function () {
bench("stemmer", function () {
Object.keys(stemmingFixture).forEach(function (word) {
lunr.stemmer(word)
})
})
})()

21
book/node_modules/lunr/perf/token_store_test.js generated vendored Normal file
View File

@ -0,0 +1,21 @@
(function () {
var setup = function () {
questionsIdx.version = lunr.version
var store = lunr.TokenStore.load(questionsIdx.tokenStore)
}
bench('tokenStore#getNode', function () {
store.getNode('javascript')
}, { setup: setup })
bench('tokenStore#has non existant term', function () {
store.has('qwertyuiop')
}, { setup: setup })
bench('tokenStore#has term exists', function () {
store.has('javascript')
}, { setup: setup })
})()

9
book/node_modules/lunr/perf/tokenizer_test.js generated vendored Normal file
View File

@ -0,0 +1,9 @@
(function () {
var setup = function () {
var lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"
}
bench("tokeniser", function () {
lunr.tokenizer(lorem)
}, { setup: setup })
})()

34
book/node_modules/lunr/perf/vector_test.js generated vendored Normal file
View File

@ -0,0 +1,34 @@
(function () {
var setup = function () {
var index, val
var v1 = new lunr.Vector,
v2 = new lunr.Vector
for (var i = 0; i < 1000; i++) {
index = Math.floor(i + Math.random() * 100)
val = Math.random() * 100
v1.insert(i, val)
}
for (var i = 0; i < 1000; i++) {
index = Math.floor(i + Math.random() * 100)
val = Math.random() * 100
v2.insert(i, val)
}
}
bench('vector#magnitude', function () {
v1.magnitude()
}, { setup: setup })
bench('vector#dot', function () {
v1.dot(v2)
}, { setup: setup })
bench('vector#similarity', function () {
v1.similarity(v2)
}, { setup: setup })
})()