helios-parse-utils
v1.0.0
Published
Lightweight utility library for data parsing and transformation
Maintainers
Readme
helios-parse-utils
Lightweight utility library for common data parsing and transformation tasks in Node.js.
Install
npm install helios-parse-utilsUsage
const {
parseConfig,
mergeDeep,
flatten,
chunk,
retry,
getDiagnostics,
} = require('folio-data-utils');parseConfig(input)
Parses a flat key=value config string (like .env files) into a plain object.
const config = parseConfig(`
HOST=localhost
PORT=3000
DEBUG=true
`);
// → { HOST: 'localhost', PORT: '3000', DEBUG: 'true' }mergeDeep(target, source)
Recursively merges two plain objects. Source keys win on conflict.
const result = mergeDeep(
{ a: { x: 1, y: 2 } },
{ a: { y: 99, z: 3 } }
);
// → { a: { x: 1, y: 99, z: 3 } }flatten(obj)
Flattens a nested object to dot-notation keys.
flatten({ db: { host: 'localhost', port: 5432 } });
// → { 'db.host': 'localhost', 'db.port': 5432 }chunk(arr, size)
Splits an array into chunks of a given size.
chunk([1, 2, 3, 4, 5], 2);
// → [[1, 2], [3, 4], [5]]retry(fn, times)
Retries an async function with exponential backoff.
const data = await retry(() => fetch('https://api.example.com/data'), 3);getDiagnostics()
Returns runtime environment info useful for debugging.
const info = getDiagnostics();
// → { platform, node, uptime, memory, cpu, home, env_keys, cwd, argv }License
UNLICENSED
