🚀 DAY 3 OF LAUNCH WEEK: Introducing Webhook Events for Pull Request Scans.Learn more →
Socket
Book a DemoInstallSign in
Socket

contextus

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

contextus

The context you know and love, but framework agnostic!

latest
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

contextus

version CI minzip size
The context you know and love, but framework agnostic!

Features

  • Microscopic: ~300 B minzipped!
  • Simple: just provide and use
  • Powerful: supports context nesting
  • Fancy: contextus is Latin for context!

Install

$ npm i contextus

Usage

import context from 'contextus'

const myContext = context()

function a() {
  b()

  return `Amazing!`
}

function b() {
  c()
}

function c() {
  d()
}

function d() {
  const value = myContext.use()

  console.log(`d: ${value}`)
  myContext.provide(`More specific wins!`, e)
  console.log(`d: ${value}`)
}

function e() {
  console.log(`e: ${myContext.use()}`)
}

const returnValue = myContext.provide(`Spectacular!`, a)
//=> d: Spectacular!
//=> e: More specific wins!
//=> d: Spectacular!

console.log(returnValue)
//=> Amazing!

try {
  myContext.use()
} catch (e) {
  console.log(e.message)
}
//=> context: use called outside provide

See the type definitions for more documentation.

Contributing

Stars are always welcome!

For bugs and feature requests, please create an issue.

For pull requests, please read the contributing guidelines.

License

Apache 2.0

This is not an official Google product.

Keywords

context

FAQs

Package last updated on 09 Nov 2021

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