Socket
Socket
Sign inDemoInstall

staack

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

staack - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

20

dist/mod.d.ts

@@ -20,16 +20,12 @@ declare const INTERNAL: unique symbol;

}
type KeyProviderFn<T, HasDefault extends boolean> = (value: T) => KeyProvider<T, HasDefault>;
interface Key<T, HasDefault extends boolean = boolean> {
type KeyProviderFn<T, HasDefault extends boolean> = (...args: undefined extends T ? [] : [value: T]) => KeyProvider<T, HasDefault>;
interface IKey<T, HasDefault extends boolean = boolean> {
Consumer: KeyConsumer<T, HasDefault>;
Provider: KeyProviderFn<T, HasDefault>;
}
declare function createKey<T>(options: {
name: string;
help?: string;
defaultValue: T;
}): Key<T, true>;
declare function createKey<T>(options: {
name: string;
help?: string;
}): Key<T, false>;
declare const Key: {
create: <T>(name: string, help?: string) => IKey<T, false>;
createWithDefault: <T_1>(name: string, defaultValue: T_1, help?: string) => IKey<T_1, true>;
createEmpty: (name: string, help?: string) => IKey<undefined, false>;
};

@@ -99,2 +95,2 @@ declare class MissingContextError extends Error {

export { Key, KeyConsumer, KeyProvider, KeyProviderFn, MissingContextError, Staack, StaackCore, StaackCoreTuple, StaackCoreValue, createKey };
export { IKey, Key, KeyConsumer, KeyProvider, KeyProviderFn, MissingContextError, Staack, StaackCore, StaackCoreTuple, StaackCoreValue };

46

dist/mod.js

@@ -28,6 +28,6 @@ "use strict";

__export(mod_exports, {
Key: () => Key,
MissingContextError: () => MissingContextError,
Staack: () => Staack,
StaackCore: () => StaackCore,
createKey: () => createKey
StaackCore: () => StaackCore
});

@@ -43,17 +43,29 @@ module.exports = __toCommonJS(mod_exports);

// src/Key.ts
function createKey(options) {
const { help, name } = options;
const Consumer = {
name,
[INTERNAL]: {
hasDefault: options.defaultValue !== void 0,
defaultValue: options.defaultValue,
help
}
};
var Key = (() => {
return {
Consumer,
Provider: (value) => ({ name, [INTERNAL]: { value, consumer: Consumer } })
create,
createWithDefault,
createEmpty
};
}
function create(name, help) {
return createInternal(name, { hasDefault: false, defaultValue: void 0, help });
}
function createWithDefault(name, defaultValue, help) {
return createInternal(name, { hasDefault: true, defaultValue, help });
}
function createEmpty(name, help) {
return createInternal(name, { hasDefault: false, defaultValue: void 0, help });
}
function createInternal(name, data) {
const Consumer = { name, [INTERNAL]: data };
const Provider = (...args) => ({
name,
[INTERNAL]: { value: args[0], consumer: Consumer }
});
return {
Consumer,
Provider
};
}
})();

@@ -286,6 +298,6 @@ // src/MissingContextError.ts

0 && (module.exports = {
Key,
MissingContextError,
Staack,
StaackCore,
createKey
StaackCore
});
{
"name": "staack",
"version": "2.0.2",
"version": "3.0.0",
"description": "A library to create type-safe opaque stacks",

@@ -5,0 +5,0 @@ "keywords": [

@@ -9,6 +9,6 @@ # 🏯 Staack

// 1. Create a key with a name and a type
const NumKey = createKey<number>({ name: 'Num' });
const NumKey = Key.create<number>('Num');
// 2. Create a stack
const stack = Staack.create();
const stack = new Staack();

@@ -36,7 +36,2 @@ // 3. Add a value to the stack using the key (Staack is immutable, it returns a new instance)

class CustomStaack extends Staack {
// Override the `create` method to return a new instance of your CustomStack
static create(...keys: KeyProvider<any, boolean>[]): CustomStaack {
return new CustomStaack().with(...keys);
}
// You need to override the `instantiate` method to return a new instance of your CustomStack

@@ -48,5 +43,5 @@ protected instantiate(staackCore: StaackCoreValue): this {

const custom = CustomStaack.create();
const custom = new CustomStaack();
expect(custom instanceof CustomStaack).toBe(true);
expect(custom instanceof Staack).toBe(true);
```

Sorry, the diff of this file is not supported yet

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