Socket
Socket
Sign inDemoInstall

babel-generate-guard-clauses

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-generate-guard-clauses

A helper to generate different guard clauses


Version published
Weekly downloads
259
increased by133.33%
Maintainers
1
Weekly downloads
 
Created
Source

Babel-Generate-Guard-Clause

A helper to generate different guard clauses.

Exports

generateTypeCheck(typeAssertion, options)({ name: argumentName })

generateTypeCheck("number")({ name: argumentName })
const typeCheckAst = genertateTypeCheck("string")({ name: "ponies" });

Generated Code:

if (typeof ponies !== "string") {
    throw new Error('ponies should be a string, but got ' + ponies + '(' + typeof ponies +  ')');
}
generateTypeCheck("number", { selector: "selector" })({ name: argumentName })
const typeCheckAst = generateTypeCheck("number", { selector: "x" })({ name: "point" });

Generated Code:

if (typeof point.x !== "number") {
    throw new Error('point.x should be a number, but got ' + point.x + '(' + typeof point.x +  ')');
}

generateIsOneOfCheck

generateIsOneOfCheck(optionArray)({ name: "argName" })
const typeCheckAst = generateIsOneOfCheck(["option1", "option2"])({ name: "argName" });

Generated Code:

if (!['option1', 'option2'].some(x => x === argName)) {
   return new Error("argName should be one of ['option1', 'option2'], but got " + argName);
}

FAQs

Package last updated on 03 Oct 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