source: frontend/node_modules/yaml/dist/warnings-793925ce.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 12.2 KB
RevLine 
[9af201e]1'use strict';
2
3var PlainValue = require('./PlainValue-516d5bc2.js');
4var resolveSeq = require('./resolveSeq-95613e94.js');
5
6/* global atob, btoa, Buffer */
7const binary = {
8 identify: value => value instanceof Uint8Array,
9 // Buffer inherits from Uint8Array
10 default: false,
11 tag: 'tag:yaml.org,2002:binary',
12 /**
13 * Returns a Buffer in node and an Uint8Array in browsers
14 *
15 * To use the resulting buffer as an image, you'll want to do something like:
16 *
17 * const blob = new Blob([buffer], { type: 'image/jpeg' })
18 * document.querySelector('#photo').src = URL.createObjectURL(blob)
19 */
20 resolve: (doc, node) => {
21 const src = resolveSeq.resolveString(doc, node);
22 if (typeof Buffer === 'function') {
23 return Buffer.from(src, 'base64');
24 } else if (typeof atob === 'function') {
25 // On IE 11, atob() can't handle newlines
26 const str = atob(src.replace(/[\n\r]/g, ''));
27 const buffer = new Uint8Array(str.length);
28 for (let i = 0; i < str.length; ++i) buffer[i] = str.charCodeAt(i);
29 return buffer;
30 } else {
31 const msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
32 doc.errors.push(new PlainValue.YAMLReferenceError(node, msg));
33 return null;
34 }
35 },
36 options: resolveSeq.binaryOptions,
37 stringify: ({
38 comment,
39 type,
40 value
41 }, ctx, onComment, onChompKeep) => {
42 let src;
43 if (typeof Buffer === 'function') {
44 src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
45 } else if (typeof btoa === 'function') {
46 let s = '';
47 for (let i = 0; i < value.length; ++i) s += String.fromCharCode(value[i]);
48 src = btoa(s);
49 } else {
50 throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
51 }
52 if (!type) type = resolveSeq.binaryOptions.defaultType;
53 if (type === PlainValue.Type.QUOTE_DOUBLE) {
54 value = src;
55 } else {
56 const {
57 lineWidth
58 } = resolveSeq.binaryOptions;
59 const n = Math.ceil(src.length / lineWidth);
60 const lines = new Array(n);
61 for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
62 lines[i] = src.substr(o, lineWidth);
63 }
64 value = lines.join(type === PlainValue.Type.BLOCK_LITERAL ? '\n' : ' ');
65 }
66 return resolveSeq.stringifyString({
67 comment,
68 type,
69 value
70 }, ctx, onComment, onChompKeep);
71 }
72};
73
74function parsePairs(doc, cst) {
75 const seq = resolveSeq.resolveSeq(doc, cst);
76 for (let i = 0; i < seq.items.length; ++i) {
77 let item = seq.items[i];
78 if (item instanceof resolveSeq.Pair) continue;else if (item instanceof resolveSeq.YAMLMap) {
79 if (item.items.length > 1) {
80 const msg = 'Each pair must have its own sequence indicator';
81 throw new PlainValue.YAMLSemanticError(cst, msg);
82 }
83 const pair = item.items[0] || new resolveSeq.Pair();
84 if (item.commentBefore) pair.commentBefore = pair.commentBefore ? `${item.commentBefore}\n${pair.commentBefore}` : item.commentBefore;
85 if (item.comment) pair.comment = pair.comment ? `${item.comment}\n${pair.comment}` : item.comment;
86 item = pair;
87 }
88 seq.items[i] = item instanceof resolveSeq.Pair ? item : new resolveSeq.Pair(item);
89 }
90 return seq;
91}
92function createPairs(schema, iterable, ctx) {
93 const pairs = new resolveSeq.YAMLSeq(schema);
94 pairs.tag = 'tag:yaml.org,2002:pairs';
95 for (const it of iterable) {
96 let key, value;
97 if (Array.isArray(it)) {
98 if (it.length === 2) {
99 key = it[0];
100 value = it[1];
101 } else throw new TypeError(`Expected [key, value] tuple: ${it}`);
102 } else if (it && it instanceof Object) {
103 const keys = Object.keys(it);
104 if (keys.length === 1) {
105 key = keys[0];
106 value = it[key];
107 } else throw new TypeError(`Expected { key: value } tuple: ${it}`);
108 } else {
109 key = it;
110 }
111 const pair = schema.createPair(key, value, ctx);
112 pairs.items.push(pair);
113 }
114 return pairs;
115}
116const pairs = {
117 default: false,
118 tag: 'tag:yaml.org,2002:pairs',
119 resolve: parsePairs,
120 createNode: createPairs
121};
122
123class YAMLOMap extends resolveSeq.YAMLSeq {
124 constructor() {
125 super();
126 PlainValue._defineProperty(this, "add", resolveSeq.YAMLMap.prototype.add.bind(this));
127 PlainValue._defineProperty(this, "delete", resolveSeq.YAMLMap.prototype.delete.bind(this));
128 PlainValue._defineProperty(this, "get", resolveSeq.YAMLMap.prototype.get.bind(this));
129 PlainValue._defineProperty(this, "has", resolveSeq.YAMLMap.prototype.has.bind(this));
130 PlainValue._defineProperty(this, "set", resolveSeq.YAMLMap.prototype.set.bind(this));
131 this.tag = YAMLOMap.tag;
132 }
133 toJSON(_, ctx) {
134 const map = new Map();
135 if (ctx && ctx.onCreate) ctx.onCreate(map);
136 for (const pair of this.items) {
137 let key, value;
138 if (pair instanceof resolveSeq.Pair) {
139 key = resolveSeq.toJSON(pair.key, '', ctx);
140 value = resolveSeq.toJSON(pair.value, key, ctx);
141 } else {
142 key = resolveSeq.toJSON(pair, '', ctx);
143 }
144 if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
145 map.set(key, value);
146 }
147 return map;
148 }
149}
150PlainValue._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
151function parseOMap(doc, cst) {
152 const pairs = parsePairs(doc, cst);
153 const seenKeys = [];
154 for (const {
155 key
156 } of pairs.items) {
157 if (key instanceof resolveSeq.Scalar) {
158 if (seenKeys.includes(key.value)) {
159 const msg = 'Ordered maps must not include duplicate keys';
160 throw new PlainValue.YAMLSemanticError(cst, msg);
161 } else {
162 seenKeys.push(key.value);
163 }
164 }
165 }
166 return Object.assign(new YAMLOMap(), pairs);
167}
168function createOMap(schema, iterable, ctx) {
169 const pairs = createPairs(schema, iterable, ctx);
170 const omap = new YAMLOMap();
171 omap.items = pairs.items;
172 return omap;
173}
174const omap = {
175 identify: value => value instanceof Map,
176 nodeClass: YAMLOMap,
177 default: false,
178 tag: 'tag:yaml.org,2002:omap',
179 resolve: parseOMap,
180 createNode: createOMap
181};
182
183class YAMLSet extends resolveSeq.YAMLMap {
184 constructor() {
185 super();
186 this.tag = YAMLSet.tag;
187 }
188 add(key) {
189 const pair = key instanceof resolveSeq.Pair ? key : new resolveSeq.Pair(key);
190 const prev = resolveSeq.findPair(this.items, pair.key);
191 if (!prev) this.items.push(pair);
192 }
193 get(key, keepPair) {
194 const pair = resolveSeq.findPair(this.items, key);
195 return !keepPair && pair instanceof resolveSeq.Pair ? pair.key instanceof resolveSeq.Scalar ? pair.key.value : pair.key : pair;
196 }
197 set(key, value) {
198 if (typeof value !== 'boolean') throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
199 const prev = resolveSeq.findPair(this.items, key);
200 if (prev && !value) {
201 this.items.splice(this.items.indexOf(prev), 1);
202 } else if (!prev && value) {
203 this.items.push(new resolveSeq.Pair(key));
204 }
205 }
206 toJSON(_, ctx) {
207 return super.toJSON(_, ctx, Set);
208 }
209 toString(ctx, onComment, onChompKeep) {
210 if (!ctx) return JSON.stringify(this);
211 if (this.hasAllNullValues()) return super.toString(ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values');
212 }
213}
214PlainValue._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
215function parseSet(doc, cst) {
216 const map = resolveSeq.resolveMap(doc, cst);
217 if (!map.hasAllNullValues()) throw new PlainValue.YAMLSemanticError(cst, 'Set items must all have null values');
218 return Object.assign(new YAMLSet(), map);
219}
220function createSet(schema, iterable, ctx) {
221 const set = new YAMLSet();
222 for (const value of iterable) set.items.push(schema.createPair(value, null, ctx));
223 return set;
224}
225const set = {
226 identify: value => value instanceof Set,
227 nodeClass: YAMLSet,
228 default: false,
229 tag: 'tag:yaml.org,2002:set',
230 resolve: parseSet,
231 createNode: createSet
232};
233
234const parseSexagesimal = (sign, parts) => {
235 const n = parts.split(':').reduce((n, p) => n * 60 + Number(p), 0);
236 return sign === '-' ? -n : n;
237};
238
239// hhhh:mm:ss.sss
240const stringifySexagesimal = ({
241 value
242}) => {
243 if (isNaN(value) || !isFinite(value)) return resolveSeq.stringifyNumber(value);
244 let sign = '';
245 if (value < 0) {
246 sign = '-';
247 value = Math.abs(value);
248 }
249 const parts = [value % 60]; // seconds, including ms
250 if (value < 60) {
251 parts.unshift(0); // at least one : is required
252 } else {
253 value = Math.round((value - parts[0]) / 60);
254 parts.unshift(value % 60); // minutes
255 if (value >= 60) {
256 value = Math.round((value - parts[0]) / 60);
257 parts.unshift(value); // hours
258 }
259 }
260 return sign + parts.map(n => n < 10 ? '0' + String(n) : String(n)).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
261;
262};
263const intTime = {
264 identify: value => typeof value === 'number',
265 default: true,
266 tag: 'tag:yaml.org,2002:int',
267 format: 'TIME',
268 test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
269 resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
270 stringify: stringifySexagesimal
271};
272const floatTime = {
273 identify: value => typeof value === 'number',
274 default: true,
275 tag: 'tag:yaml.org,2002:float',
276 format: 'TIME',
277 test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
278 resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
279 stringify: stringifySexagesimal
280};
281const timestamp = {
282 identify: value => value instanceof Date,
283 default: true,
284 tag: 'tag:yaml.org,2002:timestamp',
285 // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
286 // may be omitted altogether, resulting in a date format. In such a case, the time part is
287 // assumed to be 00:00:00Z (start of day, UTC).
288 test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' +
289 // YYYY-Mm-Dd
290 '(?:(?:t|T|[ \\t]+)' +
291 // t | T | whitespace
292 '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' +
293 // Hh:Mm:Ss(.ss)?
294 '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' +
295 // Z | +5 | -03:30
296 ')?' + ')$'),
297 resolve: (str, year, month, day, hour, minute, second, millisec, tz) => {
298 if (millisec) millisec = (millisec + '00').substr(1, 3);
299 let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
300 if (tz && tz !== 'Z') {
301 let d = parseSexagesimal(tz[0], tz.slice(1));
302 if (Math.abs(d) < 30) d *= 60;
303 date -= 60000 * d;
304 }
305 return new Date(date);
306 },
307 stringify: ({
308 value
309 }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
310};
311
312/* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
313
314function shouldWarn(deprecation) {
315 const env = typeof process !== 'undefined' && process.env || {};
316 if (deprecation) {
317 if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS;
318 return !env.YAML_SILENCE_DEPRECATION_WARNINGS;
319 }
320 if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS;
321 return !env.YAML_SILENCE_WARNINGS;
322}
323function warn(warning, type) {
324 if (shouldWarn(false)) {
325 const emit = typeof process !== 'undefined' && process.emitWarning;
326 // This will throw in Jest if `warning` is an Error instance due to
327 // https://github.com/facebook/jest/issues/2549
328 if (emit) emit(warning, type);else {
329 // eslint-disable-next-line no-console
330 console.warn(type ? `${type}: ${warning}` : warning);
331 }
332 }
333}
334function warnFileDeprecation(filename) {
335 if (shouldWarn(true)) {
336 const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
337 warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, 'DeprecationWarning');
338 }
339}
340const warned = {};
341function warnOptionDeprecation(name, alternative) {
342 if (!warned[name] && shouldWarn(true)) {
343 warned[name] = true;
344 let msg = `The option '${name}' will be removed in a future release`;
345 msg += alternative ? `, use '${alternative}' instead.` : '.';
346 warn(msg, 'DeprecationWarning');
347 }
348}
349
350exports.binary = binary;
351exports.floatTime = floatTime;
352exports.intTime = intTime;
353exports.omap = omap;
354exports.pairs = pairs;
355exports.set = set;
356exports.timestamp = timestamp;
357exports.warn = warn;
358exports.warnFileDeprecation = warnFileDeprecation;
359exports.warnOptionDeprecation = warnOptionDeprecation;
Note: See TracBrowser for help on using the repository browser.