source: node_modules/yaml/dist/schema/json/schema.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1'use strict';
2
3var Scalar = require('../../nodes/Scalar.js');
4var map = require('../common/map.js');
5var seq = require('../common/seq.js');
6
7function intIdentify(value) {
8 return typeof value === 'bigint' || Number.isInteger(value);
9}
10const stringifyJSON = ({ value }) => JSON.stringify(value);
11const jsonScalars = [
12 {
13 identify: value => typeof value === 'string',
14 default: true,
15 tag: 'tag:yaml.org,2002:str',
16 resolve: str => str,
17 stringify: stringifyJSON
18 },
19 {
20 identify: value => value == null,
21 createNode: () => new Scalar.Scalar(null),
22 default: true,
23 tag: 'tag:yaml.org,2002:null',
24 test: /^null$/,
25 resolve: () => null,
26 stringify: stringifyJSON
27 },
28 {
29 identify: value => typeof value === 'boolean',
30 default: true,
31 tag: 'tag:yaml.org,2002:bool',
32 test: /^true|false$/,
33 resolve: str => str === 'true',
34 stringify: stringifyJSON
35 },
36 {
37 identify: intIdentify,
38 default: true,
39 tag: 'tag:yaml.org,2002:int',
40 test: /^-?(?:0|[1-9][0-9]*)$/,
41 resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),
42 stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)
43 },
44 {
45 identify: value => typeof value === 'number',
46 default: true,
47 tag: 'tag:yaml.org,2002:float',
48 test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
49 resolve: str => parseFloat(str),
50 stringify: stringifyJSON
51 }
52];
53const jsonError = {
54 default: true,
55 tag: '',
56 test: /^/,
57 resolve(str, onError) {
58 onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
59 return str;
60 }
61};
62const schema = [map.map, seq.seq].concat(jsonScalars, jsonError);
63
64exports.schema = schema;
Note: See TracBrowser for help on using the repository browser.