Skip to content

Commit 4bb83c8

Browse files
authored
chore: prettify smithy-client (#1080)
* chore: prettify smithy-client * chore: prettier-ignore months array * chore: fixes for issues happened during precommit
1 parent 4bc605b commit 4bb83c8

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

packages/smithy-client/src/date-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Builds a proper UTC HttpDate timestamp from a Date object
33
* since not all environments will have this as the expected
44
* format.
5-
*
5+
*
66
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString
77
* > Prior to ECMAScript 2018, the format of the return value
88
* > varied according to the platform. The most common return
@@ -12,6 +12,7 @@
1212

1313
// Build indexes outside so we allocate them once.
1414
const days: Array<String> = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
15+
// prettier-ignore
1516
const months: Array<String> = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
1617

1718
export function dateToUtcString(date: Date): string {
@@ -25,7 +26,8 @@ export function dateToUtcString(date: Date): string {
2526

2627
// Build 0 prefixed strings for contents that need to be
2728
// two digits and where we get an integer back.
28-
const dayOfMonthString = dayOfMonthInt < 10 ? `0${dayOfMonthInt}` : `${dayOfMonthInt}`;
29+
const dayOfMonthString =
30+
dayOfMonthInt < 10 ? `0${dayOfMonthInt}` : `${dayOfMonthInt}`;
2931
const hoursString = hoursInt < 10 ? `0${hoursInt}` : `${hoursInt}`;
3032
const minutesString = minutesInt < 10 ? `0${minutesInt}` : `${minutesInt}`;
3133
const secondsString = secondsInt < 10 ? `0${secondsInt}` : `${secondsInt}`;

packages/smithy-client/src/isa.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
*/
44
export function isa<T>(o: any, ...ids: string[]): o is T {
55
return (
6-
typeof o === "object" && (
7-
// Checks for name after __type, as name is used instead for errors.
8-
"__type" in o && ids.indexOf(o["__type"]) > -1
9-
|| "name" in o && ids.indexOf(o["name"]) > -1
10-
)
6+
typeof o === "object" &&
7+
// Checks for name after __type, as name is used instead for errors.
8+
(("__type" in o && ids.indexOf(o["__type"]) > -1) ||
9+
("name" in o && ids.indexOf(o["name"]) > -1))
1110
);
1211
}

packages/smithy-client/src/lazy-json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface StringWrapper {
1313
* class including its prototype chain. So we can extend from here.
1414
*/
1515
// @ts-ignore StringWrapper implementation is not a simple constructor
16-
export const StringWrapper: StringWrapper = function() {
16+
export const StringWrapper: StringWrapper = function () {
1717
//@ts-ignore 'this' cannot be assigned to any, but Object.getPrototypeOf accepts any
1818
const Class = Object.getPrototypeOf(this).constructor;
1919
const Constructor = Function.bind.apply(String, [null as any, ...arguments]);

packages/smithy-client/src/split-every.spec.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ describe("splitEvery", () => {
1010

1111
it("Errors on <= 0", () => {
1212
expect(() => {
13-
splitEvery(m2, delim, -1)
13+
splitEvery(m2, delim, -1);
1414
}).toThrow("Invalid number of delimiters");
1515

1616
expect(() => {
17-
splitEvery(m2, delim, 0)
17+
splitEvery(m2, delim, 0);
1818
}).toThrow("Invalid number of delimiters");
1919
});
2020

2121
it("Errors on non-integer", () => {
2222
expect(() => {
23-
splitEvery(m2, delim, 1.3)
23+
splitEvery(m2, delim, 1.3);
2424
}).toThrow("Invalid number of delimiters");
2525

2626
expect(() => {
27-
splitEvery(m2, delim, 4.9)
27+
splitEvery(m2, delim, 4.9);
2828
}).toThrow("Invalid number of delimiters");
29-
})
29+
});
3030

3131
it("Handles splitting on 1", () => {
3232
const count = 1;
@@ -36,25 +36,45 @@ describe("splitEvery", () => {
3636
expect(splitEvery(m4, delim, count)).toMatchObject(m4.split(delim));
3737
expect(splitEvery(m5, delim, count)).toMatchObject(m5.split(delim));
3838
expect(splitEvery(m6, delim, count)).toMatchObject(m6.split(delim));
39-
})
39+
});
4040

4141
it("Handles splitting on 2", () => {
4242
const count = 2;
4343
expect(splitEvery(m1, delim, count)).toMatchObject(["foo"]);
4444
expect(splitEvery(m2, delim, count)).toMatchObject(["foo, bar"]);
4545
expect(splitEvery(m3, delim, count)).toMatchObject(["foo, bar", "baz"]);
46-
expect(splitEvery(m4, delim, count)).toMatchObject(["foo, bar", "baz, qux"]);
47-
expect(splitEvery(m5, delim, count)).toMatchObject(["foo, bar", "baz, qux", "coo"]);
48-
expect(splitEvery(m6, delim, count)).toMatchObject(["foo, bar", "baz, qux", "coo, tan"]);
49-
})
46+
expect(splitEvery(m4, delim, count)).toMatchObject([
47+
"foo, bar",
48+
"baz, qux"
49+
]);
50+
expect(splitEvery(m5, delim, count)).toMatchObject([
51+
"foo, bar",
52+
"baz, qux",
53+
"coo"
54+
]);
55+
expect(splitEvery(m6, delim, count)).toMatchObject([
56+
"foo, bar",
57+
"baz, qux",
58+
"coo, tan"
59+
]);
60+
});
5061

5162
it("Handles splitting on 3", () => {
5263
const count = 3;
5364
expect(splitEvery(m1, delim, count)).toMatchObject(["foo"]);
5465
expect(splitEvery(m2, delim, count)).toMatchObject(["foo, bar"]);
5566
expect(splitEvery(m3, delim, count)).toMatchObject(["foo, bar, baz"]);
56-
expect(splitEvery(m4, delim, count)).toMatchObject(["foo, bar, baz", "qux"]);
57-
expect(splitEvery(m5, delim, count)).toMatchObject(["foo, bar, baz", "qux, coo"]);
58-
expect(splitEvery(m6, delim, count)).toMatchObject(["foo, bar, baz", "qux, coo, tan"]);
59-
})
67+
expect(splitEvery(m4, delim, count)).toMatchObject([
68+
"foo, bar, baz",
69+
"qux"
70+
]);
71+
expect(splitEvery(m5, delim, count)).toMatchObject([
72+
"foo, bar, baz",
73+
"qux, coo"
74+
]);
75+
expect(splitEvery(m6, delim, count)).toMatchObject([
76+
"foo, bar, baz",
77+
"qux, coo, tan"
78+
]);
79+
});
6080
});

packages/smithy-client/src/split-every.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
* @param delimiter The delimiter to split on.
77
* @param numDelimiters The number of delimiters to have encountered to split.
88
*/
9-
export function splitEvery(value: string, delimiter: string, numDelimiters: number): Array<string> {
9+
export function splitEvery(
10+
value: string,
11+
delimiter: string,
12+
numDelimiters: number
13+
): Array<string> {
1014
// Fail if we don't have a clear number to split on.
1115
if (numDelimiters <= 0 || !Number.isInteger(numDelimiters)) {
12-
throw new Error("Invalid number of delimiters (" + numDelimiters + ") for splitEvery.");
16+
throw new Error(
17+
"Invalid number of delimiters (" + numDelimiters + ") for splitEvery."
18+
);
1319
}
1420

1521
const segments = value.split(delimiter);

0 commit comments

Comments
 (0)