Skip to content

Commit 212c866

Browse files
chore: replace deprecated String.prototype.substr() (#3488)
1 parent d3a37b2 commit 212c866

File tree

13 files changed

+15
-15
lines changed

13 files changed

+15
-15
lines changed

clients/client-s3-control/test/S3Control.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("S3Control Client", () => {
1616
s3Control.middlewareStack.add(interceptionMiddleware, { step: "finalizeRequest", name: "interceptionMiddleware" });
1717
const HEADER_OUTPOST_ID = "x-amz-outpost-id";
1818
const HEADER_ACCOUNT_ID = "x-amz-account-id";
19-
const dateStr = new Date().toISOString().substr(0, 10).replace(/[\-:]/g, "");
19+
const dateStr = new Date().toISOString().slice(0, 10).replace(/[\-:]/g, "");
2020

2121
describe("CreateBucket", () => {
2222
it("should populate correct endpoint and signing region", async () => {

clients/client-s3/test/S3.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("Accesspoint ARN", async () => {
9393
Body: "body",
9494
});
9595
expect(result.request.hostname).to.eql(`abc-111-${AccountId}.${OutpostId}.s3-outposts.us-west-2.amazonaws.com`);
96-
const date = new Date().toISOString().substr(0, 10).replace(/-/g, ""); //20201029
96+
const date = new Date().toISOString().slice(0, 10).replace(/-/g, ""); //20201029
9797
expect(result.request.headers["authorization"]).contains(
9898
`Credential=${credentials.accessKeyId}/${date}/${region}/s3-outposts/aws4_request`
9999
);

packages/eventstream-marshaller/scripts/buildTestVectorsFixture.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function headerValue(type, vectorRepresentation) {
8080
return `new Date(${vectorRepresentation})`;
8181
case 9:
8282
const hex = Buffer.from(vectorRepresentation, "base64").toString("hex");
83-
return `'${hex.substr(0, 8)}-${hex.substr(8, 4)}-${hex.substr(12, 4)}-${hex.substr(16, 4)}-${hex.substr(20)}'`;
83+
return `'${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}'`;
8484
default:
8585
return vectorRepresentation;
8686
}

packages/middleware-endpoint-discovery/src/updateDiscoveredEndpointInCache.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe(updateDiscoveredEndpointInCache.name, () => {
4949
expect(mockGet).toHaveBeenCalledTimes(1);
5050

5151
expect(options.endpointDiscoveryCommandCtor).toHaveBeenCalledWith({
52-
Operation: options.commandName.substr(0, options.commandName.length - 7),
52+
Operation: options.commandName.slice(0, -7),
5353
Identifiers: options.identifiers,
5454
});
5555
expect(mockHandler).toHaveBeenCalledTimes(1);
@@ -88,7 +88,7 @@ describe(updateDiscoveredEndpointInCache.name, () => {
8888
expect(mockGet).toHaveBeenCalledTimes(3);
8989

9090
expect(options.endpointDiscoveryCommandCtor).toHaveBeenCalledWith({
91-
Operation: options.commandName.substr(0, options.commandName.length - 7),
91+
Operation: options.commandName.slice(0, -7),
9292
Identifiers: options.identifiers,
9393
});
9494
expect(mockHandler).toHaveBeenCalledTimes(1);

packages/middleware-endpoint-discovery/src/updateDiscoveredEndpointInCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const updateDiscoveredEndpointInCache = async (
3838
endpointCache.set(cacheKey, placeholderEndpoints);
3939

4040
const command = new options.endpointDiscoveryCommandCtor({
41-
Operation: commandName.substr(0, commandName.length - 7), // strip "Command"
41+
Operation: commandName.slice(0, -7), // strip "Command"
4242
Identifiers: identifiers,
4343
});
4444
const handler = command.resolveMiddleware(options.clientStack, config, options.options);

packages/protocol-http/src/httpRequest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class HttpRequest implements HttpMessage, Endpoint {
2222
this.headers = options.headers || {};
2323
this.body = options.body;
2424
this.protocol = options.protocol
25-
? options.protocol.substr(-1) !== ":"
25+
? options.protocol.slice(-1) !== ":"
2626
? `${options.protocol}:`
2727
: options.protocol
2828
: "https:";

packages/s3-presigned-post/src/createPresignedPost.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const createPresignedPost = async (
4141

4242
// signingDate in format like '20201028T070711Z'.
4343
const signingDate = iso8601(now).replace(/[\-:]/g, "");
44-
const shortDate = signingDate.substr(0, 8);
44+
const shortDate = signingDate.slice(0, 8);
4545
const clientRegion = await client.config.region();
4646

4747
// Prepare credentials.

packages/service-client-documentation-generator/src/sdk-client-comment-update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class SdkClientCommentUpdatePlugin extends ConverterComponent {
3131
return comment.startsWith("/*") && comment.endsWith("*/")
3232
? comment
3333
.split("\n")
34-
.filter((line) => line.substr(line.indexOf("*") + 1).trim().length !== 0)
34+
.filter((line) => line.slice(line.indexOf("*") + 1).trim().length !== 0)
3535
.join("\n")
3636
: comment;
3737
}

packages/signature-v4/src/SignatureV4.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ const formatDate = (now: DateInput): { longDate: string; shortDate: string } =>
333333
const longDate = iso8601(now).replace(/[\-:]/g, "");
334334
return {
335335
longDate,
336-
shortDate: longDate.substr(0, 8),
336+
shortDate: longDate.slice(0, 8),
337337
};
338338
};
339339

packages/signature-v4/src/moveHeadersToQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const moveHeadersToQuery = (
1313
typeof (request as any).clone === "function" ? (request as any).clone() : cloneRequest(request);
1414
for (const name of Object.keys(headers)) {
1515
const lname = name.toLowerCase();
16-
if (lname.substr(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) {
16+
if (lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) {
1717
query[name] = headers[name];
1818
delete headers[name];
1919
}

packages/util-base64-browser/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ const maxLetterValue = 0b111111;
4040
*/
4141
export function fromBase64(input: string): Uint8Array {
4242
let totalByteLength = (input.length / 4) * 3;
43-
if (input.substr(-2) === "==") {
43+
if (input.slice(-2) === "==") {
4444
totalByteLength -= 2;
45-
} else if (input.substr(-1) === "=") {
45+
} else if (input.slice(-1) === "=") {
4646
totalByteLength--;
4747
}
4848
const out = new ArrayBuffer(totalByteLength);

packages/util-format-url/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { HttpRequest } from "@aws-sdk/types";
44
export function formatUrl(request: Omit<HttpRequest, "headers" | "method">): string {
55
const { port, query } = request;
66
let { protocol, path, hostname } = request;
7-
if (protocol && protocol.substr(-1) !== ":") {
7+
if (protocol && protocol.slice(-1) !== ":") {
88
protocol += ":";
99
}
1010
if (port) {

packages/util-hex-encoding/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function fromHex(encoded: string): Uint8Array {
2323

2424
const out = new Uint8Array(encoded.length / 2);
2525
for (let i = 0; i < encoded.length; i += 2) {
26-
const encodedByte = encoded.substr(i, 2).toLowerCase();
26+
const encodedByte = encoded.slice(i, i + 2).toLowerCase();
2727
if (encodedByte in HEX_TO_SHORT) {
2828
out[i / 2] = HEX_TO_SHORT[encodedByte];
2929
} else {

0 commit comments

Comments
 (0)