File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -35,12 +35,13 @@ const obj = {
35
35
36
36
const multiArray = [ ]
37
37
38
- const stringify = require ( '.' ) ( schema )
39
- const stringifyUgly = require ( '.' ) ( schema , { uglify : true } )
40
- const stringifyArray = require ( '.' ) ( arraySchema )
41
- const stringifyArrayUgly = require ( '.' ) ( arraySchema , { uglify : true } )
42
- const stringifyString = require ( '.' ) ( { type : 'string' } )
43
- const stringifyStringUgly = require ( '.' ) ( { type : 'string' , uglify : true } )
38
+ const FJS = require ( '.' )
39
+ const stringify = FJS ( schema )
40
+ const stringifyUgly = FJS ( schema , { uglify : true } )
41
+ const stringifyArray = FJS ( arraySchema )
42
+ const stringifyArrayUgly = FJS ( arraySchema , { uglify : true } )
43
+ const stringifyString = FJS ( { type : 'string' } )
44
+ const stringifyStringUgly = FJS ( { type : 'string' , uglify : true } )
44
45
var str = ''
45
46
46
47
for ( var i = 0 ; i < 10000 ; i ++ ) {
@@ -56,6 +57,10 @@ for (i = 0; i < 1000; i++) {
56
57
multiArray . push ( obj )
57
58
}
58
59
60
+ suite . add ( 'FJS creation' , function ( ) {
61
+ FJS ( schema )
62
+ } )
63
+
59
64
suite . add ( 'JSON.stringify array' , function ( ) {
60
65
JSON . stringify ( multiArray )
61
66
} )
Original file line number Diff line number Diff line change 3
3
var Ajv = require ( 'ajv' )
4
4
var merge = require ( 'deepmerge' )
5
5
6
+ // This Ajv instance is used to validate that the passed schema
7
+ // is valid json schema. We reuse the instance to avoid having to
8
+ // pay the ajv creation cost more than once.
9
+ var ajv = new Ajv ( )
10
+
6
11
var uglify = null
7
12
var isLong
8
13
try {
@@ -791,13 +796,17 @@ function loadUglify () {
791
796
}
792
797
793
798
function isValidSchema ( schema , externalSchema ) {
794
- const ajv = new Ajv ( )
795
799
if ( externalSchema ) {
796
800
Object . keys ( externalSchema ) . forEach ( key => {
797
801
ajv . addSchema ( externalSchema [ key ] , key )
798
802
} )
799
803
}
800
804
ajv . compile ( schema )
805
+ if ( externalSchema ) {
806
+ Object . keys ( externalSchema ) . forEach ( key => {
807
+ ajv . removeSchema ( key )
808
+ } )
809
+ }
801
810
}
802
811
803
812
module . exports = build
You can’t perform that action at this time.
0 commit comments