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

@solid-primitives/utils

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/utils - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

128

dist/index.d.ts
import { Accessor, onCleanup } from 'solid-js';
import { OnOptions, EffectFunction, NoInfer, Owner } from 'solid-js/types/reactive/signal';
import { OnOptions, EffectFunction, NoInfer } from 'solid-js/types/reactive/signal';
import { Store } from 'solid-js/store';
export { isServer } from 'solid-js/web';
import { N as Noop, M as MaybeAccessorValue, a as MaybeAccessor, O as OnAccessEffectFunction, I as ItemsOf, V as Values, D as Destore, F as Fn, A as AnyFunction } from './types-5d7b3b37';
export { d as AccessReturnTypes, A as AnyFunction, h as AnyObject, g as DeepPartialAny, D as Destore, k as Falsy, j as FalsyValue, F as Fn, I as ItemsOf, K as Keys, b as Many, c as MappingFn, a as MaybeAccessor, M as MaybeAccessorValue, e as Modify, f as ModifyDeep, N as Noop, O as OnAccessEffectFunction, P as Predicate, i as PrimitiveValue, T as Truthy, V as Values } from './types-5d7b3b37';
/**
* A function
*/
declare type Fn<R = void> = () => R;
/**
* Can be single or in an array
*/
declare type Many<T> = T | T[];
declare type Keys<O extends Object> = keyof O;
declare type Values<O extends Object> = O[Keys<O>];
declare type Noop = (...a: any[]) => void;
/**
* Infers the type of the array elements
*/
declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
/**
* T or a reactive/non-reactive function returning T
*/
declare type MaybeAccessor<T> = T | Accessor<T>;
/**
* Accessed value of a MaybeAccessor
* @example
* ```ts
* MaybeAccessorValue<MaybeAccessor<string>>
* // => string
* MaybeAccessorValue<MaybeAccessor<() => string>>
* // => string | (() => string)
* MaybeAccessorValue<MaybeAccessor<string> | Function>
* // => string | void
* ```
*/
declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
declare type OnAccessEffectFunction<S, Prev, Next extends Prev = Prev> = (input: AccessReturnTypes<S>, prevInput: AccessReturnTypes<S>, v: Prev) => Next;
declare type AccessReturnTypes<S> = S extends MaybeAccessor<any>[] ? {
[I in keyof S]: AccessReturnTypes<S[I]>;
} : MaybeAccessorValue<S>;
/** Allows to make shallow overwrites to an interface */
declare type Modify<T, R> = Omit<T, keyof R> & R;
/** Allows to make nested overwrites to an interface */
declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
[K in keyof A]: B[K] extends never ? A[K] : B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K];
} & (A extends AnyObject ? Omit<B, keyof A> : A);
/** Makes each property optional and turns each leaf property into any, allowing for type overrides by narrowing any. */
declare type DeepPartialAny<T> = {
[P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
};
declare type AnyObject = Record<string, any>;
declare type AnyFunction = (...args: any[]) => any;
declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
declare type FalsyValue = false | 0 | "" | null | undefined;
declare type Truthy<T> = T extends FalsyValue ? never : T;
declare type Falsy<T> = T extends FalsyValue ? T : never;
/**
* Destructible store object, with values changed to accessors
*/
declare type Destore<T extends Object> = {
[K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
};
/** no operation */

@@ -17,3 +74,16 @@ declare const noop: Noop;

declare const isFunction: <T>(value: Function | T) => value is Function;
declare const isBoolean: (val: any) => val is boolean;
declare const isNumber: (val: any) => val is number;
declare const isString: (val: unknown) => val is string;
declare const isObject: (val: any) => val is object;
declare const isArray: (val: any) => val is any[];
declare const compare: (a: any, b: any) => number;
/**
* for creating tuples by inferring type
* @example
* const users = tuple(["John", "Jeff", "Joe"]);
* // users: [string, string, string]
*/
declare const tuple: <T extends any[] | []>(input: T) => T;
/**
* Accesses the value of a MaybeAccessor

@@ -40,2 +110,9 @@ * @example

/**
* Access an array of MaybeAccessors
* @example
* const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
* const newList = accessArray(list) // T: number[]
*/
declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAccessorValue<A>[];
/**
* Run the function if the accessed value is not `undefined` nor `null`

@@ -62,5 +139,9 @@ * @param value

*/
declare const entries: <A extends MaybeAccessor<Object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
declare const entries: <A extends MaybeAccessor<object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
/**
* Creates a promise that resolves *(or rejects)* after gives time.
* Get `Object.keys()` of an MaybeAccessor<Object>
*/
declare const keys: <A extends MaybeAccessor<object>>(object: A) => (keyof MaybeAccessorValue<A>)[];
/**
* Creates a promise that resolves *(or rejects)* after given time.
*

@@ -101,2 +182,6 @@ * @param ms timeout duration in ms

/**
* Solid's `onCleanup` that is registered only if there is a root.
*/
declare const onRootCleanup: typeof onCleanup;
/**
* Allows the Solid's store to be destructured

@@ -119,33 +204,2 @@ *

declare function destore<T extends Object>(store: Store<T>): Destore<T>;
/**
* Solid's `onCleanup` that runs only if there is a root.
*/
declare const onRootCleanup: typeof onCleanup;
/**
* Creates a reactive root, which will be disposed when the passed owner does.
*
* @param fn
* @param owner a root that will trigger the cleanup
* @returns whatever the "fn" returns
*
* @example
* const owner = getOwner()
* const handleClick = () => createSubRoot(owner, () => {
* createEffect(() => {})
* });
*/
declare function createSubRoot<T>(fn: (dispose: Fn) => T, owner?: Owner | null): T;
/**
* A wrapper for creating functions with the `createSubRoot`
*
* @param callback
* @param owner a root that will trigger the cleanup
* @returns the callback function
*
* @example
* const handleClick = createSubRootFunction(() => {
* createEffect(() => {})
* })
*/
declare function createSubRootFunction<T extends AnyFunction>(callback: T, owner?: Owner | null): T;
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {

@@ -157,2 +211,2 @@ push: (...callbacks: Fn[]) => void;

export { access, accessAsArray, asAccessor, asArray, createCallbackStack, createSubRoot, createSubRootFunction, destore, entries, forEach, isClient, isDefined, isFunction, noop, onAccess, onRootCleanup, promiseTimeout, raceTimeout, withAccess };
export { AccessReturnTypes, AnyFunction, AnyObject, DeepPartialAny, Destore, Falsy, FalsyValue, Fn, ItemsOf, Keys, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, PrimitiveValue, Truthy, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, destore, entries, forEach, isArray, isBoolean, isClient, isDefined, isFunction, isNumber, isObject, isString, keys, noop, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, withAccess };
// src/index.ts
import { createRoot, getOwner, onCleanup, runWithOwner, on } from "solid-js";
import { getOwner, onCleanup, on } from "solid-js";
import { isServer } from "solid-js/web";

@@ -8,5 +8,13 @@ var noop = () => void 0;

var isFunction = (value) => typeof value === "function";
var isBoolean = (val) => typeof val === "boolean";
var isNumber = (val) => typeof val === "number";
var isString = (val) => typeof val === "string";
var isObject = (val) => toString.call(val) === "[object Object]";
var isArray = (val) => Array.isArray(val);
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
var tuple = (input) => input;
var access = (v) => isFunction(v) ? v() : v;
var accessAsArray = (value) => asArray(access(value));
var asArray = (value) => Array.isArray(value) ? value : [value];
var accessArray = (list) => list.map((v) => access(v));
var withAccess = (value, fn) => {

@@ -23,2 +31,3 @@ const _value = access(value);

var entries = (object) => Object.entries(access(object));
var keys = (object) => Object.keys(access(object));
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));

@@ -33,2 +42,3 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {

}
var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
function destore(store) {

@@ -42,11 +52,2 @@ const _store = store;

}
var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
function createSubRoot(fn, owner = getOwner()) {
const [dispose, returns] = createRoot((dispose2) => [dispose2, fn(dispose2)], owner != null ? owner : void 0);
owner && runWithOwner(owner, () => onCleanup(dispose));
return returns;
}
function createSubRootFunction(callback, owner) {
return (...args) => createSubRoot(() => callback(...args), owner);
}
var createCallbackStack = () => {

@@ -66,15 +67,21 @@ let stack = [];

access,
accessArray,
accessAsArray,
asAccessor,
asArray,
compare,
createCallbackStack,
createSubRoot,
createSubRootFunction,
destore,
entries,
forEach,
isArray,
isBoolean,
isClient,
isDefined,
isFunction,
isNumber,
isObject,
isServer,
isString,
keys,
noop,

@@ -85,3 +92,4 @@ onAccess,

raceTimeout,
tuple,
withAccess
};
{
"name": "@solid-primitives/utils",
"version": "0.1.3",
"version": "0.2.0",
"description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",

@@ -21,29 +21,2 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",

],
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},
"./fp": {
"types": "./dist/fp.d.ts",
"require": "./dist/fp.cjs",
"import": "./dist/fp.js"
},
"./setter": {
"types": "./dist/setter.d.ts",
"require": "./dist/setter.cjs",
"import": "./dist/setter.js"
}
},
"typesVersions": {
"*": {
"fp": [
"./dist/fp.d.ts"
],
"setter": [
"./dist/setter.d.ts"
]
}
},
"scripts": {

@@ -75,2 +48,2 @@ "build": "tsup",

}
}
}

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