@solid-primitives/utils 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3,18 +3,20 @@
3
3
  var solidJs = require('solid-js');
4
4
  var web = require('solid-js/web');
5
5
 
6
- // src/index.ts
7
- exports.noop = () => void 0;
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ exports.noop = /* @__PURE__ */ __name(() => void 0, "noop");
8
9
  exports.isServer = web.isServer;
9
10
  exports.isClient = !exports.isServer;
10
11
  exports.isDev = solidJs.DEV && exports.isClient;
11
12
  exports.isProd = !exports.isDev;
12
- exports.ofClass = (v, c) => v instanceof c || v && v.constructor === c;
13
+ exports.ofClass = /* @__PURE__ */ __name((v, c) => v instanceof c || v && v.constructor === c, "ofClass");
13
14
  function isObject(value) {
14
15
  return value !== null && (typeof value === "object" || typeof value === "function");
15
16
  }
16
- exports.compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
17
- exports.arrayEquals = (a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]);
17
+ __name(isObject, "isObject");
18
+ exports.compare = /* @__PURE__ */ __name((a, b) => a < b ? -1 : a > b ? 1 : 0, "compare");
19
+ exports.arrayEquals = /* @__PURE__ */ __name((a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]), "arrayEquals");
18
20
  function chain(callbacks) {
19
21
  return (...args) => {
20
22
  for (const callback of callbacks) {
@@ -23,18 +25,20 @@ function chain(callbacks) {
23
25
  }
24
26
  };
25
27
  }
26
- exports.clamp = (n, min, max) => Math.min(Math.max(n, min), max);
27
- exports.access = (v) => typeof v === "function" && !v.length ? v() : v;
28
- exports.asArray = (value) => Array.isArray(value) ? value : [value];
29
- exports.accessArray = (list) => list.map((v) => exports.access(v));
30
- exports.withAccess = (value, fn) => {
28
+ __name(chain, "chain");
29
+ exports.clamp = /* @__PURE__ */ __name((n, min, max) => Math.min(Math.max(n, min), max), "clamp");
30
+ exports.access = /* @__PURE__ */ __name((v) => typeof v === "function" && !v.length ? v() : v, "access");
31
+ exports.asArray = /* @__PURE__ */ __name((value) => Array.isArray(value) ? value : [value], "asArray");
32
+ exports.accessArray = /* @__PURE__ */ __name((list) => list.map((v) => exports.access(v)), "accessArray");
33
+ exports.withAccess = /* @__PURE__ */ __name((value, fn) => {
31
34
  const _value = exports.access(value);
32
35
  typeof _value !== "undefined" && _value !== null && fn(_value);
33
- };
34
- exports.asAccessor = (v) => typeof v === "function" ? v : () => v;
36
+ }, "withAccess");
37
+ exports.asAccessor = /* @__PURE__ */ __name((v) => typeof v === "function" ? v : () => v, "asAccessor");
35
38
  function accessWith(valueOrFn, ...args) {
36
39
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
37
40
  }
41
+ __name(accessWith, "accessWith");
38
42
  function defer(deps, fn, initialValue) {
39
43
  const isArray = Array.isArray(deps);
40
44
  let prevInput;
@@ -57,12 +61,13 @@ function defer(deps, fn, initialValue) {
57
61
  return result;
58
62
  };
59
63
  }
64
+ __name(defer, "defer");
60
65
  exports.entries = Object.entries;
61
66
  exports.keys = Object.keys;
62
- exports.tryOnCleanup = (fn) => solidJs.getOwner() ? solidJs.onCleanup(fn) : fn;
63
- exports.createCallbackStack = () => {
67
+ exports.tryOnCleanup = /* @__PURE__ */ __name((fn) => solidJs.getOwner() ? solidJs.onCleanup(fn) : fn, "tryOnCleanup");
68
+ exports.createCallbackStack = /* @__PURE__ */ __name(() => {
64
69
  let stack = [];
65
- const clear = () => stack = [];
70
+ const clear = /* @__PURE__ */ __name(() => stack = [], "clear");
66
71
  return {
67
72
  push: (...callbacks) => stack.push(...callbacks),
68
73
  execute(arg0, arg1, arg2, arg3) {
@@ -71,7 +76,7 @@ exports.createCallbackStack = () => {
71
76
  },
72
77
  clear
73
78
  };
74
- };
79
+ }, "createCallbackStack");
75
80
  function createMicrotask(fn) {
76
81
  let calls = 0;
77
82
  let args;
@@ -80,11 +85,12 @@ function createMicrotask(fn) {
80
85
  queueMicrotask(() => --calls === 0 && fn(...args));
81
86
  };
82
87
  }
88
+ __name(createMicrotask, "createMicrotask");
83
89
  function createStaticStore(init) {
84
90
  const copy = { ...init };
85
91
  const store = {};
86
92
  const cache = /* @__PURE__ */ new Map();
87
- const getValue = (key) => {
93
+ const getValue = /* @__PURE__ */ __name((key) => {
88
94
  const saved = cache.get(key);
89
95
  if (saved)
90
96
  return saved[0]();
@@ -94,21 +100,21 @@ function createStaticStore(init) {
94
100
  cache.set(key, signal);
95
101
  delete copy[key];
96
102
  return signal[0]();
97
- };
98
- const setValue = (key, value) => {
103
+ }, "getValue");
104
+ const setValue = /* @__PURE__ */ __name((key, value) => {
99
105
  const saved = cache.get(key);
100
106
  if (saved)
101
107
  return saved[1](value);
102
108
  if (key in copy)
103
109
  copy[key] = accessWith(value, [copy[key]]);
104
- };
110
+ }, "setValue");
105
111
  for (const key of exports.keys(init)) {
106
112
  store[key] = void 0;
107
113
  Object.defineProperty(store, key, {
108
114
  get: getValue.bind(void 0, key)
109
115
  });
110
116
  }
111
- const setter = (a, b) => {
117
+ const setter = /* @__PURE__ */ __name((a, b) => {
112
118
  if (isObject(a))
113
119
  solidJs.untrack(() => {
114
120
  solidJs.batch(() => {
@@ -119,9 +125,10 @@ function createStaticStore(init) {
119
125
  else
120
126
  setValue(a, b);
121
127
  return store;
122
- };
128
+ }, "setter");
123
129
  return [store, setter];
124
130
  }
131
+ __name(createStaticStore, "createStaticStore");
125
132
  function handleDiffArray(current, prev, handleAdded, handleRemoved) {
126
133
  const currLength = current.length;
127
134
  const prevLength = prev.length;
@@ -153,6 +160,7 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
153
160
  handleAdded(currEl);
154
161
  }
155
162
  }
163
+ __name(handleDiffArray, "handleDiffArray");
156
164
 
157
165
  exports.accessWith = accessWith;
158
166
  exports.chain = chain;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Accessor, Setter, AccessorArray, NoInfer, EffectFunction, onCleanup } from 'solid-js';
2
- export { EffectOptions, MemoOptions, OnOptions, SignalOptions } from 'solid-js/types/reactive/signal';
2
+ export { EffectOptions, OnOptions } from 'solid-js/types/reactive/signal';
3
3
 
4
4
  /**
5
5
  * Can be single or in an array
@@ -78,6 +78,10 @@ type Position = {
78
78
  x: number;
79
79
  y: number;
80
80
  };
81
+ type RawNarrow<T> = (T extends [] ? [] : never) | (T extends string | number | bigint | boolean ? T : never) | {
82
+ [K in keyof T]: T[K] extends Function ? T[K] : RawNarrow<T[K]>;
83
+ };
84
+ type Narrow<T extends any> = T extends [] ? T : RawNarrow<T>;
81
85
 
82
86
  /** no operation */
83
87
  declare const noop: Noop;
@@ -187,4 +191,4 @@ declare function createStaticStore<T extends Readonly<AnyStatic>>(init: T): [acc
187
191
  */
188
192
  declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
189
193
 
190
- export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterParam, Simplify, StaticStoreSetter, Tail, Truthy, UnboxLazy, UnionToIntersection, Values, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, tryOnCleanup, withAccess };
194
+ export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Narrow, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterParam, Simplify, StaticStoreSetter, Tail, Truthy, UnboxLazy, UnionToIntersection, Values, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, tryOnCleanup, withAccess };
package/dist/index.js CHANGED
@@ -1,18 +1,20 @@
1
1
  import { DEV, untrack, getOwner, onCleanup, createSignal, batch } from 'solid-js';
2
2
  import { isServer as isServer$1 } from 'solid-js/web';
3
3
 
4
- // src/index.ts
5
- var noop = () => void 0;
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var noop = /* @__PURE__ */ __name(() => void 0, "noop");
6
7
  var isServer = isServer$1;
7
8
  var isClient = !isServer;
8
9
  var isDev = DEV && isClient;
9
10
  var isProd = !isDev;
10
- var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
11
+ var ofClass = /* @__PURE__ */ __name((v, c) => v instanceof c || v && v.constructor === c, "ofClass");
11
12
  function isObject(value) {
12
13
  return value !== null && (typeof value === "object" || typeof value === "function");
13
14
  }
14
- var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
15
- var arrayEquals = (a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]);
15
+ __name(isObject, "isObject");
16
+ var compare = /* @__PURE__ */ __name((a, b) => a < b ? -1 : a > b ? 1 : 0, "compare");
17
+ var arrayEquals = /* @__PURE__ */ __name((a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]), "arrayEquals");
16
18
  function chain(callbacks) {
17
19
  return (...args) => {
18
20
  for (const callback of callbacks) {
@@ -21,18 +23,20 @@ function chain(callbacks) {
21
23
  }
22
24
  };
23
25
  }
24
- var clamp = (n, min, max) => Math.min(Math.max(n, min), max);
25
- var access = (v) => typeof v === "function" && !v.length ? v() : v;
26
- var asArray = (value) => Array.isArray(value) ? value : [value];
27
- var accessArray = (list) => list.map((v) => access(v));
28
- var withAccess = (value, fn) => {
26
+ __name(chain, "chain");
27
+ var clamp = /* @__PURE__ */ __name((n, min, max) => Math.min(Math.max(n, min), max), "clamp");
28
+ var access = /* @__PURE__ */ __name((v) => typeof v === "function" && !v.length ? v() : v, "access");
29
+ var asArray = /* @__PURE__ */ __name((value) => Array.isArray(value) ? value : [value], "asArray");
30
+ var accessArray = /* @__PURE__ */ __name((list) => list.map((v) => access(v)), "accessArray");
31
+ var withAccess = /* @__PURE__ */ __name((value, fn) => {
29
32
  const _value = access(value);
30
33
  typeof _value !== "undefined" && _value !== null && fn(_value);
31
- };
32
- var asAccessor = (v) => typeof v === "function" ? v : () => v;
34
+ }, "withAccess");
35
+ var asAccessor = /* @__PURE__ */ __name((v) => typeof v === "function" ? v : () => v, "asAccessor");
33
36
  function accessWith(valueOrFn, ...args) {
34
37
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
35
38
  }
39
+ __name(accessWith, "accessWith");
36
40
  function defer(deps, fn, initialValue) {
37
41
  const isArray = Array.isArray(deps);
38
42
  let prevInput;
@@ -55,12 +59,13 @@ function defer(deps, fn, initialValue) {
55
59
  return result;
56
60
  };
57
61
  }
62
+ __name(defer, "defer");
58
63
  var entries = Object.entries;
59
64
  var keys = Object.keys;
60
- var tryOnCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
61
- var createCallbackStack = () => {
65
+ var tryOnCleanup = /* @__PURE__ */ __name((fn) => getOwner() ? onCleanup(fn) : fn, "tryOnCleanup");
66
+ var createCallbackStack = /* @__PURE__ */ __name(() => {
62
67
  let stack = [];
63
- const clear = () => stack = [];
68
+ const clear = /* @__PURE__ */ __name(() => stack = [], "clear");
64
69
  return {
65
70
  push: (...callbacks) => stack.push(...callbacks),
66
71
  execute(arg0, arg1, arg2, arg3) {
@@ -69,7 +74,7 @@ var createCallbackStack = () => {
69
74
  },
70
75
  clear
71
76
  };
72
- };
77
+ }, "createCallbackStack");
73
78
  function createMicrotask(fn) {
74
79
  let calls = 0;
75
80
  let args;
@@ -78,11 +83,12 @@ function createMicrotask(fn) {
78
83
  queueMicrotask(() => --calls === 0 && fn(...args));
79
84
  };
80
85
  }
86
+ __name(createMicrotask, "createMicrotask");
81
87
  function createStaticStore(init) {
82
88
  const copy = { ...init };
83
89
  const store = {};
84
90
  const cache = /* @__PURE__ */ new Map();
85
- const getValue = (key) => {
91
+ const getValue = /* @__PURE__ */ __name((key) => {
86
92
  const saved = cache.get(key);
87
93
  if (saved)
88
94
  return saved[0]();
@@ -92,21 +98,21 @@ function createStaticStore(init) {
92
98
  cache.set(key, signal);
93
99
  delete copy[key];
94
100
  return signal[0]();
95
- };
96
- const setValue = (key, value) => {
101
+ }, "getValue");
102
+ const setValue = /* @__PURE__ */ __name((key, value) => {
97
103
  const saved = cache.get(key);
98
104
  if (saved)
99
105
  return saved[1](value);
100
106
  if (key in copy)
101
107
  copy[key] = accessWith(value, [copy[key]]);
102
- };
108
+ }, "setValue");
103
109
  for (const key of keys(init)) {
104
110
  store[key] = void 0;
105
111
  Object.defineProperty(store, key, {
106
112
  get: getValue.bind(void 0, key)
107
113
  });
108
114
  }
109
- const setter = (a, b) => {
115
+ const setter = /* @__PURE__ */ __name((a, b) => {
110
116
  if (isObject(a))
111
117
  untrack(() => {
112
118
  batch(() => {
@@ -117,9 +123,10 @@ function createStaticStore(init) {
117
123
  else
118
124
  setValue(a, b);
119
125
  return store;
120
- };
126
+ }, "setter");
121
127
  return [store, setter];
122
128
  }
129
+ __name(createStaticStore, "createStaticStore");
123
130
  function handleDiffArray(current, prev, handleAdded, handleRemoved) {
124
131
  const currLength = current.length;
125
132
  const prevLength = prev.length;
@@ -151,5 +158,6 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
151
158
  handleAdded(currEl);
152
159
  }
153
160
  }
161
+ __name(handleDiffArray, "handleDiffArray");
154
162
 
155
163
  export { access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, tryOnCleanup, withAccess };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "5.0.0",
3
+ "version": "5.1.1",
4
4
  "description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
5
5
  "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
6
6
  "license": "MIT",