Skip to content

Instantly share code, notes, and snippets.

View ezzabuzaid's full-sized avatar
🎯
Focusing

ezzabuzaid ezzabuzaid

🎯
Focusing
View GitHub Profile
@ezzabuzaid
ezzabuzaid / morph-inject.ts
Last active April 22, 2024 15:47
Migrate constructor injection to the new inject function.
import * as morph from 'ts-morph';
/**
* By default any component, directive, pipe, or service that have superclass is discarded
*
* If you want to permit some superclasses.
*/
const ALLOWED_SUPER_CLASSES: string[] = [];
export function resizeObservable(
element: HTMLElement,
options: ResizeObserverOptions = {}
): Observable<ResizeObserverEntry[]> {
return new Observable((observer) => {
const resizeObserver = new ResizeObserver((records) => {
observer.next(records);
});
resizeObserver.observe(element, options);
return () => {
@ezzabuzaid
ezzabuzaid / dotnet.env.js
Created February 23, 2024 10:57
DOT_NET env var style in nodejs
const env = require('dotenv').config();
const deepmerge = require('deepmerge');
const { parsed: object } = env;
let clone = {};
for(const key in object) {
if(Object.hasOwnProperty.call(object, key)) {
const value = object[key];
if(key.includes('__')) {
const keys = key.split('__');
@ezzabuzaid
ezzabuzaid / loading$.ts
Last active February 23, 2024 11:01
Extract loading state from observable
import {
Observable,
ObservableInput,
ReplaySubject,
delay,
distinctUntilChanged,
finalize,
from,
of,
tap,
import internal, { PassThrough, Transform } from 'stream';
export function concatStreams({
streams,
delimiter,
}: {
delimiter?: string;
streams: (() => internal.Readable)[];
}) {
const destination = new PassThrough({ objectMode: true });
import {
BehaviorSubject,
Observable,
ObservableInput,
Subject,
debounceTime,
exhaustMap,
filter,
finalize,
fromEvent,
@ezzabuzaid
ezzabuzaid / inject-migration.ts
Last active August 27, 2023 18:50
Migrate Angular projects to use new inject fn
import { writeFileSync } from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
/**
* Extracts files from tsconfig.json
*
* @param tsconfigPath
* @returns
*/

I was able to use the ESM version with Angular 15 following these steps:

Note: I use nx, but it should work with other executers like Angular builder

  1. install monaco-editor-webpack-plugin
  2. change the build target to use an executer that supports modifying the webpack config. in case of nx 16, use "@nx/angular:webpack-browser"
  3. add webpack.config.js

angular.json/project.json

import { MonoTypeOperatorFunction, Observable } from 'rxjs';
import {
debounceTime,
distinctUntilChanged,
filter,
map
} from 'rxjs/operators';
interface ITypeaheadOperatorOptions {
minLength: number;
import { createCustomElement } from '@angular/elements';
import { createApplication } from '@angular/platform-browser';
(async () => {
const app = await createApplication({
providers: [],
});
const WebComponent = createCustomElement(YourComponent, {
injector: app.injector,