levn
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
prelude-ls | 1.2.1 | 9.19 kB | MIT | prod | |
type-check | 0.4.0 | 6.62 kB | MIT | prod |
Levn is a JavaScript library designed for interpreting and validating short strings of human-entered data, transforming those strings into JavaScript values based on anticipated types. It's particularly useful for input taken from configurations files or command line arguments. With its concise and flexible structure, levn offers a more human-friendly, type-specific alternative to JSON.
Using levn requires installation via npm, which can be accomplished with the command npm install levn
. After installation, you can use levn's parse
function to evaluate and type-cast your input strings. For instance, to parse a string into a number, you would use var parse = require('levn').parse; parse('Number', '2');
, which outputs 2
. You can replace the 'Number'
with any expected JavaScript type suited for your needs.
Additionally, levn also comes with a parsedTypeParse
function. For this, you first need to parse the type using the parseType
function from the "type-check" library. Example usage would be var parsedType = require('type-check').parseType('[Number]'); parsedTypeParse(parsedType, '1,2,3');
, which similarly outputs [1, 2, 3]
.
var parse = require('levn').parse;
parse('Number', '2'); // Outputs: 2
var parsedType = require('type-check').parseType('[Number]');
parsedTypeParse(parsedType, '1,2,3'); // Outputs: [1, 2, 3]
The levn documentation is primarily located in its Github repository. This includes detailed explanations of how levn operates, examples of use, the list of options you can use with the parsing functions, and technical notes on the library structure and dependencies. An additional description of the type format used by levn is found in the "type-check" library documentation.