mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 21:58:19 +00:00
chore: replace substr
with slice
(#2738)
This commit is contained in:
parent
e27a0173e8
commit
4111038aa7
@ -9,7 +9,7 @@ import virtual from './virtual'
|
|||||||
const unique = (arr: any[]) => Array.from(new Set(arr))
|
const unique = (arr: any[]) => Array.from(new Set(arr))
|
||||||
|
|
||||||
export function middleware (getMiddleware: () => ServerMiddleware[]) {
|
export function middleware (getMiddleware: () => ServerMiddleware[]) {
|
||||||
const getImportId = p => '_' + hasha(p).substr(0, 6)
|
const getImportId = p => '_' + hasha(p).slice(0, 6)
|
||||||
|
|
||||||
let lastDump = ''
|
let lastDump = ''
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ export async function renderMiddleware (req, res: ServerResponse) {
|
|||||||
let isPayloadReq = false
|
let isPayloadReq = false
|
||||||
if (url.startsWith(STATIC_ASSETS_BASE) && url.endsWith(PAYLOAD_JS)) {
|
if (url.startsWith(STATIC_ASSETS_BASE) && url.endsWith(PAYLOAD_JS)) {
|
||||||
isPayloadReq = true
|
isPayloadReq = true
|
||||||
url = url.substr(STATIC_ASSETS_BASE.length, url.length - STATIC_ASSETS_BASE.length - PAYLOAD_JS.length) || '/'
|
url = url.slice(STATIC_ASSETS_BASE.length, url.length - PAYLOAD_JS.length) || '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize ssr context
|
// Initialize ssr context
|
||||||
|
@ -28,7 +28,7 @@ function filesToMiddleware (files: string[], baseDir: string, basePath: string,
|
|||||||
const route = joinURL(
|
const route = joinURL(
|
||||||
basePath,
|
basePath,
|
||||||
file
|
file
|
||||||
.substr(0, file.length - extname(file).length)
|
.slice(0, file.length - extname(file).length)
|
||||||
.replace(/\/index$/, '')
|
.replace(/\/index$/, '')
|
||||||
)
|
)
|
||||||
const handle = resolve(baseDir, file)
|
const handle = resolve(baseDir, file)
|
||||||
|
@ -22,7 +22,7 @@ export function compileTemplate (contents: string) {
|
|||||||
return (params: Record<string, any>) => contents.replace(/{{ ?([\w.]+) ?}}/g, (_, match) => {
|
return (params: Record<string, any>) => contents.replace(/{{ ?([\w.]+) ?}}/g, (_, match) => {
|
||||||
const val = dotProp.get(params, match)
|
const val = dotProp.get(params, match)
|
||||||
if (!val) {
|
if (!val) {
|
||||||
consola.warn(`cannot resolve template param '${match}' in ${contents.substr(0, 20)}`)
|
consola.warn(`cannot resolve template param '${match}' in ${contents.slice(0, 20)}`)
|
||||||
}
|
}
|
||||||
return val as string || `${match}`
|
return val as string || `${match}`
|
||||||
})
|
})
|
||||||
|
@ -30,5 +30,5 @@ export function hash (input: string, length = 8) {
|
|||||||
return createHash('sha256')
|
return createHash('sha256')
|
||||||
.update(input)
|
.update(input)
|
||||||
.digest('hex')
|
.digest('hex')
|
||||||
.substr(0, length)
|
.slice(0, length)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user