This file contains 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
// src/lib/frontmatter.plugin.mjs | |
import yaml from "js-yaml"; | |
import { valueToEstree } from "estree-util-value-to-estree"; | |
// Helper function to traverse nodes recursively | |
const traverse = (node, callback) => { | |
callback(node); | |
if ("children" in node && Array.isArray(node.children)) { | |
node.children.forEach((child) => traverse(child, callback)); |
This file contains 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
// Original source: v8/test/mjsunit/es6/promise-all-overflow-1.js | |
// https://github.com/v8/v8/blob/4b9b23521e6fd42373ebbcb20ebe03bf445494f9/test/mjsunit/es6/promise-all-overflow-1.js#L9-L12 | |
// Make sure we properly throw a RangeError when overflowing the maximum | |
// number of elements for Promise.all, which is capped at 2^21 bits right | |
// now, since we store the indices as identity hash on the resolve element | |
// closures. | |
const a = new Array(2 ** 21 - 1); | |
const p = Promise.resolve(1); |
This file contains 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
if (typeof Object.assign !== 'function') { | |
// Must be writable: true, enumerable: false, configurable: true | |
Object.defineProperty(Object, "assign", { | |
value: function assign(target, varArgs) { // .length of function is 2 | |
'use strict'; | |
if (target === null || target === undefined) { | |
throw new TypeError('Cannot convert undefined or null to object'); | |
} | |
var to = Object(target); |
This file contains 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 * as express from "express"; | |
import * as mongoose from "mongoose"; | |
const app = express(); | |
const uri = "mongodb://localhost:27017/test"; // replace with your URI | |
mongoose | |
.connect(uri, { | |
useNewUrlParser: true, |
This file contains 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
* { | |
text-align: center; | |
} | |
button { | |
padding: 10px 20px; | |
font-size: 1.5rem; | |
} | |
.flex { |
This file contains 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 React, { FC } from "react"; | |
import "./App.css"; | |
import FunctionalCounter from "./components/FunctionalCounter"; | |
import ClassCounter from "./components/ClassCounter"; | |
const App: FC = (): JSX.Element => { | |
return ( | |
<> | |
<div className="flex"> |
This file contains 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 React, { FC, useState } from "react"; | |
interface Props { | |
title: string; | |
initialCount: number; | |
} | |
const FunctionalCounter: FC<Props> = ({ title, initialCount }) => { | |
const [count, setCount] = useState(initialCount); |
This file contains 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 React, { Component } from "react"; | |
interface Props { | |
title: string; | |
initialCount: number; | |
} | |
interface State { | |
count: number; | |
} |
This file contains 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 React from 'react'; | |
import './App.css'; | |
const debounce = (fn: Function, time: number) => { | |
let timeout: NodeJS.Timer; | |
return function(...args: any[]) { | |
const functionCall = function(this: any) { | |
fn.apply(this, args); | |
clearTimeout(timeout); | |
}; |
This file contains 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 isFunction = fn => fn && Object.prototype.toString.call(fn) === '[object Function]'; | |
const isAsync = fn => fn && Object.prototype.toString.call(fn) === '[object AsyncFunction]'; | |
const isPromise = p => p && Object.prototype.toString.call(p) === '[object Promise]'; | |
const tap = f => x => { | |
f(x); | |
return x; | |
}; |
NewerOlder