392 private links
The author creates a project to gather statistics about the top most starred projects on Github or the most downloaded packages on NPM.
- 9-27% of JS/TS projects declare themselves to be ES Modules
- Less than 6% of JS/TS files declare that they are ES Modules via the
.mjs,.cjsor.mtsfile extensions.
Some ideas:
- kill
.mjs,.cjsand.mtsshould be replaced by thetype="module"in package.json. Let's stick to.js,.jsx,.tsand.tsx - Make
type="module"the default and warns when the type is not set to module. - We should upgrade the most common libraries used by the community to ES Modules
- The NPM registry can require an explicit module field on new packages, making it clear when a package intentionally uses CommonJS.
- NodeJS can officially drop support for
requireandmodule.exportsin a future version, creating a bit more pressure to migrate.
The JS Date object is not consistent: there are quirks with its constructor, the JS date is a time object, no sense of time zones beyond one and GMT, absence of daylight savings time, a need for third-party library that is a performance drain. "My problem with Date is that using it means deviating from the fundamental nature of time itself."
The Time is a location in the flow of which events occurs.
Date represents a (readable for human) time
The date object is itself mutable, so it's ok to set a day in place. It can cause unintended side-effects in codebases.
So Temporal comes in. it's a namespace object like Math. There are multiple useful functions, but another magic is in the prototype chain: equals, add, inLeapYear, monthCode.
First, there are plenty of methods and properties devoted to access, format and manipulate the details of the temporal object.
Secondly, "none of these transformations required us to manually spin up any new objects, and that the value of the object referenced by nowTemporal remains unchanged."
Using temporal reduce the boilerplate so much!
Temporal.Now.plainDateISO().add({ days: 1 })
Also Temporal have some time for experimentation.
Unobtrusive logging for modern javascript
Zero dependencies. Universal runtime. Optimized performance.
The library avoid overhead and boilerplate compared to other logger library such as Winston or Pino.
I restart the project
New generation of tools:
- Speedy Web Compiler
- ESBuild
- BiomeJS t combines code formatting and linting into a single high-performance JavaScript toolchain.
- Oxc is a collection of Rust-based Javascript tools focusing on linting, formatting and transforming Javascript and typescript tools.
- Fast Node Manager / Mise
- Typescript in Go
Another notable efforts are Turbopack and Turborepo, Bun and Deno.
Contributing becomes less accessible to the majority of JavaScript developers of course. The shift demonstrates other skills in system programming that will drive even more innovative tooling in the coming years
Testing sucks because you try to test implementation details. This results in you writing tests to pass your code. That’s not useful, because…
Instead, you should…
- Write an empty test, with one comment for each external behavior your code should display.
- Write the code to test each comment below it.
- Then write the actual code to make it so.
The author provides some code sample.
- Creating Blob Objects Safely and Efficiently
- Chunking Large Files to Avoid Memory Explosions
- Image Compression and Format Conversion on the Front End (with the canvas API)
- A Unified File Preview Component
- Data Export and Download with Blobs (JSON, CSV, “Excel”)
- Blob URL Memory Management and Leak Prevention
Not ready for ruse in production
A new API that aims to improve the history API
The author uses a service worker in wasm to render HTML. The service worker syncs the data with the server.
Note fetch requests can be intercepted with the ... fetch event in service workers
The service worker used here is written in Go. Note the "localfirst" approach runs only after the service worker is loaded. The initial page is loaded as simple HTML because of SSR. That's the advantage of WASM: the code runs on the client and the server.
(following https://shaarli.lyokolux.space/shaare/CosnyQ)
JSON module imports became baseline: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with:
import data from './data.json' with { type: 'json' };
and lazy-load it with:
const { default: data } = await import('./data.json', {
with: { type: 'json' },
});
It makes sense to use JSON module imports for local static JSON resources where you need all/most of the data within. Particularly since bundlers can understand JSON imports, and bundle the object with other modules. That isn't possible with fetch(), unless you use some pretty hacky plugins.
Generally, I try to turn any "fetch-and-process" logic into a Vite/Rollup plugin, so it happens at build time rather than runtime.
If JS fails to load, a keyframe remove the effect provided by JS in 2 seconds.
It is currently experimental, but could be amazing because it parse a string of HTML safely and then insert it into the DOM
Why Piccalilli: I’m going to side with an independent publisher every single time.
video just isn’t the water we developers swim in every day. Far as I’m concerned, learning JavaScript hinges on being able to try stuff out for yourself: copy a snippet of code, chuck it into your dev console, see what happens; move a semicolon to see how it breaks.
How a beginner should make websites? Learn to write good HTML. Learn the medium instead of the tooling (raw JS instead of a framework).
That excites Mat Marquis about the web? The comeback of web brutalism, small web, etc...
https://strange.website/
https://www.weatherishappening.com/
https://solar.lowtechmagazine.com/
https://scott.is/
Note: "The key insight is that loading massive files into memory all at once is rarely a good idea, even when technically possible."
- Read the whole file and call it a day with
fs.readFile - Read by byte chunks with file handles and buffers
- (preferred) Use stream
The streams handle the bytes and UTF-8 encoding automatically. Each state can be defined with a callback: error, data, end.
Use appropriate buffer sizes for streams. Default is 64kB. The highWaterMark can adjust it though.
When to use streams: large files, real time data processing, memory is limited, composability, unknown file sizes.
When to use file handles: precise control.
When to use fs/promises: known small files. readFileSync() and writeFileSync() are acceptable for cli tools and scripts, but forbidden for web servers and concurrent apps.
Prefer Promise.all or Promise.allSettled to leverage concurrency.
Handle specific errors. Always. await handle.close() or stream.on('error', () => stream.destroy()). Another solution is await pipeline(source, transform, destinationl)
Note: JS does not have the concept. If we wanted to mutate something, e’d need to put it in an object first, and then pass that object.
Yes, I missed that thought even if I am programming! We simply pass by value often and reassign the function output to a variable.
I’m still not entirely sure what object freezing is useful for — I feel like it’s rarely what you want.
Me too. I never found a good case for it.
I just want to be able to tell if a function is going to mess with its parameters.
It's a way to tell it. Does the parameters are mutated in-place?
To ensure the parameters
In JS, we can freeze an object. The object can be (deep) cloned in Go. ({...o} as shallow clone in JS)
and I think I start to get it: Rust is awesome as interfaces because it can tell from the function signature if it mutates the parameters.
Indeed:
Similar ideas have been around for a while: In 1990, Philip Wadler wrote Linear types can change the world!
About safety in C or C++:
But those languages should be seen as asbestos.
It comes down to the multiple data structures in Rust.
But this complexity is simply a way to encode the reality of dealing with data in a multi-threaded environment, a way that can be checked at compile-time, before the program even gets a chance to run.
When you manage to make the type system work with you rather than against you, you can build things that would be wildly irresponsible to write in C and C++. And that’s the promise of Rust.
How to build a mansory layout that works. 66 lines of JS.