Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

string-normalize-space

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-normalize-space - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+41
-25
index.js

@@ -1,40 +0,56 @@

module.exports = {
const normalizeSpace = s => {
normalizeSpace: s => {
if (typeof s !== 'string') throw Error ('Expected a string, got: ' + s)
s = s.trim ()
if (typeof s !== 'string') throw Error ('Expected a string, got: ' + s)
s = s.trim ()
const {length} = s
const {length} = s
let result = '', from = 0, to = 0, sp = false; while (to < length) {
let result = '', from = 0, to = 0, sp = false; while (to < length) {
const c = s.charCodeAt (to)
const c = s.charCodeAt (to)
switch (c) {
switch (c) {
case 0x20:
case 0x9:
case 0xD:
case 0xA:
if (!sp) result += s.slice (from, to) + ' '
from = ++ to
sp = true
break
case 0x20:
case 0x9:
case 0xD:
case 0xA:
if (!sp) result += s.slice (from, to) + ' '
from = ++ to
sp = true
break
default:
if (sp) sp = false
to ++
default:
if (sp) sp = false
to ++
}
}
if (from === 0) return s
}
return (result + s.slice (from)).trim ()
if (from === 0) return s
return (result + s.slice (from)).trim ()
}
class NormalizeSpaceLogFormat {
transform (info) {
info.message = normalizeSpace (info.message)
return info
}
}
module.exports = {
normalizeSpace,
logform: () => new NormalizeSpaceLogFormat ()
}
{
"name": "string-normalize-space",
"version": "1.0.0",
"description": "XPath 1.0 normalize-space analog",
"version": "1.0.1",
"description": "XPath 1.0 normalize-space analog, winston log formatter",
"main": "index.js",

@@ -36,3 +36,4 @@ "files": [

"normalize",
"space"
"space",
"winston"
],

@@ -45,5 +46,6 @@ "author": "Dmitry Ovsyanko",

"devDependencies": {
"jest": "^29.3.1"
"jest": "^29.3.1",
"winston": "^3.14.0"
},
"homepage": "https://github.com/do-/node-string-normalize-space#readme"
}

@@ -6,4 +6,6 @@ ![workflow](https://github.com/do-/node-string-normalize-space/actions/workflows/main.yml/badge.svg)

So it's basically like [String.prototype.trim()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim), but works also inside the string.
So it's basically like [String.prototype.trim()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim), but also works inside the string.
The [`winston`](https://github.com/winstonjs/winston) compatible log formatter is provided.
# Installation

@@ -16,2 +18,3 @@

# Usage
## General purpose

@@ -24,2 +27,20 @@ ```js

## As a `winston` log formatter
```js
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

@@ -26,0 +47,0 @@