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

args-pattern

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

args-pattern

A Nodejs lib that arranges the arguments passed to a function based on pattern string

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

args-pattern

A Nodejs lib that arranges the arguments passed to a function based on pattern string

Description

This library intends to help the developers to maintain backwards compatibility in their functions, by making and maintaining optional parameters, and not worrying to write code to assign the correct values to the arguments

Installation

npm install parse-args -S

Typical Example of optional parameters

// params ([name], [email], age, [gender])
function testFn(name="vin", email="diesel@mail.com", age, gender="female"){
    if(!email) {
        age = name;
        name = "vin"
    } else if (!age) {
        age = email
        email = "diesel@mail.com"
    }
  
}

testFn("john", 34)

Example after using this library

var parseArgs = require("args-pattern")
function testFn() {
    let [name, email, age, gender] = parseArgs(arguments, "[name] [, email] , age [, gender]", {
        args: ['vin', 'diesel@mail.com', 34, "female"]
    })

// Output name === "john"
// Output email === "diesel@mail.com"
// Output age === 35
// Output gender === "female"
} 

testFn("john", 35)

Even though the real world examples can get a little more complicate, parse-args library will be there to rescue, so that you can avoid a lot of spaghetti code :thumbsup:

Test

npm install
mocha test.js

License

MIT

Keywords

FAQs

Package last updated on 08 Apr 2017

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