2020-01

Adding special values to types in TypeScript

[2020-01-26] dev, javascript, typescript

One way of understanding types is as sets of values. Sometimes there are two levels of values:

  • Base level: normal values
  • Meta level: special values

In this blog post, we examine how we can add special values to base-level types.

TypeScript enums: How do they work? What can they be used for?

[2020-01-24] dev, javascript, typescript

This blog post answers the following two questions:

  • How do TypeScript’s enums work?
  • What can they be used for?

A class-based enum pattern for JavaScript

[2020-01-13] dev, javascript, pattern

In this blog post, we examine a pattern for implementing enums in JavaScript that is based on classes. We’ll also take a look at Enumify, a library that helps with the enum pattern.

JavaScript regular expressions: /g, /y, and .lastIndex

[2020-01-01] dev, javascript, regexp

In this blog post, we examine how the RegExp flags /g and /y work and how they depend on the RegExp property .lastIndex. We’ll also discover an interesting use case for .lastIndex that you may not have considered yet.

2019-12

Simple pluralization via Intl.PluralRules

[2019-12-29] dev, javascript, intl

In this blog post, we’ll explore a very simple way to handle reporting of numbers of items that respects grammatical number (in English: singular and plural).

ECMAScript 2020: the final feature set

[2019-12-23] dev, javascript, es2020

Update 2020-04-02: Today, the ES2020 candidate was released, with the final feature set of that version. This blog post describes what’s new.

ECMAScript proposal: RegExp match indices

[2019-12-22] dev, javascript, es proposal

The ECMAScript proposal “RegExp match indices” (by Ron Buckton) adds more information to regular expression match objects (as returned by RegExp.prototype.exec() and other methods): They now record for each captured group where it starts and where it ends. Read on for more information.

ES2021: String.prototype.replaceAll

[2019-12-21] dev, javascript, es feature, es2021

The normal string method .replace() only lets you replace one occurrence if you search for string (and not a regular expression with the flag /g). The proposal “String.prototype.replaceAll (by Peter Marshall, Jakob Gruber, Mathias Bynens) fixes that.

ES2021: Promise.any()

[2019-12-20] dev, javascript, es2021

The ECMAScript proposal “Promise.any()” (by Mathias Bynens, Kevin Gibbons, and Sergey Rubanov) introduces a new Promise combinator for JavaScript. This blog post explains how it works.

ECMAScript proposal: top-level await

[2019-12-19] dev, javascript, es proposal

The ECMAScript proposal “Top-level await by Myles Borins lets you use the asynchronous await operator at the top level of modules. Before, you could only use it in async functions and async generators.