tc39 / proposal-built-in-modules

BSD 2-Clause "Simplified" License
892 stars 25 forks source link

JavaScript standard library contents #16

Open littledan opened 5 years ago

littledan commented 5 years ago

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.

lachlanhunt commented 5 years ago

@viktor-ku wrote:

If you have general range it isn't clear what type it's gonna produce: array, maybe set, maybe weak set or any other current or future iterable? Why is it worse in your opinion than Array.range() or Set.range() hence adding methods to Array or Set directly without having to do this in standard lib? The same goes with len or take or map.

Having a range() function as a generator means that values can be pulled from it and used lazily, rather than having to populate a whole collection first. For use cases that need the values in an Array or Set, it's trivial to do:

new Set(range(10)) // Returns a Set with ten values from 0 to 9
[...range(1, 6)] // Array with five values from 1 to 5
gynet commented 5 years ago

Trees support is definitely one thing we want!

chicoxyzzy commented 5 years ago
littledan commented 5 years ago

Object.is?

ljharb commented 5 years ago

It wouldn't be web compatible to "fix" Sets and Maps to differentiate positive and negative zero, but with the rekey proposal, you'd be able to make your own Map and Set instances that did this differentiation.

chicoxyzzy commented 5 years ago

@littledan sorry I meant SameValueZero

chicoxyzzy commented 5 years ago

It wouldn't be web compatible to "fix" Sets and Maps to differentiate positive and negative zero

@ljharb yes, but it's probably possible to add new fixed versions of Set and Map to stdlib

chicoxyzzy commented 5 years ago

Also it would be web compatible to have old broken Set and Map available globally and new fixed Set and Map available via protected namespace

ljharb commented 5 years ago

It would; but I think it would be very confusing to have two things named "Map" that behaved differently.

Mouvedia commented 5 years ago

but I think it would be very confusing to have two things named "Map" that behaved differently.

Number.isNaN vs isNaN comes to mind.

ljharb commented 5 years ago

Indeed, a good example to avoid repeating :-)

js-choi commented 5 years ago

Indeed, Map and Array.prototype.map also come to mind too.

Mouvedia commented 5 years ago

Here's a summary of the most popular proposals based on the 👍:

littledan commented 5 years ago

