Skip to content

Commit aca2f08

Browse files
CommanderRootLeoYuan
authored andcommitted
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>
1 parent 6b24f9d commit aca2f08

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

packages/designer/src/designer/drag-ghost/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class DragGhost extends Component<{ designer: Designer }> {
2626
makeObservable(this);
2727
this.dispose = [
2828
this.dragon.onDragstart(e => {
29-
if (e.originalEvent.type.substr(0, 4) === 'drag') {
29+
if (e.originalEvent.type.slice(0, 4) === 'drag') {
3030
return;
3131
}
3232
this.dragObject = e.dragObject;

packages/designer/src/designer/setting/setting-prop-entry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class SettingPropEntry implements SettingEntry {
5656
constructor(readonly parent: SettingEntry, name: string | number, type?: 'field' | 'group') {
5757
makeObservable(this);
5858
if (type == null) {
59-
const c = typeof name === 'string' ? name.substr(0, 1) : '';
59+
const c = typeof name === 'string' ? name.slice(0, 1) : '';
6060
if (c === '#') {
6161
this.type = 'group';
6262
} else {

packages/designer/src/document/node/props/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function getConvertedExtraKey(key: string): string {
1414
if (key.indexOf('.') > 0) {
1515
_key = key.split('.')[0];
1616
}
17-
return EXTRA_KEY_PREFIX + _key + EXTRA_KEY_PREFIX + key.substr(_key.length);
17+
return EXTRA_KEY_PREFIX + _key + EXTRA_KEY_PREFIX + key.slice(_key.length);
1818
}
1919
export function getOriginalExtraKey(key: string): string {
2020
return key.replace(new RegExp(`${EXTRA_KEY_PREFIX}`, 'g'), '');

packages/designer/src/document/node/props/value-to-source.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function valueToSource(
6666
indentString,
6767
lineEnding,
6868
visitedObjects: new Set([value, ...visitedObjects]),
69-
}).substr(indentLevel * indentString.length)})`
69+
}).slice(indentLevel * indentString.length)})`
7070
: `${indentString.repeat(indentLevel)}new Map()`;
7171
}
7272

@@ -85,7 +85,7 @@ export function valueToSource(
8585
indentString,
8686
lineEnding,
8787
visitedObjects: new Set([value, ...visitedObjects]),
88-
}).substr(indentLevel * indentString.length)})`
88+
}).slice(indentLevel * indentString.length)})`
8989
: `${indentString.repeat(indentLevel)}new Set()`;
9090
}
9191

@@ -129,7 +129,7 @@ export function valueToSource(
129129
if (item === null) {
130130
items.push(indentString.repeat(indentLevel + 1));
131131
} else if (itemsStayOnTheSameLine) {
132-
items.push(item.substr(indentLevel * indentString.length));
132+
items.push(item.slice(indentLevel * indentString.length));
133133
} else {
134134
items.push(item);
135135
}
@@ -166,11 +166,11 @@ export function valueToSource(
166166
doubleQuote,
167167
})
168168
: propertyName;
169-
const trimmedPropertyValueString = propertyValueString.substr((indentLevel + 1) * indentString.length);
169+
const trimmedPropertyValueString = propertyValueString.slice((indentLevel + 1) * indentString.length);
170170

171171
if (typeof propertyValue === 'function' && trimmedPropertyValueString.startsWith(`${propertyName}()`)) {
172172
entries.push(
173-
`${indentString.repeat(indentLevel + 1)}${quotedPropertyName} ${trimmedPropertyValueString.substr(
173+
`${indentString.repeat(indentLevel + 1)}${quotedPropertyName} ${trimmedPropertyValueString.slice(
174174
propertyName.length,
175175
)}`,
176176
);

packages/editor-core/src/widgets/tip/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function resolvePrefer(prefer: any, targetRect: any, bounds: any) {
7979
}
8080
const force = prefer[0] === '!';
8181
if (force) {
82-
prefer = prefer.substr(1);
82+
prefer = prefer.slice(1);
8383
}
8484
let [dir, offset] = prefer.split(/\s+/);
8585
let forceDirection = false;

packages/rax-simulator-renderer/src/rax-use-router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function matchPath(route, pathname, parentParams) {
5959
}
6060

6161
return {
62-
path: !end && url.charAt(url.length - 1) === '/' ? url.substr(1) : url,
62+
path: !end && url.charAt(url.length - 1) === '/' ? url.slice(1) : url,
6363
params,
6464
};
6565
}
@@ -96,7 +96,7 @@ function matchRoute(route, baseUrl, pathname, parentParams) {
9696
childMatches = matchRoute(
9797
childRoute,
9898
baseUrl + matched.path,
99-
pathname.substr(matched.path.length),
99+
pathname.slice(matched.path.length),
100100
matched.params,
101101
);
102102
}

packages/rax-simulator-renderer/src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
291291
});
292292
this.history = history;
293293
history.listen(({ location }) => {
294-
host.project.open(location.pathname.substr(1));
294+
host.project.open(location.pathname.slice(1));
295295
});
296296
host.componentsConsumer.consume(async (componentsAsset) => {
297297
if (componentsAsset) {

packages/react-simulator-renderer/src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
264264
});
265265
this.history = history;
266266
history.listen((location, action) => {
267-
const docId = location.pathname.substr(1);
267+
const docId = location.pathname.slice(1);
268268
docId && host.project.open(docId);
269269
});
270270
host.componentsConsumer.consume(async (componentsAsset) => {

0 commit comments

Comments
 (0)