chore: replace substr with slice (#2738)

This commit is contained in:
Daniel Roe 2022-01-17 10:49:10 +00:00 committed by GitHub
parent e27a0173e8
commit 4111038aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import virtual from './virtual'
const unique = (arr: any[]) => Array.from(new Set(arr))
export function middleware (getMiddleware: () => ServerMiddleware[]) {
const getImportId = p => '_' + hasha(p).substr(0, 6)
const getImportId = p => '_' + hasha(p).slice(0, 6)
let lastDump = ''

View File

@ -75,7 +75,7 @@ export async function renderMiddleware (req, res: ServerResponse) {
let isPayloadReq = false
if (url.startsWith(STATIC_ASSETS_BASE) && url.endsWith(PAYLOAD_JS)) {
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

View File

@ -28,7 +28,7 @@ function filesToMiddleware (files: string[], baseDir: string, basePath: string,
const route = joinURL(
basePath,
file
.substr(0, file.length - extname(file).length)
.slice(0, file.length - extname(file).length)
.replace(/\/index$/, '')
)
const handle = resolve(baseDir, file)

View File

@ -22,7 +22,7 @@ export function compileTemplate (contents: string) {
return (params: Record<string, any>) => contents.replace(/{{ ?([\w.]+) ?}}/g, (_, match) => {
const val = dotProp.get(params, match)
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}`
})

View File

@ -30,5 +30,5 @@ export function hash (input: string, length = 8) {
return createHash('sha256')
.update(input)
.digest('hex')
.substr(0, length)
.slice(0, length)
}