Merge remote-tracking branch 'upstream/main'

This commit is contained in:
2026-08-26 09:31:34 +08:00
parent 9b8c4bfab6
commit 394eb0285d
34137 changed files with 3589424 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
+2
View File
@@ -0,0 +1,2 @@
node_modules
dist
+21
View File
@@ -0,0 +1,21 @@
{
"curly": true,
"eqeqeq": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"sub": true,
"validthis": true,
"undef": true,
"trailing": true,
"boss": true,
"eqnull": true,
"strict": true,
"immed": true,
"expr": true,
"latedef": "nofunc",
"quotmark": "single",
"indent": 2,
"node": true
}
+1
View File
@@ -0,0 +1 @@
node_modules
+18
View File
@@ -0,0 +1,18 @@
# v1.0.3 Short Fuse
- Improved circuit-breaker when `needle` and `haystack` length are equal
# v1.0.2 Vodka Tonic
- Slightly updated circuit-breaker that tests for equal length first
- Doubled method performance ([see jsperf tests](http://jsperf.com/fuzzysearch-regex/3))
# v1.0.1 Circuit Breaker
- Introduced a circuit-breaker where queries longer than the searched string will return `false`
- Introduced a circuit-breaker where queries identical to the searched string will return `true`
- Introduced a circuit-breaker where text containing the entire query will return `true`
# v1.0.0 IPO
- Initial Public Release
+20
View File
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright © 2015 Nicolas Bevacqua
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.
+45
View File
@@ -0,0 +1,45 @@
# fuzzysearch
> Tiny and blazing-fast fuzzy search in JavaScript
Fuzzy searching allows for flexibly matching a string with partial input, useful for filtering data very quickly based on lightweight user input.
# Demo
To see `fuzzysearch` in action, head over to [bevacqua.github.io/horsey][3], which is a demo of an autocomplete component that uses `fuzzysearch` to filter out results based on user input.
# Install
From `npm`
```shell
npm install --save fuzzysearch
```
# `fuzzysearch(needle, haystack)`
Returns `true` if `needle` matches `haystack` using a fuzzy-searching algorithm. Note that this program doesn't implement _[levenshtein distance][2]_, but rather a simplified version where **there's no approximation**. The method will return `true` only if each character in the `needle` can be found in the `haystack` and occurs after the preceding character.
```js
fuzzysearch('twl', 'cartwheel') // <- true
fuzzysearch('cart', 'cartwheel') // <- true
fuzzysearch('cw', 'cartwheel') // <- true
fuzzysearch('ee', 'cartwheel') // <- true
fuzzysearch('art', 'cartwheel') // <- true
fuzzysearch('eeel', 'cartwheel') // <- false
fuzzysearch('dog', 'cartwheel') // <- false
```
An exciting application for this kind of algorithm is to filter options from an autocomplete menu, check out [horsey][3] for an example on how that might look like.
# But! _`RegExp`s...!_
![chart showing abysmal performance for regexp-based implementation][1]
# License
MIT
[1]: https://cloud.githubusercontent.com/assets/934293/6495796/106a61a6-c2ac-11e4-945d-3d1bb066a76e.png
[2]: http://en.wikipedia.org/wiki/Levenshtein_distance
[3]: http://bevacqua.github.io/horsey
+24
View File
@@ -0,0 +1,24 @@
'use strict';
function fuzzysearch (needle, haystack) {
var tlen = haystack.length;
var qlen = needle.length;
if (qlen > tlen) {
return false;
}
if (qlen === tlen) {
return needle === haystack;
}
outer: for (var i = 0, j = 0; i < qlen; i++) {
var nch = needle.charCodeAt(i);
while (j < tlen) {
if (haystack.charCodeAt(j++) === nch) {
continue outer;
}
}
return false;
}
return true;
}
module.exports = fuzzysearch;
+23
View File
@@ -0,0 +1,23 @@
{
"name": "fuzzysearch",
"description": "Tiny and blazing-fast fuzzy search in JavaScript",
"version": "1.0.3",
"homepage": "https://github.com/bevacqua/fuzzysearch",
"author": {
"name": "Nicolas Bevacqua",
"email": "ng@bevacqua.io",
"url": "http://bevacqua.io"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/bevacqua/fuzzysearch.git"
},
"scripts": {
"test": "jshint . && tape test/*.js"
},
"devDependencies": {
"jshint": "^2.6.0",
"tape": "^3.5.0"
}
}
+14
View File
@@ -0,0 +1,14 @@
'use strict';
var test = require('tape');
var fuzzysearch = require('..');
test('fuzzysearch should match expectations', function (t) {
t.equal(fuzzysearch('car', 'cartwheel'), true);
t.equal(fuzzysearch('cwhl', 'cartwheel'), true);
t.equal(fuzzysearch('cwheel', 'cartwheel'), true);
t.equal(fuzzysearch('cartwheel', 'cartwheel'), true);
t.equal(fuzzysearch('cwheeel', 'cartwheel'), false);
t.equal(fuzzysearch('lw', 'cartwheel'), false);
t.end();
});