Skip to content

do-/node-string-normalize-space

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

workflow Jest coverage

string-normalize-space is a node.js module implementing one single function, normalizeSpace, following the definition from XPath 1.0.

So it's basically like String.prototype.trim(), but also works inside the string.

The winston compatible log formatter is provided.

Installation

npm install string-normalize-space

Usage

General purpose

const {normalizeSpace} = require ('string-normalize-space')

const ab = normalizeSpace (' A\r\n\t B ') // will be 'A B'

As a winston log formatter

const {createLogger, format: {combine, printf}, transports} = require ('winston')

const normalizeSpaceLogFormat = require ('string-normalize-space').logform

const logger = createLogger ({
  transports: [
    new transports.Console (),
  ],
  format: combine (
    printf (info => `${info.message} ${info.meta} ${info.stack}`), // may be lots of \n
    normalizeSpaceLogFormat ()                                     // exactly one line
  ),
})

Notes

Unlike numerous similar modules, this one doesn't rely on any regular expressions.

As mentioned before, the XPath 1.0 specification is followed, so only 4 characters are considered "space". No effort is made to support extended Unicode space characters.

About

XPath 1.0 normalize-space analog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published