proposal-built-in-modules icon indicating copy to clipboard operation
proposal-built-in-modules copied to clipboard

JavaScript standard library contents

Open littledan opened this issue 6 years ago • 87 comments

The JavaScript standard library is very minimal. Is this how it should be? What should we add?

Note, the purpose of this repository is to develop the infrastructure for built-in modules, not the contents. However, I know many of you have ideas for the contents as well, so let's brainstorm those in this issue exclusively.

littledan avatar Dec 17 '18 15:12 littledan

enhanced promises

@littledan is this issue a dump for proposals? If that's the case I don't think we will ever be able to close it.

Mouvedia avatar Dec 17 '18 16:12 Mouvedia

Changing something that’s already in the language would need its own proposal; i think the standard library would be for adding new things.

ljharb avatar Dec 17 '18 16:12 ljharb

Changing something that’s already in the language would need its own proposal

@ljharb If the change is too radical or breaking, it has to be externalized: an alternative with another name to avoid confusion; future comes to mind in my case.

Mouvedia avatar Dec 17 '18 16:12 Mouvedia

I meant this as a brainstorming thread. What we talk about here might graduate into proposals. As @ljharb says, let's try to focus on additions of new features, rather than changes to existing things (it's not clear how to expose what you're talking about as a built-in module). If this thread gets too unwieldy, we can close it.

littledan avatar Dec 17 '18 16:12 littledan

Composable?

Mouvedia avatar Dec 17 '18 17:12 Mouvedia

WHATWG URL should be normative. await JSON.parse() and await JSON.stringify() or similar

jasnell avatar Dec 17 '18 18:12 jasnell

Would be nice to have promise cancelation

NarHakobyan avatar Dec 17 '18 19:12 NarHakobyan

uuid?

Mouvedia avatar Dec 17 '18 19:12 Mouvedia

Anything that validates ECMAScript internal stuff. e.g. https://mothereff.in/js-variables

Mouvedia avatar Dec 17 '18 19:12 Mouvedia

@Mouvedia Would uuid make sense as part of WebCrypto? https://github.com/w3c/webcrypto/issues/215

littledan avatar Dec 17 '18 19:12 littledan

@mathiasbynens 's Unicode RegExp properties should help with making that checker more efficient!

littledan avatar Dec 17 '18 19:12 littledan

That validator is just an example. My point is that the language should expose its own validators/assertors.

That would permit to have a basis for other interfaces (like the DOM). e.g. I had to make my own class/id assertors (html/css)

Mouvedia avatar Dec 17 '18 19:12 Mouvedia

@Mouvedia Would uuid make sense as part of WebCrypto? w3c/webcrypto#215

I don't know. Last time I checked the polyfill was enormous—it was almost impractical.

Mouvedia avatar Dec 17 '18 19:12 Mouvedia

@Mouvedia Well, the idea would be that you just use uuid if you don't have the built-in one. (uuid actually uses WebCrypto in browsers today.)

littledan avatar Dec 17 '18 19:12 littledan

The idea of futures is something that should be pursued; in the same way that XMLHttpRequest was retroactively redefined in terms of fetch, we could have Promise be redefined in terms of Future where futures are more granular and hence give more control to the user.

@NarHakobyan https://github.com/tc39/proposal-javascript-standard-library/issues/16#issuecomment-447916074

Mouvedia avatar Dec 17 '18 19:12 Mouvedia

It would be great to be able to access object properties without having to do something along the lines of

const prop2 = obj && obj.prop1 && obj.prop1.prop2

Something like the lodash _.get function, or Angular's elvis operator in the templates (obj?.prop1?.prop2?) I'm not super-keen on _.get because it's turning the property path into a string, which is not great from a typing and build checking point of view, but I use it as an example of desired functionality.

JonForest avatar Dec 17 '18 20:12 JonForest

My two longstanding bugbears with the JS standard library (going back to my pre-jQuery days) are:

  1. A better interface for dealing with cookies (i.e. doesn't involve directly manipulating a string - something like Web Storage).
  2. A parser/constructor for URLs like Python's urllib.parse (other languages' standard library methods for dealing with URLs are also available).

For a language that spends a lot of its time running in a browser these seem like obvious candidates for a standard library.

decadecity avatar Dec 18 '18 10:12 decadecity

@decadecity I'm wondering if the solutions at the web level, currently shipping in browsers, are enough for your use case.

  1. Does Web Storage solve the issue for you, or are there remaining problems?
  2. Does the WHATWG URL API solve this issue for you?

littledan avatar Dec 18 '18 11:12 littledan

@JonForest Have you see the optional chaining proposal? It's attempting to add that operator.

littledan avatar Dec 18 '18 11:12 littledan

@littledan

  1. Web Storage is fine for client side storage but doesn't do cookies :stuck_out_tongue: Directly manipulating the document.cookies string is a terrible API, I'd like to see something like the extension cookies API.
  2. The URL API looks like it's about right, thanks :+1:

decadecity avatar Dec 18 '18 11:12 decadecity

@decadecity Work is ongoing to evolve the cookie API itself at https://github.com/WICG/cookie-store . TC39 is probably the wrong place to advance work in this area, as we focus on things that don't involve I/O. Cookies don't mean much outside of the Web.

littledan avatar Dec 18 '18 12:12 littledan

In terms of what we can see people using, lodash is the most depended upon library that would be potentially appropriate to exist in core: https://www.npmjs.com/browse/depended

It's a bit harder to break down which functions are used the most, but you can get an idea here: https://www.npmjs.com/search?q=lodash&ranking=popularity

There is also a minimal version of the library: https://github.com/lodash/lodash/wiki/Build-Differences

anotheredward avatar Dec 18 '18 19:12 anotheredward

No, the JS standard library should not be minimal. Part of the reason there's so many variations on the underscore theme is that there's a lot of really basic stuff missing from the language (like deep copy.)

Unfortunately it's not clear where feature requests belong. While I was writing out a flood, I was told "not here. Maybe on issue 16."

There's dozens of easy one-liners that would massively improve the language if gatekeepers would permit them

StoneCypher avatar Dec 19 '18 04:12 StoneCypher

I'll copy pasta a bunch right now if someone tells me where to put them

StoneCypher avatar Dec 19 '18 04:12 StoneCypher

@StoneCypher I'm glad you came here to do additional brainstorming for contents. For JavaScript one-liners, maybe could you make your own repository or gist for development and link to it from here?

littledan avatar Dec 19 '18 07:12 littledan

Somehow I feel like the input from @kgryte could be useful to this discussion ;)

martinheidegger avatar Dec 19 '18 09:12 martinheidegger

Would be really nice if there was an official place to give people recommendations for a more complete standard libary

StoneCypher avatar Dec 19 '18 16:12 StoneCypher

There's a whole lot of donation languishing in repos that gatekeepers don't look for

JS could be an amazingly easier language with very little work on anyone's part if the gatekeepers would facilitate donation

StoneCypher avatar Dec 19 '18 16:12 StoneCypher

In erlang, for example, there is a bug tracker where I can go, add a ticket with some code and some appropriate tags, and if my code isn't garbage and makes sense, there's a good chance it'll show up in the next standard library under some very different name

Recommendations I gave to Ian Hicks almost 20 years ago and gave code for are being invented this year and treated as important and ground breaking ☹️

Javascript should have a process for letting people who aren't friends with standards maintainers be helpful too

StoneCypher avatar Dec 19 '18 16:12 StoneCypher

I'm just going to go ahead and put what I wrote yesterday into a ticket

If I put it in my own repo nobody will ever look at it and it will die on-site

StoneCypher avatar Dec 19 '18 16:12 StoneCypher