Hacker News new | ask | show | jobs
by turnipla 2231 days ago
This breaks my use case

    function shorten(text, length)
      const t = document.createElement('input')
      t.maxlength = length
      t.value = text
      return t.value
    }
7 comments

you 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));
    }

  $ host leftpad.io
  Host leftpad.io not found: 3(NXDOMAIN)
i_do_not_know_what_i_expected.png
haha, too bad those .io domains are so expensive, would make a hilarious joke
I'm seeing $29/y or so from multiple providers. Doesn't strike me as particularly expensive.
Something similar was used to parse URLs: https://stackoverflow.com/questions/6168260/how-to-parse-a-u...
You can just use the URL object now

https://developer.mozilla.org/en-US/docs/Web/API/URL

Maybe you should submit a pull request to the npm package where that code lives.
come 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.

> 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.

Indeed. I'd suggest a change in this code even if this change in FF hadn't arrived.
I 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);
Probably way more efficient than relying on a side effect to a DOM update as well.
But it is the Web. Somebody must be using it.
whoosh
This change does not affect `t.value` behaviour. :)
I know you're joking, but this reminded me of https://xkcd.com/1172/
This is exactly it!
Me too. I suspect this was intentional :)
lol. this is awesome :)) :))