deno.land / std@0.224.0 / yaml / _type / pairs.ts

View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Ported from js-yaml v3.13.1:// https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { Type } from "../type.ts";import type { Any } from "../_utils.ts";
const _toString = Object.prototype.toString;
function resolveYamlPairs(data: Any[][]): boolean { const result = Array.from({ length: data.length });
for (const [index, pair] of data.entries()) { if (_toString.call(pair) !== "[object Object]") return false;
const keys = Object.keys(pair);
if (keys.length !== 1) return false;
result[index] = [keys[0], pair[keys[0] as Any]]; }
return true;}
function constructYamlPairs(data: string): Any[] { if (data === null) return [];
const result = Array.from({ length: data.length });
for (let index = 0; index < data.length; index += 1) { const pair = data[index]!;
const keys = Object.keys(pair);
result[index] = [keys[0], pair[keys[0] as Any]]; }
return result;}
export const pairs = new Type("tag:yaml.org,2002:pairs", { construct: constructYamlPairs, kind: "sequence", resolve: resolveYamlPairs,});
std

Version Info

Tagged at
6 months ago