mirror of https://github.com/IoTcat/docsify.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
673 B
37 lines
673 B
import {hasOwn} from '../util/core' |
|
|
|
let cache = {} |
|
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g |
|
|
|
function lower(string) { |
|
return string.toLowerCase() |
|
} |
|
|
|
export function slugify(str) { |
|
if (typeof str !== 'string') { |
|
return '' |
|
} |
|
|
|
let slug = str |
|
.trim() |
|
.replace(/[A-Z]+/g, lower) |
|
.replace(/<[^>\d]+>/g, '') |
|
.replace(re, '') |
|
.replace(/\s/g, '-') |
|
.replace(/-+/g, '-') |
|
.replace(/^(\d)/, '_$1') |
|
let count = cache[slug] |
|
|
|
count = hasOwn.call(cache, slug) ? count + 1 : 0 |
|
cache[slug] = count |
|
|
|
if (count) { |
|
slug = slug + '-' + count |
|
} |
|
|
|
return slug |
|
} |
|
|
|
slugify.clear = function () { |
|
cache = {} |
|
}
|
|
|