console-like-string-format
Advanced tools
Comparing version 1.0.1 to 1.0.5
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54221