Comparing version 1.0.11 to 1.0.12
@@ -0,166 +1,168 @@ | ||
'use strict' | ||
var nul = process.platform === 'win32' ? '\\\\.\\NUL' : '/dev/null' | ||
var bench = require('fastbench') | ||
var stream = require('fs').createWriteStream('/dev/null') | ||
var stream = require('fs').createWriteStream(nul) | ||
var alt0 = require('./') | ||
var largeStr = JSON.stringify(require('./package.json')) | ||
largeStr += largeStr | ||
largeStr += largeStr | ||
largeStr += largeStr | ||
var run = bench([ | ||
function alt0ManySmallConcats(cb) { | ||
function alt0ManySmallConcats (cb) { | ||
stream.write(alt0(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt1ManySmallConcats(cb) { | ||
function alt1ManySmallConcats (cb) { | ||
stream.write(alt1(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt2ManySmallConcats(cb) { | ||
function alt2ManySmallConcats (cb) { | ||
stream.write(alt2(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt3ManySmallConcats(cb) { | ||
function alt3ManySmallConcats (cb) { | ||
stream.write(alt3(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt4ManySmallConcats(cb) { | ||
function alt4ManySmallConcats (cb) { | ||
stream.write(alt4(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt5ManySmallConcats(cb) { | ||
function alt5ManySmallConcats (cb) { | ||
stream.write(alt5(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt6ManySmallConcats(cb) { | ||
function alt6ManySmallConcats (cb) { | ||
stream.write(alt6(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt7ManySmallConcats(cb) { | ||
function alt7ManySmallConcats (cb) { | ||
stream.write(alt7(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt8ManySmallConcats(cb) { | ||
function alt8ManySmallConcats (cb) { | ||
stream.write(alt8(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt9ManySmallConcats(cb) { | ||
function alt9ManySmallConcats (cb) { | ||
stream.write(alt9(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function alt0SeveralLargeConcats(cb) { | ||
function alt0SeveralLargeConcats (cb) { | ||
stream.write(alt0(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt1SeveralLargeConcats(cb) { | ||
function alt1SeveralLargeConcats (cb) { | ||
stream.write(alt1(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt2SeveralLargeConcats(cb) { | ||
function alt2SeveralLargeConcats (cb) { | ||
stream.write(alt2(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt3SeveralLargeConcats(cb) { | ||
function alt3SeveralLargeConcats (cb) { | ||
stream.write(alt3(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt4SeveralLargeConcats(cb) { | ||
function alt4SeveralLargeConcats (cb) { | ||
stream.write(alt4(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt5SeveralLargeConcats(cb) { | ||
function alt5SeveralLargeConcats (cb) { | ||
stream.write(alt5(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt6SeveralLargeConcats(cb) { | ||
function alt6SeveralLargeConcats (cb) { | ||
stream.write(alt6(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt7SeveralLargeConcats(cb) { | ||
function alt7SeveralLargeConcats (cb) { | ||
stream.write(alt7(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt8SeveralLargeConcats(cb) { | ||
function alt8SeveralLargeConcats (cb) { | ||
stream.write(alt8(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt9SeveralLargeConcats(cb) { | ||
function alt9SeveralLargeConcats (cb) { | ||
stream.write(alt9(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function alt0ExponentialSmallConcats(cb) { | ||
function alt0ExponentialSmallConcats (cb) { | ||
stream.write(alt0(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt1ExponentialSmallConcats(cb) { | ||
function alt1ExponentialSmallConcats (cb) { | ||
stream.write(alt1(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt2ExponentialSmallConcats(cb) { | ||
function alt2ExponentialSmallConcats (cb) { | ||
stream.write(alt2(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt3ExponentialSmallConcats(cb) { | ||
function alt3ExponentialSmallConcats (cb) { | ||
stream.write(alt3(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt4ExponentialSmallConcats(cb) { | ||
function alt4ExponentialSmallConcats (cb) { | ||
stream.write(alt4(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt5ExponentialSmallConcats(cb) { | ||
function alt5ExponentialSmallConcats (cb) { | ||
stream.write(alt5(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt6ExponentialSmallConcats(cb) { | ||
function alt6ExponentialSmallConcats (cb) { | ||
stream.write(alt6(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt7ExponentialSmallConcats(cb) { | ||
function alt7ExponentialSmallConcats (cb) { | ||
stream.write(alt7(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt8ExponentialSmallConcats(cb) { | ||
function alt8ExponentialSmallConcats (cb) { | ||
stream.write(alt8(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt9ExponentialSmallConcats(cb) { | ||
function alt9ExponentialSmallConcats (cb) { | ||
stream.write(alt9(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function alt0ExponentialLargeConcats(cb) { | ||
function alt0ExponentialLargeConcats (cb) { | ||
stream.write(alt0(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt1ExponentialLargeConcats(cb) { | ||
function alt1ExponentialLargeConcats (cb) { | ||
stream.write(alt1(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt2ExponentialLargeConcats(cb) { | ||
}, | ||
function alt2ExponentialLargeConcats (cb) { | ||
stream.write(alt2(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt3ExponentialLargeConcats(cb) { | ||
}, | ||
function alt3ExponentialLargeConcats (cb) { | ||
stream.write(alt3(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt4ExponentialLargeConcats(cb) { | ||
}, | ||
function alt4ExponentialLargeConcats (cb) { | ||
stream.write(alt4(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt5ExponentialLargeConcats(cb) { | ||
}, | ||
function alt5ExponentialLargeConcats (cb) { | ||
stream.write(alt5(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt6ExponentialLargeConcats(cb) { | ||
}, | ||
function alt6ExponentialLargeConcats (cb) { | ||
stream.write(alt6(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt7ExponentialLargeConcats(cb) { | ||
}, | ||
function alt7ExponentialLargeConcats (cb) { | ||
stream.write(alt7(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt8ExponentialLargeConcats(cb) { | ||
}, | ||
function alt8ExponentialLargeConcats (cb) { | ||
stream.write(alt8(makeExpoStr(largeStr, 7))) | ||
setImmediate(cb) | ||
}, | ||
function alt9ExponentialLargeConcats(cb) { | ||
function alt9ExponentialLargeConcats (cb) { | ||
stream.write(alt9(makeExpoStr(largeStr, 7))) | ||
@@ -174,7 +176,7 @@ setImmediate(cb) | ||
var rx = /()/ | ||
function alt1(s) { | ||
function alt1 (s) { | ||
rx.test(s) | ||
return s | ||
} | ||
function alt2(s) { | ||
function alt2 (s) { | ||
rx.exec(s) | ||
@@ -184,8 +186,8 @@ return s | ||
function alt3(s) { | ||
s|0 | ||
function alt3 (s) { | ||
s | 0 | ||
return s | ||
} | ||
function alt4(s) { | ||
function alt4 (s) { | ||
~s | ||
@@ -195,3 +197,3 @@ return s | ||
function alt5(s) { | ||
function alt5 (s) { | ||
escape(s) | ||
@@ -201,3 +203,3 @@ return s | ||
function alt6(s) { | ||
function alt6 (s) { | ||
unescape(s) | ||
@@ -207,3 +209,3 @@ return s | ||
function alt7(s) { | ||
function alt7 (s) { | ||
parseInt(s, 10) | ||
@@ -213,3 +215,3 @@ return s | ||
function alt8(s) { | ||
function alt8 (s) { | ||
parseFloat(s) | ||
@@ -219,3 +221,3 @@ return s | ||
function alt9(s) { | ||
function alt9 (s) { | ||
alt9[s] = null | ||
@@ -225,3 +227,3 @@ return s | ||
function makeStr(str, concats) { | ||
function makeStr (str, concats) { | ||
var s = '' | ||
@@ -234,3 +236,3 @@ while (concats--) { | ||
function makeExpoStr(str, concats) { | ||
function makeExpoStr (str, concats) { | ||
var s = str | ||
@@ -241,2 +243,2 @@ while (concats--) { | ||
return s | ||
} | ||
} |
@@ -0,38 +1,40 @@ | ||
'use strict' | ||
var nul = process.platform === 'win32' ? '\\\\.\\NUL' : '/dev/null' | ||
var bench = require('fastbench') | ||
var stream = require('fs').createWriteStream('/dev/null') | ||
var stream = require('fs').createWriteStream(nul) | ||
var flatstr = require('./') | ||
var largeStr = JSON.stringify(require('./package.json')) | ||
largeStr += largeStr | ||
largeStr += largeStr | ||
largeStr += largeStr | ||
var run = bench([ | ||
function unflattenedManySmallConcats(cb) { | ||
function unflattenedManySmallConcats (cb) { | ||
stream.write(makeStr('a', 200)) | ||
setImmediate(cb) | ||
}, | ||
function flattenedManySmallConcats(cb) { | ||
}, | ||
function flattenedManySmallConcats (cb) { | ||
stream.write(flatstr(makeStr('a', 200))) | ||
setImmediate(cb) | ||
}, | ||
function unflattenedSeveralLargeConcats(cb) { | ||
function unflattenedSeveralLargeConcats (cb) { | ||
stream.write(makeStr(largeStr, 10)) | ||
setImmediate(cb) | ||
}, | ||
function flattenedSeveralLargeConcats(cb) { | ||
}, | ||
function flattenedSeveralLargeConcats (cb) { | ||
stream.write(flatstr(makeStr(largeStr, 10))) | ||
setImmediate(cb) | ||
}, | ||
function unflattenedExponentialSmallConcats(cb) { | ||
function unflattenedExponentialSmallConcats (cb) { | ||
stream.write(makeExpoStr('a', 12)) | ||
setImmediate(cb) | ||
}, | ||
function flattenedExponentialSmallConcats(cb) { | ||
}, | ||
function flattenedExponentialSmallConcats (cb) { | ||
stream.write(flatstr(makeExpoStr('a', 12))) | ||
setImmediate(cb) | ||
}, | ||
function unflattenedExponentialLargeConcats(cb) { | ||
function unflattenedExponentialLargeConcats (cb) { | ||
stream.write(makeExpoStr(largeStr, 7)) | ||
setImmediate(cb) | ||
}, | ||
function flattenedExponentialLargeConcats(cb) { | ||
}, | ||
function flattenedExponentialLargeConcats (cb) { | ||
stream.write(flatstr(makeExpoStr(largeStr, 7))) | ||
@@ -45,4 +47,3 @@ setImmediate(cb) | ||
function makeStr(str, concats) { | ||
function makeStr (str, concats) { | ||
var s = '' | ||
@@ -55,3 +56,3 @@ while (concats--) { | ||
function makeExpoStr(str, concats) { | ||
function makeExpoStr (str, concats) { | ||
var s = str | ||
@@ -62,2 +63,2 @@ while (concats--) { | ||
return s | ||
} | ||
} |
37
index.js
'use strict' | ||
if (!process.versions || !process.versions.node || parseInt(process.versions.node.split('.')[0]) >= 8) { | ||
try { | ||
var flatstr = Function('s', 'return typeof s === "string" ? %FlattenString(s) : s') | ||
} catch (e) { | ||
try { | ||
var v8 = require('v' + '8') | ||
v8.setFlagsFromString('--allow-natives-syntax') | ||
var _flatstr = Function('s', 'return typeof s === "string" ? %FlattenString(s) : s') | ||
var flatstr = (s) => { | ||
try { | ||
return _flatstr(s) | ||
} catch (e) { | ||
v8.setFlagsFromString('--allow-natives-syntax') | ||
_flatstr = Function('s', 'return typeof s === "string" ? %FlattenString(s) : s') | ||
v8.setFlagsFromString('--no-allow-natives-syntax') | ||
return s | ||
} | ||
} | ||
v8.setFlagsFromString('--no-allow-natives-syntax') | ||
} catch (e) { | ||
var flatstr = function flatstr(s) { | ||
Number(s) | ||
return s | ||
} | ||
} | ||
} | ||
} else flatstr = function flatstr(s) { | ||
Number(s) | ||
// You may be tempted to copy and paste this, | ||
// but take a look at the commit history first, | ||
// this is a moving target so relying on the module | ||
// is the best way to make sure the optimization | ||
// method is kept up to date and compatible with | ||
// every Node version. | ||
function flatstr (s) { | ||
s | 0 | ||
return s | ||
@@ -32,0 +13,0 @@ } |
{ | ||
"name": "flatstr", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"description": "Flattens the underlying C structures of a concatenated JavaScript string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,2 +26,2 @@ 'use strict' | ||
t.end() | ||
}) | ||
}) |
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
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
2
0
12621
314