mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
Refactor r() into utils
This commit is contained in:
parent
b060090fb1
commit
3f84161811
23
lib/utils.js
23
lib/utils.js
@ -1,4 +1,6 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
import { resolve, sep } from 'path'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
export function encodeHtml (str) {
|
export function encodeHtml (str) {
|
||||||
return str.replace(/</g, '<').replace(/>/g, '>')
|
return str.replace(/</g, '<').replace(/>/g, '>')
|
||||||
@ -74,3 +76,24 @@ export function chainFn (base, fn) {
|
|||||||
fn.apply(this, arguments)
|
fn.apply(this, arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wp (p) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (/^win/.test(process.platform)) {
|
||||||
|
p = p.replace(/\\/g, '\\\\')
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqSep = /\//g
|
||||||
|
const sysSep = _.escapeRegExp(sep)
|
||||||
|
const normalize = string => string.replace(reqSep, sysSep)
|
||||||
|
|
||||||
|
export function r () {
|
||||||
|
let args = Array.from(arguments)
|
||||||
|
if (_.last(args).includes('~')) {
|
||||||
|
return wp(_.last(args))
|
||||||
|
}
|
||||||
|
args = args.map(normalize)
|
||||||
|
return wp(resolve.apply(null, args))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user