This file contains hidden or 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 { | |
| API, | |
| ASTPath, | |
| CallExpression, | |
| FileInfo, | |
| Literal, | |
| MemberExpression, | |
| StringLiteral, | |
| VariableDeclaration | |
| } from 'jscodeshift' |
This file contains hidden or 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 async function asyncEach<T>( | |
| array: { map(callback: (value: T) => any): Promise<any>[] }, | |
| iteratee: (value: T) => Promise<any>, | |
| ) { | |
| return Promise.all(array.map(iteratee)); | |
| } | |
| export async function asyncEachSeries<T>( | |
| array: { | |
| reduce(callback: (prev: any, value: T, index: number) => any, initialValue: any): any; |
This file contains hidden or 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
| function chunk(n: number, xs: number[]) { | |
| if (!xs.length) return []; | |
| return [xs.slice(0, n), ...chunk(n, xs.slice(n))]; | |
| } |
This file contains hidden or 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
| function day05a(xs: [number, number, number, number][], matrix: number[][]) { | |
| xs.forEach((x) => { | |
| const [x1, y1, x2, y2] = x; | |
| if (x1 == x2 || y1 == y2) { | |
| for (let yi = Math.min(y1, y2); yi <= Math.max(y1, y2); yi++) { | |
| for (let xi = Math.min(x1, x2); xi <= Math.max(x1, x2); xi++) | |
| m[yi][xi]++; | |
| } | |
| } |
This file contains hidden or 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 { load } from '@workspace/shared'; | |
| import Foo from '@workspace/shared'; | |
| import * as Bar from '@workspace/shared'; | |
| load(); | |
| Foo.doSomething(); | |
| Bar.default.doSomething(); | |
| function test() { | |
| const load = {}; |
This file contains hidden or 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 fs = require('fs'); | |
| const glob = require('glob'); | |
| const { workspaces } = require('./package.json'); | |
| const noExtraneousOverrides = workspaces | |
| .map((workspace) => { | |
| return glob | |
| .sync(workspace) | |
| .filter((entry) => entry.substr(0, 1) !== '.' && fs.lstatSync(entry).isDirectory()) |
This file contains hidden or 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 async function asyncReduce<T, U>( | |
| array: T[], | |
| iteratee: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => Promise<U>, | |
| initialValue: U | |
| ): Promise<U> { | |
| return array.reduce( | |
| (promise, currentValue, currentIndex) => | |
| promise.then((previousValue) => iteratee(previousValue, currentValue, currentIndex, array)), | |
| Promise.resolve(initialValue) | |
| ); |
This file contains hidden or 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 type { FileInfo, API } from 'jscodeshift'; | |
| const newPackagesMap: Record<string, string> = { | |
| '@material-ui/core': '@mui/material', | |
| '@material-ui/icons': '@mui/icons-material', | |
| '@material-ui/styles': '@mui/styles', | |
| }; | |
| const newPackages = Object.keys(newPackagesMap); |
This file contains hidden or 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 { asyncEach } from './asyncEach'; // From https://gist.github.com/fersilva16/bdf2d0b9a5eedbcf7232760df876a87d | |
| export async function asyncFilter<T>( | |
| array: { map(callback: (value: T) => any): Promise<any>[] }, | |
| predicate: (value: T) => Promise<boolean> | |
| ): Promise<T[]> { | |
| const result: T[] = []; | |
| await asyncEach(array, async (value, ...args) => { | |
| const shouldAdd = await predicate(value, ...args); |
OlderNewer