Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xenit-eu/finder-string-similarity-score
Calculates a similarity score between two strings
https://github.com/xenit-eu/finder-string-similarity-score
string-similarity typescript
Last synced: 21 days ago
JSON representation
Calculates a similarity score between two strings
- Host: GitHub
- URL: https://github.com/xenit-eu/finder-string-similarity-score
- Owner: xenit-eu
- License: lgpl-3.0
- Created: 2020-09-01T07:34:51.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T14:34:59.000Z (about 1 year ago)
- Last Synced: 2024-11-07T10:32:25.908Z (2 months ago)
- Topics: string-similarity, typescript
- Language: TypeScript
- Homepage:
- Size: 908 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# String similarity score
Calculates a similarity score between two strings (primarily for the purpose of autocomplete)
## Functions
### `scoreStringSimilarity`
Calculates a similarity score between two strings.
The first parameter is typically a user input string, the second parameter is the reference string.
```typescript
import scoreStringSimilarity from "@xenit/finder-string-similarity-score";const match = scoreStringSimilarity("str ma", "A long string with some text to match.");
// A score between 0 and 1 which describes how well the first parameters matches the second parameter.
// A complete match always has a score of 1. A complete mismatch has a score of 0.
console.log("Score: ", match.score);// The second parameter, chopped up into pieces.
// This can be used to highlight the parts that matched in the string
console.log("Chunks: ", match.chunks.map(chunk => chunk.matched?("*"+chunk.text+"*"):chunk.text).join(""));
```## Local Development
Below is a list of commands you will probably find useful.
### `npm start` or `yarn start`
Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for your convenience. Error messages are pretty printed and formatted for compatibility with VS Code's Problems tab.
Your library will be rebuilt if you make edits.
### `npm run build` or `yarn build`
Bundles the package to the `dist` folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).### `npm test` or `yarn test`
Runs the test watcher (Jest) in an interactive mode.
By default, runs tests related to files changed since the last commit.