@dwtechs/slughorn
Version:
is an open source library that transforms string value to a url slug optimized for SEO.
27 lines (21 loc) • 3.7 kB
JavaScript
/*
MIT License
Copyright (c) 2008 DWTechs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
https://github.com/DWTechs/Slughorn.js
*/
var Slughorn=function(exports){"use strict";function isString(string){return"string"==typeof string}function isNumber(number,typeCheck){var sym,type;return void 0===typeCheck&&(typeCheck=!0),"symbol"!=(type=typeof(sym=number))&&("object"!=type||null==sym||"[object Symbol]"!=function(tag){return null==tag?void 0===tag?"[object Undefined]":"[object Null]":toString.call(tag)}(sym))&&(typeCheck?Number(number)===number:function(number){return!isNaN(number-parseFloat(number))}(number))}function isObject(object){return null!==object&&"object"==typeof object&&(null==(array=object)||array.constructor!==Array);var array}return exports.convert=function(url,options){var _map;if(!isString(url))return!1;var number,typeCheck,separator="-",maxLength=80,seo=!0;options&&isObject(options)&&(separator=options.separator&&isString(options.separator)?options.separator:separator,maxLength=options.maxLength&&(number=options.maxLength,void 0===typeCheck&&(typeCheck=!0),!!(isNumber(number,typeCheck)&&0<number))?options.maxLength:maxLength,seo=!(options.seo&&!options.seo)&&seo);var _seoMap,seoMap,pattern,map=((_map={a:/á|à|ã|â|ª/,d:/đ|∂/,e:/é|è|ê/,i:/í|ì|î|ï/,o:/ó|ò|ô|õ/,u:/ú|ù|û|ü/,y:/ÿ|ý|ŷ/,c:/ç/,n:/ñ/,ss:/ß/,ae:/æ/," copyright ":/©/," trademark ":/®/," at ":/@/," equal ":/=/," percent ":/%/," ampersand ":/&/," sharp ":/#/," dollar ":/\$/," and ":/&/," less ":/</," greater ":/>/," or ":/\|/," cent ":/¢/," pound ":/£/," currency ":/¤/," yen ":/¥|円/," ecu ":/₠/," cruzeiro ":/₢/," french franc ":/₣/," lira ":/₤/," mill ":/₥/," naira ":/₦/," peseta ":/₧/," rupee ":/₨/," won ":/₩/," new shequel ":/₪/," dong ":/₫/," euro ":/€/," kip ":/₭/," tugrik ":/₮/," drachma ":/₯/," penny ":/₰/," peso ":/₱/," guarani ":/₲/," austral ":/₳/," hryvnia ":/₴/," cedi ":/₵/," kazakhstani-tenge ":/₸/," indian rupee ":/₹/," turkish lira ":/₺/," russian ruble ":/₽/," bitcoin ":/₿/," sm ":/℠/," tm ":/™/," delta ":/∆/," sum ":/∑/," infinity ":/∞/," love ":/♥/," yuan ":/元/," rial ":/﷼/})[separator]=/ |-|_|\/|\\|`|:|\.|;|,|\?|§|\(|\)|{|}|°|\!|\/|"|\+|\*/,_map);for(pattern in url=url.trim().toLowerCase(),seo&&((_seoMap={})[separator]=/ (the|on|and|is|of|you) /,seoMap=_seoMap,url=url.replace(new RegExp(seoMap[separator],"g"),separator)),map)map.hasOwnProperty(pattern)&&(url=url.replace(new RegExp(map[pattern],"g"),pattern).trim());return url=url.replace(new RegExp(separator+"+(?=)","g"),separator).trim().substring(0,maxLength)},Object.defineProperty(exports,"__esModule",{value:!0}),exports}({});