0.0.4 • Published 4 years ago

vscode-fuzzy-scorer v0.0.4

Weekly downloads
35
License
MIT
Repository
-
Last release
4 years ago

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
    }
  ]
}
*/