From 4111038aa75ff67286186ad16fd34f4f0693e6a9 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 17 Jan 2022 10:49:10 +0000 Subject: [PATCH] chore: replace `substr` with `slice` (#2738) --- packages/nitro/src/rollup/plugins/middleware.ts | 2 +- packages/nitro/src/runtime/app/render.ts | 2 +- packages/nitro/src/server/middleware.ts | 2 +- packages/nitro/src/utils/index.ts | 2 +- packages/vite/src/utils/index.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/nitro/src/rollup/plugins/middleware.ts b/packages/nitro/src/rollup/plugins/middleware.ts index 86c071fad4..895ca03f00 100644 --- a/packages/nitro/src/rollup/plugins/middleware.ts +++ b/packages/nitro/src/rollup/plugins/middleware.ts @@ -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 = '' diff --git a/packages/nitro/src/runtime/app/render.ts b/packages/nitro/src/runtime/app/render.ts index 70fdd3924e..93b63b8f62 100644 --- a/packages/nitro/src/runtime/app/render.ts +++ b/packages/nitro/src/runtime/app/render.ts @@ -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 diff --git a/packages/nitro/src/server/middleware.ts b/packages/nitro/src/server/middleware.ts index 9597236cbe..62684d83f5 100644 --- a/packages/nitro/src/server/middleware.ts +++ b/packages/nitro/src/server/middleware.ts @@ -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) diff --git a/packages/nitro/src/utils/index.ts b/packages/nitro/src/utils/index.ts index 3326f936aa..420f0e3f97 100644 --- a/packages/nitro/src/utils/index.ts +++ b/packages/nitro/src/utils/index.ts @@ -22,7 +22,7 @@ export function compileTemplate (contents: string) { return (params: Record) => 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}` }) diff --git a/packages/vite/src/utils/index.ts b/packages/vite/src/utils/index.ts index 15a0d7bcce..ad6b8d1c18 100644 --- a/packages/vite/src/utils/index.ts +++ b/packages/vite/src/utils/index.ts @@ -30,5 +30,5 @@ export function hash (input: string, length = 8) { return createHash('sha256') .update(input) .digest('hex') - .substr(0, length) + .slice(0, length) }