refactor: replace deprecated String.prototype.substr()

.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
This commit is contained in:
Tobias Speicher 2022-03-25 21:58:50 +01:00 committed by LeoYuan 袁力皓
parent 6b24f9d2ff
commit aca2f08b77
8 changed files with 13 additions and 13 deletions

View File

@ -26,7 +26,7 @@ export default class DragGhost extends Component<{ designer: Designer }> {
makeObservable(this); makeObservable(this);
this.dispose = [ this.dispose = [
this.dragon.onDragstart(e => { this.dragon.onDragstart(e => {
if (e.originalEvent.type.substr(0, 4) === 'drag') { if (e.originalEvent.type.slice(0, 4) === 'drag') {
return; return;
} }
this.dragObject = e.dragObject; this.dragObject = e.dragObject;

View File

@ -56,7 +56,7 @@ export class SettingPropEntry implements SettingEntry {
constructor(readonly parent: SettingEntry, name: string | number, type?: 'field' | 'group') { constructor(readonly parent: SettingEntry, name: string | number, type?: 'field' | 'group') {
makeObservable(this); makeObservable(this);
if (type == null) { if (type == null) {
const c = typeof name === 'string' ? name.substr(0, 1) : ''; const c = typeof name === 'string' ? name.slice(0, 1) : '';
if (c === '#') { if (c === '#') {
this.type = 'group'; this.type = 'group';
} else { } else {

View File

@ -14,7 +14,7 @@ export function getConvertedExtraKey(key: string): string {
if (key.indexOf('.') > 0) { if (key.indexOf('.') > 0) {
_key = key.split('.')[0]; _key = key.split('.')[0];
} }
return EXTRA_KEY_PREFIX + _key + EXTRA_KEY_PREFIX + key.substr(_key.length); return EXTRA_KEY_PREFIX + _key + EXTRA_KEY_PREFIX + key.slice(_key.length);
} }
export function getOriginalExtraKey(key: string): string { export function getOriginalExtraKey(key: string): string {
return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), ''); return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), '');

View File

@ -66,7 +66,7 @@ export function valueToSource(
indentString, indentString,
lineEnding, lineEnding,
visitedObjects: new Set([value, ...visitedObjects]), visitedObjects: new Set([value, ...visitedObjects]),
}).substr(indentLevel * indentString.length)})` }).slice(indentLevel * indentString.length)})`
: `${indentString.repeat(indentLevel)}new Map()`; : `${indentString.repeat(indentLevel)}new Map()`;
} }
@ -85,7 +85,7 @@ export function valueToSource(
indentString, indentString,
lineEnding, lineEnding,
visitedObjects: new Set([value, ...visitedObjects]), visitedObjects: new Set([value, ...visitedObjects]),
}).substr(indentLevel * indentString.length)})` }).slice(indentLevel * indentString.length)})`
: `${indentString.repeat(indentLevel)}new Set()`; : `${indentString.repeat(indentLevel)}new Set()`;
} }
@ -129,7 +129,7 @@ export function valueToSource(
if (item === null) { if (item === null) {
items.push(indentString.repeat(indentLevel + 1)); items.push(indentString.repeat(indentLevel + 1));
} else if (itemsStayOnTheSameLine) { } else if (itemsStayOnTheSameLine) {
items.push(item.substr(indentLevel * indentString.length)); items.push(item.slice(indentLevel * indentString.length));
} else { } else {
items.push(item); items.push(item);
} }
@ -166,11 +166,11 @@ export function valueToSource(
doubleQuote, doubleQuote,
}) })
: propertyName; : propertyName;
const trimmedPropertyValueString = propertyValueString.substr((indentLevel + 1) * indentString.length); const trimmedPropertyValueString = propertyValueString.slice((indentLevel + 1) * indentString.length);
if (typeof propertyValue === 'function' && trimmedPropertyValueString.startsWith(`${propertyName}()`)) { if (typeof propertyValue === 'function' && trimmedPropertyValueString.startsWith(`${propertyName}()`)) {
entries.push( entries.push(
`${indentString.repeat(indentLevel + 1)}${quotedPropertyName} ${trimmedPropertyValueString.substr( `${indentString.repeat(indentLevel + 1)}${quotedPropertyName} ${trimmedPropertyValueString.slice(
propertyName.length, propertyName.length,
)}`, )}`,
); );

View File

@ -79,7 +79,7 @@ function resolvePrefer(prefer: any, targetRect: any, bounds: any) {
} }
const force = prefer[0] === '!'; const force = prefer[0] === '!';
if (force) { if (force) {
prefer = prefer.substr(1); prefer = prefer.slice(1);
} }
let [dir, offset] = prefer.split(/\s+/); let [dir, offset] = prefer.split(/\s+/);
let forceDirection = false; let forceDirection = false;

View File

@ -59,7 +59,7 @@ function matchPath(route, pathname, parentParams) {
} }
return { return {
path: !end && url.charAt(url.length - 1) === '/' ? url.substr(1) : url, path: !end && url.charAt(url.length - 1) === '/' ? url.slice(1) : url,
params, params,
}; };
} }
@ -96,7 +96,7 @@ function matchRoute(route, baseUrl, pathname, parentParams) {
childMatches = matchRoute( childMatches = matchRoute(
childRoute, childRoute,
baseUrl + matched.path, baseUrl + matched.path,
pathname.substr(matched.path.length), pathname.slice(matched.path.length),
matched.params, matched.params,
); );
} }

View File

@ -291,7 +291,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
}); });
this.history = history; this.history = history;
history.listen(({ location }) => { history.listen(({ location }) => {
host.project.open(location.pathname.substr(1)); host.project.open(location.pathname.slice(1));
}); });
host.componentsConsumer.consume(async (componentsAsset) => { host.componentsConsumer.consume(async (componentsAsset) => {
if (componentsAsset) { if (componentsAsset) {

View File

@ -264,7 +264,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
}); });
this.history = history; this.history = history;
history.listen((location, action) => { history.listen((location, action) => {
const docId = location.pathname.substr(1); const docId = location.pathname.slice(1);
docId && host.project.open(docId); docId && host.project.open(docId);
}); });
host.componentsConsumer.consume(async (componentsAsset) => { host.componentsConsumer.consume(async (componentsAsset) => {