index-of-newline

Find indexOf CR, LF or CRLF

MIT 44 个版本
安装
npm install index-of-newline
yarn add index-of-newline
pnpm add index-of-newline
bun add index-of-newline
README

index-of-newline

Find next line ending in CR, LF or CRLF

Example 1

import indexOfNewline from "index-of-newline";

const string = "some\r\nstring\ncombination\r";
let index = indexOfNewline(string) as number;
console.log(index); // 4

index = indexOfNewline(string, index + 2) as number;
console.log(index); // 12

index = indexOfNewline(string, index + 1) as number;
console.log(index); // 24

Example 2

import indexOfNewline from "index-of-newline";

const string = "some\r\nstring\ncombination\r";
const results = [];
let [index, length] = indexOfNewline(string, 0, true) as number[];
while (index >= 0) {
  results.push(index);
  [index, length] = indexOfNewline(string, index + length, true) as number[];
}
console.log(results); // [4, 12, 24]

Documentation

API Docs

版本列表
1.2.11 2026-05-26
1.2.10 2025-12-12
1.2.9 2025-12-12
1.2.8 2025-12-04
1.2.7 2025-12-04
1.2.6 2025-12-02
1.2.5 2025-11-06
1.2.4 2025-10-21
1.2.3 2025-10-21
1.2.2 2025-07-08
1.2.1 2025-06-29
1.2.0 2025-06-29
1.1.33 2025-06-20
1.1.32 2025-06-18
1.1.31 2025-05-19
1.1.30 2025-05-18
1.1.29 2025-01-23
1.1.28 2025-01-23
1.1.27 2025-01-23
1.1.26 2025-01-19
1.1.25 2025-01-18
1.1.24 2025-01-15
1.1.23 2025-01-15
1.1.22 2025-01-14
1.1.21 2025-01-12
1.1.20 2025-01-12
1.1.17 2025-01-04
1.1.16 2025-01-04
1.1.15 2025-01-04
1.1.14 2025-01-04
1.1.13 2025-01-04
1.1.12 2025-01-04
1.1.11 2025-01-04
1.1.10 2025-01-04
1.1.8 2022-07-03
1.1.7 2022-07-03
1.1.6 2022-06-27
1.1.5 2022-06-23
1.1.4 2021-10-17
1.1.3 2021-10-17
1.1.2 2021-10-10
1.1.1 2021-10-07
1.1.0 2021-10-03
1.0.0 2021-10-03