didyoumean3
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -38,3 +38,3 @@ 'use strict'; | ||
var defaultOptions = { | ||
const defaultOptions = { | ||
ignore: false, | ||
@@ -45,4 +45,4 @@ trim: true, | ||
var normalize = function normalize(input, opt) { | ||
var s = input; | ||
const normalize = (input, opt) => { | ||
let s = input; | ||
if (opt.ignore) s = s.toLowerCase(); | ||
@@ -56,12 +56,8 @@ if (opt.trim) s = s.trim().replace(/\s+/g, ' '); // handle diacritics, such as 'café' | ||
var dice = function dice(left, right, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
const dice = (left, right, opts = {}) => { | ||
right = normalize(right, opts); | ||
var l = [].concat(left); | ||
var r = [].concat(right); | ||
var lenl = l.length; | ||
var lenr = r.length; | ||
let l = [...left]; | ||
let r = [...right]; | ||
let lenl = l.length; | ||
let lenr = r.length; | ||
if (!lenr) return 0; | ||
@@ -71,22 +67,21 @@ if (left === right) return 1; | ||
if (lenr < 2) r.unshift('*'); | ||
var intersections = 0; | ||
var idxl = -1; | ||
var map = new Map(); | ||
let intersections = 0; | ||
let idxl = -1; | ||
let map = new Map(); | ||
while (++idxl < lenl - 1) { | ||
var bigram = l.slice(idxl, idxl + 2).join(''); | ||
var count = map.has(bigram) ? map.get(bigram) + 1 : 1; | ||
const bigram = l.slice(idxl, idxl + 2).join(''); | ||
const count = map.has(bigram) ? map.get(bigram) + 1 : 1; | ||
map.set(bigram, count); | ||
} | ||
var idxr = -1; | ||
let idxr = -1; | ||
while (++idxr < lenr - 1) { | ||
var _bigram = r.slice(idxr, idxr + 2).join(''); | ||
const bigram = r.slice(idxr, idxr + 2).join(''); | ||
const count = map.has(bigram) ? map.get(bigram) : 0; | ||
var _count = map.has(_bigram) ? map.get(_bigram) : 0; | ||
if (_count > 0) { | ||
if (count > 0) { | ||
intersections++; | ||
map.set(_bigram, _count - 1); | ||
map.set(bigram, count - 1); | ||
} | ||
@@ -98,30 +93,28 @@ } | ||
var val = function val(v, k) { | ||
const val = (v, k) => { | ||
return typeof v === 'string' ? v : typeof k === 'function' ? k(v) : v[k || '']; | ||
}; | ||
var didyoumean3 = function didyoumean3(input, list, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
const didyoumean3 = (input, list, opts = {}) => { | ||
const _defaultOptions$opts = _extends({}, defaultOptions, {}, opts), | ||
{ | ||
key | ||
} = _defaultOptions$opts, | ||
rest = _objectWithoutPropertiesLoose(_defaultOptions$opts, ["key"]); | ||
var _defaultOptions$opts = _extends({}, defaultOptions, {}, opts), | ||
key = _defaultOptions$opts.key, | ||
rest = _objectWithoutPropertiesLoose(_defaultOptions$opts, ["key"]); | ||
input = normalize(input, rest); | ||
if (!input) return null; | ||
var len = list.length; | ||
var matches = []; | ||
var idx = -1; | ||
var max = 0; | ||
var closest = -1; | ||
var first = null; | ||
const len = list.length; | ||
let matches = []; | ||
let idx = -1; | ||
let max = 0; | ||
let closest = -1; | ||
let first = null; | ||
while (++idx < len) { | ||
var target = list[idx]; | ||
var score = dice(input, val(target, key), rest); | ||
const target = list[idx]; | ||
const score = dice(input, val(target, key), rest); | ||
matches.push({ | ||
score: score, | ||
target: target | ||
score, | ||
target | ||
}); | ||
@@ -137,4 +130,4 @@ | ||
return { | ||
matches: matches, | ||
first: first | ||
matches, | ||
first | ||
}; | ||
@@ -141,0 +134,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
"use strict";function r(){return(r=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0});var e={ignore:!1,trim:!0,normalize:!1},t=function(r,e){var t=r;return e.ignore&&(t=t.toLowerCase()),e.trim&&(t=t.trim().replace(/\s+/g," ")),e.normalize&&(t=t.normalize()),t},n=function(r,e,n){void 0===n&&(n={}),e=t(e,n);var o=[].concat(r),i=[].concat(e),a=o.length,u=i.length;if(!u)return 0;if(r===e)return 1;a<2&&o.unshift("*"),u<2&&i.unshift("*");for(var s=0,f=-1,c=new Map;++f<a-1;){var l=o.slice(f,f+2).join(""),v=c.has(l)?c.get(l)+1:1;c.set(l,v)}for(var p=-1;++p<u-1;){var g=i.slice(p,p+2).join(""),h=c.has(g)?c.get(g):0;h>0&&(s++,c.set(g,h-1))}return 2*s/(a+u)},o=function(o,i,a){void 0===a&&(a={});var u=r({},e,{},a),s=u.key,f=function(r,e){if(null==r)return{};var t,n,o={},i=Object.keys(r);for(n=0;n<i.length;n++)e.indexOf(t=i[n])>=0||(o[t]=r[t]);return o}(u,["key"]);if(!(o=t(o,f)))return null;for(var c,l,v=i.length,p=[],g=-1,h=0,y=-1,d=null;++g<v;){var m=i[g],j=n(o,(l=s,"string"==typeof(c=m)?c:"function"==typeof l?l(c):c[l||""]),f);p.push({score:j,target:m}),j>h&&(y=g,h=j)}return~y&&(d=i[y]),{matches:p,first:d}};exports.default=o,exports.dice=n,exports.didyoumean3=o; | ||
"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0});const t={ignore:!1,trim:!0,normalize:!1},r=(e,t)=>{let r=e;return t.ignore&&(r=r.toLowerCase()),t.trim&&(r=r.trim().replace(/\s+/g," ")),t.normalize&&(r=r.normalize()),r},n=(e,t,n={})=>{t=r(t,n);let o=[...e],s=[...t],i=o.length,l=s.length;if(!l)return 0;if(e===t)return 1;i<2&&o.unshift("*"),l<2&&s.unshift("*");let u=0,a=-1,c=new Map;for(;++a<i-1;){const e=o.slice(a,a+2).join(""),t=c.has(e)?c.get(e)+1:1;c.set(e,t)}let f=-1;for(;++f<l-1;){const e=s.slice(f,f+2).join(""),t=c.has(e)?c.get(e):0;t>0&&(u++,c.set(e,t-1))}return 2*u/(i+l)},o=(o,s,i={})=>{const l=e({},t,{},i),{key:u}=l,a=function(e,t){if(null==e)return{};var r,n,o={},s=Object.keys(e);for(n=0;n<s.length;n++)t.indexOf(r=s[n])>=0||(o[r]=e[r]);return o}(l,["key"]);if(!(o=r(o,a)))return null;const c=s.length;let f=[],p=-1,g=0,h=-1,y=null;for(;++p<c;){const e=s[p],t=n(o,(d=u,"string"==typeof(m=e)?m:"function"==typeof d?d(m):m[d||""]),a);f.push({score:t,target:e}),t>g&&(h=p,g=t)}var m,d;return~h&&(y=s[h]),{matches:f,first:y}};exports.default=o,exports.dice=n,exports.didyoumean3=o; | ||
//# sourceMappingURL=didyoumean3.cjs.production.min.js.map |
@@ -34,3 +34,3 @@ function _extends() { | ||
var defaultOptions = { | ||
const defaultOptions = { | ||
ignore: false, | ||
@@ -41,4 +41,4 @@ trim: true, | ||
var normalize = function normalize(input, opt) { | ||
var s = input; | ||
const normalize = (input, opt) => { | ||
let s = input; | ||
if (opt.ignore) s = s.toLowerCase(); | ||
@@ -52,12 +52,8 @@ if (opt.trim) s = s.trim().replace(/\s+/g, ' '); // handle diacritics, such as 'café' | ||
var dice = function dice(left, right, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
const dice = (left, right, opts = {}) => { | ||
right = normalize(right, opts); | ||
var l = [].concat(left); | ||
var r = [].concat(right); | ||
var lenl = l.length; | ||
var lenr = r.length; | ||
let l = [...left]; | ||
let r = [...right]; | ||
let lenl = l.length; | ||
let lenr = r.length; | ||
if (!lenr) return 0; | ||
@@ -67,22 +63,21 @@ if (left === right) return 1; | ||
if (lenr < 2) r.unshift('*'); | ||
var intersections = 0; | ||
var idxl = -1; | ||
var map = new Map(); | ||
let intersections = 0; | ||
let idxl = -1; | ||
let map = new Map(); | ||
while (++idxl < lenl - 1) { | ||
var bigram = l.slice(idxl, idxl + 2).join(''); | ||
var count = map.has(bigram) ? map.get(bigram) + 1 : 1; | ||
const bigram = l.slice(idxl, idxl + 2).join(''); | ||
const count = map.has(bigram) ? map.get(bigram) + 1 : 1; | ||
map.set(bigram, count); | ||
} | ||
var idxr = -1; | ||
let idxr = -1; | ||
while (++idxr < lenr - 1) { | ||
var _bigram = r.slice(idxr, idxr + 2).join(''); | ||
const bigram = r.slice(idxr, idxr + 2).join(''); | ||
const count = map.has(bigram) ? map.get(bigram) : 0; | ||
var _count = map.has(_bigram) ? map.get(_bigram) : 0; | ||
if (_count > 0) { | ||
if (count > 0) { | ||
intersections++; | ||
map.set(_bigram, _count - 1); | ||
map.set(bigram, count - 1); | ||
} | ||
@@ -94,30 +89,28 @@ } | ||
var val = function val(v, k) { | ||
const val = (v, k) => { | ||
return typeof v === 'string' ? v : typeof k === 'function' ? k(v) : v[k || '']; | ||
}; | ||
var didyoumean3 = function didyoumean3(input, list, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
const didyoumean3 = (input, list, opts = {}) => { | ||
const _defaultOptions$opts = _extends({}, defaultOptions, {}, opts), | ||
{ | ||
key | ||
} = _defaultOptions$opts, | ||
rest = _objectWithoutPropertiesLoose(_defaultOptions$opts, ["key"]); | ||
var _defaultOptions$opts = _extends({}, defaultOptions, {}, opts), | ||
key = _defaultOptions$opts.key, | ||
rest = _objectWithoutPropertiesLoose(_defaultOptions$opts, ["key"]); | ||
input = normalize(input, rest); | ||
if (!input) return null; | ||
var len = list.length; | ||
var matches = []; | ||
var idx = -1; | ||
var max = 0; | ||
var closest = -1; | ||
var first = null; | ||
const len = list.length; | ||
let matches = []; | ||
let idx = -1; | ||
let max = 0; | ||
let closest = -1; | ||
let first = null; | ||
while (++idx < len) { | ||
var target = list[idx]; | ||
var score = dice(input, val(target, key), rest); | ||
const target = list[idx]; | ||
const score = dice(input, val(target, key), rest); | ||
matches.push({ | ||
score: score, | ||
target: target | ||
score, | ||
target | ||
}); | ||
@@ -133,4 +126,4 @@ | ||
return { | ||
matches: matches, | ||
first: first | ||
matches, | ||
first | ||
}; | ||
@@ -137,0 +130,0 @@ }; |
{ | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"license": "MIT", | ||
@@ -11,6 +11,6 @@ "main": "dist/index.js", | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"build": "tsdx build --target node", | ||
"test": "tsdx test", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build" | ||
"prepare": "tsdx build --target node" | ||
}, | ||
@@ -17,0 +17,0 @@ "husky": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27168
247