Levn is a JavaScript library for parsing human-readable string input into structured JavaScript values, leveraging type validation. It is designed for concise, human-authored data, such as configuration files or command-line arguments, distinguishing itself from JSON by prioritizing human readability, conciseness, and built-in type validation via `type-check`. It supports regex and date literals and is extensible with custom types. Unlike JSON, it is not optimized for large-scale data transport due to its parsing overhead. The current stable version is 0.4.1. This package appears to be largely unmaintained, with its last npm publish over six years ago and minimal activity on its GitHub repository in recent years.
npm install levnVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic `parse` usage for various types (Number, String, Boolean, Array, Object) and the `parsedTypeParse` function with a pre-parsed type from `type-check`.
Consider modern alternatives like `yaml`, `toml`, or robust JSON parsers. If `levn` is critical, fork the project, update dependencies, and address any Node.js compatibility issues.
Always use `require()` for importing `levn` and its functions: `const { parse } = require('levn');`.Do not use `levn` for performance-critical data serialization/deserialization involving large payloads. Stick to its intended use case for small, human-editable configuration or command-line inputs.
Familiarize yourself with the `type-check` library's documentation, especially its type format, before attempting advanced parsing with `levn`.
Ensure your project is configured for CommonJS, or use dynamic `import()` if absolutely necessary within an ESM file. `levn` is designed for CommonJS (`require`).
Install the peer dependency: `npm install type-check`.
Review the Levn format documentation and ensure the input string correctly matches the `type` string provided to the `parse` function. Pay attention to delimiters and value formats (e.g., dates with `#`, regex with `/`).
Verify that `levn` is installed (`npm list levn`) and that the `require` path is correct. Ensure no other module is inadvertently shadowing `levn`.