summaryrefslogtreecommitdiff
path: root/django/contrib/admin/media/js/urlify.js
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/admin/media/js/urlify.js')
-rw-r--r--django/contrib/admin/media/js/urlify.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/django/contrib/admin/media/js/urlify.js b/django/contrib/admin/media/js/urlify.js
new file mode 100644
index 0000000000..412130ad6f
--- /dev/null
+++ b/django/contrib/admin/media/js/urlify.js
@@ -0,0 +1,16 @@
+function URLify(s, num_chars) {
+ // changes, e.g., "Petty theft" to "petty_theft"
+
+ // remove all these words from the string before urlifying
+ removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from",
+ "is", "in", "into", "like", "of", "off", "on", "onto", "per",
+ "since", "than", "the", "this", "that", "to", "up", "via",
+ "with"];
+ r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi');
+ s = s.replace(r, '');
+ s = s.replace(/[^\w\s]/g, ''); // remove unneeded chars
+ s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
+ s = s.replace(/\s+/g, '_'); // convert spaces to underscores
+ s = s.toLowerCase(); // convert to lowercase
+ return s.substring(0, num_chars);// trim to first num_chars chars
+} \ No newline at end of file