deno.land / std@0.224.0 / yaml / _type / pairs.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// 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,});
Version Info