This module provides a class for splitting a string into an array of lines based on line breaks (both \n
and \r\n
).
To use this module, you should have the "node-string-methods" npm package installed. You can install it using npm or yarn:
npm install node-string-methods
const SplitLines = require('node-string-methods/splitLines');
// Create an instance of the SplitLines class with a string
const str = 'Line 1\nLine 2\r\nLine 3';
const splitter = new SplitLines(str);
// Execute the split-lines operation
const result = splitter.execute();
console.log(result);
// Output: ['Line 1', 'Line 2', 'Line 3']
str
(String): The input string that you want to split into lines.
Creates a new instance of the SplitLines
class with the provided input string.
Splits the input string into an array of lines based on line breaks (both \n
and \r\n
).
- Returns: An array containing the split lines.
const SplitLines = require('node-string-methods/splitLines');
const str = 'Line 1\nLine 2\r\nLine 3';
const splitter = new SplitLines(str);
const result = splitter.execute();
console.log(result);
// Output: ['Line 1', 'Line 2', 'Line 3']