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

define-constants

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

define-constants

description

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

define-constants

Gets rid of repeating stuff when declaring self-defined constants.

Instead of writing smth like that:

const MY_CONSTANT = "MY_CONSTANT"
const MY_FAVOURITE_CONSTANT = "MY_FAVOURITE_CONSTANT"
const MY_CONSTANT_FOR_FUN = "MY_CONSTANT_FOR_FUN"

You can write your constant just once when declaring it:

const {
	MY_CONSTANT,
	MY_FAVOURITE_CONSTANT,
	MY_CONSTANT_FOR_FUN,
} = defineConstants()

// MY_CONSTANT === "MY_CONSTANT"
// MY_FAVOURITE_CONSTANT === "MY_FAVOURITE_CONSTANT"
// MY_CONSTANT_FOR_FUN === "MY_CONSTANT_FOR_FUN"

and get the same result.

You can also add some namespace to your constants:

const {
	MY_NAMESPACE,
} = defineConstants()

const {
	MY_CONSTANT,
	MY_FAVOURITE_CONSTANT,
	MY_CONSTANT_FOR_FUN,
} = defineConstants(MY_NAMESPACE)

// MY_CONSTANT === "MY_NAMESPACE.MY_CONSTANT"
// MY_FAVOURITE_CONSTANT === "MY_NAMESPACE.MY_FAVOURITE_CONSTANT"
// MY_CONSTANT_FOR_FUN === "MY_NAMESPACE.MY_CONSTANT_FOR_FUN"

Tweak namespace delimiter if you wish:

const {
	MY_CONSTANT,
	MY_FAVOURITE_CONSTANT,
	MY_CONSTANT_FOR_FUN,
} = defineConstants("MY_NAMESPACE", "/")

// MY_CONSTANT === "MY_NAMESPACE/MY_CONSTANT"
// MY_FAVOURITE_CONSTANT === "MY_NAMESPACE/MY_FAVOURITE_CONSTANT"
// MY_CONSTANT_FOR_FUN === "MY_NAMESPACE/MY_CONSTANT_FOR_FUN"

TODO: babel plugin to transform the code at compile time.

FAQs

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