Skip to content

Instantly share code, notes, and snippets.

@kevinbuhmann
kevinbuhmann / rollup.config.js
Last active September 28, 2022 20:12
React Rollup
import commonjs from '@rollup/plugin-commonjs';
import html from '@rollup/plugin-html';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import license from 'rollup-plugin-license';
import livereload from 'rollup-plugin-livereload';
import serve from 'rollup-plugin-serve';
import styles from 'rollup-plugin-styles';
import { terser } from 'rollup-plugin-terser';
interface Property {
hasValue?: boolean;
lastInputPropertyValue?: any;
currentValue?: any;
}
export function ProjectProperty<T, K extends keyof T>(inputPropertyName: K, projectFn: (input: T[K]) => any) {
const propertySymbol = Symbol();
return (target: T, propertyKey: PropertyKey) => {
@kevinbuhmann
kevinbuhmann / jest-screenshot+0.3.5.patch
Last active September 24, 2021 17:56
jest-screenshot: report/delete obsolete screenshot files
diff --git a/node_modules/jest-screenshot/dist/jest-screenshot.js b/node_modules/jest-screenshot/dist/jest-screenshot.js
index 4c43c6c..18daa4a 100644
--- a/node_modules/jest-screenshot/dist/jest-screenshot.js
+++ b/node_modules/jest-screenshot/dist/jest-screenshot.js
@@ -2,6 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupJestScreenshot = void 0;
const to_match_image_snapshot_1 = require("./to-match-image-snapshot");
+const fs = require("fs");
+const path = require("path");
@kevinbuhmann
kevinbuhmann / custom serializer
Last active September 22, 2021 18:53
email snapshots
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`SendEmailsWhenBuyerMessagedSellerAboutOrderEventHandler should generate the correct emails: email event 1`] = `
Id: 0000000-0000-0000-0000-000000000000
From: Bob Smith <feedback+0000000-0000-0000-0000-000000000000@transactional.example.com>
ReplyTo: Bob Smith <[email protected]>
To: [email protected]
UtcDateToSend: null
Archived: true
export function fileExists(filePath: string) {
return fs.existsSync(filePath);
}
export function readFile(filePath: string) {
return fs.readFileSync(filePath).toString();
}
export function writeFile(filePath: string, contents: string, silent = false) {
filePath = path.normalize(filePath);
@kevinbuhmann
kevinbuhmann / parse5-helpers.ts
Last active September 20, 2017 19:45
"[innerHTML] causes the server to duplicate content" workaround (angular/angular#19278)
import { parse, serialize, AST } from 'parse5';
export function transformHtml(html: string, visitors: NodeVisitor[]) {
const document = parse(html) as AST.Default.Document;
visitNode(document, visitors);
return serialize(document);
}
export function removeInnerHtmlAttributes(node: any) {
if (node.attrs) {