1/** 2 * angular-slugify -- provides slugification for AngularJS 3 * 4 * Copyright © 2013 Paul Smith <[email protected]> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the âSoftwareâ), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in all 14 * copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25(function() { 26 "use strict"; 27 28 var mod = angular.module("slugifier", []); 29 30 // Unicode (non-control) characters in the Latin-1 Supplement and Latin 31 // Extended-A blocks, transliterated into ASCII characters. 32 var charmap = { 33 ' ': " ", 34 '¡': "!", 35 '¢': "c", 36 '£': "lb", 37 'Â¥': "yen", 38 '¦': "|", 39 '§': "SS", 40 '¨': "\"", 41 '©': "(c)", 42 'ª': "a", 43 '«': "<<", 44 '¬': "not", 45 'Â': "-", 46 '®': "(R)", 47 '°': "^0", 48 '±': "+/-", 49 '²': "^2", 50 '³': "^3", 51 '´': "'", 52 'µ': "u", 53 '¶': "P", 54 '·': ".", 55 '¸': ",", 56 '¹': "^1", 57 'º': "o", 58 '»': ">>", 59 '¼': " 1/4 ", 60 '½': " 1/2 ", 61 '¾': " 3/4 ", 62 '¿': "?", 63 'Ã': "`A", 64 'Ã': "'A", 65 'Ã': "^A", 66 'Ã': "~A", 67 'Ã': '"A', 68 'à ': "A", 69 'Ã': "AE", 70 'Ã': "C", 71 'Ã': "`E", 72 'Ã': "'E", 73 'Ã': "^E", 74 'Ã': '"E', 75 'Ã': "`I", 76 'Ã': "'I", 77 'Ã': "^I", 78 'Ã': '"I', 79 'Ã': "D", 80 'Ã': "~N", 81 'Ã': "`O", 82 'Ã': "'O", 83 'Ã': "^O", 84 'Ã': "~O", 85 'Ã': '"O', 86 'Ã': "x", 87 'Ã': "O", 88 'Ã': "`U", 89 'Ã': "'U", 90 'Ã': "^U", 91 'Ã': '"U', 92 'Ã': "'Y", 93 'Ã': "Th", 94 'Ã': "ss", 95 'à ': "`a", 96 'á': "'a", 97 'â': "^a", 98 'ã': "~a", 99 'ä': '"a', 100 'Ã¥': "a", 101 'æ': "ae", 102 'ç': "c", 103 'è': "`e", 104 'é': "'e", 105 'ê': "^e", 106 'ë': '"e', 107 'ì': "`i", 108 'Ã': "'i", 109 'î': "^i", 110 'ï': '"i', 111 'ð': "d", 112 'ñ': "~n", 113 'ò': "`o", 114 'ó': "'o", 115 'ô': "^o", 116 'õ': "~o", 117 'ö': '"o', 118 '÷': ":", 119 'ø': "o", 120 'ù': "`u", 121 'ú': "'u", 122 'û': "^u", 123 'ü': '"u', 124 'ý': "'y", 125 'þ': "th", 126 'ÿ': '"y', 127 'Ä': "A", 128 'Ä': "a", 129 'Ä': "A", 130 'Ä': "a", 131 'Ä': "A", 132 'Ä ': "a", 133 'Ä': "'C", 134 'Ä': "'c", 135 'Ä': "^C", 136 'Ä': "^c", 137 'Ä': "C", 138 'Ä': "c", 139 'Ä': "C", 140 'Ä': "c", 141 'Ä': "D", 142 'Ä': "d", 143 'Ä': "D", 144 'Ä': "d", 145 'Ä': "E", 146 'Ä': "e", 147 'Ä': "E", 148 'Ä': "e", 149 'Ä': "E", 150 'Ä': "e", 151 'Ä': "E", 152 'Ä': "e", 153 'Ä': "E", 154 'Ä': "e", 155 'Ä': "^G", 156 'Ä': "^g", 157 'Ä': "G", 158 'Ä': "g", 159 'Ä ': "G", 160 'Ä¡': "g", 161 'Ä¢': "G", 162 'Ä£': "g", 163 'Ĥ': "^H", 164 'Ä¥': "^h", 165 'Ħ': "H", 166 'ħ': "h", 167 'Ĩ': "~I", 168 'Ä©': "~i", 169 'Ī': "I", 170 'Ä«': "i", 171 'Ĭ': "I", 172 'Ä': "i", 173 'Ä®': "I", 174 'į': "i", 175 'İ': "I", 176 'ı': "i", 177 'IJ': "IJ", 178 'ij': "ij", 179 'Ä´': "^J", 180 'ĵ': "^j", 181 'Ķ': "K", 182 'Ä·': "k", 183 'Ĺ': "L", 184 'ĺ': "l", 185 'Ä»': "L", 186 'ļ': "l", 187 'Ľ': "L", 188 'ľ': "l", 189 'Ä¿': "L", 190 'Å': "l", 191 'Å': "L", 192 'Å': "l", 193 'Å': "'N", 194 'Å': "'n", 195 'Å ': "N", 196 'Å': "n", 197 'Å': "N", 198 'Å': "n", 199 'Å': "'n", 200 'Å': "O", 201 'Å': "o", 202 'Å': "O", 203 'Å': "o", 204 'Å': '"O', 205 'Å': '"o', 206 'Å': "OE", 207 'Å': "oe", 208 'Å': "'R", 209 'Å': "'r", 210 'Å': "R", 211 'Å': "r", 212 'Å': "R", 213 'Å': "r", 214 'Å': "'S", 215 'Å': "'s", 216 'Å': "^S", 217 'Å': "^s", 218 'Å': "S", 219 'Å': "s", 220 'Å ': "S", 221 'Å¡': "s", 222 'Å¢': "T", 223 'Å£': "t", 224 'Ť': "T", 225 'Å¥': "t", 226 'Ŧ': "T", 227 'ŧ': "t", 228 'Ũ': "~U", 229 'Å©': "~u", 230 'Ū': "U", 231 'Å«': "u", 232 'Ŭ': "U", 233 'Å': "u", 234 'Å®': "U", 235 'ů': "u", 236 'Ű': '"U', 237 'ű': '"u', 238 'Ų': "U", 239 'ų': "u", 240 'Å´': "^W",
241 'ŵ': "^w", 242 'Ŷ': "^Y", 243 'ŷ': "^y", 244 'Ÿ': '"Y', 245 'Ź': "'Z", 246 'ź': "'z", 247 'Ż': "Z", 248 'ż': "z", 249 'Ž': "Z", 250 'ž': "z", 251 'ſ': "s" 252 }; 253 254 function _slugify(s) { 255 if (!s) return ""; 256 var ascii = []; 257 var ch, cp; 258 for (var i = 0; i < s.length; i++) { 259 if ((cp = s.charCodeAt(i)) < 0x180) { 260 ch = String.fromCharCode(cp); 261 ascii.push(charmap[ch] || ch); 262 } 263 } 264 s = ascii.join(""); 265 s = s.replace(/[^\w\s-]/g, "").trim().toLowerCase(); 266 return s.replace(/[-\s]+/g, "-"); 267 } 268 269 mod.factory("Slug", function() { 270 return { 271 slugify: _slugify 272 }; 273 }); 274 275 mod.directive("slug", ["Slug", function(Slug) { 276 return { 277 restrict: "E", 278 scope: { 279 to: "=", 280 }, 281 transclude: true, 282 replace: true, 283 template: "<div ng-transclude></div>", 284 link: function(scope, elem, attrs) { 285 if (!attrs.from) { 286 throw "must set attribute 'from'"; 287 } 288 scope.$parent.$watch(attrs.from, function(val) { 289 scope.to = Slug.slugify(val); 290 }); 291 } 292 }; 293 }]); 294 295 mod.filter("slugify", ["Slug", function(Slug) { 296 return function(input) { 297 return Slug.slugify(input); 298 }; 299 }]); 300})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.