ECMAScript 2017 addresses left-pad gate, alongside various improvements
In March, 2016, as a result of a naming conflict with instant messaging app Kik, developer Azer Koçulu withdrew more than 250 of his modules from NPM, the service Node.js developers use to install dependencies.
Web developers have managed to move on, but now ECMAScript 2017, aka ES8, provides an official mechanism for string padding. The specification, initially proposed in 2015 before the left-pad incident, defines two new String methods: padStart and padEnd.
"It is highly probable that the majority of current string padding implementations are inefficient," the proposal says. "Bringing this into the platform will improve performance of the web, and developer productivity as they no longer have to implement these common functions."
let t = ['Alice', 'Bob', 'Carol']; t.forEach(p => console.log(p.padStart(8, '-')));
The resulting output pads the list of names out to eight character spaces each:
---Alice -----Bob ---Carol
There are other more interesting additions to ECMAScript, however.
ES2015's Promises helped somewhat. But ES2017's Async/Await implementation means complex server queries can be built in a far more readable and maintainable way.
Trailing commas, meanwhile, allow lists of parameters in a function to conclude with a trailing comma after the last element. This lets developers put additional parameters on a new line, without adding a comma on the previous line to extend the series. Though seemingly trivial, reducing the number of lines where editing might occur is likely to reduce errors.
Sponsored: Beyond the Data Frontier