Ticket #2282: str2url.js

File str2url.js, 868 bytes (added by David Larlet, 18 years ago)

str2url

Line 
1function str2url(str,encoding,ucfirst)
2{
3 str = str.toUpperCase();
4 str = str.toLowerCase();
5
6 str = str.replace(/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]/g,'a');
7 str = str.replace(/[\u00E7]/g,'c');
8 str = str.replace(/[\u00E8\u00E9\u00EA\u00EB]/g,'e');
9 str = str.replace(/[\u00EC\u00ED\u00EE\u00EF]/g,'i');
10 str = str.replace(/[\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8]/g,'o');
11 str = str.replace(/[\u00F9\u00FA\u00FB\u00FC]/g,'u');
12 str = str.replace(/[\u00FD\u00FF]/g,'y');
13 str = str.replace(/[\u00F1]/g,'n');
14 str = str.replace(/[\u0153]/g,'oe');
15 str = str.replace(/[\u00E6]/g,'ae');
16 str = str.replace(/[\u00DF]/g,'ss');
17
18 str = str.replace(/[^a-z0-9_\s\'\:\/\[\]-]/g,'');
19 str = trim(str);
20 str = str.replace(/[\s\'\:\/\[\]-]+/g,' ');
21 str = str.replace(/[ ]/g,'-');
22
23 if (ucfirst == 1) {
24 c = str.charAt(0);
25 str = c.toUpperCase()+str.slice(1);
26 }
27
28 return str;
Back to Top