Skip to content

Instantly share code, notes, and snippets.

const credentials = {
username: process.env.USERNAME ?? '',
password: process.env.PASSWORD ?? '',
};
export class AuthPage {
constructor(page, baseUrl = '') {
this.page = page;
this.baseUrl = baseUrl;
}
const TRUCK = 1;
function getCarByType(type) {
if (type === TRUCK) {
return { name: 'Super Truck' }; // imagine that it's a truck object
}
return { name: 'Usual Car' };
}
try {
// your code is here
} catch(e) {
// in case of exception, handle it here
}
@rkhaslarov
rkhaslarov / builder-pattern.js
Last active July 14, 2022 10:46
"Less popular" JavaScript Design Patterns
class Report {
constructor(consumer, products, preferences) {
this.consumer = consumer;
this.products = products;
this.preferences = preferences;
}
}
class ReportBuilder {
constructor() {
// Given an array of strings, return another array containing all of its longest strings.
function getAllLongestStrings(inputArray) {}
export function call<Ctx extends { [P in Name]:
(this: Ctx, ...args: any[]) => any }, Name extends string>(
ctxAndFnName: [Ctx, Name],
...args: Parameters<Ctx[Name]>
): CallEffect<SagaReturnType<Ctx[Name]>