UNPKG

@gulujs/toml

Version:

TOML parser and serializer

28 lines (27 loc) 678 B
import { ObjectPath } from '@gulujs/object-path'; export function stringifyKey(key, keyPath) { if (typeof key === 'string') { return key; } else if (Array.isArray(key)) { return keyPath.stringify(key); } else { throw new Error(`Invalid key "${key}"`); } } export function flattenPath(path) { let keys = []; for (const key of path) { if (Array.isArray(key)) { keys = [...keys, ...key]; } else if (typeof key === 'number') { keys.push(key); } else { keys = [...keys, ...ObjectPath.quoteStyle.keyPath.parse(key)]; } } return keys; }