Set an Attribute Without Value in JavaScript

Often, we see HTML code snippets that set an attribute of an element without any value, like the following: <button id="my-button" disabled>I'm a button</button> In the HTML code snippet above, the id attribute has a value of "my-button", while the disabled attribute is present without any specified value. Many of us may wonder: How can I add such an attribute without a value like disabled above in JavaScript? The answer is probably trickier than most of us may have thought: This is impossible, and you may have been misled by the appearance of the HTML code. ...

May 1, 2024 · (Updated June 4, 2024) · 3 min · 551 words

Maintaining an Open Source JavaScript Project? Help Dependents Retain Notices

This post is not legal advice. By reading this post, you agree and acknowledge that this post does not advise you on how to properly license your work and you would not rely on this post to license your work; that this post does not advise licensees of open source work on how to comply with the licenses; and that this post only provides technical guidance on programming tasks that are common to licensing open source projects. Most popular open source licenses require redistributors to retain the copyright and permission notices, among other things. For example, even the brief MIT License explicitly requires so: …The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software… However, without any automation, this simple task is not so simple for a browser (front-end) JavaScript project: Tens and even hundreds of open source dependencies are often bundled and minified into a single .js file. Then, this .js file is commonly distributed to browsers via the Internet. As maintainers of open source JavaScript projects, what can we do to make retaining copyright and permission notices easier for dependent browser JavaScript projects? ...

April 20, 2024 · (Updated June 4, 2024) · 3 min · 574 words

Unleash Git Power with User Configuration

Git is an open source distributed version control system. It is currently the most popular version control system according to various surveys, and has been the core driver of many popular development platforms, such as GitHub, GitLab, Bitbucket, etc. While Git comes with a decent default configuration, it is far from the full power of Git. In this post, we will walk through some Git user configuration that unleash more power within Git. ...

April 11, 2024 · (Updated June 4, 2024) · 4 min · 711 words

Make TypeDoc Generate a 404 Page

Motivation TypeDoc is a document generator that, among other things, converts comments in TypeScript source code into rendered HTML documentation. The generated HTML documentation can be hosted on static website hosting services, such as GitHub Pages, GitLab Pages, Netlify, and CloudFlare Pages. All of them by default use a 404.html file as the content of the 404 page of the site. However, TypeDoc does not generate a 404.html by default. How can we make TypeDoc generate such a 404.html file? ...

April 6, 2024 · (Updated June 4, 2024) · 3 min · 464 words

Typing Wrapper Functions in Typescript

Motivation Very often in TypeScript, we would like to wrap an existing function into a wrapper function, with some additional preprocessing or postprocessing. For example, function existingFunc(arg1: number, arg2: string): number { return arg1 + arg2.length; } function wrapperFunc(arg1: number, arg2: string): number { // Preprocess arg1 and arg2... return existingFunc(arg1, arg2); } In this case, the wrapper function often shares the same parameter types and return type. If the existing function is already typed, we can reuse those typing information. This would reduce redundancy and is also able to reflect any changes that would happen in the typing of the existing function in the future. ...

April 3, 2024 · (Updated June 4, 2024) · 3 min · 539 words