Skip to content

Commit bd0679e

Browse files
L2jLigamcollina
authored andcommitted
Dropped uglifier support (#166)
1 parent 06acd3b commit bd0679e

File tree

11 files changed

+4
-128
lines changed

11 files changed

+4
-128
lines changed

README.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ FJS creation x 8,951 ops/sec ±0.51% (92 runs sampled)
1313
1414
JSON.stringify array x 5,146 ops/sec ±0.32% (97 runs sampled)
1515
fast-json-stringify array x 8,402 ops/sec ±0.62% (95 runs sampled)
16-
fast-json-stringify-uglified array x 8,474 ops/sec ±0.49% (93 runs sampled)
1716
1817
JSON.stringify long string x 13,061 ops/sec ±0.25% (98 runs sampled)
1918
fast-json-stringify long string x 13,059 ops/sec ±0.21% (98 runs sampled)
20-
fast-json-stringify-uglified long string x 13,099 ops/sec ±0.14% (98 runs sampled)
2119
2220
JSON.stringify short string x 6,295,988 ops/sec ±0.28% (98 runs sampled)
2321
fast-json-stringify short string x 43,335,575 ops/sec ±1.24% (86 runs sampled)
24-
fast-json-stringify-uglified short string x 40,042,871 ops/sec ±1.38% (93 runs sampled)
2522
2623
JSON.stringify obj x 2,557,026 ops/sec ±0.20% (97 runs sampled)
2724
fast-json-stringify obj x 9,001,890 ops/sec ±0.48% (90 runs sampled)
28-
fast-json-stringify-uglified obj x 9,073,607 ops/sec ±0.41% (94 runs sampled)
2925
```
3026

3127
#### Table of contents:
@@ -40,7 +36,6 @@ fast-json-stringify-uglified obj x 9,073,607 ops/sec ±0.41% (94 runs sampled)
4036
- <a href="#anyof">`AnyOf`</a>
4137
- <a href="#ref">`Reuse - $ref`</a>
4238
- <a href="#long">`Long integers`</a>
43-
- <a href="#uglify">`Uglify`</a>
4439
- <a href="#nullable">`Nullable`</a>
4540
- <a href="#caveat">`Caveat`</a>
4641
- <a href="#acknowledgements">`Acknowledgements`</a>
@@ -429,30 +424,6 @@ const obj = {
429424
console.log(stringify(obj)) // '{"id":18446744073709551615}'
430425
```
431426
432-
<a name="uglify"></a>
433-
#### Uglify
434-
If you want to squeeze a little bit more performance out of the serialization at the cost of readability in the generated code, you can pass `uglify: true` as an option.
435-
Note that you have to manually install `uglify-es` in order for this to work. Only version 3 is supported.
436-
Example:
437-
438-
Note that if you are using Node 8.3.0 or newer, there are no performance gains from using Uglify. See https://www.nearform.com/blog/node-js-is-getting-a-new-v8-with-turbofan/
439-
440-
```javascript
441-
442-
const stringify = fastJson({
443-
title: 'Example Schema',
444-
type: 'object',
445-
properties: {
446-
id: {
447-
type: 'integer'
448-
}
449-
}
450-
}, { uglify: true })
451-
452-
// stringify is now minified code
453-
console.log(stringify({ some: 'object' })) // '{"some":"object"}'
454-
```
455-
456427
<a name="nullable"></a>
457428
#### Nullable
458429

bench.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ const CJSStringifyString = CJS({ type: 'string' })
7070

7171
const FJS = require('.')
7272
const stringify = FJS(schema)
73-
const stringifyUgly = FJS(schema, { uglify: true })
7473
const stringifyArray = FJS(arraySchema)
75-
const stringifyArrayUgly = FJS(arraySchema, { uglify: true })
7674
const stringifyString = FJS({ type: 'string' })
77-
const stringifyStringUgly = FJS({ type: 'string', uglify: true })
7875
var str = ''
7976

8077
for (var i = 0; i < 10000; i++) {
@@ -108,10 +105,6 @@ suite.add('fast-json-stringify array', function () {
108105
stringifyArray(multiArray)
109106
})
110107

111-
suite.add('fast-json-stringify-uglified array', function () {
112-
stringifyArrayUgly(multiArray)
113-
})
114-
115108
suite.add('json-strify array', function () {
116109
JSTRArray(multiArray)
117110
})
@@ -128,10 +121,6 @@ suite.add('fast-json-stringify long string', function () {
128121
stringifyString(str)
129122
})
130123

131-
suite.add('fast-json-stringify-uglified long string', function () {
132-
stringifyStringUgly(str)
133-
})
134-
135124
suite.add('json-strify long string', function () {
136125
JSTRInstance(str)
137126
})
@@ -148,10 +137,6 @@ suite.add('fast-json-stringify short string', function () {
148137
stringifyString('hello world')
149138
})
150139

151-
suite.add('fast-json-stringify-uglified short string', function () {
152-
stringifyStringUgly('hello world')
153-
})
154-
155140
suite.add('json-strify short string', function () {
156141
JSTRInstance('hello world')
157142
})
@@ -168,10 +153,6 @@ suite.add('fast-json-stringify obj', function () {
168153
stringify(obj)
169154
})
170155

171-
suite.add('fast-json-stringify-uglified obj', function () {
172-
stringifyUgly(obj)
173-
})
174-
175156
suite.add('json-strify obj', function () {
176157
JSTRStringify(obj)
177158
})

index.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ declare namespace build {
141141
* Optionally add an external definition to reference from your schema
142142
*/
143143
schema?: Record<string, Schema>
144-
/**
145-
* Uglify the generated serialization function to get a performance increase on Node.js versions lower than 8.3.0
146-
*/
147-
uglify?: boolean
148144
/**
149145
* Configure Ajv, which is used to evaluate conditional schemas and combined (anyOf) schemas
150146
*/

index.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ var merge = require('deepmerge')
77
var util = require('util')
88
var validate = require('./schema-validator')
99

10-
var uglify = null
1110
var isLong
1211
try {
1312
isLong = require('long').isLong
@@ -119,10 +118,6 @@ function build (schema, options) {
119118
return ${main}
120119
`
121120

122-
if (options.uglify) {
123-
code = uglifyCode(code)
124-
}
125-
126121
var dependencies = []
127122
var dependenciesName = []
128123
if (hasAnyOf(schema) || hasSchemaSomeIf) {
@@ -996,38 +991,6 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema, subKe
996991
}
997992
}
998993

999-
function uglifyCode (code) {
1000-
if (!uglify) {
1001-
loadUglify()
1002-
}
1003-
1004-
var uglified = uglify.minify(code, { parse: { bare_returns: true } })
1005-
1006-
if (uglified.error) {
1007-
throw uglified.error
1008-
}
1009-
1010-
return uglified.code
1011-
}
1012-
1013-
function loadUglify () {
1014-
try {
1015-
uglify = require('uglify-es')
1016-
var uglifyVersion = require('uglify-es/package.json').version
1017-
1018-
if (uglifyVersion[0] !== '3') {
1019-
throw new Error('Only version 3 of uglify-es is supported')
1020-
}
1021-
} catch (e) {
1022-
uglify = null
1023-
if (e.code === 'MODULE_NOT_FOUND') {
1024-
throw new Error('In order to use uglify, you have to manually install `uglify-es`')
1025-
}
1026-
1027-
throw e
1028-
}
1029-
}
1030-
1031994
function isEmpty (schema) {
1032995
for (var key in schema) {
1033996
if (schema.hasOwnProperty(key)) return false

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"tap": "^12.6.5",
4242
"tap-mocha-reporter": "^3.0.9",
4343
"typescript": "^3.0.0",
44-
"uglify-es": "^3.3.9",
4544
"compile-json-stringify": "^0.1.2",
4645
"json-strify": "^0.1.7"
4746
},

test/array.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ const build = require('..')
66

77
function buildTest (schema, toStringify) {
88
test(`render a ${schema.title} as JSON`, (t) => {
9-
t.plan(5)
9+
t.plan(3)
1010

1111
const validate = validator(schema)
1212
const stringify = build(schema)
13-
const stringifyUgly = build(schema, { uglify: true })
1413
const output = stringify(toStringify)
15-
const outputUglify = stringifyUgly(toStringify)
1614

1715
t.deepEqual(JSON.parse(output), toStringify)
18-
t.deepEqual(JSON.parse(outputUglify), toStringify)
1916
t.equal(output, JSON.stringify(toStringify))
20-
t.equal(outputUglify, JSON.stringify(toStringify))
2117
t.ok(validate(JSON.parse(output)), 'valid schema')
2218
})
2319
}

test/basic.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ const build = require('..')
66

77
function buildTest (schema, toStringify) {
88
test(`render a ${schema.title} as JSON`, (t) => {
9-
t.plan(5)
9+
t.plan(3)
1010

1111
const validate = validator(schema)
1212
const stringify = build(schema)
13-
const stringifyUgly = build(schema, { uglify: true })
1413
const output = stringify(toStringify)
15-
const outputUglify = stringifyUgly(toStringify)
1614

1715
t.deepEqual(JSON.parse(output), toStringify)
18-
t.deepEqual(JSON.parse(outputUglify), toStringify)
1916
t.equal(output, JSON.stringify(toStringify))
20-
t.equal(outputUglify, JSON.stringify(toStringify))
2117
t.ok(validate(JSON.parse(output)), 'valid schema')
2218
})
2319
}

test/defaults.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ const build = require('..')
55

66
function buildTest (schema, toStringify, expected) {
77
test(`render a ${schema.title} with default as JSON`, (t) => {
8-
t.plan(2)
8+
t.plan(1)
99

1010
const stringify = build(schema)
1111

12-
const stringifyUgly = build(schema, { uglify: true })
1312
const output = stringify(toStringify)
14-
const outputUglify = stringifyUgly(toStringify)
1513

1614
t.strictEqual(output, JSON.stringify(expected))
17-
t.strictEqual(outputUglify, JSON.stringify(expected))
1815
})
1916
}
2017

test/if-then-else.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,6 @@ t.test('if-then-else', t => {
272272
const serialized = stringify(test.input)
273273
t.equal(serialized, test.expected)
274274
})
275-
276-
t.test(test.name + ' - uglify', t => {
277-
t.plan(1)
278-
279-
const stringify = build(JSON.parse(JSON.stringify(test.schema)), { uglify: true })
280-
const serialized = stringify(test.input)
281-
t.equal(serialized, test.expected)
282-
})
283275
})
284276

285277
t.end()

test/inferType.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ const build = require('..')
66

77
function buildTest (schema, toStringify) {
88
test(`render a ${schema.title} as JSON`, (t) => {
9-
t.plan(5)
9+
t.plan(3)
1010

1111
const validate = validator(schema)
1212
const stringify = build(schema)
13-
const stringifyUgly = build(schema, { uglify: true })
1413
const output = stringify(toStringify)
15-
const outputUglify = stringifyUgly(toStringify)
1614

1715
t.deepEqual(JSON.parse(output), toStringify)
18-
t.deepEqual(JSON.parse(outputUglify), toStringify)
1916
t.equal(output, JSON.stringify(toStringify))
20-
t.equal(outputUglify, JSON.stringify(toStringify))
2117
t.ok(validate(JSON.parse(output)), 'valid schema')
2218
})
2319
}

0 commit comments

Comments
 (0)