提交 3cf64914 编写于 作者: fxy060608's avatar fxy060608 提交者: qiang

chore: substr => slice

上级 4940892a
......@@ -7,13 +7,13 @@ export function encodeQueryString(url: string) {
return url
}
const query = url
.substr(index + 1)
.slice(index + 1)
.trim()
.replace(/^(\?|#|&)/, '')
if (!query) {
return url
}
url = url.substr(0, index)
url = url.slice(0, index)
const params: string[] = []
query.split('&').forEach((param) => {
const parts = param.replace(/\+/g, ' ').split('=')
......
......@@ -181,7 +181,7 @@ function createNormalizeUrl(type: string) {
}
if (routeOptions.meta.isTabBar) {
const pages = getCurrentPages()
const tabBarPagePath = routeOptions.path.substr(1)
const tabBarPagePath = routeOptions.path.slice(1)
if (pages.find((page) => page.route === tabBarPagePath)) {
return 'tabBar page `' + tabBarPagePath + '` already exists'
}
......
......@@ -1609,7 +1609,7 @@ function getRealRoute(fromRoute, toRoute) {
return toRoute;
}
if (toRoute.indexOf('./') === 0) {
return getRealRoute(fromRoute, toRoute.substr(2));
return getRealRoute(fromRoute, toRoute.slice(2));
}
const toRouteArray = toRoute.split('/');
const toRouteLength = toRouteArray.length;
......@@ -11956,13 +11956,13 @@ function encodeQueryString(url) {
return url;
}
const query = url
.substr(index + 1)
.slice(index + 1)
.trim()
.replace(/^(\?|#|&)/, '');
if (!query) {
return url;
}
url = url.substr(0, index);
url = url.slice(0, index);
const params = [];
query.split('&').forEach((param) => {
const parts = param.replace(/\+/g, ' ').split('=');
......@@ -12115,7 +12115,7 @@ function createNormalizeUrl(type) {
}
if (routeOptions.meta.isTabBar) {
const pages = getCurrentPages();
const tabBarPagePath = routeOptions.path.substr(1);
const tabBarPagePath = routeOptions.path.slice(1);
if (pages.find((page) => page.route === tabBarPagePath)) {
return 'tabBar page `' + tabBarPagePath + '` already exists';
}
......@@ -14481,7 +14481,7 @@ const cookiesParse = (header) => {
};
function formatResponse(res, args) {
if (typeof res.data === 'string' && res.data.charCodeAt(0) === 65279) {
res.data = res.data.substr(1);
res.data = res.data.slice(1);
}
res.statusCode = parseInt(String(res.statusCode), 10);
if (isPlainObject(res.header)) {
......@@ -15308,7 +15308,7 @@ function initMusic() {
if (event === 'pause' || event === 'ended' || event === 'stop') {
stopTimeUpdateTimer();
}
const eventName = `onMusic${event[0].toUpperCase() + event.substr(1)}`;
const eventName = `onMusic${event[0].toUpperCase() + event.slice(1)}`;
publish(eventName, {
dataUrl: audio.src,
errMsg: `${eventName}:ok`,
......@@ -17475,8 +17475,8 @@ function encode(val) {
function initUniPageUrl(path, query) {
const queryString = query ? stringifyQuery$1(query, encode) : '';
return {
path: path.substr(1),
query: queryString ? queryString.substr(1) : queryString,
path: path.slice(1),
query: queryString ? queryString.slice(1) : queryString,
};
}
function initDebugRefresh(isTab, path, query) {
......@@ -17484,8 +17484,8 @@ function initDebugRefresh(isTab, path, query) {
return {
isTab,
arguments: JSON.stringify({
path: path.substr(1),
query: queryString ? queryString.substr(1) : queryString,
path: path.slice(1),
query: queryString ? queryString.slice(1) : queryString,
}),
};
}
......
......@@ -127,7 +127,7 @@ function initMusic() {
stopTimeUpdateTimer()
}
const eventName = `onMusic${event[0].toUpperCase() + event.substr(1)}`
const eventName = `onMusic${event[0].toUpperCase() + event.slice(1)}`
publish(eventName, {
dataUrl: audio.src,
errMsg: `${eventName}:ok`,
......
......@@ -54,7 +54,7 @@ const cookiesParse = (header: Record<string, string>) => {
function formatResponse(res: RequestTaskState, args: UniApp.RequestOptions) {
if (typeof res.data === 'string' && res.data.charCodeAt(0) === 65279) {
res.data = res.data.substr(1)
res.data = res.data.slice(1)
}
res.statusCode = parseInt(String(res.statusCode), 10)
......
......@@ -20,8 +20,8 @@ export type DebugRefresh = ReturnType<typeof initDebugRefresh>
export function initUniPageUrl(path: string, query: Record<string, any>) {
const queryString = query ? stringifyQuery(query, encode) : ''
return {
path: path.substr(1),
query: queryString ? queryString.substr(1) : queryString,
path: path.slice(1),
query: queryString ? queryString.slice(1) : queryString,
}
}
......@@ -34,8 +34,8 @@ export function initDebugRefresh(
return {
isTab,
arguments: JSON.stringify({
path: path.substr(1),
query: queryString ? queryString.substr(1) : queryString,
path: path.slice(1),
query: queryString ? queryString.slice(1) : queryString,
}),
}
}
......@@ -47,9 +47,9 @@ function parseHex(color: string) {
opacity: 1,
}
}
const opacity = color.substr(7, 2)
const opacity = color.slice(7, 9)
return {
color: color.substr(0, 7),
color: color.slice(0, 7),
opacity: opacity ? Number('0x' + opacity) / 255 : 1,
}
}
......
......@@ -11,7 +11,7 @@ export function decodeAttr(el: UniCustomElement, value: unknown) {
return value
}
if (value.indexOf(JSON_PROTOCOL) === 0) {
value = JSON.parse(value.substr(JSON_PROTOCOL_LEN))
value = JSON.parse(value.slice(JSON_PROTOCOL_LEN))
} else if (value.indexOf(WXS_PROTOCOL) === 0) {
value = invokeWxs(el, value)
}
......
......@@ -86,7 +86,7 @@ function resolveOwnerEl(el: UniCustomElement, ownerId: number) {
}
function parseWxs(wxsStr: string) {
return JSON.parse(wxsStr.substr(WXS_PROTOCOL_LEN)) as [
return JSON.parse(wxsStr.slice(WXS_PROTOCOL_LEN)) as [
number,
string,
string,
......@@ -140,7 +140,7 @@ function getWxsProp(
if (!module) {
return console.error(formatLog('wxs', 'module ' + dataPath + ' not found'))
}
return getValueByDataPath(module, dataPath.substr(dataPath.indexOf('.') + 1))
return getValueByDataPath(module, dataPath.slice(dataPath.indexOf('.') + 1))
}
export type WxsPropsInvoker = (newValue: unknown) => void
......
......@@ -124,7 +124,7 @@ function initEasycom({
Object.keys(custom).forEach((name) => {
const componentPath = custom[name]
easycomsObj[name] = componentPath.startsWith('@/')
? normalizePath(path.join(rootDir!, componentPath.substr(2)))
? normalizePath(path.join(rootDir!, componentPath.slice(2)))
: componentPath
})
}
......
......@@ -47,9 +47,7 @@ function resolveNodeModulePath(modulePath: string) {
}
const index = modulePath.lastIndexOf('node_modules')
if (index > -1) {
nodeModulesPaths.push(
path.join(modulePath.substr(0, index), 'node_modules')
)
nodeModulesPaths.push(path.join(modulePath.slice(0, index), 'node_modules'))
}
return nodeModulesPaths
}
......
......@@ -17,7 +17,7 @@ export function getRealRoute(fromRoute: string, toRoute: string): string {
return toRoute
}
if (toRoute.indexOf('./') === 0) {
return getRealRoute(fromRoute, toRoute.substr(2))
return getRealRoute(fromRoute, toRoute.slice(2))
}
const toRouteArray = toRoute.split('/')
const toRouteLength = toRouteArray.length
......
......@@ -122,7 +122,7 @@ export function assetFileNamesToFileName(
// placeholders for `assetFileNames`
// `hash` is slightly different from the rollup's one
const extname = path.extname(basename)
const ext = extname.substr(1)
const ext = extname.slice(1)
const name = basename.slice(0, -extname.length)
const hash = contentHash
......
......@@ -239,7 +239,7 @@ ${globalName}.__uniRoutes=[${[
...generatePagesRoute(normalizePagesRoute(pagesJson), config),
].join(
','
)}].map(uniRoute=>(uniRoute.meta.route = (uniRoute.alias || uniRoute.path).substr(1),uniRoute))`
)}].map(uniRoute=>(uniRoute.meta.route = (uniRoute.alias || uniRoute.path).slice(1),uniRoute))`
}
function generateConfig(
......
......@@ -349,7 +349,7 @@ function getRealRoute(fromRoute, toRoute) {
return toRoute;
}
if (toRoute.indexOf("./") === 0) {
return getRealRoute(fromRoute, toRoute.substr(2));
return getRealRoute(fromRoute, toRoute.slice(2));
}
const toRouteArray = toRoute.split("/");
const toRouteLength = toRouteArray.length;
......@@ -899,7 +899,7 @@ function getRealPath(filePath) {
}
const pages = getCurrentPages();
if (pages.length) {
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1));
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).slice(1));
}
return filePath;
}
......
......@@ -989,7 +989,7 @@ function getRealRoute(fromRoute, toRoute) {
return toRoute;
}
if (toRoute.indexOf("./") === 0) {
return getRealRoute(fromRoute, toRoute.substr(2));
return getRealRoute(fromRoute, toRoute.slice(2));
}
const toRouteArray = toRoute.split("/");
const toRouteLength = toRouteArray.length;
......@@ -2012,7 +2012,7 @@ function getRealPath(filePath) {
}
const pages = getCurrentPages();
if (pages.length) {
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1));
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).slice(1));
}
return filePath;
}
......@@ -5102,11 +5102,11 @@ function encodeQueryString(url) {
if (index2 === -1) {
return url;
}
const query = url.substr(index2 + 1).trim().replace(/^(\?|#|&)/, "");
const query = url.slice(index2 + 1).trim().replace(/^(\?|#|&)/, "");
if (!query) {
return url;
}
url = url.substr(0, index2);
url = url.slice(0, index2);
const params = [];
query.split("&").forEach((param) => {
const parts = param.replace(/\+/g, " ").split("=");
......@@ -5232,7 +5232,7 @@ function createNormalizeUrl(type) {
} else if (type === API_PRELOAD_PAGE) {
if (routeOptions.meta.isTabBar) {
const pages = getCurrentPages();
const tabBarPagePath = routeOptions.path.substr(1);
const tabBarPagePath = routeOptions.path.slice(1);
if (pages.find((page) => page.route === tabBarPagePath)) {
return "tabBar page `" + tabBarPagePath + "` already exists";
}
......@@ -16110,7 +16110,7 @@ class InnerAudioContext {
if (this._stoping && stopEventNames.indexOf(eventName) >= 0) {
return;
}
const EventName = `on${eventName.substr(0, 1).toUpperCase()}${eventName.substr(1)}`;
const EventName = `on${eventName.slice(0, 1).toUpperCase()}${eventName.slice(1)}`;
this._events[EventName].forEach((callback) => {
callback();
});
......
......@@ -56,7 +56,7 @@ export function getRealPath(filePath: string) {
const pages = getCurrentPages()
if (pages.length) {
return addBase(
getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1)
getRealRoute(pages[pages.length - 1].$page.route, filePath).slice(1)
)
}
......
......@@ -189,8 +189,8 @@ class InnerAudioContext implements UniApp.InnerAudioContext {
return
}
const EventName = `on${eventName
.substr(0, 1)
.toUpperCase()}${eventName.substr(1)}` as InnerAudioContextEvent
.slice(0, 1)
.toUpperCase()}${eventName.slice(1)}` as InnerAudioContextEvent
this._events[EventName]!.forEach((callback) => {
callback()
})
......
......@@ -691,7 +691,7 @@ function initSpecialMethods(mpInstance) {
return;
}
if (path.indexOf('/') === 0) {
path = path.substr(1);
path = path.slice(1);
}
const specialMethods = my.specialMethods && my.specialMethods[path];
if (specialMethods) {
......
......@@ -53,7 +53,7 @@ export function initSpecialMethods(
return
}
if (path.indexOf('/') === 0) {
path = path.substr(1)
path = path.slice(1)
}
const specialMethods =
(my as any).specialMethods && (my as any).specialMethods[path]
......
......@@ -42,7 +42,7 @@ export const decodeHtml: ParserOptions['decodeEntities'] = (
)
}
for (let length = maxCRNameLength; !value && length > 0; --length) {
name = rawText.substr(1, length)
name = rawText.slice(1, 1 + length)
value = (namedCharacterReferences as Record<string, string>)[name]
}
if (value) {
......
......@@ -332,7 +332,7 @@ function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
return hasLeadingSlash(str) ? str.slice(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
......
......@@ -328,7 +328,7 @@ function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
return hasLeadingSlash(str) ? str.slice(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
......
......@@ -25,7 +25,7 @@ export function addLeadingSlash(str: string) {
}
export function removeLeadingSlash(str: string) {
return hasLeadingSlash(str) ? str.substr(1) : str
return hasLeadingSlash(str) ? str.slice(1) : str
}
export const invokeArrayFns = (fns: Function[], arg?: any) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册