MCPcopy
hub / github.com/jamstack-cms/jamstack-ecommerce / slugify

Function slugify

utils/helpers.js:1–14  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

1function slugify(string) {
2 const a = 'àáäâãåăæąçćčđďèéěėëêęğǵḧìíïîįłḿǹńňñòóöôœøṕŕřßşśšșťțùúüûǘůűūųẃẍÿýźžż·/_,:;'
3 const b = 'aaaaaaaaacccddeeeeeeegghiiiiilmnnnnooooooprrsssssttuuuuuuuuuwxyyzzz------'
4 const p = new RegExp(a.split('').join('|'), 'g')
5
6 return string.toString().toLowerCase()
7 .replace(/\s+/g, '-') // Replace spaces with -
8 .replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
9 .replace(/&/g, '-and-') // Replace & with 'and'
10 .replace(/[^\w-]+/g, '') // Remove all non-word characters
11 .replace(/--+/g, '-') // Replace multiple - with single -
12 .replace(/^-+/, '') // Trim - from start of text
13 .replace(/-+$/, '') // Trim - from end of text
14}
15
16function titleIfy(slug) {
17 var words = slug.split('-')

Callers 4

index.jsFile · 0.90
getStaticPathsFunction · 0.90
getStaticPropsFunction · 0.90
[name].jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected