Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 1.44 KB

README.md

File metadata and controls

69 lines (55 loc) · 1.44 KB

vscode-fuzzy-scorer

Build Status npm version

A shameless rip off of vscode fuzzy scorer algorithm used to search files and stuff.

Install

npm install --save vscode-fuzzy-scorer

Usage

import { compareFilePathsByFuzzyScore } from 'vscode-fuzzy-scorer';

const sourceA = '/some/path/fileA.txt';
const sourceB = '/some/path/other/fileB.txt';
const sourceC = '/unrelated/some/path/other/fileC.txt';

const query = 'path fileB';

const result = [sourceA, sourceB, sourceC].sort((r1, r2) =>
  compareFilePathsByFuzzyScore({ pathA: r1, pathB: r2, query })
);

console.log(result);

/*
Result:
[
  '/some/path/other/fileB.txt'                // sourceB
  '/some/path/fileA.txt'                      // sourceA
  '/unrelated/some/path/other/fileC.txt'      // sourceC
]
*/

or

import { scoreFilePathFuzzy } from 'vscode-fuzzy-scorer';

const path = '/xyz/some/path/someFile123.txt';
const query = 'xyz some';
const result = scoreFilePathFuzzy({ path, query });

console.log(result);

/*
Result:
{
  "score": 131098,
  "labelMatch": [
    {
      "start": 0,
      "end": 4
    }
  ],
  "descriptionMatch": [
    {
      "start": 1,
      "end": 4
    }
  ]
}
*/