Good summary, those all seem like good ideas (though I'm skeptical of the last one).

Mouvedia commented 5 years ago

though I'm skeptical of the last one

If partial application ever reaches stage 4, you will have to bow down to our new functional overlords.

ljharb commented 5 years ago

Certainly a Result would work very well in Promise.allSettled, and in the proposed Set/Map find methods, and a number of other places.

evanplaice commented 5 years ago

I kinda wish Promises never happened in JS core. They're eager evaluated and miss valuable use cases (ex async vs waterfall vs parallel) that some of the more popular Promise libs (ex bluebird, async.js) provide out of the box.

I like the idea of Futures as a 'do over' to provide a more useful alternative to promises.

Jack-Works commented 5 years ago

Hello, for anyone who wants a range in JS, here is an independent proposal about range https://github.com/Jack-Works/proposal-Number.range

Mouvedia commented 5 years ago

If you are adding a static method for numbers then Id expect the analogue on String to generate range of characters:


/* String.range(range: String, charset = 'UTF-8': String): String */

String.range('∏-»', 'machintosh'); // ∏π∫ªºΩæø¿¡¬√ƒ≈∆«»
String.range('Ø-é', 'ISO-8859-1'); // ØÙÚÛÜÝÞßàáâãäåæçèé
Jack-Works commented 5 years ago

If you are adding a static method for numbers then Id expect the analogue on String to generate range of characters:

/* String.range(range: String, charset = 'UTF-8': String): String */

String.range('∏-»', 'machintosh'); // ∏π∫ªºΩæø¿¡¬√ƒ≈∆«»
String.range('Ø-é', 'ISO-8859-1'); // ØÙÚÛÜÝÞßàáâãäåæçèé

The range for String is not in the goals of Number.range, you can build your own proposal, I'll focus on numbers and BigInts only 😉

Mouvedia commented 5 years ago

I was using the generic you i.e. I wasn't talking to you :) What I meant is that a generic range module would have to support characters and numbers.

obedm503 commented 5 years ago

@Mouvedia This might be derailing the conversation, but what is the purpose/use case of a string range generator?

Mouvedia commented 5 years ago

@obedm503 you will have to come up with the use cases yourself.

ruby: https://ruby-doc.org/core-2.2.0/Range.html PHP: http://php.net/manual/fr/function.range.php groovy: http://groovy-lang.org/operators.html#_range_operator swift: Range/ClosedRange nim: https://nim-lang.org/docs/system.html#..%2CT%2CU prototype: http://prototypejs.org/doc/latest/language/ObjectRange/ etc.

kaizhu256 commented 5 years ago

Trees support is definitely one thing we want!

a builtin sqlite3 (like python) would be far more practical and useful in web-applications than a low-level tree-library.

kaizhu256 commented 5 years ago

i don't know how it would be implemented, but some sort of full-text-search primitives would greatly benefit the industry.

evanplaice commented 5 years ago

@kaizhu256 a builtin sqlite3 (like python) would be far more practical and useful in web-applications than a low-level tree-library.

Local storage can be used for quickly/easily persisting smaller amounts of data. Also, keep in mind that this would be for JS as a whole; so probably needs to be useful in bith the browser and node.

kaizhu256 commented 5 years ago

i may be wrong but i think what industry really wants is a "standardized" sqlite3 in browser with full-text-search capabilities (ala websql, which never seems to have truly died [1]). indexeddb is just terrible in terms of practical usability/performance (joins need to be done in userland-javascript? really?).

adding a low-level tree-library so users can reinvent even crappier versions of indexeddb is pointless.

i also don't mind a sqlite3-library to be memory-only, so it can be encapsulated for security reasons. one can always [infrequently] persist it to indexeddb as a blob.

speaking of indexedb, its sorely in need of an appendFile feature. without it, popular browser-db's like nedb are impractical for persisting largish datasets (> 20mb) [2].

[1] current websql browser-support https://caniuse.com/#search=websql

[2] nedb emulates appendFile by re-saving its entire database as a blob to indexedb whenever a row insert/delete/update is performed. https://github.com/louischatriot/nedb/blob/v1.6.0/browser-version/browser-specific/lib/storage.js#L49

littledan commented 5 years ago

I'd recommend making feature requests for IndexedDB in their GitHub repository; you're not likely to reach the right folks here.

Mouvedia commented 5 years ago

related: https://github.com/samchon/tstl

tarjei commented 5 years ago

leftpad?

lazarljubenovic commented 5 years ago

leftpad?

It exists.

ege-lmobile commented 5 years ago

SQL is everywhere, and I think some sort of supported SQL library built in on top of indexedDB without downloading a megabyte of asm.js generated code would be amazing.

We also need generic versions of the whole array and string -prototype functions. For extra functionality, see python for inspiration. For example: https://docs.python.org/3/library/textwrap.html A universal print function! That must be in. Math and date functions. Especially date functions for dealing with time-zones and all. Some way to work with complex numbers in the math library?

Just look here: https://docs.python.org/3/library/ Let's tackle all the relevant ones!

tarjei commented 5 years ago

@lazarljubenovic I stand corrected! Thanks :)

kaizhu256 commented 5 years ago

there already exists asm.js-compiled sqlite3 at http://kripken.github.io/sql.js/GUI/. curious on feasibility of having something similar (or wasm-variant) incorporated as standard-library?

maetl commented 5 years ago
bfattori-TDA commented 5 years ago

The stdlib should be similar in functionality to that of other languages. As such, I would suggest taking something like lodash or underscore and pairing it down to its most useful functions. For example, JS has never had a simple way to deep-extend an object - but the two aforementioned libraries do. They are essentially the same thing and probably the most ubiquitous libs for basic operations.

Suggestion: Start from Lodash or Underscore and pair back, then extend with any missing functionality but only those that affect the built-in objects.

evanplaice commented 5 years ago

@bfattori-TDA IMO, lodash/underscore are a step in the right direction in terms of providing functional transforms for data.

Unfortunately, if the pipeline-operator proposal passes, we'll likely see their functionality re-incarnated in a new library that fully leverages native pipes. Adding them in their current form would be premature.