Files
shields/lib/path-helpers.js
Paul Melnikow 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

31 lines
653 B
JavaScript

'use strict'
// Escapes `t` using the format specified in
// <https://github.com/espadrine/gh-badges/issues/12#issuecomment-31518129>
function escapeFormat(t) {
return (
t
// Inline single underscore.
.replace(/([^_])_([^_])/g, '$1 $2')
// Leading or trailing underscore.
.replace(/([^_])_$/, '$1 ')
.replace(/^_([^_])/, ' $1')
// Double underscore and double dash.
.replace(/__/g, '_')
.replace(/--/g, '-')
)
}
function escapeFormatSlashes(t) {
return (
escapeFormat(t)
// Double slash
.replace(/\/\//g, '/')
)
}
module.exports = {
escapeFormat,
escapeFormatSlashes,
}