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

@julo-ui/context

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@julo-ui/context - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

dist/chunk-DGEY3FWG.mjs

2

dist/context.d.ts
import { CreateContextOptions, CreateContextReturn } from './types.js';
import 'react';
declare function createContext<T>(options?: CreateContextOptions<T>): CreateContextReturn<T | undefined> | CreateContextReturn<T>;
declare function createContext<T, Strict extends boolean = true>(options: CreateContextOptions<T, Strict>): CreateContextReturn<T, Strict>;
export { createContext };

@@ -27,6 +27,10 @@ "use strict";

var import_react = require("react");
// src/utils.ts
function getDefaultErrorMessage(hook, provider) {
return `${hook} must be used within ${provider}`;
}
function createContext(options = {}) {
// src/context.ts
function createContext(options) {
const {

@@ -38,11 +42,12 @@ name,

providerName = "Provider",
errorMessage
errorMessage: rootErrorMessage
} = options;
const Context = (0, import_react.createContext)(defaultValue);
Context.displayName = name;
function useContext() {
function useContext(errorMessage) {
var _a;
const context = (0, import_react.useContext)(Context);
if (!context && strict) {
const error = new Error(
errorMessage != null ? errorMessage : getDefaultErrorMessage(hookName, providerName)
(_a = errorMessage != null ? errorMessage : rootErrorMessage) != null ? _a : getDefaultErrorMessage(hookName, providerName)
);

@@ -54,4 +59,2 @@ error.name = "ContextError";

}
if (!strict)
return [Context.Provider, useContext, Context];
return [Context.Provider, useContext, Context];

@@ -58,0 +61,0 @@ }

@@ -29,6 +29,10 @@ "use strict";

var import_react = require("react");
// src/utils.ts
function getDefaultErrorMessage(hook, provider) {
return `${hook} must be used within ${provider}`;
}
function createContext(options = {}) {
// src/context.ts
function createContext(options) {
const {

@@ -40,11 +44,12 @@ name,

providerName = "Provider",
errorMessage
errorMessage: rootErrorMessage
} = options;
const Context = (0, import_react.createContext)(defaultValue);
Context.displayName = name;
function useContext() {
function useContext(errorMessage) {
var _a;
const context = (0, import_react.useContext)(Context);
if (!context && strict) {
const error = new Error(
errorMessage != null ? errorMessage : getDefaultErrorMessage(hookName, providerName)
(_a = errorMessage != null ? errorMessage : rootErrorMessage) != null ? _a : getDefaultErrorMessage(hookName, providerName)
);

@@ -56,4 +61,2 @@ error.name = "ContextError";

}
if (!strict)
return [Context.Provider, useContext, Context];
return [Context.Provider, useContext, Context];

@@ -60,0 +63,0 @@ }

import { Provider, Context } from 'react';
interface CreateContextOptions<T> {
/**
* @default true
*/
strict?: boolean;
interface BaseCreateContextOptions<T> {
hookName?: string;

@@ -17,4 +13,14 @@ providerName?: string;

}
type CreateContextReturn<T> = [Provider<T>, () => T, Context<T>];
type CreateContextOptions<T, Strict extends boolean = true> = BaseCreateContextOptions<T> & (Strict extends true ? {
strict?: true;
} : {
strict: false;
});
type ContextValue<T, Strict extends boolean = true> = Strict extends true ? T : T | undefined;
type CreateContextReturn<T, Strict extends boolean> = [
Provider<ContextValue<T, Strict>>,
(errorMessage?: string) => ContextValue<T, Strict>,
Context<ContextValue<T, Strict>>
];
export { CreateContextOptions, CreateContextReturn };
{
"name": "@julo-ui/context",
"version": "0.0.5",
"version": "0.0.6",
"description": "Custom context hooks extended from React",

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

Sorry, the diff of this file is not supported yet

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