UNPKG

optima

Version:

Join all elements of an array and create a human-readable string

19 lines (15 loc) 414 B
/*! * lines-to-json | MIT (c) Shinnosuke Watanabe * https://github.com/shinnn/lines-to-json */ 'use strict'; var newLineRegex = /\r?\n/; module.exports = function linesToJson(str, option) { if (typeof str !== 'string') { throw new TypeError( String(str) + ' is not a string.' ); } var space = option ? option.space : ' '; return JSON.stringify(str.split(newLineRegex), null, space); };