-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google clousure compiler #748
Comments
This project is plain JavaScript. There isn't any need for compiling anything. |
|
I suggest providing some evidence that this would be an improvement/necessary. In my opinion, it will just complicate maintenance and debugging. |
this is just a try with 'use strict'
const fastJson = require('fast-json-stringify')
const { minify } = require("terser"); // nmp install terser
const stringify = fastJson({
title: 'Example Schema',
type: 'object',
properties: {
firstName: {
type: 'string'
},
lastName: {
type: 'string'
},
age: {
description: 'Age in years',
type: 'integer'
},
now: {
type: 'string'
},
birthdate: {
type: ['string'],
format: 'date-time'
},
reg: {
type: 'string'
},
obj: {
type: 'object',
properties: {
bool: {
type: 'boolean'
}
}
},
arr: {
type: 'array',
items: {
type: 'object',
properties: {
str: {
type: 'string'
}
}
}
}
},
required: ['now'],
patternProperties: {
'.*foo$': {
type: 'string'
},
test: {
type: 'number'
},
date: {
type: 'string',
format: 'date-time'
}
},
additionalProperties: {
type: 'string'
}
}, {mode: 'standalone'})
const fs = require('fs')
const path = require('path')
minify(stringify).then(result => {
fs.writeFileSync(path.join(__dirname, 'terser.js'), result.code, {encoding: 'utf-8'})
fs.writeFileSync(path.join(__dirname, 'raw.js'), stringify, {encoding: 'utf-8'})
const tfjs = require('./terser')
const rfjs = require('./raw')
const RUN = 5000;
const OBJ = {
firstName: 'Matteo',
lastName: 'Collina',
age: 32,
now: new Date(),
reg: /"([^"]|\\")*"/,
foo: 'hello',
numfoo: 42,
test: 42,
strtest: '23',
arr: [{ str: 'stark' }, { str: 'lannister' }],
obj: { bool: true },
notmatch: 'valar morghulis',
notmatchobj: { a: true },
notmatchnum: 42
};
console.time('terser')
for (let index = 0; index < RUN; index++) {
tfjs(OBJ)
}
console.timeEnd('terser')
console.time('raw')
for (let index = 0; index < RUN; index++) {
rfjs(OBJ)
}
console.timeEnd('raw')
}) result:
|
Prerequisites
🚀 Feature Proposal
The idea is compile the stringify method with https://www.npmjs.com/package/google-closure-compiler in ADVANCED mode (https://developers.google.com/closure/compiler/docs/api-tutorial3)
The main goal of
google-closure-compiler
is reduce the size of the script, but:is something like this #633
The text was updated successfully, but these errors were encountered: