Comparing version 1.0.3 to 1.0.4
# devalue changelog | ||
## 1.0.4 | ||
* Smaller output ([#10](https://github.com/Rich-Harris/devalue/pull/10)) | ||
## 1.0.3 | ||
@@ -4,0 +8,0 @@ |
@@ -7,5 +7,3 @@ var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$'; | ||
function devalue(value) { | ||
var repeated = new Map(); | ||
var seen = new Set(); | ||
var n = 0; | ||
var counts = new Map(); | ||
function walk(thing) { | ||
@@ -15,7 +13,7 @@ if (typeof thing === 'function') { | ||
} | ||
if (seen.has(thing)) { | ||
repeated.set(thing, getName(n++)); | ||
if (counts.has(thing)) { | ||
counts.set(thing, counts.get(thing) + 1); | ||
return; | ||
} | ||
seen.add(thing); | ||
counts.set(thing, 1); | ||
if (!isPrimitive(thing)) { | ||
@@ -51,5 +49,13 @@ var type = getType(thing); | ||
} | ||
walk(value); | ||
var names = new Map(); | ||
Array.from(counts) | ||
.filter(function (entry) { return entry[1] > 1; }) | ||
.sort(function (a, b) { return b[1] - a[1]; }) | ||
.forEach(function (entry, i) { | ||
names.set(entry[0], getName(i)); | ||
}); | ||
function stringify(thing) { | ||
if (repeated.has(thing)) { | ||
return repeated.get(thing); | ||
if (names.has(thing)) { | ||
return names.get(thing); | ||
} | ||
@@ -87,9 +93,8 @@ if (isPrimitive(thing)) { | ||
} | ||
walk(value); | ||
var str = stringify(value); | ||
if (repeated.size) { | ||
if (names.size) { | ||
var params_1 = []; | ||
var statements_1 = []; | ||
var values_1 = []; | ||
repeated.forEach(function (name, thing) { | ||
names.forEach(function (name, thing) { | ||
params_1.push(name); | ||
@@ -165,3 +170,6 @@ if (isPrimitive(thing)) { | ||
return '-0'; | ||
return String(thing); | ||
var str = String(thing); | ||
if (typeof thing === 'number') | ||
return str.replace(/^(-)?0\./, '$1.'); | ||
return str; | ||
} | ||
@@ -168,0 +176,0 @@ function getType(thing) { |
@@ -13,5 +13,3 @@ (function (global, factory) { | ||
function devalue(value) { | ||
var repeated = new Map(); | ||
var seen = new Set(); | ||
var n = 0; | ||
var counts = new Map(); | ||
function walk(thing) { | ||
@@ -21,7 +19,7 @@ if (typeof thing === 'function') { | ||
} | ||
if (seen.has(thing)) { | ||
repeated.set(thing, getName(n++)); | ||
if (counts.has(thing)) { | ||
counts.set(thing, counts.get(thing) + 1); | ||
return; | ||
} | ||
seen.add(thing); | ||
counts.set(thing, 1); | ||
if (!isPrimitive(thing)) { | ||
@@ -57,5 +55,13 @@ var type = getType(thing); | ||
} | ||
walk(value); | ||
var names = new Map(); | ||
Array.from(counts) | ||
.filter(function (entry) { return entry[1] > 1; }) | ||
.sort(function (a, b) { return b[1] - a[1]; }) | ||
.forEach(function (entry, i) { | ||
names.set(entry[0], getName(i)); | ||
}); | ||
function stringify(thing) { | ||
if (repeated.has(thing)) { | ||
return repeated.get(thing); | ||
if (names.has(thing)) { | ||
return names.get(thing); | ||
} | ||
@@ -93,9 +99,8 @@ if (isPrimitive(thing)) { | ||
} | ||
walk(value); | ||
var str = stringify(value); | ||
if (repeated.size) { | ||
if (names.size) { | ||
var params_1 = []; | ||
var statements_1 = []; | ||
var values_1 = []; | ||
repeated.forEach(function (name, thing) { | ||
names.forEach(function (name, thing) { | ||
params_1.push(name); | ||
@@ -171,3 +176,6 @@ if (isPrimitive(thing)) { | ||
return '-0'; | ||
return String(thing); | ||
var str = String(thing); | ||
if (typeof thing === 'number') | ||
return str.replace(/^(-)?0\./, '$1.'); | ||
return str; | ||
} | ||
@@ -174,0 +182,0 @@ function getType(thing) { |
{ | ||
"name": "devalue", | ||
"description": "Gets the job done when JSON.stringify can't", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"repository": "Rich-Harris/devalue", | ||
@@ -6,0 +6,0 @@ "main": "dist/devalue.umd.js", |
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
20211
369