@prantlf/jsonlint 5.0.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -14
- package/lib/cli.js +2 -24
- package/lib/formatter.js +21 -13
- package/lib/jsonlint.js +182 -40
- package/lib/sorter.js +37 -0
- package/lib/validator.js +32 -20
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -9,14 +9,17 @@
|
|
|
9
9
|
|
|
10
10
|
A JSON parser and validator with a command-line client. A [pure JavaScript version](http://prantlf.github.com/jsonlint/) of the service provided at [jsonlint.com](http://jsonlint.com).
|
|
11
11
|
|
|
12
|
-
This is a fork of the original package with the following
|
|
12
|
+
This is a fork of the original package with the following enhancements:
|
|
13
13
|
|
|
14
14
|
* Handles multiple files on the command line (by Greg Inman).
|
|
15
15
|
* Walks directories recursively (by Paul Vollmer).
|
|
16
|
-
* Supports JSON
|
|
16
|
+
* Supports JSON Schema drafts 04, 06 and 07.
|
|
17
17
|
* Can parse and skip JavaScript-style comments.
|
|
18
18
|
* Can accept single quotes (apostrophes) as string delimiters.
|
|
19
|
+
* Implements JavaScript modules using [UMD](https://github.com/umdjs/umd) to work everywhere.
|
|
20
|
+
* Can use the native JSON parser to gain the best performance, while showing error messages pf the same quality.
|
|
19
21
|
* Depends on up-to-date npm modules with no installation warnings.
|
|
22
|
+
* Small size - 13.4 kB minified, 4.6 kB gzipped.
|
|
20
23
|
|
|
21
24
|
## Command-line Interface
|
|
22
25
|
|
|
@@ -76,33 +79,58 @@ Install `jsonlint` with `npm` locally to be able to use the module programmatica
|
|
|
76
79
|
You might prefer methods this module to the built-in `JSON.parse` method because of a better error reporting or support for JavaScript-like comments:
|
|
77
80
|
|
|
78
81
|
```js
|
|
79
|
-
const { parser } = require('jsonlint')
|
|
82
|
+
const { parser } = require('@prantlf/jsonlint')
|
|
80
83
|
// Fails at the position of the character "?".
|
|
81
84
|
parser.parse('{"creative": ?}') // throws an error
|
|
82
85
|
// Succeeds returning the parsed JSON object.
|
|
83
|
-
parser.
|
|
84
|
-
//
|
|
85
|
-
parser.parse(
|
|
86
|
+
parser.parse('{"creative": false}')
|
|
87
|
+
// Recognizes comments and single-quoted strings.
|
|
88
|
+
parser.parse("{'creative': true /* for creativity */}", {
|
|
89
|
+
ignoreComments: true,
|
|
90
|
+
allowSingleQuotedStrings: true
|
|
91
|
+
})
|
|
86
92
|
```
|
|
87
93
|
|
|
88
|
-
Parsing methods return the parsed object or throw an
|
|
94
|
+
Parsing methods return the parsed object or throw an error. If the data cam be parsed, you will be able to validate them against a JSON schema in addition:
|
|
89
95
|
|
|
90
96
|
```js
|
|
91
|
-
const { parser } = require('jsonlint')
|
|
92
|
-
const validator = require('jsonlint/lib/validator')
|
|
97
|
+
const { parser } = require('@prantlf/jsonlint')
|
|
98
|
+
const validator = require('@prantlf/jsonlint/lib/validator')
|
|
93
99
|
const validate = validator.compile('string with JSON schema')
|
|
100
|
+
// Throws an error in case of failure.
|
|
94
101
|
validate(parser.parse('string with JSON data'))
|
|
95
102
|
```
|
|
96
103
|
|
|
97
104
|
### Performance
|
|
98
105
|
|
|
99
|
-
|
|
106
|
+
This is a part of [performance test results](./benchmarks/results/performance.md) of parsing a 3.8 KB formatted string ([package.json](./package,json)) with Node.js 10.15.3:
|
|
100
107
|
|
|
101
|
-
the built-in parser x
|
|
102
|
-
the
|
|
103
|
-
the
|
|
108
|
+
the built-in parser x 75,073 ops/sec ±0.51% (88 runs sampled)
|
|
109
|
+
the pure jison parser x 2,593 ops/sec ±0.79% (89 runs sampled)
|
|
110
|
+
the extended jison parser x 2,319 ops/sec ±0.96% (87 runs sampled)
|
|
104
111
|
|
|
105
|
-
The custom pure-
|
|
112
|
+
The custom pure-JSON parser is a lot slower than the built-in one. However, it is more important to have a clear error reporting than the highest speed in scenarios like parsing configuration files. Extending the parser with the support for comments and single-quoted strings does not affect significantly the performance.
|
|
113
|
+
|
|
114
|
+
You can enable the (fastest) native JSON parser, if you do not need the full structured error information provided by the custom parser. The error thrown by the native parser includes the same rich message, but some properties are missing, because the native parser does not return structured information. Parts of the message are returned instead to allow custom error reporting:
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
const { parse } = require('@prantlf/jsonlint')
|
|
118
|
+
try {
|
|
119
|
+
parse('{"creative": ?}', { limitedErrorInfo: true })
|
|
120
|
+
} catch (error) {
|
|
121
|
+
const { message, reason, exzerpt, pointer, location } = error
|
|
122
|
+
const { column, line, offset } = location.start
|
|
123
|
+
// Logs the same text as is included in the `message` property:
|
|
124
|
+
// Parse error on line 1, column 14:
|
|
125
|
+
// {"creative": ?}
|
|
126
|
+
// -------------^
|
|
127
|
+
// Unexpected token ?
|
|
128
|
+
console.log(`Parse error on line ${line}, ${column} column:
|
|
129
|
+
${exzerpt}
|
|
130
|
+
${pointer}
|
|
131
|
+
${reason}`)
|
|
132
|
+
}
|
|
133
|
+
```
|
|
106
134
|
|
|
107
135
|
## License
|
|
108
136
|
|
package/lib/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ var fs = require('fs')
|
|
|
4
4
|
var path = require('path')
|
|
5
5
|
var parser = require('./jsonlint').parser
|
|
6
6
|
var formatter = require('./formatter')
|
|
7
|
+
var sorter = require('./sorter')
|
|
7
8
|
var validator = require('./validator')
|
|
8
9
|
var pkg = require('../package')
|
|
9
10
|
|
|
@@ -74,7 +75,7 @@ function parse (source, file) {
|
|
|
74
75
|
allowSingleQuotedStrings: options.singleQuotedStrings
|
|
75
76
|
})
|
|
76
77
|
if (options.sortKeys) {
|
|
77
|
-
parsed = sortObject(parsed)
|
|
78
|
+
parsed = sorter.sortObject(parsed)
|
|
78
79
|
}
|
|
79
80
|
if (options.validate) {
|
|
80
81
|
var validate
|
|
@@ -188,27 +189,4 @@ function main () {
|
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
|
|
191
|
-
// from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript
|
|
192
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty
|
|
193
|
-
function sortObject (o) {
|
|
194
|
-
if (Array.isArray(o)) {
|
|
195
|
-
return o.map(sortObject)
|
|
196
|
-
} else if (Object.prototype.toString.call(o) !== '[object Object]') {
|
|
197
|
-
return o
|
|
198
|
-
}
|
|
199
|
-
var sorted = {}
|
|
200
|
-
var key
|
|
201
|
-
var a = []
|
|
202
|
-
for (key in o) {
|
|
203
|
-
if (hasOwnProperty.call(o, key)) {
|
|
204
|
-
a.push(key)
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
a.sort()
|
|
208
|
-
for (key = 0; key < a.length; key++) {
|
|
209
|
-
sorted[a[key]] = sortObject(o[a[key]])
|
|
210
|
-
}
|
|
211
|
-
return sorted
|
|
212
|
-
}
|
|
213
|
-
|
|
214
192
|
main()
|
package/lib/formatter.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
// eslint-disable-next-line no-unused-expressions
|
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports)
|
|
4
|
+
// eslint-disable-next-line no-undef
|
|
5
|
+
: typeof define === 'function' && define.amd ? define('jsonlint-formatter', ['exports'], factory)
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
: (global = global || self, factory(global.jsonlintFormatter = {}))
|
|
8
|
+
}(this, function (exports) {
|
|
9
|
+
'use strict'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Manual formatter taken straight from https://github.com/umbrae/jsonlintdotcom
|
|
13
|
+
*
|
|
14
|
+
* jsl.format - Provide json reformatting in a character-by-character approach,
|
|
15
|
+
* so that even invalid JSON may be reformatted (to the best of its ability).
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
9
19
|
function repeat (s, count) {
|
|
10
20
|
return new Array(count + 1).join(s)
|
|
11
21
|
}
|
|
@@ -76,9 +86,7 @@ var formatter = (function () {
|
|
|
76
86
|
return newJson
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
}())
|
|
89
|
+
exports.format = format
|
|
81
90
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
91
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
92
|
+
}))
|
package/lib/jsonlint.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('jsonlint', ['exports'], factory) :
|
|
4
|
+
(global = global || self, factory(global.jsonlint = {}));
|
|
5
|
+
}(this, function (exports) { 'use strict';
|
|
6
|
+
|
|
1
7
|
/* parser generated by jison 0.4.18 */
|
|
2
8
|
/*
|
|
3
9
|
Returns a Parser object of the following structure:
|
|
@@ -708,59 +714,195 @@ Parser.prototype = parser;parser.Parser = Parser;
|
|
|
708
714
|
return new Parser;
|
|
709
715
|
})();
|
|
710
716
|
|
|
711
|
-
|
|
712
|
-
var
|
|
717
|
+
function getLineAndColumn (input, offset) {
|
|
718
|
+
var lines = input
|
|
719
|
+
.substr(0, offset)
|
|
720
|
+
.split(/\r?\n/)
|
|
721
|
+
var line = lines.length
|
|
722
|
+
var column = lines[line - 1].length + 1
|
|
723
|
+
return {
|
|
724
|
+
line: line,
|
|
725
|
+
column: column
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function pastInput (input, offset) {
|
|
730
|
+
var start = Math.max(0, offset - 20)
|
|
731
|
+
var previous = input.substr(start, offset - start)
|
|
732
|
+
return (offset > 20 ? '...' : '') + previous.replace(/\n/g, '')
|
|
733
|
+
}
|
|
713
734
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
735
|
+
function upcomingInput (input, offset) {
|
|
736
|
+
var start = Math.max(0, offset - 20)
|
|
737
|
+
start += offset - start
|
|
738
|
+
var rest = input.length - start
|
|
739
|
+
var next = input.substr(start, Math.min(20, rest))
|
|
740
|
+
return next.replace(/\n/g, '') + (rest > 20 ? '...' : '')
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function getPositionContext (input, offset) {
|
|
744
|
+
var past = pastInput(input, offset)
|
|
745
|
+
var upcoming = upcomingInput(input, offset)
|
|
746
|
+
var pointer = new Array(past.length + 1).join('-') + '^'
|
|
747
|
+
return {
|
|
748
|
+
exzerpt: past + upcoming,
|
|
749
|
+
pointer: pointer
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function improveNativeError (input, error) {
|
|
754
|
+
var message = error.message
|
|
755
|
+
var match = / in JSON at position (\d+)$/.exec(message)
|
|
756
|
+
var offset
|
|
757
|
+
if (match) {
|
|
758
|
+
offset = +match[1]
|
|
759
|
+
message = message.substr(0, match.index)
|
|
760
|
+
} else {
|
|
761
|
+
offset = input.length
|
|
762
|
+
}
|
|
763
|
+
var location = getLineAndColumn(input, offset)
|
|
764
|
+
var line = location.line
|
|
765
|
+
var column = location.column
|
|
766
|
+
location = 'line ' + line + ', column ' + column
|
|
767
|
+
var position = getPositionContext(input, offset)
|
|
768
|
+
var exzerpt = position.exzerpt
|
|
769
|
+
var pointer = position.pointer
|
|
770
|
+
error.message = 'Parse error on ' + location + ':\n' +
|
|
771
|
+
exzerpt + '\n' + pointer + '\n' + message
|
|
772
|
+
error.reason = message
|
|
773
|
+
error.exzerpt = exzerpt
|
|
774
|
+
error.pointer = pointer
|
|
775
|
+
error.location = {
|
|
776
|
+
start: {
|
|
777
|
+
column: column,
|
|
778
|
+
line: line,
|
|
779
|
+
offset: offset
|
|
780
|
+
}
|
|
717
781
|
}
|
|
782
|
+
return error
|
|
783
|
+
}
|
|
718
784
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
return
|
|
785
|
+
function parseNatively (input) { // eslint-disable-line no-unused-vars
|
|
786
|
+
try {
|
|
787
|
+
return JSON.parse(input)
|
|
788
|
+
} catch (error) {
|
|
789
|
+
throw improveNativeError(input, error)
|
|
722
790
|
}
|
|
791
|
+
}
|
|
723
792
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
793
|
+
function needsCustomParser () { // eslint-disable-line no-unused-vars
|
|
794
|
+
var yy = this.yy
|
|
795
|
+
return yy.ignoreComments || yy.allowSingleQuotedStrings ||
|
|
796
|
+
yy.limitedErrorInfo !== true
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function getOffset (input, line, column) {
|
|
800
|
+
if (line > 1) {
|
|
801
|
+
var breaks = /\r?\n/g
|
|
802
|
+
var match
|
|
803
|
+
while (match = breaks.exec(input)) { // eslint-disable-line no-cond-assign
|
|
804
|
+
if (--line === 1) {
|
|
805
|
+
return match.index + column
|
|
731
806
|
}
|
|
732
807
|
}
|
|
733
808
|
}
|
|
809
|
+
return column - 1
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function improveCustomError (input, error) {
|
|
813
|
+
var location = error.hash.loc
|
|
814
|
+
var line = location.first_line
|
|
815
|
+
var column = location.first_column
|
|
816
|
+
var offset = getOffset(input, line, column)
|
|
817
|
+
var lines = error.message.split(/\r?\n/)
|
|
818
|
+
error.reason = lines[3]
|
|
819
|
+
error.exzerpt = lines[2]
|
|
820
|
+
error.pointer = lines[1]
|
|
821
|
+
error.location = {
|
|
822
|
+
start: {
|
|
823
|
+
line: line,
|
|
824
|
+
column: column,
|
|
825
|
+
offset: offset
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return error
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function parseCustom (parse, input) { // eslint-disable-line no-unused-vars
|
|
832
|
+
if (this.yy.limitedErrorInfo) {
|
|
833
|
+
try {
|
|
834
|
+
return parse.call(this, input)
|
|
835
|
+
} catch (error) {
|
|
836
|
+
throw improveCustomError(input, error)
|
|
837
|
+
}
|
|
838
|
+
} else {
|
|
839
|
+
return parse.call(this, input)
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/* globals jsonlint, needsCustomParser, parseCustom, parseNatively */
|
|
734
844
|
|
|
735
|
-
|
|
736
|
-
ConfigurableParser.prototype.constructor = ConfigurableParser;
|
|
737
|
-
ConfigurableParser.prototype.parse = parse;
|
|
738
|
-
ConfigurableParser.prototype.Parser = ConfigurableParser;
|
|
845
|
+
var Parser = jsonlint.Parser
|
|
739
846
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
847
|
+
function ConfigurableParser (options) {
|
|
848
|
+
Parser.prototype.constructor.call(this)
|
|
849
|
+
processOptions.call(this, options)
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
function parse (input, options) {
|
|
853
|
+
var changed = processOptions.call(this, options)
|
|
854
|
+
try {
|
|
855
|
+
return needsCustomParser.call(this)
|
|
856
|
+
? parseCustom.call(this, Parser.prototype.parse, input)
|
|
857
|
+
: parseNatively(input)
|
|
858
|
+
} finally {
|
|
859
|
+
restoreContext.call(this, changed)
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
function processOptions (options) {
|
|
864
|
+
if (options) {
|
|
865
|
+
var changed = {}
|
|
866
|
+
if (options.ignoreComments !== undefined) {
|
|
867
|
+
changed.ignoreComments = this.yy.ignoreComments
|
|
868
|
+
this.yy.ignoreComments = options.ignoreComments
|
|
869
|
+
}
|
|
870
|
+
if (options.allowSingleQuotedStrings !== undefined) {
|
|
871
|
+
changed.allowSingleQuotedStrings = this.yy.allowSingleQuotedStrings
|
|
872
|
+
this.yy.allowSingleQuotedStrings = options.allowSingleQuotedStrings
|
|
873
|
+
}
|
|
874
|
+
if (options.limitedErrorInfo !== undefined) {
|
|
875
|
+
changed.limitedErrorInfo = this.yy.limitedErrorInfo
|
|
876
|
+
this.yy.limitedErrorInfo = options.limitedErrorInfo
|
|
877
|
+
}
|
|
878
|
+
return changed
|
|
743
879
|
}
|
|
744
|
-
|
|
745
|
-
ParserWithComments.prototype.constructor = ParserWithComments;
|
|
880
|
+
}
|
|
746
881
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
882
|
+
function restoreContext (changed) {
|
|
883
|
+
if (changed) {
|
|
884
|
+
var yy = this.yy
|
|
885
|
+
for (var option in changed) {
|
|
886
|
+
var value = changed[option]
|
|
887
|
+
if (value === undefined) {
|
|
888
|
+
delete yy[option]
|
|
889
|
+
} else {
|
|
890
|
+
yy[option] = value
|
|
891
|
+
}
|
|
892
|
+
}
|
|
751
893
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
ConfigurableParser.prototype = Object.create(Parser.prototype)
|
|
897
|
+
ConfigurableParser.prototype.constructor = ConfigurableParser
|
|
898
|
+
ConfigurableParser.prototype.parse = parse
|
|
899
|
+
ConfigurableParser.prototype.Parser = ConfigurableParser
|
|
900
|
+
|
|
901
|
+
jsonlint = new ConfigurableParser() // eslint-disable-line no-global-assign
|
|
755
902
|
|
|
756
|
-
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
|
|
757
903
|
exports.parser = jsonlint;
|
|
758
904
|
exports.Parser = jsonlint.Parser;
|
|
759
|
-
exports.
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
exports.parseWithComments = function () {
|
|
764
|
-
return jsonlint.parseWithComments.apply(jsonlint, arguments);
|
|
765
|
-
};
|
|
766
|
-
}
|
|
905
|
+
exports.parse = jsonlint.parse.bind(jsonlint)
|
|
906
|
+
|
|
907
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
908
|
+
}));
|
package/lib/sorter.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
// eslint-disable-next-line no-unused-expressions
|
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports)
|
|
4
|
+
// eslint-disable-next-line no-undef
|
|
5
|
+
: typeof define === 'function' && define.amd ? define('jsonlint-sorter', ['exports'], factory)
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
: (global = global || self, factory(global.jsonlintSorter = {}))
|
|
8
|
+
}(this, function (exports) {
|
|
9
|
+
'use strict'
|
|
10
|
+
|
|
11
|
+
// from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript
|
|
12
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty
|
|
13
|
+
function sortObject (o) {
|
|
14
|
+
if (Array.isArray(o)) {
|
|
15
|
+
return o.map(sortObject)
|
|
16
|
+
} else if (Object.prototype.toString.call(o) !== '[object Object]') {
|
|
17
|
+
return o
|
|
18
|
+
}
|
|
19
|
+
var sorted = {}
|
|
20
|
+
var key
|
|
21
|
+
var a = []
|
|
22
|
+
for (key in o) {
|
|
23
|
+
if (hasOwnProperty.call(o, key)) {
|
|
24
|
+
a.push(key)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
a.sort()
|
|
28
|
+
for (key = 0; key < a.length; key++) {
|
|
29
|
+
sorted[a[key]] = sortObject(o[a[key]])
|
|
30
|
+
}
|
|
31
|
+
return sorted
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.sortObject = sortObject
|
|
35
|
+
|
|
36
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
37
|
+
}))
|
package/lib/validator.js
CHANGED
|
@@ -1,33 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
3
|
+
var jsonlint = require('./jsonlint')
|
|
4
|
+
var Ajv = require('ajv')
|
|
5
|
+
// eslint-disable-next-line no-inner-declarations
|
|
6
|
+
function requireSchemaDraft (environment) {
|
|
7
|
+
return require('ajv/lib/refs/' + environment + '.json')
|
|
8
8
|
}
|
|
9
|
+
factory(exports, Ajv, jsonlint, requireSchemaDraft)
|
|
10
|
+
// eslint-disable-next-line no-undef
|
|
11
|
+
} else if (typeof define === 'function' && define.amd) {
|
|
12
|
+
// eslint-disable-next-line no-undef
|
|
13
|
+
define('jsonlint-validator', ['exports', 'ajv', 'jsonlint', 'jsonlint-schema-drafts'],
|
|
14
|
+
function (exports, jsonlint, Ajv, schemaDrafts) {
|
|
15
|
+
function requireSchemaDraft (environment) {
|
|
16
|
+
return schemaDrafts[environment]
|
|
17
|
+
}
|
|
18
|
+
factory(exports, Ajv, jsonlint, requireSchemaDraft)
|
|
19
|
+
})
|
|
9
20
|
} else {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
21
|
+
// eslint-disable-next-line no-undef
|
|
22
|
+
global = global || self
|
|
23
|
+
var requireSchemaDraft = function (environment) {
|
|
24
|
+
return global.jsonlintSchemaDrafts[environment]
|
|
14
25
|
}
|
|
26
|
+
factory(global.jsonlintValidator = {}, global.Ajv, global.jsonlint, requireSchemaDraft)
|
|
15
27
|
}
|
|
28
|
+
}(this, function (exports, Ajv, jsonlint, requireSchemaDraft) {
|
|
29
|
+
'use strict'
|
|
16
30
|
|
|
17
31
|
function compile (schema, environment) {
|
|
18
32
|
var ajv
|
|
19
33
|
if (!environment) {
|
|
20
34
|
ajv = new Ajv({ schemaId: 'auto' })
|
|
21
|
-
ajv.addMetaSchema(
|
|
22
|
-
ajv.addMetaSchema(
|
|
35
|
+
ajv.addMetaSchema(requireSchemaDraft('json-schema-draft-04'))
|
|
36
|
+
ajv.addMetaSchema(requireSchemaDraft('json-schema-draft-06'))
|
|
23
37
|
} else if (environment === 'json-schema-draft-07') {
|
|
24
38
|
ajv = new Ajv()
|
|
25
39
|
} else if (environment === 'json-schema-draft-06') {
|
|
26
40
|
ajv = new Ajv()
|
|
27
|
-
ajv.addMetaSchema(
|
|
41
|
+
ajv.addMetaSchema(requireSchemaDraft('json-schema-draft-06'))
|
|
28
42
|
} else if (environment === 'json-schema-draft-04') {
|
|
29
43
|
ajv = new Ajv({ schemaId: 'id' })
|
|
30
|
-
ajv.addMetaSchema(
|
|
44
|
+
ajv.addMetaSchema(requireSchemaDraft('json-schema-draft-04'))
|
|
31
45
|
} else {
|
|
32
46
|
throw new Error('Unsupported environment for the JSON schema validation: "' +
|
|
33
47
|
environment + '".')
|
|
@@ -48,9 +62,7 @@ var validator = (function () {
|
|
|
48
62
|
}
|
|
49
63
|
}
|
|
50
64
|
|
|
51
|
-
|
|
52
|
-
}())
|
|
65
|
+
exports.compile = compile
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
67
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
68
|
+
}))
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prantlf/jsonlint",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "JSON parser and validator - checks syntax and semantics of JSON data.",
|
|
5
5
|
"author": "Ferdinand Prantl <prantlf@gmail.com> (http://prantl.tk)",
|
|
6
6
|
"contributors": [
|
|
7
|
-
"Ferdinand Prantl <prantlf@gmail.com> (http://prantl.tk)",
|
|
8
7
|
"Greg Inman <ginman@itriagehealth.com>",
|
|
9
8
|
"Paul Vollmer <mail@paulvollmer.net> (http://paulvollmer.net)",
|
|
10
9
|
"Zach Carter <zach@carter.name> (http://zaa.ch)"
|
|
@@ -35,17 +34,19 @@
|
|
|
35
34
|
"scripts": {
|
|
36
35
|
"prepare": "npm run lint && npm run build",
|
|
37
36
|
"lint": "standard --fix -v",
|
|
38
|
-
"build": "jison -m js -o lib/jsonlint.js src/jsonlint.y src/jsonlint.l && node scripts/wrap-
|
|
37
|
+
"build": "jison -m js -o lib/jsonlint.js src/jsonlint.y src/jsonlint.l && node scripts/wrap-jsonlint && uglifyjs -o web/jsonlint.min.js --source-map \"filename='jsonlint.js',url='jsonlint.min.js.map',includeSources=true\" lib/jsonlint.js && uglifyjs -o web/validator.min.js --source-map \"filename='validator.js',url='validator.min.js.map',includeSources=true\" lib/validator.js && uglifyjs -o web/formatter.min.js --source-map \"filename='formatter.js',url='formatter.min.js.map',includeSources=true\" lib/formatter.js && uglifyjs -o web/sorter.min.js --source-map \"filename='sorter.js',url='sorter.min.js.map',includeSources=true\" lib/sorter.js && node scripts/bundle-schema-drafts | uglifyjs -o web/schema-drafts.min.js --source-map \"filename='schema-drafts.js',url='schema-drafts.min.js.map',includeSources=true\" && uglifyjs -o web/ajv.min.js --source-map \"filename='ajv.js',url='ajv.min.js.map',includeSources=true\" node_modules/ajv/dist/ajv.bundle.js",
|
|
39
38
|
"benchmarks": "npm run benchmarks:build && npm run benchmarks:run",
|
|
40
39
|
"benchmarks:build": "jison -o benchmarks/jison/pure.js benchmarks/jison/pure.y benchmarks/jison/pure.l && jison -o benchmarks/jison/extended.js benchmarks/jison/extended.y benchmarks/jison/extended.l && pegjs benchmarks/pegjs/pure.pegjs && pegjs benchmarks/pegjs/extended.pegjs",
|
|
41
40
|
"benchmarks:run": "node benchmarks/parse.js",
|
|
42
41
|
"test": "npm run test:module && npm run test:cli",
|
|
43
|
-
"test:
|
|
44
|
-
"test:
|
|
42
|
+
"test:old": "node test/all-tests && node test/all-tests --native-parser && node lib/cli package.json test/recursive && node lib/cli -sq test/passes/hasOwnProperty.json && node lib/cli -s -e json-schema-draft-04 -V test/passes/3.schema.json test/passes/3.json && node lib/cli -C test/passes/comments.txt && node lib/cli -S test/passes/strings.txt && node lib/cli -v && node lib/cli -h",
|
|
43
|
+
"test:module": "nyc --silent node test/all-tests && nyc --silent --no-clean node test/all-tests --native-parser",
|
|
44
|
+
"test:cli": "nyc --silent --no-clean node lib/cli package.json test/recursive && nyc --silent --no-clean node lib/cli -sq test/passes/hasOwnProperty.json && nyc --silent --no-clean node lib/cli -s -e json-schema-draft-04 -V test/passes/3.schema.json test/passes/3.json && nyc --silent --no-clean node lib/cli -C test/passes/comments.txt && nyc --silent --no-clean node lib/cli -S test/passes/strings.txt && nyc --silent --no-clean node lib/cli -v && nyc --silent --no-clean node lib/cli -h && nyc --silent --no-clean node lib/cli -pc test/fails/10.json || nyc report",
|
|
45
45
|
"coverage": "cat coverage/lcov.info | npx coveralls",
|
|
46
46
|
"start": "python -m SimpleHTTPServer",
|
|
47
47
|
"web": "npm run web:sync && npm run web:deploy",
|
|
48
48
|
"web:clone": "test ! -d ../jsonlint-pages && git clone --single-branch --branch gh-pages `git remote get-url origin` ../jsonlint-pages",
|
|
49
|
+
"web:pull": "cd ../jsonlint-pages && git pull",
|
|
49
50
|
"web:sync": "cp web/*.min.* ../jsonlint-pages/ && cp web/jsonlint.html ../jsonlint-pages/index.html",
|
|
50
51
|
"web:deploy": "cd ../jsonlint-pages && git commit -a -m 'Deploy site updates' && git push origin gh-pages"
|
|
51
52
|
},
|