string-true-oneline

This module transforms a string to a oneline string considering escape sequences: so('test noop test') -> 'noop test'

Usage no npm install needed!

<script type="module">
  import stringTrueOneline from 'https://cdn.skypack.dev/string-true-oneline';
</script>

README

string-true-oneline

Build Status Coverage Status

This module is written on typescript, and contains the .d.ts file.
If you write on typescript: just use it in your project and definitions will be automatically uploaded.

npm i -S string-true-oneline

About

This module transforms a string to a oneline string considering escape sequences.

Warning!

This module does not supported an ANSI escape codes. And simply removes them before forming line.

const so = require('string-true-oneline')
const inspect = require('util').inspect
const assert = require('assert')
const chalk = require('chalk')

const actColor = so(chalk.blue('\nhello') + ' ' + chalk.blue('world!\n'))
const actClear = so('\nhello world!\n')
const exp = 'hello world!'
assert.equal(actColor, exp)
assert.equal(actClear, exp)

Examples

const so = require('string-true-oneline')
const inspect = require('util').inspect
const assert = require('assert')

var act = so('   \n   hello   world!   \n   ')
var exp = 'hello world!'
assert.equal(act, exp)

var act = so('h\ve\vl\rl\f\bo \nw\no\r\v\r\vr\v\rl\nd !')
var exp = 'h e l l o w o r l d !'
assert.equal(act, exp)

Related