Skip to content

Instantly share code, notes, and snippets.

View GeoffreyBooth's full-sized avatar

Geoffrey Booth GeoffreyBooth

View GitHub Profile
@GeoffreyBooth
GeoffreyBooth / count-npm-package-downloads.mjs
Created July 7, 2022 19:00
Downloads of npm packages by major version (last 7 days)
// Run this script via: node --no-warnings --experimental-fetch count-npm-package-downloads.mjs <package>
import { argv } from 'node:process'
const packageName = argv.at(-1)
const downloadsByMajorVersion = new Map()
const page = await (await fetch(`https://www.npmjs.com/package/${packageName}?activeTab=versions`)).text()
const regex = /">(?<version>[\d.]+)<\/a><div class="[^"]+"><\/div><code class="downloads">(?<downloads>[\d,]+)<\/code>/g

There is a Google Web Fundamentals article “Using JavaScript modules on the web” that explains how to use ECMAScript modules in browsers, such as via <script type="module">. It includes a section titled “A note on file extensions” that encourages developers to use the .mjs file extension, with the reasoning being that developers should want to tell apart their ES Module code from their Script code and also to save files for use with Node’s --experimental-modules implementation (at least, until it’s replaced with the new version that allows ES modules in .js files).

Most interesting to me, though, was the section “Web adoption of JS modules” with a link to usage counters

@GeoffreyBooth
GeoffreyBooth / npm-packages-module-field-analysis.md
Last active November 22, 2018 11:16
Analysis of public NPM packages using the “module” field

I did some research into the package.json "module" field. I wrote some code to download all the the package.json files from all the public packages in the NPM registry. Here are some findings:

941 public NPM packages use the "module" field as of 2018-10-22.

Here are the top 30 packages, as ranked by number of public dependents (or see the full list):

Dependents Package Name "module" Field Value
16,286 should ./es6/should.js
15,472 sinon ./pkg/sinon-esm.js
@GeoffreyBooth
GeoffreyBooth / npm-packages-module-field.md
Last active October 29, 2018 00:38
Full list of public NPM packages using the “module” field

Public NPM packages using the "module" field

These are the packages in the public NPM registry as of 2018-10-22 that have a value defined for the "module" field in their package.json files.

Dependents Name "module" value
16286 should ./es6/should.js
15472 sinon ./pkg/sinon-esm.js
1641 redux es/redux.js
1579 rollup dist/rollup.es.js

Keybase proof

I hereby claim:

  • I am geoffreybooth on github.
  • I am geoffreybooth (https://keybase.io/geoffreybooth) on keybase.
  • I have a public key ASCC0jgjIYKHBuZte1eKYWlMkqws78Yqm1NEZooCeAWrZAo

To claim this, I am signing this object:

@GeoffreyBooth
GeoffreyBooth / coffeescript-pr-4854-affected-tests.coffee
Created January 15, 2018 04:54
CoffeeScript tests affected by PR #4854
test "Ensure that the closure wrapper preserves local variables.", ->
obj = {}
for method in ['one', 'two', 'three'] then do (method) ->
obj[method] = ->
"I'm " + method
ok obj.one() is "I'm one"
ok obj.two() is "I'm two"
Error.stackTraceLimit = Infinity;
var {
Scope
} = require("./scope");
var {
isUnassignable,
JS_FORBIDDEN
} = require("./lexer");
@GeoffreyBooth
GeoffreyBooth / Model.coffee
Last active October 13, 2016 08:39
Ember.js rollback relationships, including deletions of child objects
# RollbackAttributes should also rollback relationships
# Based on http://stackoverflow.com/a/27184207/223225 and https://github.com/emberjs/rfcs/pull/21#issuecomment-135134132
DS.Model.reopen
rollbackAttributes: ->
@_super()
@rollbackRelationships()
cacheOriginalRelations: ->