Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prettify smithy-client #1080

Merged
merged 3 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/smithy-client/src/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Builds a proper UTC HttpDate timestamp from a Date object
* since not all environments will have this as the expected
* format.
*
*
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString
* > Prior to ECMAScript 2018, the format of the return value
* > varied according to the platform. The most common return
Expand All @@ -12,6 +12,7 @@

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

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

// Build 0 prefixed strings for contents that need to be
// two digits and where we get an integer back.
const dayOfMonthString = dayOfMonthInt < 10 ? `0${dayOfMonthInt}` : `${dayOfMonthInt}`;
const dayOfMonthString =
dayOfMonthInt < 10 ? `0${dayOfMonthInt}` : `${dayOfMonthInt}`;
const hoursString = hoursInt < 10 ? `0${hoursInt}` : `${hoursInt}`;
const minutesString = minutesInt < 10 ? `0${minutesInt}` : `${minutesInt}`;
const secondsString = secondsInt < 10 ? `0${secondsInt}` : `${secondsInt}`;
Expand Down
9 changes: 4 additions & 5 deletions packages/smithy-client/src/isa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
*/
export function isa<T>(o: any, ...ids: string[]): o is T {
return (
typeof o === "object" && (
// Checks for name after __type, as name is used instead for errors.
"__type" in o && ids.indexOf(o["__type"]) > -1
|| "name" in o && ids.indexOf(o["name"]) > -1
)
typeof o === "object" &&
// Checks for name after __type, as name is used instead for errors.
(("__type" in o && ids.indexOf(o["__type"]) > -1) ||
("name" in o && ids.indexOf(o["name"]) > -1))
);
}
2 changes: 1 addition & 1 deletion packages/smithy-client/src/lazy-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface StringWrapper {
* class including its prototype chain. So we can extend from here.
*/
// @ts-ignore StringWrapper implementation is not a simple constructor
export const StringWrapper: StringWrapper = function() {
export const StringWrapper: StringWrapper = function () {
//@ts-ignore 'this' cannot be assigned to any, but Object.getPrototypeOf accepts any
const Class = Object.getPrototypeOf(this).constructor;
const Constructor = Function.bind.apply(String, [null as any, ...arguments]);
Expand Down
48 changes: 34 additions & 14 deletions packages/smithy-client/src/split-every.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ describe("splitEvery", () => {

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

expect(() => {
splitEvery(m2, delim, 0)
splitEvery(m2, delim, 0);
}).toThrow("Invalid number of delimiters");
});

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

expect(() => {
splitEvery(m2, delim, 4.9)
splitEvery(m2, delim, 4.9);
}).toThrow("Invalid number of delimiters");
})
});

it("Handles splitting on 1", () => {
const count = 1;
Expand All @@ -36,25 +36,45 @@ describe("splitEvery", () => {
expect(splitEvery(m4, delim, count)).toMatchObject(m4.split(delim));
expect(splitEvery(m5, delim, count)).toMatchObject(m5.split(delim));
expect(splitEvery(m6, delim, count)).toMatchObject(m6.split(delim));
})
});

it("Handles splitting on 2", () => {
const count = 2;
expect(splitEvery(m1, delim, count)).toMatchObject(["foo"]);
expect(splitEvery(m2, delim, count)).toMatchObject(["foo, bar"]);
expect(splitEvery(m3, delim, count)).toMatchObject(["foo, bar", "baz"]);
expect(splitEvery(m4, delim, count)).toMatchObject(["foo, bar", "baz, qux"]);
expect(splitEvery(m5, delim, count)).toMatchObject(["foo, bar", "baz, qux", "coo"]);
expect(splitEvery(m6, delim, count)).toMatchObject(["foo, bar", "baz, qux", "coo, tan"]);
})
expect(splitEvery(m4, delim, count)).toMatchObject([
"foo, bar",
"baz, qux"
]);
expect(splitEvery(m5, delim, count)).toMatchObject([
"foo, bar",
"baz, qux",
"coo"
]);
expect(splitEvery(m6, delim, count)).toMatchObject([
"foo, bar",
"baz, qux",
"coo, tan"
]);
});

it("Handles splitting on 3", () => {
const count = 3;
expect(splitEvery(m1, delim, count)).toMatchObject(["foo"]);
expect(splitEvery(m2, delim, count)).toMatchObject(["foo, bar"]);
expect(splitEvery(m3, delim, count)).toMatchObject(["foo, bar, baz"]);
expect(splitEvery(m4, delim, count)).toMatchObject(["foo, bar, baz", "qux"]);
expect(splitEvery(m5, delim, count)).toMatchObject(["foo, bar, baz", "qux, coo"]);
expect(splitEvery(m6, delim, count)).toMatchObject(["foo, bar, baz", "qux, coo, tan"]);
})
expect(splitEvery(m4, delim, count)).toMatchObject([
"foo, bar, baz",
"qux"
]);
expect(splitEvery(m5, delim, count)).toMatchObject([
"foo, bar, baz",
"qux, coo"
]);
expect(splitEvery(m6, delim, count)).toMatchObject([
"foo, bar, baz",
"qux, coo, tan"
]);
});
});
10 changes: 8 additions & 2 deletions packages/smithy-client/src/split-every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
* @param delimiter The delimiter to split on.
* @param numDelimiters The number of delimiters to have encountered to split.
*/
export function splitEvery(value: string, delimiter: string, numDelimiters: number): Array<string> {
export function splitEvery(
value: string,
delimiter: string,
numDelimiters: number
): Array<string> {
// Fail if we don't have a clear number to split on.
if (numDelimiters <= 0 || !Number.isInteger(numDelimiters)) {
throw new Error("Invalid number of delimiters (" + numDelimiters + ") for splitEvery.");
throw new Error(
"Invalid number of delimiters (" + numDelimiters + ") for splitEvery."
);
}

const segments = value.split(delimiter);
Expand Down