← #87 Create a function that accepts a single parameter

Save a few bytes when checking the existence of module

Topics: JavaScript

Say we are creating a library and want to export our APIs to the consumers. In order to support the CommonJS module, we use the following check:

if (typeof module !== 'undefined') {
module.exports = ourFunction;

However, it can be shorten and saved a few bytes when being minified:

if (typeof module < 'u') {
// ...

I saw that trick when looking at the Preact's source.

Fix a typo or suggest an improvement
#89 Truncate long text