File tree Expand file tree Collapse file tree 4 files changed +37
-36
lines changed Expand file tree Collapse file tree 4 files changed +37
-36
lines changed Original file line number Diff line number Diff line change @@ -4,22 +4,22 @@ const benchmark = require('benchmark')
4
4
const suite = new benchmark . Suite ( )
5
5
6
6
const schema = {
7
- " title" : " Example Schema" ,
8
- " type" : " object" ,
9
- " properties" : {
10
- " firstName" : {
11
- " type" : " string"
12
- } ,
13
- " lastName" : {
14
- " type" : " string"
15
- } ,
16
- " age" : {
17
- " description" : " Age in years" ,
18
- " type" : " integer" ,
19
- " minimum" : 0
20
- }
21
- } ,
22
- " required" : [ " firstName" , " lastName" ]
7
+ ' title' : ' Example Schema' ,
8
+ ' type' : ' object' ,
9
+ ' properties' : {
10
+ ' firstName' : {
11
+ ' type' : ' string'
12
+ } ,
13
+ ' lastName' : {
14
+ ' type' : ' string'
15
+ } ,
16
+ ' age' : {
17
+ ' description' : ' Age in years' ,
18
+ ' type' : ' integer' ,
19
+ ' minimum' : 0
20
+ }
21
+ } ,
22
+ ' required' : [ ' firstName' , ' lastName' ]
23
23
}
24
24
25
25
const obj = {
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
function build ( schema ) {
4
+ /*eslint no-new-func: "off"*/
4
5
5
6
let code = `
6
7
'use strict'
7
8
let json = '{'
8
9
`
9
10
10
11
Object . keys ( schema . properties ) . forEach ( ( key , i , a ) => {
11
-
12
12
const type = schema . properties [ key ] . type
13
13
14
14
code += `
@@ -20,17 +20,16 @@ function build (schema) {
20
20
code += `
21
21
json += '"' + obj.${ key } + '"'
22
22
`
23
- break ;
23
+ break
24
24
case 'integer' :
25
25
code += `
26
26
json += '' + obj.${ key }
27
27
`
28
- break ;
28
+ break
29
29
default :
30
30
throw new Error ( `${ type } unsupported` )
31
31
}
32
32
33
-
34
33
if ( i < a . length - 1 ) {
35
34
code += 'json += \',\''
36
35
}
Original file line number Diff line number Diff line change 6
6
"scripts" : {
7
7
"test" : " standard && tap test.js"
8
8
},
9
+ "precommit" : " test" ,
9
10
"repository" : {
10
11
"type" : " git" ,
11
12
"url" : " git+https://github.com/mcollina/fast-json-stringify.git"
25
26
"devDependencies" : {
26
27
"benchmark" : " ^2.1.1" ,
27
28
"is-my-json-valid" : " ^2.13.1" ,
29
+ "pre-commit" : " ^1.1.3" ,
28
30
"standard" : " ^7.1.2" ,
29
31
"tap" : " ^6.2.0"
30
32
}
Original file line number Diff line number Diff line change @@ -4,22 +4,22 @@ const test = require('tap').test
4
4
const build = require ( '.' )
5
5
6
6
const example = {
7
- " title" : " Example Schema" ,
8
- " type" : " object" ,
9
- " properties" : {
10
- " firstName" : {
11
- " type" : " string"
12
- } ,
13
- " lastName" : {
14
- " type" : " string"
15
- } ,
16
- " age" : {
17
- " description" : " Age in years" ,
18
- " type" : " integer" ,
19
- " minimum" : 0
20
- }
21
- } ,
22
- " required" : [ " firstName" , " lastName" ]
7
+ ' title' : ' Example Schema' ,
8
+ ' type' : ' object' ,
9
+ ' properties' : {
10
+ ' firstName' : {
11
+ ' type' : ' string'
12
+ } ,
13
+ ' lastName' : {
14
+ ' type' : ' string'
15
+ } ,
16
+ ' age' : {
17
+ ' description' : ' Age in years' ,
18
+ ' type' : ' integer' ,
19
+ ' minimum' : 0
20
+ }
21
+ } ,
22
+ ' required' : [ ' firstName' , ' lastName' ]
23
23
}
24
24
25
25
test ( 'render a basic json' , ( t ) => {
You can’t perform that action at this time.
0 commit comments