2 ms·
One of the weird problems here is performance, though. A naive approach to left-pad, might involve (new Array(n+1)).join(padChar), for example, since javascript
by pfooti 11y ago
One of the weird problems here is performance, though. A naive approach to left-pad, might involve (new Array(n+1)).join(padChar), for example, since javascript doesn't actually have a consistent language-native way to create an arbitrary-length string. That technique ends up, in some javascript runtimes, taking orders of magnitude longer to run compared to a for loop with string concatenation. The array.join method is one line though.
So, imagine the scenario where you've got a commonly-used function that gets vendored and from there copypasta'd into a lib/common or some other location in your project. You've basically just cut yourself off from any updates that the module author might make when new javascript optimization hacks come around (or obscure corner-case bugs need protecting against). It's a small problem, but it is at least worth considering.
There's also this whole thing with licenses - there's a fundamental difference between using a library and copying its source into your build tree. The MIT license doesn't care, but the LGPL certainly does.
I do like the idea in general. You should extend it by doing tree-shaking or dead-code analysis. "This library is big, but you're just using one function call, let's just copypasta that one in here".
- esailija 11y agoThe code needs to pass threshold of originality to be copyrightable, otherwise you don't need to care about the license. For example `(new Array(n+1)).join(padChar)` is definitely not copyrightable.