Skip to content

Commit 4d84ced

Browse files
committed
Update version to 0.0.10
Fix #9. Update .travis.yml to only deploy gh-pages from master. Remove extraneous code from transform-string.test.js. Update devDependencies to the latest, fixing a vulnerability in jest. Rename preprocessString() to transformString(). Add test/transform-string.test.js to cover the transformString option. Update method JSDoc comments. Use [].concat() to create new arrays from the params passed to setItems() and setKeys(). Change lc to transformed in QuickScore.js and quick-score.js. Update CHANGELOG.md and add links to releases. Change prepare to npm run build:lib. Change prepublishOnly back to prepare. Add preprocessString() option to QuickScore options parameter. Use preprocessString() function to convert the query and all searchable strings before scoring them. The default function calls toLocaleLowerCase() on the strings. Replace stray == with ===.
1 parent cbedd26 commit 4d84ced

8 files changed

Lines changed: 1708 additions & 1702 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ deploy:
2222
skip-cleanup: true
2323
github-token: $GITHUB_TOKEN
2424
on:
25-
branch: develop
25+
branch: master

CHANGELOG.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
# Changelog
22

3-
## [0.0.9] - 2020-07-25
3+
## [0.0.10](https://github.com/fwextensions/quick-score/releases/tag/v0.0.10) - 2021-01-02
4+
5+
### Added
6+
7+
- A new `transformString` option to the `QuickScore` constructor can be used to ignore diacritics and accents when searching.
8+
9+
### Fixed
10+
11+
- Update `devDependencies` to latest packages, fixing a vulnerability in jest.
12+
13+
14+
## [0.0.9](https://github.com/fwextensions/quick-score/releases/tag/v0.0.9) - 2020-07-25
415

516
### Fixed
617

718
- Update `devDependencies` to latest packages.
819

920

10-
## [0.0.8] - 2020-05-07
21+
## [0.0.8](https://github.com/fwextensions/quick-score/releases/tag/v0.0.8) - 2020-05-07
1122

1223
### Fixed
1324

1425
- Use the correct unpkg.com CDN URL in the readme.
1526
- Highlight needing to access the methods through a global when loading the library via a `<script>` tag.
1627

1728

18-
## [0.0.7] - 2020-05-03
29+
## [0.0.7](https://github.com/fwextensions/quick-score/releases/tag/v0.0.7) - 2020-05-03
1930

2031
### Added
2132

@@ -26,48 +37,48 @@
2637
### Fixed
2738

2839
- Update `devDependencies` to latest packages.
29-
- Update node version in .travis.yml to latest.
40+
- Update node version in `.travis.yml` to latest.
3041
- Update to rollup 2.0.
3142

3243

33-
## [0.0.6] - 2020-01-19
44+
## [0.0.6](https://github.com/fwextensions/quick-score/releases/tag/v0.0.6) - 2020-01-19
3445

3546
### Fixed
3647

3748
- The correct match indices were not returned in some cases, since the whole `matches` array was getting cleared when `remainingScore` was 0 during a search.
3849
- Update `devDependencies` to latest packages.
3950

4051

41-
## [0.0.5] - 2019-10-19
52+
## [0.0.5](https://github.com/fwextensions/quick-score/releases/tag/v0.0.5) - 2019-10-19
4253

4354
### Fixed
4455

4556
- Update `devDependencies` to latest packages.
4657

4758

48-
## [0.0.4] - 2019-05-27
59+
## [0.0.4](https://github.com/fwextensions/quick-score/releases/tag/v0.0.4) - 2019-05-27
4960

5061
### Fixed
5162

5263
- Update to babel 7, jest 24, and rollup 1.0.
5364
- Update `devDependencies` to latest packages.
5465

5566

56-
## [0.0.3] - 2019-05-27
67+
## [0.0.3](https://github.com/fwextensions/quick-score/releases/tag/v0.0.3) - 2019-05-27
5768

5869
### Added
5970

6071
- Support searching nested keys on objects use dot-delimited key names, like `"foo.bar"`.
6172

6273

63-
## [0.0.2] - 2018-11-05
74+
## [0.0.2](https://github.com/fwextensions/quick-score/releases/tag/v0.0.2) - 2018-11-05
6475

6576
### Fixed
6677

6778
- Changed `prepare` script to `prepublishOnly`.
6879

6980

70-
## [0.0.1] - 2018-11-05
81+
## [0.0.1](https://github.com/fwextensions/quick-score/releases/tag/v0.0.1) - 2018-11-05
7182

7283
### Added
7384

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ You can then call `quickScore()` with a `string` and a `query` to score against
5858
```js
5959
quickScore("thought", "gh"); // 0.4142857142857143
6060
quickScore("GitHub", "gh"); // 0.9166666666666666
61-
6261
```
6362

6463
Matching `gh` against `GitHub` returns a higher score than `thought`, because it matches the capital letters in `GitHub`, which are weighted more highly.
@@ -148,6 +147,36 @@ Each item in the results array has a few more properties when matching against o
148147

149148
When two items have the same score, they're sorted alphabetically and case-insensitively on the first key in the keys array. In the example above, that would be `title`.
150149

150+
Each result item also has a `_` property, which caches transformed versions of the item's strings, and might contain additional internal metadata in the future. It can be ignored.
151+
152+
153+
### Ignoring diacritics and accents when scoring
154+
155+
If the strings you're matching against contain diacritics on some of the letters, like `à` or `ç`, you may want to count a match even when the query string contains the unaccented forms of those letters. The QuickScore library doesn't contain support for this by default, since it's only needed with certain strings and the code to remove accents would triple its size. But it's easy to combine QuickScore with other libraries to ignore diacritics.
156+
157+
One example is the [latinize](https://github.com/dundalek/latinize) [npm package](https://www.npmjs.com/package/latinize), which will strip accents from a string and can be used in a `transformString()` function that's passed as an option to the [QuickScore constructor](https://fwextensions.github.io/quick-score/QuickScore.html#QuickScore). This function takes a `string` parameter and returns a transformed version of that string:
158+
159+
```js
160+
// including latinize.js on the page creates a global latinize() function
161+
import {QuickScore} from "quick-score";
162+
163+
const items = ["Café", "Cafeteria"];
164+
const qs = new QuickScore(items, { transformString: s => latinize(s).toLowerCase() });
165+
const results = qs.search("cafe");
166+
167+
//=>
168+
[
169+
{
170+
"item": "Café",
171+
"score": 1,
172+
"matches": [[0, 4]],
173+
"_": "cafe"
174+
},
175+
...
176+
```
177+
178+
`transformString()` will be called on each of the searchable keys in the `items` array as well as on the `query` parameter to the `search()` method. The default function calls `toLocaleLowerCase()` on each string, for a case-insensitive search. In the example above, the basic `toLowerCase()` call is sufficient, since `latinize()` will have already stripped the accents.
179+
151180

152181
### Highlighting matched letters
153182

0 commit comments

Comments
 (0)