Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

levn

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

levn

Light ECMAScript (JavaScript) Value Notation - human written, concise, typed, flexible

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is levn?

The levn npm package is used for parsing and casting values to specific types based on a string input. It is particularly useful for configuration files and command-line arguments where you need to ensure the data types are correctly interpreted.

What are levn's main functionalities?

Parse and cast values

This feature allows you to parse a string and cast it to a specific type, such as a number, boolean, or string. The example shows how to parse the string '42' into an actual number.

const levn = require('levn');
const parsed = levn.parse('number', '42');
console.log(parsed); // 42 as a number

Coerce arrays and objects

Levn can also parse strings representing arrays and objects, coercing each element to the specified type. The example demonstrates parsing a string into an array of numbers.

const levn = require('levn');
const parsedArray = levn.parse('[number]', '[1, 2, 3]');
console.log(parsedArray); // [1, 2, 3] as an array of numbers

Custom types

Levn allows you to define custom types with validation and parsing rules. This example shows how to add a custom type and parse a string that matches the custom type.

const levn = require('levn');
levn.addType({
  name: 'myType',
  validate: (x) => x === 'special',
  parse: (x) => ({ special: x })
});
const parsedCustom = levn.parse('myType', 'special');
console.log(parsedCustom); // { special: 'special' }

Other packages similar to levn

Keywords

FAQs

Package last updated on 04 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc