0

I want to know whether we can convert from DOS(CR LF) format to UNIX(LF) format in Javascript/JQuery?

In linux/unix, we have a dos2unix command and I'm looking similar thing in javascript.

Thanks in advance, happy coding :)

  • [`"string".replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)? – knittl Sep 13 '21 at 07:06
  • thanks for reply, Can you elaborate your answer ? – user2388677 Sep 13 '21 at 07:07
  • Just a regex substitution like `s/\015\012/\012/g` should do. – cornuz Sep 13 '21 at 07:08
  • If you don't want to roll your own perhaps search the vast multitude of npm libraries. First I found was [eol](https://www.npmjs.com/package/eol). – Paul Rooney Sep 13 '21 at 07:08
  • https://www.npmjs.com/package/dos2unix – cornuz Sep 13 '21 at 07:12
  • I want in plain javascript as my requirement is to download a text file from windows to unix format. It is a client side only application so used plain html5 and javascript/jquery. – user2388677 Sep 13 '21 at 07:18
  • Thanks All for the quick reply. I found my answer :) Below is the solution with string.replace. `the_string.replace(/\r\n/g, "\n")` – user2388677 Sep 13 '21 at 07:25

1 Answers1

1

I found answer for my question. Below is the way we can do it in javscript with the help of "string".replace.

the_string.replace(/\r\n/g, "\n")

Thanks everyone, happy coding :)