Simplify imports with path mapping→
Your TypeScript application uses relative imports. Every time you move a file, the imports break. You've configured path mapping, and now things break in an entirely new way.
Your TypeScript application uses relative imports. Every time you move a file, the imports break. You've configured path mapping, and now things break in an entirely new way.
You need to check a date using Chai. You also need to account for the test execution time.
Gatsby supports TypeScript out-the-box. Unfortunately, the official solution has several shortcomings which limit its usefulness. There is a better way.
You can use JavaScript's optional chaining operator multiple times within a statement. That is useful if you need to access nested properties which may not exist.
You're using Decap CMS to manage the content of your Gatsby-powered website. The default Decap CMS preview displays every field, including metadata. That probably isn't what you want.
JSON Schema includes the multipleOf keyword. This is very useful for checking that a number is rounded to a specific number of decimal places.
Your site uses Gatsby and Netlify CMS. Tailwind and PostCSS take care of the styling. You run gatsby develop
, and encounter a cryptic error message.
Chai lets you assert that some code throws an error. The key is to pass the test subject to expect
, not the test result.
You can disable ESLint for a single line, a block of code, or an entire file. Wherever possible, specify the rule or rules you wish to disable.
Don't use "deep equals" when comparing arrays with Chai; it depends on element order. Examine the array members instead.
TypeScript's strict type checking can cause problems when working with numeric environment variables. Here's a solution.
Assume we have two JavaScript arrays, alpha
and bravo
. We need to determine which items appear in alpha
, but not in bravo
.
If you're accustomed to PHP's logical operators, JavaScript's implementation can be confusing.
Avoid Array.prototype.push
. It modifies the array in place, which is asking for trouble. It also returns the array length, not the modified array, which is plain confusing.
The default "recurse depth" of console.dir
is 2. This is rarely what I want.
Faker is a useful JavaScript library for generating dummy data. For example, faker.random.words(3)
generates a string containing three random words. But what if you want to generate an array of random words?
There are countless blog posts detailing how to split a JavaScript array into chunks. However, many of these solutions fail with arrays containing hundreds of thousands of items.
You can generate a pseudo-random boolean in JavaScript or PHP using a single line of code. No, you do not need to install yet another idiotic JavaScript package.
Statecharts are a very useful tool for modelling complex workflows in your application.
A monthly round-up of blog posts, projects, and internet oddments.