didyoumean
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "didyoumean", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Match human-quality input to potential matches by edit distance.", | ||
@@ -18,6 +18,6 @@ "homepage": "https://github.com/dcporter/didyoumean.js", | ||
], | ||
"main": "./didYouMean-1.1.0.js", | ||
"main": "./didYouMean-1.2.0.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dcporter/didyoumean.js" | ||
"url": "https://github.com/dcporter/didyoumean.js.git" | ||
}, | ||
@@ -24,0 +24,0 @@ "bugs": { |
@@ -1,2 +0,1 @@ | ||
didYouMean.js - A simple JavaScript matching engine | ||
@@ -9,5 +8,6 @@ =================================================== | ||
matches. You can use it to suggest a misspelled command-line utility option to a user, or to offer | ||
links to nearby valid URLs on your 404 page. (The examples below are taken from my personal site, | ||
[dcporter.net](http://dcporter.net/), which uses didYouMean.js to suggest correct URLs from | ||
misspelled ones, such as [dcporter.net/me/instargm](http://dcporter.net/me/instargm).) | ||
links to nearby valid URLs on your 404 page. (The examples below are taken from a personal project, | ||
my [HTML5 business card](http://dcporter.aws.af.cm/me), which uses didYouMean.js to suggest correct | ||
URLs from misspelled ones, such as [dcporter.aws.af.cm/me/instagarm](http://dcporter.aws.af.cm/me/instagarm).) | ||
Uses the [Levenshtein distance algorithm](https://en.wikipedia.org/wiki/Levenshtein_distance). | ||
@@ -21,2 +21,35 @@ didYouMean.js works in the browser as well as in node.js. To install it for use in node: | ||
Examples | ||
-------- | ||
Matching against a list of strings: | ||
``` | ||
var input = 'insargrm' | ||
var list = ['facebook', 'twitter', 'instagram', 'linkedin']; | ||
console.log(didYouMean(input, list)); | ||
> 'instagram' | ||
// The method matches 'insargrm' to 'instagram'. | ||
input = 'google plus'; | ||
console.log(didYouMean(input, list)); | ||
> null | ||
// The method was unable to find 'google plus' in the list of options. | ||
``` | ||
Matching against a list of objects: | ||
``` | ||
var input = 'insargrm'; | ||
var list = [ { id: 'facebook' }, { id: 'twitter' }, { id: 'instagram' }, { id: 'linkedin' } ]; | ||
var key = 'id'; | ||
console.log(didYouMean(input, list, key)); | ||
> 'instagram' | ||
// The method returns the matching value. | ||
didYouMean.returnWinningObject = true; | ||
console.log(didYouMean(input, list, key)); | ||
> { id: 'instagram' } | ||
// The method returns the matching object. | ||
``` | ||
didYouMean(str, list, [key]) | ||
@@ -88,39 +121,7 @@ ---------------------------- | ||
Examples | ||
-------- | ||
Matching against a list of strings: | ||
``` | ||
var input = 'insargrm' | ||
var list = ['facebook', 'twitter', 'instagram', 'linkedin']; | ||
console.log(didYouMean(input, list)); | ||
> 'instagram' | ||
// The method matches 'insargrm' to 'instagram'. | ||
input = 'google plus'; | ||
console.log(didYouMean(input, list)); | ||
> null | ||
// The method is unable to match 'google plus' to any of a list of useful social networks. | ||
``` | ||
Matching against a list of objects: | ||
``` | ||
var input = 'insargrm'; | ||
var list = [ { id: 'facebook' }, { id: 'twitter' }, { id: 'instagram' }, { id: 'linkedin' } ]; | ||
var key = 'id'; | ||
console.log(didYouMean(input, list, key)); | ||
> 'instagram' | ||
// The method returns the matching value. | ||
didYouMean.returnWinningObject = true; | ||
console.log(didYouMean(input, list, key)); | ||
> { id: 'instagram' } | ||
// The method returns the matching object. | ||
``` | ||
License | ||
------- | ||
didYouMean copyright (c) 2013 Dave Porter. | ||
didYouMean copyright (c) 2013-2014 Dave Porter. | ||
@@ -127,0 +128,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17165
225
135
1