Skip to content

Allow possibilities array to be complex objects #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dist/difflib-browser.js: lib/difflib.js util/build.coffee
lib/difflib.js: src/difflib.coffee
@coffee -c -o lib src

test:
test: lib/difflib.js dist/difflib-browser.js
@NODE_ENV=test \
node_modules/.bin/mocha \
--ui qunit \
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ If not specified, the strings default to blanks.
```

<a name="getCloseMatches" />
### difflib.*getCloseMatches*(word, possibilities\[, n\]\[, cutoff\])
### difflib.*getCloseMatches*(word, possibilities\[, n\]\[, cutoff\]\[, formatter\])

Return a list of the best “good enough” matches.
*word* is a sequence for which close matches are desired
Expand All @@ -454,12 +454,26 @@ Optional argument *cutoff* (default 0.6) is a float in the range
[0, 1].
Possibilities that don’t score at least that similar to word are ignored.

Optional argument *formatter* is a function that is run on each element from
*possibilities* before matching is run.


The best (no more than n) matches among the possibilities are
returned in a list, sorted by similarity score, most similar first.

```js
>>> difflib.getCloseMatches('appel', ['ape', 'apple', 'peach', 'puppy'])
['apple', 'ape']

>>> difflib.getCloseMatches('appel', [
{ id: 'a', fruit: 'apple' },
{ id: 'b', fruit: 'pineapple' },
{ id: 'c', fruit: 'cherry' },
{ id: 'd', fruit: 'mango' }
], null, null, function (i) {
return i.fruit;
})
[{ id: 'a', fruit: 'apple' }]
```

<a name="ndiff" />
Expand Down
3 changes: 2 additions & 1 deletion dist/difflib-browser.js

Large diffs are not rendered by default.

Loading