Git Product home page Git Product logo

string-render's Introduction

string-render

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-render

About

This module replaces all escape sequence by spaces and line breaks.

Warning!

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

const sr = require('string-render')
const inspect = require('util').inspect
const assert = require('assert')
const chalk = require('chalk')

var actColor = sr(`${chalk.green(`12${chalk.red('345')}67`)}8\r!${chalk.blue('@#$')}`)
var actClear = sr('12345678\r!@#$')
var exp = '!@#$5678'
assert.equal(inspect(actColor), inspect(exp))
assert.equal(inspect(actClear), inspect(exp))

Examples

const sr = require('string-render')
const inspect = require('util').inspect
const assert = require('assert')

var act = sr('some\be\rsom\vstrange\r\vline')
var exp = 'some\n'
        + '   strange\n'
        + 'line'
assert.equal(inspect(act), inspect(exp))

var act = sr('1\b\v2\b\v3')
var exp = '1\n'
        + '2\n'
        + '3'
assert.equal(inspect(act), inspect(exp))

var act = sr('wow\rwow\f space\t!\rbig\n01234567012345670')
var exp = 'wow\n'
        + 'big space       !\n'
        + '01234567012345670'
assert.equal(inspect(act), inspect(exp))

Related

  • string-true-oneline - transforms a string to a oneline string considering escape sequences
  • murky - like util.format with additional placeholders

string-render's People

Contributors

nskazki avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.