forked from Teradata/lasca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlasca.nouca.min.js
16 lines (16 loc) · 4.46 KB
/
lasca.nouca.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
* Copyright © 2011-2012 by Teradata Corporation.
*
* Issued under the MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function(a){"use strict";var b={},c={},d={},e={},f={},g=[],h=-1,i,j={},k=typeof exports!="undefined"?!0:!1,l=function(a){var b,c,d=0,e=0,g=0,h="",i="",j=0,k,l=[],m=[],n,o=function(){};c=a.split(""),e=c.length,b=[];for(d;d<e;d++){c[d]!=="+"&&(h+=c[d].toString(),g++);if(g===4){i=c[d+1];if(i!=="+"){m=h.replace(/\w{4}/g,"|$&"),n="",m=m.split("|"),m.shift();for(var p=0;p<m.length;p++)n+=String.fromCharCode(parseInt("0x"+m[p],16));b.push(n),m.length>1&&l.push({codePoints:n,collationWeight:b.length-1}),h=""}g=0}}f.language.collation=b,l.length&&(f.language.multiLetters=l,o())};e.single=function(a,b){i&&(a=a[i],b=b[i]);if(a===b)return 0;var c,d,e,g,j=f.language.collation,k=0,l=0,m=f.language.collationLength,n=function(a){var b=0;for(b=0;b<m;b++)if(j[b]===a)return b;return-1};c=a.split(""),d=b.split(""),l=Math.min(c.length,d.length);for(k=0;k<l;k++){e=n(c[k]),g=n(d[k]);if(e===-1||g===-1)return h===-1&&(typeof f.language.compareNonCollVal=="function"?h=!0:h=!1),h?f.language.compareNonCollVal(c[k],d[k]):c[k].charCodeAt(0)>d[k].charCodeAt(0)?1:-1;if(e>g)return 1;if(e<g)return-1}return a.length>b.length?-1:1},e.multi=function(a,b){i&&(a=a[i],b=b[i]);if(a===b)return 0;var c={},d=!1,g,j,k=0,l=0,m=-1,n=-1,o=-1,p=-1,q=f.language.collationLength,r=f.language.collation,s=0,t=0,u=function(a){var b=0;for(b=0;b<q;b++)if(r[b]===a)return b;return-1};c.a={},c.b={};var v=function(){var e=f.language.multiLetters,g=0,h=e.length,i,j;for(g;g<h;g++)o=a.indexOf(e[g].codePoints),p=b.indexOf(e[g].codePoints),o!==-1&&(c.a[o]=e[g].collationWeight,d=!0),p!==-1&&(c.b[p]=e[g].collationWeight,d=!0),o=-1,p=-1};v();if(!d)return e.single(a,b);g=a.split(""),j=b.split(""),l=Math.min(g.length,j.length);for(k=0;k<l;k++)return m=c.a[k],n=c.b[k],o=m&&m!==-1?m:u(g[k]),p=n&&n!==-1?n:u(j[k]),o===-1||p===-1?(h===-1&&(typeof f.language.compareNonCollVal=="function"?h=!0:h=!1),h?f.language.compareNonCollVal(g[k],j[k]):g[k].charCodeAt(0)>j[k].charCodeAt(0)?1:-1):o>p?1:o<p?-1:(m!==-1||n!==-1?(m!==-1&&(s+=r[m].length),n!==-1&&(t+=r[n].length)):(s++,t++),m=-1,n=-1,o.length>p.length?-1:1)},f.setLanguage=function(a){var b=this,c=g.length,d=0,f=!1,h=function(){l(b.language.collation),b.language.compiled=!0,b.language.collationLength=b.language.collation.length,typeof b.language.compare=="string"&&(b.language.compare=e[b.language.compare])};if(Object.prototype.toString.call(a)==="[object Object]"){if(!a.key||0)throw'Lasca says, "You must define a unique key for your collation."';if(!a.collation)throw'Lasca says, "You must define a collation."';if(!a.compare)throw'Lasca says, "You must define a compare type."';g.push(a),b.language=g[c-1],h()}else for(d;d<c;d++)if(g[d].key===a){b.language=g[d],b.language.compiled||h();break}},f.setNonCollValCompare=function(a){typeof a=="function"?(this.language.compareNonCollVal=a,h=!0):(typeof this.language.compareNonCollVal!==undefined&&delete this.language.compareNonCollVal,h=!1)},f.sort=function(a,b){return i=b?b:null,!this.language.compare||!this.language.collation?a:a.sort(this.language.compare)},f.compare=function(a,b){return i=null,!this.language.compare||!this.language.collation?array:this.language.compare(a,b)},f.getLanguageKeys=function(){var a=[],b=g.length,c=0;for(c;c<b;c++)a.push(g[c].key);return a},f.getLanguage=function(a){var b=[],c=g.length,d=0;for(d;d<c;d++)if(g[d].key===a)return g[d];return},k?module.exports=f:typeof define=="function"?define(f):a.lasca=f})(this)