Created
September 18, 2012 09:38
-
-
Save leizongmin/3742269 to your computer and use it in GitHub Desktop.
根据标题生成URL函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 生成用于title的URL | |
* | |
* @param {string} title | |
* @return {string} | |
*/ | |
function titleUrl (title) { | |
if (typeof(title) !== 'string') return false; | |
return title.trim().replace(/[^0-9a-zA-Z \-]/g, '').replace(/[ ]+/g, '-').replace(/[\-]+/g, '-').toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment