Skip to content

Commit

Permalink
chore: replace deprecated String.prototype.substr() (#3488)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderRoot committed Mar 25, 2022
1 parent d3a37b2 commit 212c866
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion clients/client-s3-control/test/S3Control.spec.ts
Expand Up @@ -16,7 +16,7 @@ describe("S3Control Client", () => {
s3Control.middlewareStack.add(interceptionMiddleware, { step: "finalizeRequest", name: "interceptionMiddleware" });
const HEADER_OUTPOST_ID = "x-amz-outpost-id";
const HEADER_ACCOUNT_ID = "x-amz-account-id";
const dateStr = new Date().toISOString().substr(0, 10).replace(/[\-:]/g, "");
const dateStr = new Date().toISOString().slice(0, 10).replace(/[\-:]/g, "");

describe("CreateBucket", () => {
it("should populate correct endpoint and signing region", async () => {
Expand Down
2 changes: 1 addition & 1 deletion clients/client-s3/test/S3.spec.ts
Expand Up @@ -93,7 +93,7 @@ describe("Accesspoint ARN", async () => {
Body: "body",
});
expect(result.request.hostname).to.eql(`abc-111-${AccountId}.${OutpostId}.s3-outposts.us-west-2.amazonaws.com`);
const date = new Date().toISOString().substr(0, 10).replace(/-/g, ""); //20201029
const date = new Date().toISOString().slice(0, 10).replace(/-/g, ""); //20201029
expect(result.request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${date}/${region}/s3-outposts/aws4_request`
);
Expand Down
Expand Up @@ -80,7 +80,7 @@ function headerValue(type, vectorRepresentation) {
return `new Date(${vectorRepresentation})`;
case 9:
const hex = Buffer.from(vectorRepresentation, "base64").toString("hex");
return `'${hex.substr(0, 8)}-${hex.substr(8, 4)}-${hex.substr(12, 4)}-${hex.substr(16, 4)}-${hex.substr(20)}'`;
return `'${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}'`;
default:
return vectorRepresentation;
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ describe(updateDiscoveredEndpointInCache.name, () => {
expect(mockGet).toHaveBeenCalledTimes(1);

expect(options.endpointDiscoveryCommandCtor).toHaveBeenCalledWith({
Operation: options.commandName.substr(0, options.commandName.length - 7),
Operation: options.commandName.slice(0, -7),
Identifiers: options.identifiers,
});
expect(mockHandler).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -88,7 +88,7 @@ describe(updateDiscoveredEndpointInCache.name, () => {
expect(mockGet).toHaveBeenCalledTimes(3);

expect(options.endpointDiscoveryCommandCtor).toHaveBeenCalledWith({
Operation: options.commandName.substr(0, options.commandName.length - 7),
Operation: options.commandName.slice(0, -7),
Identifiers: options.identifiers,
});
expect(mockHandler).toHaveBeenCalledTimes(1);
Expand Down
Expand Up @@ -38,7 +38,7 @@ export const updateDiscoveredEndpointInCache = async (
endpointCache.set(cacheKey, placeholderEndpoints);

const command = new options.endpointDiscoveryCommandCtor({
Operation: commandName.substr(0, commandName.length - 7), // strip "Command"
Operation: commandName.slice(0, -7), // strip "Command"
Identifiers: identifiers,
});
const handler = command.resolveMiddleware(options.clientStack, config, options.options);
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-http/src/httpRequest.ts
Expand Up @@ -22,7 +22,7 @@ export class HttpRequest implements HttpMessage, Endpoint {
this.headers = options.headers || {};
this.body = options.body;
this.protocol = options.protocol
? options.protocol.substr(-1) !== ":"
? options.protocol.slice(-1) !== ":"
? `${options.protocol}:`
: options.protocol
: "https:";
Expand Down
2 changes: 1 addition & 1 deletion packages/s3-presigned-post/src/createPresignedPost.ts
Expand Up @@ -41,7 +41,7 @@ export const createPresignedPost = async (

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

// Prepare credentials.
Expand Down
Expand Up @@ -31,7 +31,7 @@ export class SdkClientCommentUpdatePlugin extends ConverterComponent {
return comment.startsWith("/*") && comment.endsWith("*/")
? comment
.split("\n")
.filter((line) => line.substr(line.indexOf("*") + 1).trim().length !== 0)
.filter((line) => line.slice(line.indexOf("*") + 1).trim().length !== 0)
.join("\n")
: comment;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/signature-v4/src/SignatureV4.ts
Expand Up @@ -333,7 +333,7 @@ const formatDate = (now: DateInput): { longDate: string; shortDate: string } =>
const longDate = iso8601(now).replace(/[\-:]/g, "");
return {
longDate,
shortDate: longDate.substr(0, 8),
shortDate: longDate.slice(0, 8),
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/signature-v4/src/moveHeadersToQuery.ts
Expand Up @@ -13,7 +13,7 @@ export const moveHeadersToQuery = (
typeof (request as any).clone === "function" ? (request as any).clone() : cloneRequest(request);
for (const name of Object.keys(headers)) {
const lname = name.toLowerCase();
if (lname.substr(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) {
if (lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) {
query[name] = headers[name];
delete headers[name];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/util-base64-browser/src/index.ts
Expand Up @@ -40,9 +40,9 @@ const maxLetterValue = 0b111111;
*/
export function fromBase64(input: string): Uint8Array {
let totalByteLength = (input.length / 4) * 3;
if (input.substr(-2) === "==") {
if (input.slice(-2) === "==") {
totalByteLength -= 2;
} else if (input.substr(-1) === "=") {
} else if (input.slice(-1) === "=") {
totalByteLength--;
}
const out = new ArrayBuffer(totalByteLength);
Expand Down
2 changes: 1 addition & 1 deletion packages/util-format-url/src/index.ts
Expand Up @@ -4,7 +4,7 @@ import { HttpRequest } from "@aws-sdk/types";
export function formatUrl(request: Omit<HttpRequest, "headers" | "method">): string {
const { port, query } = request;
let { protocol, path, hostname } = request;
if (protocol && protocol.substr(-1) !== ":") {
if (protocol && protocol.slice(-1) !== ":") {
protocol += ":";
}
if (port) {
Expand Down
2 changes: 1 addition & 1 deletion packages/util-hex-encoding/src/index.ts
Expand Up @@ -23,7 +23,7 @@ export function fromHex(encoded: string): Uint8Array {

const out = new Uint8Array(encoded.length / 2);
for (let i = 0; i < encoded.length; i += 2) {
const encodedByte = encoded.substr(i, 2).toLowerCase();
const encodedByte = encoded.slice(i, i + 2).toLowerCase();
if (encodedByte in HEX_TO_SHORT) {
out[i / 2] = HEX_TO_SHORT[encodedByte];
} else {
Expand Down

0 comments on commit 212c866

Please sign in to comment.