blog.iankulin.com

Js

Node.js built in test runner

A look at Node’s built-in test runner from my perspective as a long-time Mocha and Chai user, showing how to write and run basic tests with node:test and node:assert. Coming from Mocha requires few changes, though test files need to live in a test directory to be picked up. I weigh the convenience of a bundled runner against lock-in to a particular runtime...

A bit of web-scraping with Cheerio

The ‘show all’ button on The Rest Is History podcast’s episodes page is broken, and there’s no JSON endpoint behind the player, so the episode list has to be scraped from the page’s HTML. Using Cheerio, a jQuery-like library for the server, I show how to select the playlist’s list items and extract each episode’s title and link, ending with a complete working script...

React code is not HTML

A failed attempt to replace my React component’s inline-styled div with plain HTML and CSS leads to the realization that JSX is JavaScript code that mutates the virtual DOM, not HTML. I question why React uses the faux-HTML syntax instead of a pure JavaScript DOM API. An update notes that a video revealed the HTML-like syntax was an intentional selling point of React, and that similar ideas have already been tried and abandoned...

De-structuring objects in JS

My notes from a first React tutorial, with a focus on JavaScript object destructuring. Examples show extracting object properties as local variables, either in a function’s parameter list or inside the function body, along with my thoughts on the readability trade-offs between the two approaches...

Calculator

After a podcast episode on JavaScript features to avoid piqued my interest in eval(), I built a browser-based calculator that passes button presses as a string directly to eval(). The app mimics the iPhone calculator’s design, with most of the effort going into CSS that displays correctly across different devices. I also cover browser responsive-mode tooling and a touch-action fix for iOS Safari’s double-tap zoom, with links to the source and live version...

CWD - 185 - Problem solving

I give a line-by-line walkthrough of my JavaScript solution to the “clean the room” coding challenge, which groups equal values in an array into subarrays and returns them sorted. My explanation covers spread syntax for array copying, sort() comparison behavior, the difference between for…of and for…in loops, and building an object keyed by value, with occasional comparisons to Swift equivalents...