Skip to content

Instantly share code, notes, and snippets.

View omarkdev's full-sized avatar

Marcos Felipe omarkdev

View GitHub Profile
function setApiVersion(constructor) {
return class extends constructor {
version = '0.0.1';
}
}
@setApiVersion
class Wizard {
}
function logProperty(target: any, key: string) {
const newKey = `_${key}`;
Object.defineProperty(target, key, {
get() {
console.log(`Get: ${key} => ${this[newKey]}`);
return this[newKey];
},
set(newVal) {
console.log(`Set: ${key} => ${newVal}`);
function analyze(target: any, key: string) {
console.log(target, key);
}
class Task {
@analyze
public title: string;
constructor(title: string) {
this.title = title;
const arr1 = ['a', 'b', 'c', [1, 2, 3]];
const arr1Flatted = arr1.flat();
// ["a", "b", "c", 1, 2, 3]
const arr1 = ['a', ['b', ['c']], 1, [2, [3, [4, [5]]]]];
const arr1Flatted1 = arr1.flat();
// ["a", "b", Array(1), 1, 2, Array(2)]
const arr1Flatted2 = arr1.flat(2);
// ["a", "b", "c", 1, 2, 3, Array(2)]
const arr1FlattedInfinity = arr1.flat(Infinity);
// ["a", "b", "c", 1, 2, 3, 4, 5]
const arr1 = ['a', 'b', , , , ['c', , 1, null, undefined, '', 0]];
const arr1Flatted = arr1.flat();
// ["a", "b", "c", 1, null, undefined, "", 0]
const arr1 = [1, 2, 3, 4];
const arr1FlattedMultipliedByTwo = arr1.flatMap(v => [ v * 2 ]);
// arr1FlattedMultipliedByTwo
const entries = [ ['name', 'Marcos'], ['site', 'omark.dev'], ['twitter', '@omarkdev'] ];
Object.fromEntries(entries);
// {name: "Marcos", site: "omark.dev", twitter: "@omarkdev"}
const message = ' Hello world! ';
message.trimEnd();
// " Hello world!"
message.trimStart();
// "Hello world! "
const symbol1 = Symbol('Awesome');
symbol1.toString();
// "Symbol(Awesome)"