This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ORIGINAL CODE https://github.com/jscutlery/devkit/tree/main/packages/operators | |
import { | |
MonoTypeOperatorFunction, | |
Observable, | |
ObservableNotification, | |
OperatorFunction, | |
ReplaySubject, | |
} from 'rxjs'; | |
import { debounce, map, materialize, scan, startWith } from 'rxjs/operators'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef } from "@angular/core"; | |
import { AuthService } from "./auth.service"; | |
import { Subscription, Subject } from "rxjs"; | |
@Directive({ | |
selector: "[hasRole]", | |
standalone: true | |
}) | |
export class HasRoleDirective { | |
constructor( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ORIGINAL CODE BY https://twitter.com/mattpocockuk/status/1633064377518628866?s=20 | |
/** | |
* First, create a type helper that represents | |
* the result that we'll get from our safe function | |
*/ | |
export type SafeResult<T> = | |
| { | |
ok: true; | |
value: T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ORIGINAL CODE INSPIRED BY Wassim Chegham https://twitter.com/manekinekko/status/1624440889216057347/photo/1 | |
export function fromReadableStream( | |
stream: ReadableStream, | |
signal?: AbortSignal, | |
writableStrategy?: QueuingStrategy, | |
readableStrategy?: QueuingStrategy | |
): Observable<string> { | |
const createTextDecoderStream = ()=> new TextDecoderStream(); | |
const transformer = () => new TransformStream( | |
{ transform(chunk, controller) { controller.enqueue(chunk); } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"@Input Observable for Angular": { | |
"prefix": "in$", | |
"description": "Create an Observable @Input", | |
"body": [ | |
"#${1:prop} = new BehaviorSubject<${2:type}|undefined>(undefined);", | |
"protected ${1:prop}\\$ = this.#${1:prop}.pipe(filter(p=>p!==undefined));", | |
"@Input() set ${1:prop}(value: ${2:type}) {", | |
"\t$0//if (value!==this.${1:prop}) //eventual validation logic", | |
"\tthis.#${1:prop}.next(value);", | |
"}", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChangeDetectionStrategy, Directive, EventEmitter, Input, OnDestroy, Output } from "@angular/core"; | |
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms"; | |
import { Subject } from "rxjs"; | |
@Directive(/*{ | |
selector: "base-formctrl", | |
standalone: true, | |
// templateUrl: "./n-date-picker.component.html", //IL TEMPLATE VA SPECIFICATO SULLA @Component OSSIA LA CLASSE EREDITATA | |
// styleUrls: ["./n-date-picker.component.css"], //GLI STYLE VANNO SPECIFICATI SULLA @Component OSSIA LA CLASSE EREDITATA | |
// providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: NBaseFormCtrlComponent, multi: true }], //PURTROPPO QUESTO NON FUNZIONA SULLA ABSTRACT DEVO FARE IL PROVIDER NELLA CLASSE EREDITARE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type N<T> = T | null; | |
export type NU<T> = T extends undefined ? never : T; | |
export type NN<T> = NonNullable<T>; | |
//SAMPLE USE CASES | |
interface TryNull{ | |
nullable: N<number>; | |
maybe?: string; | |
flag?: N<boolean>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const __base__: unique symbol = Symbol(); //SUPER TRICK TO DEFINE UNIQUE __base__ TO HOLD THE Type BECAUSE infer DON'T WORK IN inferValue | |
export type Unique<T, U extends symbol> = T & { readonly __unique: U } & { [__base__]: T }; | |
export type inferValue<U> = U extends Unique<infer T, symbol> ? U[typeof __base__] : never; | |
export function cast<U extends Unique<unknown, symbol>>(value: inferValue<U>): U { return value as U; } | |
export function val<U extends Unique<unknown, symbol>>(value: U): inferValue<U> { return value as inferValue<U>; } | |
//SAMPLE USE CASES | |
declare const sEUR: unique symbol; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//EXPERIMENTS WITH TYPESCRIPT UTILITY TYPES: https://www.typescriptlang.org/docs/handbook/utility-types.html | |
//AND MAPPED TYPES: https://mariusschulz.com/blog/mapped-types-in-typescript | |
//READ MORE HERE: https://blog.logrocket.com/mastering-mapped-types-typescript/ | |
type KeepOnlyPropOfT<O, T> = { | |
[K in keyof O]: O[K] extends T ? K : never | |
}[keyof O] | |
type ExtractOnlyT<O, T> = { | |
[P in KeepOnlyPropOfT<O,T>]: O[P] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Inspired by https://gist.github.com/JoeyBurzynski/617fb6201335779f8424ad9528b72c41 */ | |
html { | |
max-width: 70ch; | |
padding: 3em 1em; | |
margin: auto; | |
line-height: 1.75; | |
font-size: 1.25em; | |
font-family: Verdana Arial Currier sans-serif Monospace; | |
box-sizing: border-box; | |
} |