Skip to content

Instantly share code, notes, and snippets.

View regex.ts
export function escapeRegex(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
export function regex(
strings: TemplateStringsArray,
...values: Array<RegExp | string>
): RegExp;
export function regex(
View regex.js
export function escapeRegex(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
/**
* regex`${'escaped'} ${regex`nestable`}`
* regex('gi')`withFlags`
*/
export function regex(...args) {
function _regex(flags, strings, ...values) {
View babel-comment-to-decorate.js
// plugin.js
'use strict';
const BabelParser = require("@babel/parser");
// https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md
// TODO import decorate/extendObservable
module.exports = function ({ types }) {
const visitor = {
/*
@urugator
urugator / useDerivedState.js
Last active Apr 16, 2019
useDerivedState
View useDerivedState.js
const React = require('react');
const __DEV__ = process.env.NODE_ENV !== 'production';
const HOOK_NAME = 'useDerivedState';
const NO_DEPS_HINT = 'If there are no dependencies, use "const [state] = useState(fn)"'
/**
* Copied from from React sources and adjusted
* inlined Object.is polyfill to avoid requiring consumers ship their own
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is