Remix.run Logo
josephg 2 days ago

What functionality is still missing from the JS standard library? The JS standard library seems massive these days.

Edit: Removed a reference to node and bun.

Frotag 2 days ago | parent | next [-]

Some utility stuff I copy paste between projects:

  - range, clamp, inIvl, enumerate, topK
  - groupBy (array to record), numeric / lexical array sorts
  - seeded rng
  - throttling
  - attachDragListener (like d3's mousedown -> mousemove -> mouseup)
  - Maps / Sets that accept non-primitive keys (ie custom hash)
So basically functions that every *dash variant includes.
spartanatreyu a day ago | parent [-]

Also, all the functions that are already in the standard library but are made in a way that don't use more modern features:

- Functions that use map-like and set-like objects instead of maps and sets.

- Functions that should be async that aren't

- Async functions that should be cancellable, but aren't

- Functions that should use the disposable and async disposable stack (e.g. the `using` keyword)

- Functions that should return deeply immutable data structures but can't. (The R̶e̶c̶o̶r̶d̶s̶ ̶a̶n̶d̶ ̶T̶u̶p̶l̶e̶s̶ / Composites, and Structs proposals would help here)

- Concurrency coordination primitives (Imagine an array of 10 async functions that we wish to run. Going through them one at a time is too slow. `Promise.allSettled()` executes them all at the same time which might slow things down even more due to bottlenecking. We should have an easy way to say only execute a maximum of 3 at a time. As 1 function resolves, the next one is started, until all are resolved).

Sharlin 2 days ago | parent | prev | next [-]

It's not standard unless it's in the actual standard.

simonw 2 days ago | parent | prev | next [-]

Those aren't a standard library for the language itself - they're not showing up in browsers, for example.

josephg 2 days ago | parent [-]

Thanks but that doesn't answer my question. Forget node and bun then. What is missing from the standard library?

realityking 2 days ago | parent | next [-]

There’s been a lot of progress (Temporal, URL, TextDecoder, Base64 encoding, etc.) but there are still gaps.

Math.clamp is a big one (it’s a TC39 proposal). I’d also love to have the stats functions that Python has (geometric mean, median, etc.).

On the more ambitious end: CSV reading/writing and IPv4/IPv6 manipulation.

spartanatreyu a day ago | parent [-]

> On the more ambitious end: CSV reading/writing

Deno's standard libary has nice CSV parsing/serializing, and you can use it in any environment.

Docs: https://docs.deno.com/examples/parsing_serializing_csv/

simonw 2 days ago | parent | prev | next [-]

What standard library? Do you mean the built-in Array.x etc methods you get in the core language spec?

skydhash 2 days ago | parent | next [-]

In the browser, Javascript’s role is to add interactivity to the web page, and the API has a good surface area (even if not really pretty). People talk about the lack of standard library, but they can never say what’s missing.

https://developer.mozilla.org/en-US/docs/Web/API

The above seems fairly expansive, even if we remove all the experimental ones in the list.

tshaddox 2 days ago | parent | prev [-]

I suppose we could quibble about what exactly “standard library” means, but I’m presuming we’re talking about the web (rather than, say, Node or Bun). And to me it’s fair to use it to refer to all web APIs that are widely available. Things like crypto, ArrayBuffer, TextEncoder, File and the File System Access API, Intl, the Streams API, Window.performance, etc.

throw-the-towel 2 days ago | parent | prev | next [-]

String.splitRight, for one. (As an example: "www.a.north.website.com".splitRight(".", 3) == ["www.a.north", "website", "com"].)

bakkoting 2 days ago | parent | next [-]

Python and Rust have such a thing, but not e.g. Java, Go, C#. And I can't find any libraries on npm which do this. That seems like a very niche need, not actually the sort of thing whose absence causes people to have lots of npm dependencies.

fireflash38 2 days ago | parent | prev [-]

When would you want that when it wouldn't be covered by more domain-specific use cases?

eudamoniac 2 days ago | parent | prev [-]

Most things in Remeda, ramda, rxjs, the methods in the Ruby stdlib, etc. would all be great to have. I use at least Remeda in every project when I can.

jefftk 2 days ago | parent | prev [-]

We're talking about JS in browsers: many fewer options there, plus needing to support old devices.