PageSourceSearch

https://www.westcaldwell.com/_Assets/js/angular/libs/slugify/angular-slugify.js

js westcaldwell.com collected 2026-10-02 18:29:06 UTC 7,035 bytes, 300 lines download raw bytes

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': "'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.