Socket
Socket
Sign inDemoInstall

@dldc/stack

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dldc/stack

A library to create type-safe opaque stacks


Version published
Weekly downloads
6
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

🏯 Stack

A library to create type-safe opaque stacks

Example

// 1. Create a key with a name and a type
const NumKey = Key.create<number>('Num');

// 2. Create a stack
const stack = new Stack();

// 3. Add a value to the stack using the key (Stack is immutable, it returns a new instance)
const stack2 = stack.with(NumKey.Provider(42));

// 4. Get the value from the stack using the key
expect(stack2.get(NumKey.Consumer)).toBe(42);

Installation

npm install stack
# or
yarn add stack

Extending Stack

You can create your own Stack, this is useful to define custom properties and methods.

class CustomStack extends Stack {
  // You need to override the `instantiate` method to return a new instance of your CustomStack
  protected instantiate(stackCore: StackCoreValue): this {
    return new CustomStack(stackCore) as any;
  }
}

const custom = new CustomStack();
expect(custom instanceof CustomStack).toBe(true);
expect(custom instanceof Stack).toBe(true);

Keywords

FAQs

Package last updated on 20 Sep 2023

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