PhaultLines

Validating Markdoc attribute values with Zod

In a React application written in TypeScript, the language’s type system is the first line of defense against type errors in component props. In Markdoc, where content is decoupled from rendering logic and can’t take advantage of TypeScript types, the schema-based validation system plays an important role in bridging the gap between declarative tag definitions and typed React components. The Markdoc validator ensures that tag attribute values in a document match the types declared in the corresponding schema.

Continue Reading ›

Accessing parent nodes in a Markdoc validation function

A recent Markdoc release introduced a new feature that makes it possible for validation functions to access the parents of the current node. This feature is useful for writing custom validation logic that analyzes document structure or enforces rules based on a node’s position in the hierarchy. For example, you might want to impose restrictions on where an image can be nested in a document, prohibiting the use of images in specific tags like callouts and asides.

Continue Reading ›

Using cancellation with async iterators in JavaScript

Chrome 63, released in December, included async iterators and the associated for-await-of syntax. As the feature is now official in V8 6.3, it’s also likely to land in the upcoming Node.js 10 release this April. In light of its imminent availability in Node.js, I figured that it was time to start exploring the real-world potential of async iterators on the backend. Combining the async and await keywords with generator functions provides an elegant way to express streaming operations in modern JavaScript applications.

Continue Reading ›

Get the advantages of TypeScript without transpiling

Microsoft’s TypeScript programming language brings many of the advantages of static typing to JavaScript. Although it doesn’t enforce types at runtime, it enables richer static analysis, encourages more safety, and opens the door for better IDE integration. TypeScript code is typically transpiled to standards-based JavaScript so that it can run natively in browsers and Node.js. Given the attractiveness of TypeScript’s benefits, it is unsurprising that adoption is growing at a rapid pace.

Continue Reading ›

Using the Plex webhook API to control Hue lights

A Plex Media Server update released earlier this year introduced a new webhook API that exposes media playback events, making it possible to track when Plex starts and stops playing content. I used the API to make my living room lights dim automatically when I’m watching a movie or television show. To use the API, you create a simple web application that receives HTTP POST requests at a given URL endpoint.

Continue Reading ›