Skip to content

Instantly share code, notes, and snippets.

View LayZeeDK's full-sized avatar
🇩🇰
Denmark

Lars Gyrup Brink Nielsen LayZeeDK

🇩🇰
Denmark
View GitHub Profile
@LayZeeDK
LayZeeDK / with-injector-prop.storybook-decorator.ts
Created March 26, 2025 10:26
Storybook 7+ decorator to access Angular Injector as `injector` prop
import {
APP_INITIALIZER,
EnvironmentProviders,
FactoryProvider,
Injector,
makeEnvironmentProviders,
} from '@angular/core';
import { AngularRenderer } from '@storybook/angular';
import { DecoratorFunction } from '@storybook/types';
@LayZeeDK
LayZeeDK / get-storybook-injector.ts
Created March 26, 2025 10:24
Get Angular Injector in Storybook 7+ `play` function
import { Injector } from '@angular/core';
import { getStorybookNg } from './get-storybook-ng';
/**
* Get root-level injector for a component story.
*
* @example
* play: ({ canvasElement }) = {
* const injector = getStorybookInjector(canvasElement);
*
@LayZeeDK
LayZeeDK / test-setup.ts
Last active December 19, 2024 08:05
Resolve Nx generator unit test issues in Nx 18/19.
/// <reference types="jest" />
import { createProjectGraphAsync } from '@nx/devkit';
/**
* Resolve `TypeError: performance.mark is not a function`.
*
* @see https://github.com/nrwl/nx/issues/23435#issuecomment-2127183725
*/
const performanceMock: Performance = {
...performance,
@LayZeeDK
LayZeeDK / error-handler-with-plugins.syntax-error.ts
Created December 3, 2024 08:13
Angular ErrorHandler with plugins
@Injectable()
export class ErrorHandlerWithPlugins extends ErrorHandler {
readonly #plugins = inject(errorHandlerPluginToken, { optional: true }) ?? [];
override handleError(originalError: unknown): void {
super.handleError(originalError);
this.#plugins.forEach((plugin) => {
try {
plugin.handleError(originalError);
@LayZeeDK
LayZeeDK / README.md
Last active November 3, 2023 04:14
Nx generator wrapping jscodeshift transform: TypeScript private properties to ECMAScript private fields

Nx generator wrapping jscodeshift transform: TypeScript private properties to ECMAScript private fields

This library contains local Nx migration generators. To use them, run

nx generate @myorg/typescript-migrations:<migration-name> <project-name>

For example

@LayZeeDK
LayZeeDK / a-router-history-service-in-angular.md
Last active May 22, 2023 23:47
A Router History Service in Angular by Zach Tindall
@LayZeeDK
LayZeeDK / angular-testing-library-with-spectacular-0_5.ts
Last active July 17, 2023 12:13
Spectacular 15 Feature testing API design
// Angular Testing Library + Spectacular 0.5
const {
fixture: {
debugElement: { injector },
},
} = await render(SpectacularAppComponent, {
excludeComponentDeclaration: true,
imports: [
SpectacularFeatureTestingModule.withFeature({
featureModule: HeroesModule,
@LayZeeDK
LayZeeDK / input.scss
Created April 11, 2023 00:04
Generated by SassMeister.com.
/// Scales a color to be darker if it's light, or lighter if it's dark. Use this function to tint a color appropriate to its lightness.
///
/// @param {Color} $color - Color to scale.
/// @param {Percentage} $scale [5%] - Amount to scale up or down.
/// @param {Percentage} $threshold [40%] - Threshold of lightness to check against.
///
/// @returns {Color} A scaled color.
@function smart-scale($color, $scale: 5%, $threshold: 40%) {
@if lightness($color) > $threshold {
$scale: -$scale;
@LayZeeDK
LayZeeDK / input.scss
Created April 10, 2023 23:54
Generated by SassMeister.com.
// Copyright © 2011-2020 ZURB, Inc.
// MIT License
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
@LayZeeDK
LayZeeDK / project\.storybook\docs-page.ts
Created April 6, 2023 14:09
Custom Storybook Angular DocsPage.
import {
// ArgsTable,
Description,
Primary,
// PRIMARY_STORY,
Stories,
Subtitle,
Title,
} from '@storybook/addon-docs';
import { createElement } from 'react';