https://github.com/perry-mitchell/urldiff
URL difference processor, sorter and filter
https://github.com/perry-mitchell/urldiff
diff scoring sorting url url-diff url-diffing url-parser url-sort
Last synced: 20 days ago
JSON representation
URL difference processor, sorter and filter
- Host: GitHub
- URL: https://github.com/perry-mitchell/urldiff
- Owner: perry-mitchell
- License: mit
- Created: 2019-07-09T20:30:20.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:16:11.000Z (over 2 years ago)
- Last Synced: 2024-05-02T05:34:50.977Z (12 months ago)
- Topics: diff, scoring, sorting, url, url-diff, url-diffing, url-parser, url-sort
- Language: JavaScript
- Size: 227 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# urldiff
> URL difference processor, sorter and filter[](https://travis-ci.org/perry-mitchell/urldiff) [](https://www.npmjs.com/package/urldiff)
## About
**urldiff** is a library for parsing, diff'ing and scoring URLs based on their differences. These scores can then be used for comparing similar URLs and then sorting them within result sets.
Install by running `npm install urldiff --save`.
urldiff is designed to work on Node 6 and up.
## Usage
The `urldiff` package provides a couple of methods for working with URLs and their scores. You can easily calculate the likeness score of 2 URLs by using `calcuateURLScore`:
```javascript
const { calcuateURLScore } = require("urldiff");const score = calcuateURLScore("http://somesite.com/test.html", "https://test.somesite.com/");
// `score` is a number between 0 and 1, where 1 is more similar
```You can also sort an array of URLs or objects containing URLs:
```javascript
const { sortByURL } = require("urldiff");sortByURL(
"https://test.com", // reference URL
[
{ name: "two", url: "http://page.org/sub" },
{ name: "one", url: "http://test.com/page.html" }
], // Array of items to sort
0, // Min diff score
item => item.url // Getter to fetch the URL
);// Output would be:
// [
// { name: "one", url: "http://test.com/page.html" },
// { name: "two", url: "http://page.org/sub" }
// ]
```