Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
sindresorhus / esm-package.md
Last active June 1, 2024 19:35
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@abozhilov
abozhilov / gist:2997730
Created June 26, 2012 18:23
Wildcard to RegExp
/**
* Convert wildcard pattern to RegExp
* Pattern:
* * - Zero or more characters
* ? - Exactly one character
*
* @param {String} pattern Wildcard pattern
* @returns {RegExp} regular expression for wildcard matching
*/
function wc2reg(pattern) {
@dherman
dherman / map-dict.js
Created June 9, 2012 02:42
Map vs object for dictionary
// A Dict class that works in ES6 using Map. Basically it's identical to Map, but
// only expected to be used on string keys.
function Dict() {
this.elts = new Map();
}
// (string) -> any
Dict.prototype.get = function get(key) {
return this.elts.get(key);
anonymous
anonymous / gist:2507667
Created April 27, 2012 09:07
RegExp creation
var REGEX = {
NUMBER : /^-?[0-9]*\.?[0-9]+$/,
KEYWORD : /^(?:top\s+|bottom\s+)?(?:right|left)|(?:right\s+|left\s+)?(?:top|bottom)$/
};
var direction = RegExp([
'^(?:',
REGEX.NUMBER.source.slice(1, -1),
'|',
'(?:', REGEX.KEYWORD.source.slice(1, -1), ')deg',
@sillage
sillage / common.js
Created December 16, 2011 22:49
common.js
// *********************************************************************
// Add a new button in the toolbar which replaces `s' caracters by a
// `ſ' (long s, old style), but NOT at the end of a word.
// *********************************************************************
$(function() {
$.getScript('https://fr.wikisource.org/w/index.php?title=Utilisateur:FitzSai/xregexp.js&action=raw', // load XRegExp
function() {
$.getScript('https://fr.wikisource.org/w/index.php?title=Utilisateur:FitzSai/unicode-base.js&action=raw', // load Letter category only
function() {
!function() {
var doc = document,
htm = doc.documentElement,
lct = null, // last click target
nearest = function(elm, tag) {
while (elm && elm.nodeName != tag) {
elm = elm.parentNode;
}
return elm;
};