5 ms·
This breaks my use case function shorten(text, length) const t = document.createElement('input') t.maxlength = length t.value = text
by turnipla 6y ago
This breaks my use case
function shorten(text, length)
const t = document.createElement('input')
t.maxlength = length
t.value = text
return t.value
}
- jagged-chisel 6y agoIndeed. I'd suggest a change in this code even if this change in FF hadn't arrived.
- 1f60c 6y agoI think GP was joking. A far more straightforward way to shorten text to a given length is: const shorten = (text, length) => text.substring(0, length);
- seanmcdirmid 6y agoProbably way more efficient than relying on a side effect to a DOM update as well.
- fpoling 6y agoBut it is the Web. Somebody must be using it.
- deleted 6y ago[deleted]
- gruez 6y agowhoosh
- deleted 6y ago[deleted]
- anchpop 6y agoI know you're joking, but this reminded me of https://xkcd.com/1172/ https://xkcd.com/1172/
- deleted 6y ago[deleted]
- jbverschoor 6y agoMaybe you should submit a pull request to the npm package where that code lives.
- jbverschoor 6y agocome to think about it.. You don't even need to! If you dockerize a chrome instance to start an electron app, you can then use it as a miroservice to truncate! I even has the possibility to inspect the element and actually see what's going on.
- rumanator 6y ago> If you dockerize a chrome instance to start an electron app, you can then use it as a miroservice to truncate! Needs more Kubernetes and a service mesh.
- roberto 6y agoSomething similar was used to parse URLs: https://stackoverflow.com/questions/6168260/how-to-parse-a-url#6168370 https://stackoverflow.com/questions/6168260/how-to-parse-a-u...
- no_wizard 6y agoYou can just use the URL object now https://developer.mozilla.org/en-US/docs/Web/API/URL https://developer.mozilla.org/en-US/docs/Web/API/URL
- 764_OC 6y agoThis change does not affect `t.value` behaviour. :)
- stestagg 6y agoyou can replace with this: function shorten(text, length) { return new Promise((a, r) => fetch(`http://leftpad.io/shorten?l=${length}&v=${encodeURIComponent(text)}`).then(rx=>rx.text().then(a, r), r)); }
- k3liutZu 6y agolol. this is awesome :)) :))