Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ASI police.

commit c3f19f833578eb2301ea3e276d7ea40a16cd2d1d 1 parent df2a2f0
@DimitarChristoff authored
Showing with 48 additions and 47 deletions.
  1. +22 −21 src/String.distance.js
  2. +26 −26 src/mootools.mailcheck.js
View
43 src/String.distance.js
@@ -19,8 +19,9 @@
...
*/
-!function() {
- 'use strict'
+(function(){
+
+ 'use strict';
String.implement({
sift3: function(s2) {
@@ -31,65 +32,65 @@
offset2 = 0,
lcs = 0,
maxOffset = 5,
- i = 0
+ i = 0;
if (s1 == null || s1.length === 0) {
if (s2 == null || s2.length === 0) {
return 0;
} else {
- return s2.length
+ return s2.length;
}
}
if (s2 == null || s2.length === 0) {
- return s1.length
+ return s1.length;
}
while ((c + offset1 < s1.length) && (c + offset2 < s2.length)) {
if (s1.charAt(c + offset1) == s2.charAt(c + offset2)) {
- lcs++
+ lcs++;
} else {
- offset1 = 0
- offset2 = 0
+ offset1 = 0;
+ offset2 = 0;
for (; i < maxOffset; i++) {
if ((c + i < s1.length) && (s1.charAt(c + i) == s2.charAt(c))) {
- offset1 = i
- break
+ offset1 = i;
+ break;
}
if ((c + i < s2.length) && (s1.charAt(c) == s2.charAt(c + i))) {
- offset2 = i
- break
+ offset2 = i;
+ break;
}
}
}
c++;
}
- return (s1.length + s2.length) / 2 - lcs
+ return (s1.length + s2.length) / 2 - lcs;
},
levenstein: function(str2) {
// distance by levenstein, seems more reliable
- str2 = str2.split("")
+ str2 = str2.split("");
var str1 = String(this).split(""),
distance = [],
l = str1.length,
m = str2.length,
i,
- j
+ j;
for(i = 0; i <= l; i++)
- distance[i] = [i]
+ distance[i] = [i];
for(j = 0; j <= m; j++)
- distance[0][j] = j
+ distance[0][j] = j;
for(i = 1; i <= l; i++)
for(j = 1; j <= m; j++)
- distance[i][j] = Math.min(distance[i-1][j]+1, distance[i][j-1]+1, distance[i-1][j-1]+((str1[i-1]==str2[j-1])?0:1))
+ distance[i][j] = Math.min(distance[i-1][j]+1, distance[i][j-1]+1, distance[i-1][j-1]+((str1[i-1]==str2[j-1])?0:1));
- return distance[l][m]
+ return distance[l][m];
}
- })
+ });
-}()
+}())
View
52 src/mootools.mailcheck.js
@@ -24,12 +24,12 @@
...
*/
-!function(scope) {
+(function(scope){
- 'use strict'
+ 'use strict';
// global cache for all instances
- var cache = {}
+ var cache = {};
var Mailcheck = scope.Mailcheck = new Class({
@@ -93,9 +93,9 @@
},
initialize: function(element, options){
- this.element = document.id(element)
- this.setOptions(options)
- this.cache = cache
+ this.element = document.id(element);
+ this.setOptions(options);
+ this.cache = cache;
},
suggest: function(){
@@ -103,21 +103,21 @@
parts = value.split('@'),
closestDomain,
userBit,
- domainBit
+ domainBit;
if (parts.length < 2)
- return false
+ return false;
- domainBit = parts.pop().toLowerCase()
- userBit = parts.join('@')
+ domainBit = parts.pop().toLowerCase();
+ userBit = parts.join('@');
- closestDomain = typeof this.cache[domainBit] !== 'undefined' ? this.cache[domainBit] : this.findClosestDomain(domainBit)
+ closestDomain = typeof this.cache[domainBit] !== 'undefined' ? this.cache[domainBit] : this.findClosestDomain(domainBit);
return (closestDomain) ? {
user: userBit,
domain: closestDomain,
full: [userBit, closestDomain].join('@')
- } : false
+ } : false;
},
findClosestDomain: function(domain){
@@ -126,40 +126,40 @@
closestDomain,
domains = this.options.domains,
i = 0,
- len = domains.length
+ len = domains.length;
- this.cache[domain] = false
+ this.cache[domain] = false;
for (;i < len; ++i) {
- if (domain === domains[i]) return false
- dist = String[this.options.method](domain, domains[i])
- dist < minDist && (minDist = dist) && (closestDomain = domains[i])
+ if (domain === domains[i]) return false;
+ dist = String[this.options.method](domain, domains[i]);
+ dist < minDist && (minDist = dist) && (closestDomain = domains[i]);
}
if (minDist <= this.options.threshold && closestDomain)
- this.cache[domain] = closestDomain
+ this.cache[domain] = closestDomain;
- return this.cache[domain]
+ return this.cache[domain];
}
- })
+ });
Element.Properties.mailcheck = {
set: function(options){
this.get('mailcheck').setOptions(options);
- return this
+ return this;
},
get: function(){
- var mailcheck = this.retrieve('mailcheck')
+ var mailcheck = this.retrieve('mailcheck');
if (!mailcheck) {
- mailcheck = new Mailcheck(this)
- this.store('mailcheck', mailcheck)
+ mailcheck = new Mailcheck(this);
+ this.store('mailcheck', mailcheck);
}
- return mailcheck
+ return mailcheck;
}
}
-}(this)
+}(this));
Please sign in to comment.
Something went wrong with that request. Please try again.