by thomasfoster96 · 9y ago · 0 comments
* Object.values/Object.entries - https://github.com/tc39/proposal-object-values-entries
* String padding - https://github.com/tc39/proposal-string-pad-start-end
* Object.getOwnPropertyDescriptors - https://github.com/ljharb/proposal-object-getownpropertydesc...
* Trailing commas - https://github.com/tc39/proposal-trailing-function-commas
* Async functions - https://github.com/tc39/ecmascript-asyncawait
* Shared memory and atomics - https://github.com/tc39/ecmascript_sharedmem
The first five have been available via Babel and/or polyfills for ~18 months or so, so they’ve been used for a while now.
[0] https://github.com/tc39/proposals/blob/master/finished-propo...
I consider the fact that a stupid-simple package was depended-upon by so many mature libraries as an indication it should be a language feature.
Working with network protocols I find myself needing padding functions all the time, and there isn't really an elegant way to do so inline, so I welcome this addition.
Unfortunately neither the npm module nor the browser version really do what most people want and string handling in javascript is still a minefield.
'\u{1F4A9}'.padStart(5, '1') => "111" // oops (\u{1F4A9} is at the end of this, HN filter)
'\u{1F4A9}'.length => 2
[...'\u{1F4A9}'].length => 1 //WTF?
'mañana'.padStart(7, '1') => "1mañana" // ok
'man\u0303ana'.padStart(7, '1') => "mañana" // oops
'man\u0303ana'.length => 7
[...'man\u0303ana'].length => 7 // WTF? Why doesn't this match the behavior of [...'\u{1F4A9}'].length ?
'man\u0303ana'.normalize('NFC').padStart(7, '1') => "1mañana" // OK
I do understand the unicode issues here, but the inconsistency in the APIs from a user perspective and lack of any fully cross browser support for sane string processing in Javascript means we still have only a few options:
1) Don't do string processing in javascript at all.
2) Include a library to make it sane, these are usually huge as they usually need large lookup tables.
3) Accept that things won't always be correct.
This is one example but the lack of a sane standard library in Javascript is one of the biggest problems the web has right now. I'd be curious to know how many bytes of JS are loaded on the average website just to work around the lack of standard library support for basic functionality, I'd bet it's a very large number. Another fun one: Try to parse a URL and append extra query params to it, correctly.
'mañana'.padStart(7, '1') => "1mañana" // ok
'man\u0303ana'.padStart(7, '1') => "mañana" // oops
You are being disingenuous here. Those are different strings, with different lengths (try copying this into the console): 'mañana'.length // 6
'mañana'.length // 7
The latter has two stacked characters. These issues are inherent to Unicode and `padStart` is treating the strings correctly. If you need normalization, use the .normalize method you mentioned yourself.This is a major improvement: double-wide and stacked characters have been there since ES3, but now the language is providing standard tools to work with them.
The key thing to remember is that iteration over Unicode strings only makes sense as iteration over code points, not UCS-2 characters, not bytes, not grapheme clusters. The JS String iterator was very deliberately made to iterate over code points. That length reports UCS-2 characters is a historical mistake. That padding is operating on UCS-2 characters is probably a reflection of the fact that the operation isn't well-defined beyond ASCII.
As to your last bit, I tend to favor encodeURIComponent and have done it correctly... the main reason, is to avoid "+" vs " " in query strings.
Sure, left-pad being deleted was what resulted in most people's problems but this was just the fallout from npm Inc forcibly reassigning an actively used package name from a major open source contributor to appease a company that didn't even threaten them directly.
const hello = {
, 'one'
, 'two'
, 'three
}
would be easier to visually parse than: const hello = {
'one',
'two',
'three',
}
Since the commas actually work as a guide.I'm basing this on the assumption that the desire for trailing commas is making editing easier and reducing noise in diffs.
Just curious if there are niches where people are spending a lot of time manually editing JSON or if the use case is something else entirely.
I love them in code, despite initial resistance.
...but in my experience usage of ES6/ES7/ES8 as names far outweighs usage of ES2015/ES2016/ES2017. Calling it ES2017, while technically correct, would in my opinion be far more confusing to most people than calling it ES8.
I personally prefer the terse version, but there are advantages to using the year-based naming.