Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

console-like-string-format

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-like-string-format - npm Package Compare versions

Comparing version 1.0.1 to 1.0.5

64

lib/index.js

@@ -10,42 +10,42 @@ export default function () {

const token = firstArg[i]
if (hasPercentSign && ['c', 's', 'i', 'd', 'f', 'O', 'o'].indexOf(token) > -1) {
hasPercentSign = false
if ('c' === token) {
// ignore %c
argumentArray.shift()
} else if ('s' === token) {
resultString += argumentArray.shift()
} else if ('o' === token.toLowerCase()) {
resultString += JSON.stringify(argumentArray.shift())
} else if ('i' === token || 'd' === token) {
let val = ''
try {
val = parseInt(argumentArray.shift())
} catch (e){
console.warn(e)
if (hasPercentSign) {
if (['c', 's', 'i', 'd', 'f', 'O', 'o', '%'].indexOf(token) > -1) {
hasPercentSign = false
if ('c' === token) {
// ignore %c
argumentArray.shift()
} else if ('s' === token) {
resultString += argumentArray.shift()
} else if ('o' === token.toLowerCase()) {
resultString += JSON.stringify(argumentArray.shift())
} else if ('i' === token || 'd' === token) {
let val = ''
try {
val = parseInt(argumentArray.shift())
} catch (e) {
console.warn(e)
}
resultString += '' + val
} else if ('f' === token) {
let val = ''
try {
val = parseFloat(argumentArray.shift())
} catch (e) {
console.warn(e)
}
resultString += '' + val
} else if ('%' === token) {
resultString += '' + '%'
hasPercentSign = false
}
resultString += '' + val
} else if ('f' === token) {
let val = ''
try {
val = parseFloat(argumentArray.shift())
} catch (e){
console.warn(e)
}
resultString += '' + val
} else if ('%' === token) {
resultString += '' + '%'
} else {
resultString += '' + '%' + token
hasPercentSign = true
}
i++
} else if ('%' === token) {
if (hasPercentSign) {
resultString += '%'
}
hasPercentSign = true
i++
} else {
resultString += '' + token
i++
}
i++
}

@@ -52,0 +52,0 @@

@@ -8,3 +8,3 @@ {

"name": "console-like-string-format",
"version": "1.0.1",
"version": "1.0.5",
"main": "lib/index.js",

@@ -11,0 +11,0 @@ "directories": {

// import format from '../lib/console-like-format'
const format = require('../dist/console-like-string-format')
// import format from '../lib/console-like-format'
// const format = require('../dist/console-like-string-format')
import format from '../lib/index'
const {expect} = require('chai')

@@ -76,4 +76,4 @@

it('', function () {
expect(format('abcd %%f %%ss %o %d %i', '100.3', 'foo', {a: 1, b: '1'}, 100, 100.10, 1000, {a: 1})).equal('abcd %100.3 %foos {"a":1,"b":"1"} 100 100 1000 {"a":1}')
expect(format('abcd %%f %%ss %o %d %i', '100.3', 'foo', {a: 1, b: '1'}, 100, 100.10, 1000, {a: 1})).equal('abcd %f %ss "100.3" NaN NaN 100 100.1 1000 {"a":1}')
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc