Skip to content

Instantly share code, notes, and snippets.

View OliverJAsh's full-sized avatar

Oliver Joseph Ash OliverJAsh

View GitHub Profile
diff --git a/cjs/react-dom.production.min.js b/cjs/react-dom.production.min.js
index 7bbc786deca6afaee7c96ed87fcdcfbbea03f11e..28f9f729d3fb0786f77c912e7251f6a1e23e9077 100644
--- a/cjs/react-dom.production.min.js
+++ b/cjs/react-dom.production.min.js
@@ -115,7 +115,19 @@ vf(x),u--;for(;w--;){if(t===x||null!==x&&t===x.alternate)break b;t=vf(t);x=vf(x)
xa.controlled&&"number"===h.type&&cb(h,"number",h.value)}xa=d?ue(d):window;switch(a){case "focusin":if(me(xa)||"true"===xa.contentEditable)Qe=xa,Re=d,Se=null;break;case "focusout":Se=Re=Qe=null;break;case "mousedown":Te=!0;break;case "contextmenu":case "mouseup":case "dragend":Te=!1;Ue(g,c,e);break;case "selectionchange":if(Pe)break;case "keydown":case "keyup":Ue(g,c,e)}var $a;if(ae)b:{switch(a){case "compositionstart":var ba="onCompositionStart";break b;case "compositionend":ba="onCompositionEnd";
break b;case "compositionupdate":ba="onCompositionUpdate";break b}ba=void 0}else ie?ge(a,c)&&(ba="onCompositionEnd"):"keydown"===a&&229===c.keyCode&&(ba="onCompositi
function reverseFormatNumber(val,locale){
var parts = new Intl.NumberFormat(locale).formatToParts(1111.1);
var group = parts.find(part => part.type === 'group').value;
var decimal = parts.find(part => part.type === 'decimal').value;
var reversedVal = val.replace(new RegExp('\\' + group, 'g'), '');
reversedVal = reversedVal.replace(new RegExp('\\' + decimal, 'g'), '.');
return Number.isNaN(reversedVal)?0:+reversedVal;
}
console.log(reverseFormatNumber('1,234.56','en'));
import * as A from 'fp-ts/Array';
import { pipe } from 'fp-ts/function';
import * as IO from 'fp-ts/IO';
// Space: https://unicodeplus.com/U+0020
const space = String.fromCharCode(32);
// Narrow No-Break Space: https://unicodeplus.com/U+202F
const narrowNoBreakSpace = String.fromCharCode(8239);
// Thin Space: https://unicodeplus.com/U+2009
const thinSpace = String.fromCharCode(8201);
@OliverJAsh
OliverJAsh / doc.md
Created June 22, 2021 11:32
Unsplash: Architectural Decision Record (ADR): Mocking API requests in E2E (Cypress) tests

Mocking API requests in E2E (Cypress) tests

Problem

Testing at the network level

In our E2E tests, when the test runner navigates through the site, we don't want to make real API requests but rather we want to mock these requests so that we can easily test many different scenarios, and so that our tests are more resilient and less likely to flake if API is suffering any downtime.

Up until now, this has been achieved by "mocking the fetch function". For example:

import { TSESLint, TSESTree } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';
import { getChecker, getParserSvc, ruleCreator } from '../utils';
export const RequireObjectTypeAnnotations = ruleCreator({
defaultOptions: [],
meta: {
docs: {

Require type annotations for objects

For object literals without type annotations, many TypeScript features don't work. Contrived example:

type User = { name: string; age: number };

const makeUser = () => ({ name: 'bob', age: 123 });
@OliverJAsh
OliverJAsh / foo.ts
Created December 3, 2020 17:48
ts-morph: Convert named imports to namespace import
// https://gist.github.com/OliverJAsh/5de515ad1f81b88409c13cd548c20893
// https://twitter.com/OliverJAsh/status/1334537098469265413
const { Project } = require('ts-morph');
const project = new Project({
tsConfigFilePath: 'tsconfig.app.no-references.json',
});
const PATH_TO_MATCH = '/Users/oliverash/Development/unsplash-web/shared/helpers/booleans.ts';
@OliverJAsh
OliverJAsh / foo.ts
Last active November 17, 2022 10:05
TypeScript type hierarchy for `object`, primitives, `{}`, and `unknown`
/*
----------- primitive ----------
object non-nullable primitive nullable
------------- {} --------------
---------------- unknown -----------------
https://www.oreilly.com/library/view/programming-typescript/9781492037644/ch04.html
https://gist.github.com/OliverJAsh/381cd397008309c4a95d8f9bd31adcd7
*/
@OliverJAsh
OliverJAsh / foo.ts
Last active October 26, 2022 15:07
TypeScript: infer function parameter as a tuple, not an array
{
declare const fn: <T>(fn: (t: T) => void, t: T) => void;
fn(
(t) => {
// $ExpectType [number, string]
// ❌
// Actual: (string | number)[)
t;
},