You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

helpers.js 464B

1234567891011121314151617181920212223
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. exports.getNumberOfLines = function getNumberOfLines(str) {
  7. let nr = -1;
  8. let idx = -1;
  9. do {
  10. nr++
  11. idx = str.indexOf("\n", idx + 1);
  12. } while(idx >= 0);
  13. return nr;
  14. };
  15. exports.getUnfinishedLine = function getUnfinishedLine(str) {
  16. const idx = str.lastIndexOf("\n");
  17. if(idx === -1)
  18. return str.length;
  19. else
  20. return str.length - idx - 1;
  21. };